Skip to content

Commit 2e32351

Browse files
authored
Merge pull request #2137 from yoyo930021/use-server-command
Use pure server command
2 parents 7431ed1 + a0b499b commit 2e32351

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Component Data - `type: 'boolean'` should trigger completion without `=""`. #2127.
1313
- Component Data doesn't work if it comes from devDependencies. #2132.
1414
- 🙌 Add support for analyzing vue-class-component and vue-property-decorator. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #864, #1105 and #1323.
15+
- 🙌 Remove lsp client commands for improve third party lsp client. Thanks to contribution from [@yoyo930021](https://github.com/yoyo930021). #2137.
1516
- 🙌 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.
1617

1718
### 0.26.1 | 2020-08-07 | [VSIX](https://marketplace.visualstudio.com/_apis/public/gallery/publishers/octref/vsextensions/vetur/0.26.1/vspackage)

client/vueMain.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ export async function activate(context: vscode.ExtensionContext) {
3838
)
3939
);
4040

41-
context.subscriptions.push(
42-
vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => {
43-
client.sendRequest<WorkspaceEdit | undefined>('requestCodeActionEdits', args).then(edits => {
44-
if (edits) {
45-
vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!);
46-
}
47-
});
48-
})
49-
);
50-
5141
registerLanguageConfigurations();
5242

5343
/**

server/src/modes/script/javascript.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import { toCompletionItemKind, toSymbolKind } from '../../services/typescriptSer
4949
// https://microsoft.github.io/language-server-protocol/specification#completion-request-leftwards_arrow_with_hook
5050
const NON_SCRIPT_TRIGGERS = ['<', '*', ':'];
5151

52+
export const APPLY_REFACTOR_COMMAND = 'vetur.applyRefactorCommand';
53+
5254
export async function getJavascriptMode(
5355
serviceHost: IServiceHost,
5456
documentRegions: LanguageModelCache<VueDocumentRegions>,
@@ -589,7 +591,7 @@ function collectRefactoringCommands(
589591
kind: CodeActionKind.Refactor,
590592
command: {
591593
title: action.description,
592-
command: 'vetur.chooseTypeScriptRefactoring',
594+
command: APPLY_REFACTOR_COMMAND,
593595
arguments: [action]
594596
}
595597
});

server/src/services/vls.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {
1818
DocumentSymbolParams,
1919
CodeActionParams,
2020
CompletionParams,
21-
CompletionTriggerKind
21+
CompletionTriggerKind,
22+
ExecuteCommandParams,
23+
ApplyWorkspaceEditRequest
2224
} from 'vscode-languageserver';
2325
import {
2426
ColorInformation,
@@ -51,6 +53,7 @@ import { VueHTMLMode } from '../modes/template';
5153
import { logger } from '../log';
5254
import { getDefaultVLSConfig, VLSFullConfig, VLSConfig } from '../config';
5355
import { LanguageId } from '../embeddedSupport/embeddedSupport';
56+
import { APPLY_REFACTOR_COMMAND } from '../modes/script/javascript';
5457

5558
export class VLS {
5659
// @Todo: Remove this and DocumentContext
@@ -158,7 +161,7 @@ export class VLS {
158161
this.lspConnection.onDocumentColor(this.onDocumentColors.bind(this));
159162
this.lspConnection.onColorPresentation(this.onColorPresentations.bind(this));
160163

161-
this.lspConnection.onRequest('requestCodeActionEdits', this.getRefactorEdits.bind(this));
164+
this.lspConnection.onExecuteCommand(this.executeCommand.bind(this));
162165
}
163166

164167
private setupCustomLSPHandlers() {
@@ -507,6 +510,18 @@ export class VLS {
507510
return diagnostics;
508511
}
509512

513+
async executeCommand(arg: ExecuteCommandParams) {
514+
if (arg.command === APPLY_REFACTOR_COMMAND && arg.arguments) {
515+
const edit = this.getRefactorEdits(arg.arguments[0] as RefactorAction);
516+
if (edit) {
517+
this.lspConnection.sendRequest(ApplyWorkspaceEditRequest.type, { edit });
518+
}
519+
return;
520+
}
521+
522+
logger.logInfo(`Unknown command ${arg.command}.`);
523+
}
524+
510525
removeDocument(doc: TextDocument): void {
511526
this.languageModes.onDocumentRemoved(doc);
512527
}
@@ -530,7 +545,10 @@ export class VLS {
530545
definitionProvider: true,
531546
referencesProvider: true,
532547
codeActionProvider: true,
533-
colorProvider: true
548+
colorProvider: true,
549+
executeCommandProvider: {
550+
commands: [APPLY_REFACTOR_COMMAND]
551+
}
534552
};
535553
}
536554
}

0 commit comments

Comments
 (0)