@@ -11,23 +11,17 @@ export type RunnableEnvCfg =
11
11
12
12
export class Config {
13
13
readonly extensionId = "rust-lang.rust-analyzer" ;
14
+ configureLang : vscode . Disposable | undefined ;
14
15
15
16
readonly rootSection = "rust-analyzer" ;
16
- private readonly requiresWorkspaceReloadOpts = [
17
- // FIXME: This shouldn't be here, changing this setting should reload
18
- // `continueCommentsOnNewline` behavior without restart
19
- "typing" ,
20
- ] . map ( ( opt ) => `${ this . rootSection } .${ opt } ` ) ;
21
17
private readonly requiresReloadOpts = [
22
18
"cargo" ,
23
19
"procMacro" ,
24
20
"serverPath" ,
25
21
"server" ,
26
22
"files" ,
27
23
"lens" , // works as lens.*
28
- ]
29
- . map ( ( opt ) => `${ this . rootSection } .${ opt } ` )
30
- . concat ( this . requiresWorkspaceReloadOpts ) ;
24
+ ] . map ( ( opt ) => `${ this . rootSection } .${ opt } ` ) ;
31
25
32
26
readonly package : {
33
27
version : string ;
@@ -45,6 +39,11 @@ export class Config {
45
39
ctx . subscriptions
46
40
) ;
47
41
this . refreshLogging ( ) ;
42
+ this . configureLanguage ( ) ;
43
+ }
44
+
45
+ dispose ( ) {
46
+ this . configureLang ?. dispose ( ) ;
48
47
}
49
48
50
49
private refreshLogging ( ) {
@@ -58,33 +57,86 @@ export class Config {
58
57
private async onDidChangeConfiguration ( event : vscode . ConfigurationChangeEvent ) {
59
58
this . refreshLogging ( ) ;
60
59
60
+ this . configureLanguage ( ) ;
61
+
61
62
const requiresReloadOpt = this . requiresReloadOpts . find ( ( opt ) =>
62
63
event . affectsConfiguration ( opt )
63
64
) ;
64
65
65
66
if ( ! requiresReloadOpt ) return ;
66
67
67
- const requiresWorkspaceReloadOpt = this . requiresWorkspaceReloadOpts . find ( ( opt ) =>
68
- event . affectsConfiguration ( opt )
69
- ) ;
70
-
71
- if ( ! requiresWorkspaceReloadOpt && this . restartServerOnConfigChange ) {
68
+ if ( this . restartServerOnConfigChange ) {
72
69
await vscode . commands . executeCommand ( "rust-analyzer.reload" ) ;
73
70
return ;
74
71
}
75
72
76
- const message = requiresWorkspaceReloadOpt
77
- ? `Changing "${ requiresWorkspaceReloadOpt } " requires a window reload`
78
- : `Changing "${ requiresReloadOpt } " requires a reload` ;
79
- const userResponse = await vscode . window . showInformationMessage ( message , "Reload now" ) ;
80
-
81
- if ( userResponse === "Reload now" ) {
82
- const command = requiresWorkspaceReloadOpt
83
- ? "workbench.action.reloadWindow"
84
- : "rust-analyzer.reload" ;
85
- if ( userResponse === "Reload now" ) {
86
- await vscode . commands . executeCommand ( command ) ;
87
- }
73
+ const message = `Changing "${ requiresReloadOpt } " requires a server restart` ;
74
+ const userResponse = await vscode . window . showInformationMessage ( message , "Restart now" ) ;
75
+
76
+ if ( userResponse ) {
77
+ const command = "rust-analyzer.reload" ;
78
+ await vscode . commands . executeCommand ( command ) ;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Sets up additional language configuration that's impossible to do via a
84
+ * separate language-configuration.json file. See [1] for more information.
85
+ *
86
+ * [1]: https://github.com/Microsoft/vscode/issues/11514#issuecomment-244707076
87
+ */
88
+ private configureLanguage ( ) {
89
+ if ( this . typingContinueCommentsOnNewline && ! this . configureLang ) {
90
+ const indentAction = vscode . IndentAction . None ;
91
+
92
+ this . configureLang = vscode . languages . setLanguageConfiguration ( "rust" , {
93
+ onEnterRules : [
94
+ {
95
+ // Doc single-line comment
96
+ // e.g. ///|
97
+ beforeText : / ^ \s * \/ { 3 } .* $ / ,
98
+ action : { indentAction, appendText : "/// " } ,
99
+ } ,
100
+ {
101
+ // Parent doc single-line comment
102
+ // e.g. //!|
103
+ beforeText : / ^ \s * \/ { 2 } \! .* $ / ,
104
+ action : { indentAction, appendText : "//! " } ,
105
+ } ,
106
+ {
107
+ // Begins an auto-closed multi-line comment (standard or parent doc)
108
+ // e.g. /** | */ or /*! | */
109
+ beforeText : / ^ \s * \/ \* ( \* | \! ) (? ! \/ ) ( [ ^ \* ] | \* (? ! \/ ) ) * $ / ,
110
+ afterText : / ^ \s * \* \/ $ / ,
111
+ action : {
112
+ indentAction : vscode . IndentAction . IndentOutdent ,
113
+ appendText : " * " ,
114
+ } ,
115
+ } ,
116
+ {
117
+ // Begins a multi-line comment (standard or parent doc)
118
+ // e.g. /** ...| or /*! ...|
119
+ beforeText : / ^ \s * \/ \* ( \* | \! ) (? ! \/ ) ( [ ^ \* ] | \* (? ! \/ ) ) * $ / ,
120
+ action : { indentAction, appendText : " * " } ,
121
+ } ,
122
+ {
123
+ // Continues a multi-line comment
124
+ // e.g. * ...|
125
+ beforeText : / ^ ( \ \ ) * \ \* ( \ ( [ ^ \* ] | \* (? ! \/ ) ) * ) ? $ / ,
126
+ action : { indentAction, appendText : "* " } ,
127
+ } ,
128
+ {
129
+ // Dedents after closing a multi-line comment
130
+ // e.g. */|
131
+ beforeText : / ^ ( \ \ ) * \ \* \/ \s * $ / ,
132
+ action : { indentAction, removeText : 1 } ,
133
+ } ,
134
+ ] ,
135
+ } ) ;
136
+ }
137
+ if ( ! this . typingContinueCommentsOnNewline && this . configureLang ) {
138
+ this . configureLang . dispose ( ) ;
139
+ this . configureLang = undefined ;
88
140
}
89
141
}
90
142
0 commit comments