-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[LS] Cannot use CreateFile
, RenameFile
, and DeleteFile
inside a WorkspaceEdit
#4723
Comments
Here is a workaround, if you want to patch your extension's protected patch4085(client: MonacoLanguageClient): MonacoLanguageClient {
let patchedClient = super.patch4085(client);
patchedClient = this.patch4723(patchedClient);
return patchedClient;
}
/**
* https://github.com/theia-ide/theia/issues/4723
* Patched with https://github.com/Microsoft/vscode-languageserver-node/blob/71fc1da3fed87329080f9c2a2c32e5e07aed3128/client/src/client.ts#L3158-L3180
*/
protected patch4723(client: MonacoLanguageClient): MonacoLanguageClient {
(client as any).handleApplyWorkspaceEdit = ((params: ApplyWorkspaceEditParams): Thenable<ApplyWorkspaceEditResponse> => {
// This is some sort of workaround since the version check should be done by VS Code in the Workspace.applyEdit.
// However doing it here adds some safety since the server can lag more behind then an extension.
let workspaceEdit: WorkspaceEdit = params.edit;
let openTextDocuments: Map<string, number> = new Map<string, number>();
this.editorManager.all.forEach(editorWidget => {
if (editorWidget.editor instanceof MonacoEditor) {
const model = editorWidget.editor.getControl().getModel();
openTextDocuments.set(model.uri.toString(), model.getVersionId())
}
});
let versionMismatch = false;
if (workspaceEdit.documentChanges) {
for (const change of workspaceEdit.documentChanges) {
if (TextDocumentEdit.is(change) && change.textDocument.version && change.textDocument.version >= 0) {
let textDocumentVersion = openTextDocuments.get(change.textDocument.uri);
if (!!textDocumentVersion && textDocumentVersion !== change.textDocument.version) {
versionMismatch = true;
break;
}
}
}
}
if (versionMismatch) {
return Promise.resolve({ applied: false });
}
return this.workspace.applyEdit((client as any)._p2c.asWorkspaceEdit(params.edit)).then((value) => { return { applied: value }; });
}).bind(client);
return client;
} Edit: fixed the snippet. |
Upstream question: microsoft/monaco-editor#1396 |
@akosyakov, was this solved with #5901? If so, I am going to verify it. |
@kittaakos I've fixed it in monaco-languageclient: https://github.com/TypeFox/monaco-languageclient/blame/b8f6f32429111f4d96f9581e63ecebc3cd104a7d/client/src/monaco-converter.ts#L405-L429 But we have to change MonacoWorkspace.groupEdits to respect |
Thanks for your feedback. Sure; I'll take care of it. |
Closes #4723 Signed-off-by: Akos Kitta <[email protected]>
Closes #4723 Signed-off-by: Akos Kitta <[email protected]>
Closes #4723 Signed-off-by: Akos Kitta <[email protected]>
Closes #4723 Signed-off-by: Akos Kitta <[email protected]>
Closes #4723 Signed-off-by: Akos Kitta <[email protected]>
Closes eclipse-theia#4723 Signed-off-by: Akos Kitta <[email protected]>
Spec: https://microsoft.github.io/language-server-protocol/specification#version_3_13_0
Currently, we use
[email protected]
in Theia which has the following logic to handleworkspace/applyEdit
:Link: https://github.com/Microsoft/vscode-languageserver-node/blob/5f9c993ff38f5c369949aeb359b3e9b178172dbc/client/src/client.ts#L3019
VS. the
5.1.0
version:Link: https://github.com/Microsoft/vscode-languageserver-node/blob/71fc1da3fed87329080f9c2a2c32e5e07aed3128/client/src/client.ts#L3167
The older version of the language client does not support these new
documentChanges
and will result in an error on the server side:The text was updated successfully, but these errors were encountered: