@@ -673,13 +673,16 @@ export async function activateRoslynLanguageServer(
673
673
const capabilities = await _languageServer . getServerCapabilities ( ) ;
674
674
675
675
if ( capabilities . _vs_onAutoInsertProvider ) {
676
- if ( ! capabilities . _vs_onAutoInsertProvider . _vs_triggerCharacters . includes ( change . text ) ) {
676
+ // Regular expression to match all whitespace characters except the newline character
677
+ const changeTrimmed = change . text . replace ( / [ ^ \S \n ] + / g, '' ) ;
678
+
679
+ if ( ! capabilities . _vs_onAutoInsertProvider . _vs_triggerCharacters . includes ( changeTrimmed ) ) {
677
680
return ;
678
681
}
679
682
680
683
source . cancel ( ) ;
681
684
source = new vscode . CancellationTokenSource ( ) ;
682
- await applyAutoInsertEdit ( e , source . token ) ;
685
+ await applyAutoInsertEdit ( e , changeTrimmed , source . token ) ;
683
686
}
684
687
} ) ;
685
688
@@ -822,7 +825,11 @@ function registerRazorCommands(context: vscode.ExtensionContext, languageServer:
822
825
) ;
823
826
}
824
827
825
- async function applyAutoInsertEdit ( e : vscode . TextDocumentChangeEvent , token : vscode . CancellationToken ) {
828
+ async function applyAutoInsertEdit (
829
+ e : vscode . TextDocumentChangeEvent ,
830
+ changeTrimmed : string ,
831
+ token : vscode . CancellationToken
832
+ ) {
826
833
const change = e . contentChanges [ 0 ] ;
827
834
828
835
// Need to add 1 since the server expects the position to be where the caret is after the last token has been inserted.
@@ -833,9 +840,10 @@ async function applyAutoInsertEdit(e: vscode.TextDocumentChangeEvent, token: vsc
833
840
const request : RoslynProtocol . OnAutoInsertParams = {
834
841
_vs_textDocument : textDocument ,
835
842
_vs_position : position ,
836
- _vs_ch : change . text ,
843
+ _vs_ch : changeTrimmed ,
837
844
_vs_options : formattingOptions ,
838
845
} ;
846
+
839
847
const response = await _languageServer . sendRequest ( RoslynProtocol . OnAutoInsertRequest . type , request , token ) ;
840
848
if ( response ) {
841
849
const textEdit = response . _vs_textEdit ;
0 commit comments