Skip to content

Commit

Permalink
feat: use vscode-html-languageservice formatter instead of `prettyh…
Browse files Browse the repository at this point in the history
…tml`

close #1078
  • Loading branch information
johnsoncodehk committed Apr 3, 2022
1 parent 8317859 commit 54bd095
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 1,164 deletions.
7 changes: 1 addition & 6 deletions extensions/vscode-vue-language-features/src/common.ts
Expand Up @@ -7,7 +7,6 @@ import * as callGraph from './features/callGraph';
import * as createWorkspaceSnippets from './features/createWorkspaceSnippets';
import * as documentVersion from './features/documentVersion';
import * as documentContent from './features/documentContent';
import * as documentPrintWidth from './features/documentPrintWidth';
import * as preview from './features/preview';
import * as showReferences from './features/showReferences';
import * as splitEditors from './features/splitEditors';
Expand Down Expand Up @@ -170,7 +169,6 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
showReferences.activate(context, client);
documentVersion.activate(context, client);
documentContent.activate(context, client);
documentPrintWidth.activate(context, client);
activeSelection.activate(context, client);
}

Expand Down Expand Up @@ -250,10 +248,7 @@ function getInitializationOptions(
linkedEditingRange: true,
documentSymbol: true,
documentColor: true,
documentFormatting: {
defaultPrintWidth: 100,
getDocumentPrintWidthRequest: true,
},
documentFormatting: true,
} : undefined,
initializationMessage: initMessage,
};
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -18,8 +18,5 @@
"lerna": "latest",
"typescript": "latest",
"vitest": "^0.8.4"
},
"resolutions": {
"to-vfile": "7.1.0"
}
}
8 changes: 1 addition & 7 deletions packages/shared/src/types.ts
Expand Up @@ -79,13 +79,7 @@ export interface ServerInitializationOptions {
linkedEditingRange?: boolean
documentSymbol?: boolean
documentColor?: boolean
documentFormatting?: {
defaultPrintWidth: number,
/**
* {@link __requests.GetDocumentPrintWidthRequest}
* */
getDocumentPrintWidthRequest?: boolean,
},
documentFormatting?: boolean,
}
initializationMessage?: string
}
9 changes: 0 additions & 9 deletions packages/vue-language-server/src/common.ts
Expand Up @@ -64,15 +64,6 @@ export function createLanguageServer(connection: vscode.Connection, runtimeEnv:
const ts = runtimeEnv.loadTypescript(options);
const documentService = vue.getDocumentService(
{ typescript: ts },
async (uri) => {
if (options.documentFeatures?.documentFormatting?.getDocumentPrintWidthRequest) {
const response = await connection.sendRequest(shared.GetDocumentPrintWidthRequest.type, { uri });
if (response !== undefined) {
return response;
}
}
return options.documentFeatures?.documentFormatting?.defaultPrintWidth ?? 100;
},
configHost,
runtimeEnv.fileSystemProvide,
loadCustomPlugins(folders[0]),
Expand Down
2 changes: 0 additions & 2 deletions packages/vue-language-service/package.json
Expand Up @@ -19,7 +19,6 @@
},
"dependencies": {
"@johnsoncodehk/pug-beautify": "^0.2.2",
"@starptech/prettyhtml": "^0.10.0",
"@volar/html2pug": "0.33.9",
"@volar/pug-language-service": "0.33.9",
"@volar/shared": "0.33.9",
Expand All @@ -44,7 +43,6 @@
},
"browser": {
"./out/commonPlugins/prettier.js": "./out/commonPlugins/empty.js",
"./out/commonPlugins/prettyhtml.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
36 changes: 0 additions & 36 deletions packages/vue-language-service/src/commonPlugins/prettyhtml.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/vue-language-service/src/documentService.ts
Expand Up @@ -9,7 +9,6 @@ import useCssPlugin from './commonPlugins/css';
import useHtmlPlugin from './commonPlugins/html';
import useJsonPlugin from './commonPlugins/json';
import usePrettierPlugin from './commonPlugins/prettier';
import usePrettyhtmlPlugin from './commonPlugins/prettyhtml';
import usePugPlugin from './commonPlugins/pug';
import usePugFormatPlugin from './commonPlugins/pugBeautify';
import useSassFormatPlugin from './commonPlugins/sassFormatter';
Expand All @@ -34,7 +33,6 @@ export interface DocumentService extends ReturnType<typeof getDocumentService> {

export function getDocumentService(
{ typescript: ts }: { typescript: typeof import('typescript/lib/tsserverlibrary') },
getPrintWidth: (uri: string) => Promise<number>,
configurationHost: ConfigurationHost | undefined,
fileSystemProvider: html.FileSystemProvider | undefined,
customPlugins: EmbeddedLanguageServicePlugin[],
Expand Down Expand Up @@ -74,13 +72,11 @@ export function getDocumentService(

// formatter plugins
const cssFormatPlugin = usePrettierPlugin({ allowLanguageIds: ['css', 'less', 'scss', 'postcss'] });
const prettyhtmlPlugin = usePrettyhtmlPlugin({ getPrintWidth });
const pugFormatPlugin = usePugFormatPlugin();
const sassFormatPlugin = useSassFormatPlugin();
const formatPlugns = [
...customPlugins,
cssFormatPlugin,
prettyhtmlPlugin, // ignore in browser
htmlPlugin,
pugFormatPlugin,
sassFormatPlugin,
Expand Down

0 comments on commit 54bd095

Please sign in to comment.