@@ -13,6 +13,7 @@ import {
13
13
} from 'vscode-languageclient/node' ;
14
14
import * as RoslynProtocol from '../server/roslynProtocol' ;
15
15
import { RoslynLanguageServer } from '../server/roslynLanguageServer' ;
16
+ import { EOL } from 'node:os' ;
16
17
17
18
export function registerOnAutoInsert ( languageServer : RoslynLanguageServer , languageClient : LanguageClient ) {
18
19
let source = new vscode . CancellationTokenSource ( ) ;
@@ -57,11 +58,18 @@ export function registerOnAutoInsert(languageServer: RoslynLanguageServer, langu
57
58
// Regular expression to match all whitespace characters except the newline character
58
59
let changeTrimmed = change . text . replace ( / [ ^ \S \n ] + / g, '' ) ;
59
60
61
+ // If the change is empty after removing whitespace, we don't need to process it.
62
+ if ( changeTrimmed . length === 0 ) {
63
+ return ;
64
+ }
65
+
60
66
// When hitting enter between braces, we can end up with two new lines added (one to move the cursor down to an empty line,
61
- // and another to move the close brace to a new line below that). We still want to trigger on auto insert here, so if we
62
- // have a whitespace only edit (meaning its new lines only) with multiple characters, we reduce it to a single newline.
63
- if ( changeTrimmed . length > 1 && changeTrimmed . trim ( ) === '' ) {
64
- changeTrimmed = [ ...new Set ( changeTrimmed ) ] . join ( '' ) ;
67
+ // and another to move the close brace to a new line below that). We want to detect that edit as a single new line trigger.
68
+ //
69
+ // Since we already removed all whitespace except new lines above, we can just trim the string to remove new lines as well
70
+ // and check if there is anything left. If not, we know the change is just whitespace and new lines and can set the trigger to the new line character.
71
+ if ( changeTrimmed . trim ( ) === '' ) {
72
+ changeTrimmed = EOL ;
65
73
}
66
74
67
75
if ( ! vsTriggerCharacters . includes ( changeTrimmed ) ) {
0 commit comments