Skip to content

Commit

Permalink
feat(doctor): check emmet.includeLanguages, files.associations
Browse files Browse the repository at this point in the history
close #2487
  • Loading branch information
johnsoncodehk committed Mar 10, 2023
1 parent ecfa0fc commit 1b9c246
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/vscode-vue/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
'vue-semantic-server',
'Vue Semantic Server',
getDocumentSelector(context),
getInitializationOptions(ServerMode.PartialSemantic, context),
await getInitializationOptions(ServerMode.PartialSemantic, context),
6009,
),
createLc(
'vue-syntactic-server',
'Vue Syntactic Server',
getDocumentSelector(context),
getInitializationOptions(ServerMode.Syntactic, context),
await getInitializationOptions(ServerMode.Syntactic, context),
6011,
)
]);
Expand Down Expand Up @@ -244,7 +244,7 @@ function fullCompletionList() {
return vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.fullCompletionList');
}

function getInitializationOptions(
async function getInitializationOptions(
serverMode: ServerMode,
context: vscode.ExtensionContext,
) {
Expand All @@ -259,7 +259,7 @@ function getInitializationOptions(
full: lsp.TextDocumentSyncKind.Full,
none: lsp.TextDocumentSyncKind.None,
}[textDocumentSync] : lsp.TextDocumentSyncKind.Incremental,
typescript: { tsdk: getTsdk(context).tsdk },
typescript: { tsdk: (await getTsdk(context)).tsdk },
noProjectReferences: noProjectReferences(),
reverseConfigFilePriority: reverseConfigFilePriority(),
disableFileWatcher: disableFileWatcher(),
Expand Down
36 changes: 29 additions & 7 deletions packages/vscode-vue/src/features/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseLanguageClient } from 'vscode-languageclient';
import { GetMatchTsConfigRequest, ParseSFCRequest, GetVueCompilerOptionsRequest } from '@volar/vue-language-server';

const scheme = 'vue-doctor';
const knownValidSyntanxHighlightExtensions = {
const knownValidSyntaxHighlightExtensions = {
postcss: ['cpylua.language-postcss', 'vunguyentuan.vscode-postcss', 'csstools.postcss'],
stylus: ['sysoev.language-stylus'],
sass: ['Syler.sass-indented'],
Expand Down Expand Up @@ -41,15 +41,19 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
}

content += '---\n\n';
content += `> Have any questions about the report message? You can see how it is composed by inspecting the [source code](https://github.com/johnsoncodehk/volar/blob/master/packages/vscode-vue/src/features/doctor.ts).\n\n`;
content += `> Have any questions about the report message? You can see how it is composed by inspecting the [source code](https://github.com/vuejs/language-tools/blob/master/packages/vscode-vue/src/features/doctor.ts).\n\n`;

return content.trim();
}
},
));
context.subscriptions.push(vscode.commands.registerCommand('volar.action.doctor', () => {
const doc = vscode.window.activeTextEditor?.document;
if (doc?.languageId === 'vue' && doc.uri.scheme === 'file') {
if (
doc
&& (doc.languageId === 'vue' || doc.uri.toString().endsWith('.vue'))
&& doc.uri.scheme === 'file'
) {
vscode.commands.executeCommand('markdown.showPreviewToSide', getDoctorUri(doc.uri));
}
}));
Expand All @@ -62,7 +66,7 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
if (
vscode.workspace.getConfiguration('volar').get<boolean>('doctor.status')
&& editor
&& editor.document.languageId === 'vue'
&& (editor.document.languageId === 'vue' || editor.document.uri.toString().endsWith('.vue'))
&& editor.document.uri.scheme === 'file'
) {
const problems = await getProblems(editor.document.uri);
Expand Down Expand Up @@ -173,7 +177,7 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
// check using pug but don't install @volar/vue-language-plugin-pug
if (
sfc?.descriptor.template?.lang === 'pug'
&& !vueOptions?.plugins?.some((pluginPath: string) => pluginPath.indexOf('vue-language-plugin-pug') >= 0)
&& !await getPackageJsonOfWorkspacePackage(fileUri.fsPath, '@volar/vue-language-plugin-pug')
) {
problems.push({
title: '`@volar/vue-language-plugin-pug` missing',
Expand Down Expand Up @@ -204,8 +208,8 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
];
for (const block of blocks) {
if (!block) continue;
if (block.lang && block.lang in knownValidSyntanxHighlightExtensions) {
const validExts = knownValidSyntanxHighlightExtensions[block.lang as keyof typeof knownValidSyntanxHighlightExtensions];
if (block.lang && block.lang in knownValidSyntaxHighlightExtensions) {
const validExts = knownValidSyntaxHighlightExtensions[block.lang as keyof typeof knownValidSyntaxHighlightExtensions];
const someInstalled = validExts.some(ext => !!vscode.extensions.getExtension(ext));
if (!someInstalled) {
problems.push({
Expand All @@ -218,6 +222,24 @@ export async function register(context: vscode.ExtensionContext, client: BaseLan
}
}

// emmet.includeLanguages
const emmetIncludeLanguages = vscode.workspace.getConfiguration('emmet').get<{ [lang: string]: string; }>('includeLanguages');
if (emmetIncludeLanguages?.['vue']) {
problems.push({
title: 'Unnecessary `emmet.includeLanguages.vue`',
message: 'Vue language server already supports Emmet. You can remove `emmet.includeLanguages.vue` from `.vscode/settings.json`.',
});
}

// files.associations
const filesAssociations = vscode.workspace.getConfiguration('files').get<{ [pattern: string]: string; }>('associations');
if (filesAssociations?.['*.vue'] === 'html') {
problems.push({
title: 'Unnecessary `files.associations["*.vue"]`',
message: 'With `"files.associations": { "*.vue": html }`, language server cannot to recognize Vue files. You can remove `files.associations["*.vue"]` from `.vscode/settings.json`.',
});
}

// check outdated language services plugins
// check outdated vue language plugins
// check node_modules has more than one vue versions
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-language-server/src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from 'vscode-languageserver-protocol';
import { TagNameCasing, AttrNameCasing, SFCParseResult } from '@volar/vue-language-service';
import { TagNameCasing, AttrNameCasing, SFCParseResult, VueCompilerOptions } from '@volar/vue-language-service';
import { ComponentMeta } from 'vue-component-meta';

export namespace GetVueCompilerOptionsRequest {
export type ParamsType = vscode.TextDocumentIdentifier;
export type ResponseType = any | null | undefined;
export type ResponseType = VueCompilerOptions | null | undefined;
export type ErrorType = never;
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/vueCompilerOptions');
}
Expand Down

0 comments on commit 1b9c246

Please sign in to comment.