Skip to content

Commit

Permalink
feat: use vscode-css-languageservice formatter instead of prettier
Browse files Browse the repository at this point in the history
close #1131
  • Loading branch information
johnsoncodehk committed Apr 3, 2022
1 parent 54bd095 commit d567b3c
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 220 deletions.
8 changes: 4 additions & 4 deletions extensions/vscode-vue-language-features/package.json
Expand Up @@ -649,13 +649,13 @@
"@types/ws": "^8.5.3",
"@volar/shared": "0.33.9",
"@volar/vue-language-server": "0.33.9",
"@vue/compiler-dom": "^3.2.27",
"@vue/compiler-sfc": "^3.2.27",
"@vue/reactivity": "^3.2.27",
"@vue/compiler-dom": "^3.2.31",
"@vue/compiler-sfc": "^3.2.31",
"@vue/reactivity": "^3.2.31",
"esbuild": "latest",
"path-browserify": "^1.0.1",
"vsce": "latest",
"vscode-languageclient": "^8.0.0-next.8",
"vscode-languageclient": "^8.0.0-next.14",
"vscode-nls": "5.0.0",
"ws": "^8.5.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/html2pug/package.json
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"domelementtype": "^2.2.0",
"domhandler": "^4.3.0",
"domhandler": "^4.3.1",
"htmlparser2": "^7.2.0",
"pug": "^3.0.2"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pug-language-service/package.json
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/pug-language-service"
},
"devDependencies": {
"vscode-html-languageservice": "^4.2.1"
"vscode-html-languageservice": "^4.2.4"
},
"dependencies": {
"@volar/code-gen": "0.33.9",
Expand All @@ -22,7 +22,7 @@
"@volar/transforms": "0.33.9",
"pug-lexer": "^5.0.1",
"pug-parser": "^6.0.0",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-languageserver-types": "^3.17.0-next.6"
}
}
5 changes: 2 additions & 3 deletions packages/shared/package.json
Expand Up @@ -15,12 +15,11 @@
},
"dependencies": {
"upath": "^2.0.1",
"vscode-jsonrpc": "^8.0.0-next.5",
"vscode-uri": "^3.0.3"
},
"devDependencies": {
"typescript": "latest",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3"
"vscode-languageserver-protocol": "^3.17.0-next.16",
"vscode-languageserver-textdocument": "^1.0.4"
}
}
31 changes: 15 additions & 16 deletions packages/shared/src/requests.ts
@@ -1,5 +1,4 @@
import * as rpc from 'vscode-jsonrpc';
import type * as vscode from 'vscode-languageserver-protocol';
import * as vscode from 'vscode-languageserver-protocol';

/**
* Client Requests
Expand All @@ -9,19 +8,19 @@ export namespace GetDocumentContentRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = string;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('vscode/content');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vscode/content');
}

export namespace GetDocumentVersionRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = number | null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('vue/docVersion');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vue/docVersion');
}

export namespace ShowReferencesNotification {
export type ParamsType = vscode.TextDocumentPositionParams & { references: vscode.Location[] };
export const type = new rpc.NotificationType<ParamsType>('vue.findReferences');
export type ResponseType = vscode.TextDocumentPositionParams & { references: vscode.Location[] };
export const type = new vscode.NotificationType<ResponseType>('vue.findReferences');
}

export namespace GetDocumentNameCasesRequest {
Expand All @@ -31,20 +30,20 @@ export namespace GetDocumentNameCasesRequest {
attrNameCase: 'kebabCase' | 'camelCase',
};
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('volar/getAttrNameCaseClient');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/getAttrNameCaseClient');
}

export namespace GetDocumentPrintWidthRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = number | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('vue/getDocumentWordWrapColumn');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vue/getDocumentWordWrapColumn');
}

export namespace GetEditorSelectionRequest {
export type ResponseType = vscode.TextDocumentPositionParams | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType0<ResponseType, ErrorType>('vue/activeSelection');
export const type = new vscode.RequestType0<ResponseType, ErrorType>('vue/activeSelection');
}

/**
Expand All @@ -54,21 +53,21 @@ export namespace GetEditorSelectionRequest {
export namespace InitDoneRequest {
export type ResponseType = null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType0<ResponseType, ErrorType>('volar/init');
export const type = new vscode.RequestType0<ResponseType, ErrorType>('volar/init');
}

export namespace GetMatchTsConfigRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = string | null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('volar/tsconfig');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/tsconfig');
}

export namespace D3Request {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = string | null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('volar/d3');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/d3');
}

export namespace AutoInsertRequest {
Expand All @@ -84,16 +83,16 @@ export namespace AutoInsertRequest {
};
export type ResponseType = string | vscode.TextEdit | null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('vue/autoInsert');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('vue/autoInsert');
}

export namespace VerifyAllScriptsNotification {
export const type = new rpc.NotificationType0('volar.action.verifyAllScripts');
export const type = new vscode.NotificationType0('volar.action.verifyAllScripts');
}

export namespace WriteVirtualFilesNotification {
export type ParamsType = { lsType: 'template' | 'script' };
export const type = new rpc.NotificationType<ParamsType>('volar.action.writeVirtualFiles');
export const type = new vscode.NotificationType<ParamsType>('volar.action.writeVirtualFiles');
}

export namespace DetectDocumentNameCasesRequest {
Expand All @@ -103,5 +102,5 @@ export namespace DetectDocumentNameCasesRequest {
attr: 'both' | 'kebabCase' | 'camelCase' | 'unsure',
} | null | undefined;
export type ErrorType = never;
export const type = new rpc.RequestType<ParamsType, ResponseType, ErrorType>('volar/getTagNameCaseServer');
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/getTagNameCaseServer');
}
2 changes: 1 addition & 1 deletion packages/transforms/package.json
Expand Up @@ -14,6 +14,6 @@
},
"dependencies": {
"@volar/shared": "0.33.9",
"vscode-languageserver-types": "^3.17.0-next.6"
"vscode-languageserver-types": "^3.17.0-next.9"
}
}
6 changes: 3 additions & 3 deletions packages/typescript-language-service/package.json
Expand Up @@ -13,15 +13,15 @@
"directory": "packages/typescript-language-service"
},
"devDependencies": {
"@types/semver": "^7.3.8",
"@types/semver": "^7.3.9",
"typescript": "latest"
},
"dependencies": {
"@volar/shared": "0.33.9",
"semver": "^7.3.5",
"upath": "^2.0.1",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-languageserver-protocol": "^3.17.0-next.16",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-nls": "^5.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/vue-code-gen/package.json
Expand Up @@ -18,8 +18,8 @@
"dependencies": {
"@volar/code-gen": "0.33.9",
"@volar/source-map": "0.33.9",
"@vue/compiler-core": "^3.2.27",
"@vue/compiler-dom": "^3.2.27",
"@vue/shared": "^3.2.27"
"@vue/compiler-core": "^3.2.31",
"@vue/compiler-dom": "^3.2.31",
"@vue/shared": "^3.2.31"
}
}
10 changes: 5 additions & 5 deletions packages/vue-language-server/package.json
Expand Up @@ -20,13 +20,13 @@
"@volar/shared": "0.33.9",
"@volar/vue-language-service": "0.33.9",
"@volar/vue-typescript": "0.33.9",
"@vue/shared": "^3.2.27",
"@vue/shared": "^3.2.31",
"request-light": "^0.5.7",
"upath": "^2.0.1",
"vscode-html-languageservice": "^4.2.1",
"vscode-languageserver": "^8.0.0-next.6",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-html-languageservice": "^4.2.4",
"vscode-languageserver": "^8.0.0-next.10",
"vscode-languageserver-protocol": "^3.17.0-next.16",
"vscode-languageserver-textdocument": "^1.0.4",
"vscode-uri": "^3.0.3"
}
}
4 changes: 2 additions & 2 deletions packages/vue-language-service-types/package.json
Expand Up @@ -13,7 +13,7 @@
"directory": "packages/vue-language-service-types"
},
"dependencies": {
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3"
"vscode-languageserver-protocol": "^3.17.0-next.16",
"vscode-languageserver-textdocument": "^1.0.4"
}
}
2 changes: 1 addition & 1 deletion packages/vue-language-service-types/src/index.ts
Expand Up @@ -70,7 +70,7 @@ export type EmbeddedLanguageServicePlugin = {
getFoldingRanges?(document: TextDocument): NullableResult<vscode.FoldingRange[]>;
getSelectionRanges?(document: TextDocument, positions: vscode.Position[]): NullableResult<vscode.SelectionRange[]>;
getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
format?(document: TextDocument, range: vscode.Range | undefined, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;

callHierarchy?: {
doPrepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>;
Expand Down
23 changes: 10 additions & 13 deletions packages/vue-language-service/package.json
Expand Up @@ -13,8 +13,7 @@
"directory": "packages/vue-language-service"
},
"devDependencies": {
"@types/prettier": "^1.16.4",
"@types/semver": "^7.3.8",
"@types/semver": "^7.3.9",
"typescript": "latest"
},
"dependencies": {
Expand All @@ -28,21 +27,19 @@
"@volar/vue-code-gen": "0.33.9",
"@volar/vue-language-service-types": "0.33.9",
"@volar/vue-typescript": "0.33.9",
"@vscode/emmet-helper": "^2.8.3",
"@vue/reactivity": "^3.2.27",
"@vue/shared": "^3.2.27",
"prettier": "^1.16.4",
"sass-formatter": "^0.7.2",
"@vscode/emmet-helper": "^2.8.4",
"@vue/reactivity": "^3.2.31",
"@vue/shared": "^3.2.31",
"sass-formatter": "^0.7.3",
"semver": "^7.3.5",
"upath": "^2.0.1",
"vscode-css-languageservice": "^5.1.9",
"vscode-html-languageservice": "^4.2.1",
"vscode-json-languageservice": "^4.1.10",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3"
"vscode-css-languageservice": "^5.4.1",
"vscode-html-languageservice": "^4.2.4",
"vscode-json-languageservice": "^4.2.1",
"vscode-languageserver-protocol": "^3.17.0-next.16",
"vscode-languageserver-textdocument": "^1.0.4"
},
"browser": {
"./out/commonPlugins/prettier.js": "./out/commonPlugins/empty.js",
"./out/commonPlugins/emmet.js": "./out/commonPlugins/empty.js",
"./out/commonPlugins/pug.js": "./out/commonPlugins/empty.js",
"./out/vuePlugins/htmlPugConversions.js": "./out/commonPlugins/empty.js"
Expand Down
6 changes: 6 additions & 0 deletions packages/vue-language-service/src/commonPlugins/css.ts
Expand Up @@ -174,6 +174,12 @@ export default function (options: {
return cssLs.getSelectionRanges(document, positions, stylesheet);
});
},

format(document, range, options) {
return worker(document, (stylesheet, cssLs) => {
return cssLs.format(document, range, options);
});
},
};

async function initCustomData() {
Expand Down
8 changes: 0 additions & 8 deletions packages/vue-language-service/src/commonPlugins/json.ts
Expand Up @@ -85,14 +85,6 @@ export default function (options: {

format(document, range, options) {
return worker(document, (jsonDocument) => {

if (!range) {
range = vscode.Range.create(
vscode.Position.create(0, 0),
document.positionAt(document.getText().length),
);
}

return jsonLs.format(document, range, options);
});
},
Expand Down
36 changes: 0 additions & 36 deletions packages/vue-language-service/src/commonPlugins/prettier.ts

This file was deleted.

6 changes: 5 additions & 1 deletion packages/vue-language-service/src/documentFeatures/format.ts
Expand Up @@ -129,6 +129,10 @@ export function register(context: DocumentServiceRuntimeContext) {
async function tryFormat(document: TextDocument) {

const plugins = context.getFormatPlugins();
const range: vscode.Range = {
start: document.positionAt(0),
end: document.positionAt(document.getText().length),
};

context.updateTsLs(document);

Expand All @@ -140,7 +144,7 @@ export function register(context: DocumentServiceRuntimeContext) {
let edits: vscode.TextEdit[] | null | undefined;

try {
edits = await plugin.format(document, undefined, options);
edits = await plugin.format(document, range, options);
}
catch (err) {
console.error(err);
Expand Down

0 comments on commit d567b3c

Please sign in to comment.