Skip to content

Commit

Permalink
Merge branch 'lsp-3.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jan 21, 2021
2 parents e10f4df + 8292d01 commit a0eeb3f
Show file tree
Hide file tree
Showing 25 changed files with 626 additions and 337 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,8 @@ jobs:
yarn --frozen-lockfile
yarn compile
- name: Start xvfb
if: matrix.os == 'ubuntu-latest'
run: |
set -e
/usr/bin/Xvfb :10 -ac >> /tmp/Xvfb.out 2>&1 &
disown -ar
echo "Started xvfb"
# https://github.com/microsoft/vscode/issues/106569#issuecomment-717450642
- name: Server and E2E test
run: yarn test
env:
DISPLAY: :10
uses: GabrielBB/xvfb-action@v1.4
with:
run: yarn test
2 changes: 1 addition & 1 deletion client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TransportKind,
LanguageClientOptions,
DocumentFilter
} from 'vscode-languageclient';
} from 'vscode-languageclient/node';
import { resolve } from 'path';
import { existsSync } from 'fs';

Expand Down
10 changes: 4 additions & 6 deletions client/commands/doctorCommand.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';

export function generateDoctorCommand (client: LanguageClient) {
export function generateDoctorCommand(client: LanguageClient) {
return async () => {
if (!vscode.window.activeTextEditor || !vscode.window.activeTextEditor.document.fileName.endsWith('.vue')) {
return vscode.window.showInformationMessage(
'Failed to doctor. Make sure the current file is a .vue file.'
);
return vscode.window.showInformationMessage('Failed to doctor. Make sure the current file is a .vue file.');
}

const fileName = vscode.window.activeTextEditor.document.fileName;

const result = await client.sendRequest('$/doctor', { fileName }) as string;
const result = (await client.sendRequest('$/doctor', { fileName })) as string;
const showText = result.slice(0, 1000) + '....';
const action = await vscode.window.showInformationMessage(showText, { modal: true }, 'Ok', 'Copy');
if (action === 'Copy') {
Expand Down
2 changes: 1 addition & 1 deletion client/commands/virtualFileCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';

let fileName = '';
let virtualFileSource = '';
Expand Down
4 changes: 2 additions & 2 deletions client/vueMain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vscode from 'vscode';
import { LanguageClient } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { generateGrammarCommandHandler } from './commands/generateGrammarCommand';
import { registerLanguageConfigurations } from './languages';
import { initializeLanguageClient } from './client';
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerCustomLSPCommands(context, client);
registerRestartVLSCommand(context, client);
})
.catch(e => {
.catch((e: Error) => {
console.error(e.stack);
console.log('Client initialization failed');
});
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"Programming Languages"
],
"engines": {
"vscode": "^1.47.0"
"vscode": "^1.52.0"
},
"activationEvents": [
"onLanguage:vue"
Expand Down Expand Up @@ -554,27 +554,27 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-node-resolve": "^11.1.0",
"@rollup/plugin-replace": "^2.3.3",
"@types/glob": "^7.1.3",
"@types/js-yaml": "^3.12.5",
"@types/lodash": "^4.14.167",
"@types/js-yaml": "^4.0.0",
"@types/lodash": "^4.14.168",
"@types/minimist": "^1.2.1",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.20",
"@types/node": "^14.14.22",
"@types/shelljs": "^0.8.8",
"@types/vscode": "^1.47.0",
"esbuild": "^0.8.32",
"fs-extra": "^9.0.1",
"@types/vscode": "^1.52.0",
"esbuild": "^0.8.33",
"fs-extra": "^9.1.0",
"glob": "^7.1.6",
"husky": "^4.3.7",
"js-yaml": "^3.14.1",
"husky": "^4.3.8",
"js-yaml": "^4.0.0",
"lint-staged": "^10.5.3",
"minimist": "^1.2.5",
"mocha": "^8.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"rollup": "^2.36.1",
"rollup": "^2.37.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^2.0.1",
"rollup-plugin-terser": "^7.0.2",
Expand All @@ -583,8 +583,8 @@
"ts-node": "^9.1.1",
"tslint": "^6.1.3",
"typescript": "^4.1.3",
"vscode-languageclient": "^6.1.3",
"vscode-languageserver-types": "^3.15.1",
"vscode-languageclient": "^7.0.0",
"vscode-languageserver-types": "^3.16.0",
"vscode-test": "^1.4.1"
}
}
4 changes: 2 additions & 2 deletions scripts/build_grammar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import glob from 'glob';
import { safeLoad } from 'js-yaml';
import { load } from 'js-yaml';
import { writeFileSync, readFileSync } from 'fs';
import { parse } from 'path';
import { getGeneratedGrammar } from '../client/grammar';
Expand All @@ -9,7 +9,7 @@ glob('syntaxes/**/*.yaml', { nocase: true }, (_, files) => {
const pathData = parse(file);
writeFileSync(
pathData.dir + '/' + pathData.name + '.tmLanguage.json',
JSON.stringify(safeLoad(readFileSync(file).toString()), null, 2)
JSON.stringify(load(readFileSync(file).toString()), null, 2)
);
}

Expand Down
26 changes: 13 additions & 13 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/vuejs/vetur/tree/master/server",
"dependencies": {
"eslint": "^7.17.0",
"eslint": "^7.18.0",
"eslint-plugin-vue": "^7.4.1",
"prettier": "^2.2.1",
"tslint": "6.1.3",
Expand All @@ -39,40 +39,40 @@
"@types/eslint-visitor-keys": "^1.0.0",
"@types/glob": "^7.1.3",
"@types/js-beautify": "1.13.1",
"@types/lodash": "^4.14.167",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.20",
"@types/node": "^14.14.22",
"@types/prettier": "^2.1.6",
"@types/read-pkg-up": "^6.0.0",
"@types/resolve": "1.17.1",
"bootstrap-vue-helper-json": "^1.1.1",
"codecov": "^3.8.1",
"core-js": "^3.8.2",
"core-js": "^3.8.3",
"element-helper-json": "^2.0.6",
"fast-glob": "^3.2.4",
"fast-glob": "^3.2.5",
"glob": "^7.1.6",
"gridsome-helper-json": "^1.0.3",
"js-beautify": "^1.13.1",
"js-beautify": "^1.13.4",
"lodash": "^4.17.20",
"mocha": "^8.2.1",
"nuxt-helper-json": "^1.0.0",
"nyc": "^15.1.0",
"parse-gitignore": "^1.0.1",
"prettier-eslint": "^12.0.0",
"prettier-tslint": "^0.4.2",
"rollup": "^2.36.1",
"rollup": "^2.37.1",
"sass-formatter": "^0.5.2",
"source-map-support": "^0.5.19",
"stylus": "^0.54.8",
"stylus-supremacy": "^2.14.5",
"vscode-css-languageservice": "4.4.0",
"vscode-emmet-helper": "2.0.9",
"vscode-languageserver": "7.0.0-next.11",
"vscode-css-languageservice": "5.0.2",
"vscode-emmet-helper": "2.2.4-2",
"vscode-languageserver": "7.0.0",
"vscode-languageserver-textdocument": "^1.0.1",
"vscode-languageserver-types": "3.16.0-next.5",
"vscode-uri": "^2.1.2",
"vscode-languageserver-types": "3.16.0",
"vscode-uri": "^3.0.2",
"vscode-web-custom-data": "^0.3.2",
"vue-eslint-parser": "^7.3.0",
"vue-eslint-parser": "^7.4.1",
"vue-onsenui-helper-json": "^1.0.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions server/src/embeddedSupport/languageModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getCSSMode, getSCSSMode, getLESSMode, getPostCSSMode } from '../modes/s
import { getJavascriptMode } from '../modes/script/javascript';
import { VueHTMLMode } from '../modes/template';
import { getStylusMode } from '../modes/style/stylus';
import { DocumentContext, RefactorAction } from '../types';
import { DocumentContext, CodeActionData } from '../types';
import { VueInfoService } from '../services/vueInfoService';
import { DependencyService } from '../services/dependencyService';
import { nullMode } from '../modes/nullMode';
Expand Down Expand Up @@ -58,7 +58,7 @@ export interface LanguageMode {
formatParams: FormattingOptions,
context: CodeActionContext
): CodeAction[];
getRefactorEdits?(doc: TextDocument, args: RefactorAction): WorkspaceEdit;
doCodeActionResolve?(document: TextDocument, action: CodeAction): CodeAction;
doComplete?(document: TextDocument, position: Position): CompletionList;
doResolve?(document: TextDocument, item: CompletionItem): CompletionItem;
doHover?(document: TextDocument, position: Position): Hover;
Expand Down
83 changes: 83 additions & 0 deletions server/src/modes/script/CodeActionKindConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CodeActionKind } from 'vscode-languageserver';

export interface TSCodeActionKind {
kind: CodeActionKind;
matches(refactor: { actionName: string }): boolean;
}

/* tslint:disable:variable-name */
const Extract_Function = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorExtract + '.function',
matches: refactor => refactor.actionName.startsWith('function_')
});

const Extract_Constant = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorExtract + '.constant',
matches: refactor => refactor.actionName.startsWith('constant_')
});

const Extract_Type = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorExtract + '.type',
matches: refactor => refactor.actionName.startsWith('Extract to type alias')
});

const Extract_Interface = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorExtract + '.interface',
matches: refactor => refactor.actionName.startsWith('Extract to interface')
});

const Move_NewFile = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.Refactor + '.move' + '.newFile',
matches: refactor => refactor.actionName.startsWith('Move to a new file')
});

const Rewrite_Import = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorRewrite + '.import',
matches: refactor =>
refactor.actionName.startsWith('Convert namespace import') ||
refactor.actionName.startsWith('Convert named imports')
});

const Rewrite_Export = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorRewrite + '.export',
matches: refactor =>
refactor.actionName.startsWith('Convert default export') || refactor.actionName.startsWith('Convert named export')
});

const Rewrite_Arrow_Braces = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorRewrite + '.arrow' + '.braces',
matches: refactor =>
refactor.actionName.startsWith('Convert default export') || refactor.actionName.startsWith('Convert named export')
});

const Rewrite_Parameters_ToDestructured = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorRewrite + '.parameters' + '.toDestructured',
matches: refactor => refactor.actionName.startsWith('Convert parameters to destructured object')
});

const Rewrite_Property_GenerateAccessors = Object.freeze<TSCodeActionKind>({
kind: CodeActionKind.RefactorRewrite + '.property' + '.generateAccessors',
matches: refactor => refactor.actionName.startsWith("Generate 'get' and 'set' accessors")
});
/* tslint:enable:variable-name */

const allKnownCodeActionKinds = [
Extract_Function,
Extract_Constant,
Extract_Type,
Extract_Interface,
Move_NewFile,
Rewrite_Import,
Rewrite_Export,
Rewrite_Arrow_Braces,
Rewrite_Parameters_ToDestructured,
Rewrite_Property_GenerateAccessors
];

export function getCodeActionKind(refactor: { actionName: string }): CodeActionKind {
return allKnownCodeActionKinds.find(kind => kind.matches(refactor))?.kind ?? CodeActionKind.Refactor;
}
Loading

0 comments on commit a0eeb3f

Please sign in to comment.