Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ProtocolConverter#asWorkspaceEdit to correctly support workspace edits with snippets #1424

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
"vsdiag",
"whitespaces",
"XCOPY"
]
],
"githubPullRequests.createDefaultBaseBranch": "repositoryDefault"
}
2 changes: 1 addition & 1 deletion client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
groupsOnLabel: true
};
workspaceEdit.metadataSupport = true;
workspaceEdit.snippetEditSupport = false;
workspaceEdit.snippetEditSupport = true;

const diagnostics = ensure(ensure(result, 'textDocument')!, 'publishDiagnostics')!;
diagnostics.relatedInformation = true;
Expand Down
8 changes: 5 additions & 3 deletions client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,15 +1085,17 @@ export function createConverter(uriConverter: URIConverter | undefined, trustMar
result.deleteFile(_uriConverter(change.uri), change.options, asMetadata(change.annotationId));
} else if (ls.TextDocumentEdit.is(change)) {
const uri = _uriConverter(change.textDocument.uri);
const edits: [code.TextEdit | code.SnippetTextEdit, code.WorkspaceEditEntryMetadata | undefined][] = [];
for (const edit of change.edits) {
if (ls.AnnotatedTextEdit.is(edit)) {
result.replace(uri, asRange(edit.range), edit.newText, asMetadata(edit.annotationId));
edits.push([new code.TextEdit(asRange(edit.range), edit.newText), asMetadata(edit.annotationId)]);
} else if (ls.SnippetTextEdit.is(edit)) {
result.replace(uri, asRange(edit.range), edit.snippet.value, asMetadata(edit.annotationId));
edits.push([new code.SnippetTextEdit(asRange(edit.range), new code.SnippetString(edit.snippet.value)), asMetadata(edit.annotationId)]);
} else {
result.replace(uri, asRange(edit.range), edit.newText);
edits.push([new code.TextEdit(asRange(edit.range), edit.newText), undefined]);
}
}
result.set(uri, edits);
} else {
throw new Error(`Unknown workspace edit change received:\n${JSON.stringify(change, undefined, 4)}`);
}
Expand Down