@@ -86,58 +86,80 @@ export class Config {
8686 * [1]: https://github.com/Microsoft/vscode/issues/11514#issuecomment-244707076
8787 */
8888 private configureLanguage ( ) {
89- if ( this . typingContinueCommentsOnNewline && ! this . configureLang ) {
89+ if ( this . configureLang ) return ;
90+
91+ let onEnterRules : vscode . OnEnterRule [ ] = [
92+ {
93+ // Carry indentation from the previous line
94+ beforeText : / ^ \s * $ / ,
95+ action : { indentAction : vscode . IndentAction . None } ,
96+ } ,
97+ {
98+ // After the end of a function/field chain,
99+ // with the semicolon on the same line
100+ beforeText : / ^ \s + \. .* ; / ,
101+ action : { indentAction : vscode . IndentAction . Outdent } ,
102+ } ,
103+ {
104+ // After the end of a function/field chain,
105+ // with semicolon detached from the rest
106+ beforeText : / ^ \s + ; / ,
107+ previousLineText : / ^ \s + \. .* / ,
108+ action : { indentAction : vscode . IndentAction . Outdent } ,
109+ } ,
110+ ] ;
111+
112+ if ( this . typingContinueCommentsOnNewline ) {
90113 const indentAction = vscode . IndentAction . None ;
91114
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 : "/// " } ,
115+ onEnterRules = [
116+ ...onEnterRules ,
117+ {
118+ // Doc single-line comment
119+ // e.g. ///|
120+ beforeText : / ^ \s * \/ { 3 } .* $ / ,
121+ action : { indentAction, appendText : "/// " } ,
122+ } ,
123+ {
124+ // Parent doc single-line comment
125+ // e.g. //!|
126+ beforeText : / ^ \s * \/ { 2 } \! .* $ / ,
127+ action : { indentAction, appendText : "//! " } ,
128+ } ,
129+ {
130+ // Begins an auto-closed multi-line comment (standard or parent doc)
131+ // e.g. /** | */ or /*! | */
132+ beforeText : / ^ \s * \/ \* ( \* | \! ) (? ! \/ ) ( [ ^ \* ] | \* (? ! \/ ) ) * $ / ,
133+ afterText : / ^ \s * \* \/ $ / ,
134+ action : {
135+ indentAction : vscode . IndentAction . IndentOutdent ,
136+ appendText : " * " ,
99137 } ,
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 ;
138+ } ,
139+ {
140+ // Begins a multi-line comment (standard or parent doc)
141+ // e.g. /** ...| or /*! ...|
142+ beforeText : / ^ \s * \/ \* ( \* | \! ) (? ! \/ ) ( [ ^ \* ] | \* (? ! \/ ) ) * $ / ,
143+ action : { indentAction, appendText : " * " } ,
144+ } ,
145+ {
146+ // Continues a multi-line comment
147+ // e.g. * ...|
148+ beforeText : / ^ ( \ \ ) * \ \* ( \ ( [ ^ \* ] | \* (? ! \/ ) ) * ) ? $ / ,
149+ action : { indentAction, appendText : "* " } ,
150+ } ,
151+ {
152+ // Dedents after closing a multi-line comment
153+ // e.g. */|
154+ beforeText : / ^ ( \ \ ) * \ \* \/ \s * $ / ,
155+ action : { indentAction, removeText : 1 } ,
156+ } ,
157+ ] ;
140158 }
159+
160+ this . configureLang = vscode . languages . setLanguageConfiguration ( "rust" , {
161+ onEnterRules,
162+ } ) ;
141163 }
142164
143165 // We don't do runtime config validation here for simplicity. More on stackoverflow:
0 commit comments