-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Closed
Labels
apifeature-requestRequest for new features or functionalityRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesIssues identified as good community contribution opportunitiesinsiders-releasedPatch has been released in VS Code InsidersPatch has been released in VS Code Insiderson-release-notesIssue/pull request mentioned in release notesIssue/pull request mentioned in release notessnippetsverifiedVerification succeededVerification succeeded
Milestone
Description
This is a very similar issue to #44200/#57093 but that fix appears to be only being applied to completions, but applying snippets causes the same issues.
Here's a repro:
vs.workspace.openTextDocument(vs.Uri.parse(`untitled:${os.tmpdir}/a.dart`)).then(async (document) => {
const originalCode = `main() {
// code indented with two spaces
}`;
const editor = await vs.window.showTextDocument(document);
await editor.edit((eb) => eb.insert(new vs.Position(0, 0), originalCode));
const startOffset = originalCode.indexOf("// code indented with two spaces");
const endOffset = originalCode.indexOf("\n}");
const snippetString = new vs.SnippetString("// new code indented with two spaces\n // newer code indented with two spaces");
await editor.insertSnippet(snippetString, new vs.Range(document.positionAt(startOffset), document.positionAt(endOffset)));
});This creates a doc and inserts into it the code:
main() {
// code indented with two spaces
}It then applies a snippet string that includes an additional line that is also indented by two spaces. However what you end up with is:
main() {
// new code indented with two spaces
// newer code indented with two spaces
}The inserted line has been re-indented.
Whilst this behaviour may be useful if applying basic hard-coded strings, it's incorrect for language servers that are correctly calculating edits to leave the file indented/formatted correctly (I guess for the same reasons that left to #57093).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
apifeature-requestRequest for new features or functionalityRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesIssues identified as good community contribution opportunitiesinsiders-releasedPatch has been released in VS Code InsidersPatch has been released in VS Code Insiderson-release-notesIssue/pull request mentioned in release notesIssue/pull request mentioned in release notessnippetsverifiedVerification succeededVerification succeeded