Skip to content

Commit e2407a5

Browse files
authored
On Auto Insert - Fix lack of newline support (#5945)
* fix comment issue * cleanup + comment
1 parent 170e039 commit e2407a5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,16 @@ export async function activateRoslynLanguageServer(
673673
const capabilities = await _languageServer.getServerCapabilities();
674674

675675
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)) {
677680
return;
678681
}
679682

680683
source.cancel();
681684
source = new vscode.CancellationTokenSource();
682-
await applyAutoInsertEdit(e, source.token);
685+
await applyAutoInsertEdit(e, changeTrimmed, source.token);
683686
}
684687
});
685688

@@ -822,7 +825,11 @@ function registerRazorCommands(context: vscode.ExtensionContext, languageServer:
822825
);
823826
}
824827

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+
) {
826833
const change = e.contentChanges[0];
827834

828835
// 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
833840
const request: RoslynProtocol.OnAutoInsertParams = {
834841
_vs_textDocument: textDocument,
835842
_vs_position: position,
836-
_vs_ch: change.text,
843+
_vs_ch: changeTrimmed,
837844
_vs_options: formattingOptions,
838845
};
846+
839847
const response = await _languageServer.sendRequest(RoslynProtocol.OnAutoInsertRequest.type, request, token);
840848
if (response) {
841849
const textEdit = response._vs_textEdit;

0 commit comments

Comments
 (0)