@@ -11,23 +11,17 @@ export type RunnableEnvCfg =
1111
1212export class Config {
1313 readonly extensionId = "rust-lang.rust-analyzer" ;
14+ configureLang : vscode . Disposable | undefined ;
1415
1516 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 } ` ) ;
2117 private readonly requiresReloadOpts = [
2218 "cargo" ,
2319 "procMacro" ,
2420 "serverPath" ,
2521 "server" ,
2622 "files" ,
2723 "lens" , // works as lens.*
28- ]
29- . map ( ( opt ) => `${ this . rootSection } .${ opt } ` )
30- . concat ( this . requiresWorkspaceReloadOpts ) ;
24+ ] . map ( ( opt ) => `${ this . rootSection } .${ opt } ` ) ;
3125
3226 readonly package : {
3327 version : string ;
@@ -45,6 +39,11 @@ export class Config {
4539 ctx . subscriptions
4640 ) ;
4741 this . refreshLogging ( ) ;
42+ this . configureLanguage ( ) ;
43+ }
44+
45+ dispose ( ) {
46+ this . configureLang ?. dispose ( ) ;
4847 }
4948
5049 private refreshLogging ( ) {
@@ -58,33 +57,86 @@ export class Config {
5857 private async onDidChangeConfiguration ( event : vscode . ConfigurationChangeEvent ) {
5958 this . refreshLogging ( ) ;
6059
60+ this . configureLanguage ( ) ;
61+
6162 const requiresReloadOpt = this . requiresReloadOpts . find ( ( opt ) =>
6263 event . affectsConfiguration ( opt )
6364 ) ;
6465
6566 if ( ! requiresReloadOpt ) return ;
6667
67- const requiresWorkspaceReloadOpt = this . requiresWorkspaceReloadOpts . find ( ( opt ) =>
68- event . affectsConfiguration ( opt )
69- ) ;
70-
71- if ( ! requiresWorkspaceReloadOpt && this . restartServerOnConfigChange ) {
68+ if ( this . restartServerOnConfigChange ) {
7269 await vscode . commands . executeCommand ( "rust-analyzer.reload" ) ;
7370 return ;
7471 }
7572
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 ;
88140 }
89141 }
90142
0 commit comments