diff --git a/CHANGELOG.md b/CHANGELOG.md index 41e171fdd9..981dfbe31f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Component Data - `type: 'boolean'` should trigger completion without `=""`. #2127. - Component Data doesn't work if it comes from devDependencies. #2132. - 🙌 Add support for analyzing vue-class-component and vue-property-decorator. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #864, #1105 and #1323. +- 🙌 Remove lsp client commands for improve third party lsp client. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #2137. - 🙌 Fix "Go to definition" for methods/computeds does not work in the template. Thanks to contribution from [@cereschen](https://github.com/cereschen). #1484 and #2161. ### 0.26.1 | 2020-08-07 | [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/octref/vsextensions/vetur/0.26.1/vspackage) diff --git a/client/vueMain.ts b/client/vueMain.ts index 4b27082e9f..3cfc33fb3a 100644 --- a/client/vueMain.ts +++ b/client/vueMain.ts @@ -38,16 +38,6 @@ export async function activate(context: vscode.ExtensionContext) { ) ); - context.subscriptions.push( - vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => { - client.sendRequest('requestCodeActionEdits', args).then(edits => { - if (edits) { - vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!); - } - }); - }) - ); - registerLanguageConfigurations(); /** diff --git a/server/src/modes/script/javascript.ts b/server/src/modes/script/javascript.ts index b1b89c586a..290780e25b 100644 --- a/server/src/modes/script/javascript.ts +++ b/server/src/modes/script/javascript.ts @@ -49,6 +49,8 @@ import { toCompletionItemKind, toSymbolKind } from '../../services/typescriptSer // https://microsoft.github.io/language-server-protocol/specification#completion-request-leftwards_arrow_with_hook const NON_SCRIPT_TRIGGERS = ['<', '*', ':']; +export const APPLY_REFACTOR_COMMAND = 'vetur.applyRefactorCommand'; + export async function getJavascriptMode( serviceHost: IServiceHost, documentRegions: LanguageModelCache, @@ -589,7 +591,7 @@ function collectRefactoringCommands( kind: CodeActionKind.Refactor, command: { title: action.description, - command: 'vetur.chooseTypeScriptRefactoring', + command: APPLY_REFACTOR_COMMAND, arguments: [action] } }); diff --git a/server/src/services/vls.ts b/server/src/services/vls.ts index 40d54046c2..01aec2d48d 100644 --- a/server/src/services/vls.ts +++ b/server/src/services/vls.ts @@ -18,7 +18,9 @@ import { DocumentSymbolParams, CodeActionParams, CompletionParams, - CompletionTriggerKind + CompletionTriggerKind, + ExecuteCommandParams, + ApplyWorkspaceEditRequest } from 'vscode-languageserver'; import { ColorInformation, @@ -51,6 +53,7 @@ import { VueHTMLMode } from '../modes/template'; import { logger } from '../log'; import { getDefaultVLSConfig, VLSFullConfig, VLSConfig } from '../config'; import { LanguageId } from '../embeddedSupport/embeddedSupport'; +import { APPLY_REFACTOR_COMMAND } from '../modes/script/javascript'; export class VLS { // @Todo: Remove this and DocumentContext @@ -158,7 +161,7 @@ export class VLS { this.lspConnection.onDocumentColor(this.onDocumentColors.bind(this)); this.lspConnection.onColorPresentation(this.onColorPresentations.bind(this)); - this.lspConnection.onRequest('requestCodeActionEdits', this.getRefactorEdits.bind(this)); + this.lspConnection.onExecuteCommand(this.executeCommand.bind(this)); } private setupCustomLSPHandlers() { @@ -507,6 +510,18 @@ export class VLS { return diagnostics; } + async executeCommand(arg: ExecuteCommandParams) { + if (arg.command === APPLY_REFACTOR_COMMAND && arg.arguments) { + const edit = this.getRefactorEdits(arg.arguments[0] as RefactorAction); + if (edit) { + this.lspConnection.sendRequest(ApplyWorkspaceEditRequest.type, { edit }); + } + return; + } + + logger.logInfo(`Unknown command ${arg.command}.`); + } + removeDocument(doc: TextDocument): void { this.languageModes.onDocumentRemoved(doc); } @@ -530,7 +545,10 @@ export class VLS { definitionProvider: true, referencesProvider: true, codeActionProvider: true, - colorProvider: true + colorProvider: true, + executeCommandProvider: { + commands: [APPLY_REFACTOR_COMMAND] + } }; } }