Skip to content

Commit

Permalink
Merge pull request #2137 from yoyo930021/use-server-command
Browse files Browse the repository at this point in the history
Use pure server command
  • Loading branch information
octref authored Aug 14, 2020
2 parents 7431ed1 + a0b499b commit 2e32351
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions client/vueMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ export async function activate(context: vscode.ExtensionContext) {
)
);

context.subscriptions.push(
vscode.commands.registerCommand('vetur.chooseTypeScriptRefactoring', (args: any) => {
client.sendRequest<WorkspaceEdit | undefined>('requestCodeActionEdits', args).then(edits => {
if (edits) {
vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edits)!);
}
});
})
);

registerLanguageConfigurations();

/**
Expand Down
4 changes: 3 additions & 1 deletion server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<VueDocumentRegions>,
Expand Down Expand Up @@ -589,7 +591,7 @@ function collectRefactoringCommands(
kind: CodeActionKind.Refactor,
command: {
title: action.description,
command: 'vetur.chooseTypeScriptRefactoring',
command: APPLY_REFACTOR_COMMAND,
arguments: [action]
}
});
Expand Down
24 changes: 21 additions & 3 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
DocumentSymbolParams,
CodeActionParams,
CompletionParams,
CompletionTriggerKind
CompletionTriggerKind,
ExecuteCommandParams,
ApplyWorkspaceEditRequest
} from 'vscode-languageserver';
import {
ColorInformation,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand All @@ -530,7 +545,10 @@ export class VLS {
definitionProvider: true,
referencesProvider: true,
codeActionProvider: true,
colorProvider: true
colorProvider: true,
executeCommandProvider: {
commands: [APPLY_REFACTOR_COMMAND]
}
};
}
}
Expand Down

0 comments on commit 2e32351

Please sign in to comment.