Skip to content

Commit

Permalink
feat: support volar.config.js path setting
Browse files Browse the repository at this point in the history
close #2078
  • Loading branch information
johnsoncodehk committed Dec 18, 2022
1 parent b27556c commit 09dbada
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions extensions/vscode-vue-language-features/package.json
Expand Up @@ -291,6 +291,11 @@
"default": "off",
"description": "Traces the communication between VS Code and the language server."
},
"volar.vueserver.configFilePath": {
"type": "string",
"default": "./volar.config.js",
"description": "Path to volar.config.js."
},
"volar.vueserver.maxFileSize": {
"type": "number",
"default": 20971520,
Expand Down
6 changes: 4 additions & 2 deletions extensions/vscode-vue-language-features/src/common.ts
Expand Up @@ -168,6 +168,7 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
|| e.affectsConfiguration('volar.vueserver.vitePress.processMdFile')
|| e.affectsConfiguration('volar.vueserver.additionalExtensions')
|| e.affectsConfiguration('volar.vueserver.maxFileSize')
|| e.affectsConfiguration('volar.vueserver.configFilePath')
) {
requestReloadVscode();
}
Expand Down Expand Up @@ -304,6 +305,7 @@ function getInitializationOptions(
const textDocumentSync = vscode.workspace.getConfiguration('volar').get<'incremental' | 'full' | 'none'>('vueserver.textDocumentSync');
const initializationOptions: VueServerInitializationOptions = {
// volar
configFilePath: vscode.workspace.getConfiguration('volar').get<string>('vueserver.configFilePath'),
respectClientCapabilities: true,
serverMode,
diagnosticModel: diagnosticModel() === 'pull' ? DiagnosticModel.Pull : DiagnosticModel.Push,
Expand All @@ -316,6 +318,7 @@ function getInitializationOptions(
noProjectReferences: noProjectReferences(),
reverseConfigFilePriority: reverseConfigFilePriority(),
disableFileWatcher: disableFileWatcher(),
maxFileSize: vscode.workspace.getConfiguration('volar').get<number>('vueserver.maxFileSize'),
// vue
petiteVue: {
processHtmlFile: processHtml(),
Expand All @@ -324,10 +327,9 @@ function getInitializationOptions(
processMdFile: processMd(),
},
json: {
customBlockSchemaUrls: vscode.workspace.getConfiguration('volar').get<Record<string, string>>('vueserver.json.customBlockSchemaUrls')
customBlockSchemaUrls: vscode.workspace.getConfiguration('volar').get<Record<string, string>>('vueserver.json.customBlockSchemaUrls'),
},
additionalExtensions: additionalExtensions(),
maxFileSize: vscode.workspace.getConfiguration('volar').get<number>('vueserver.maxFileSize'),
};
return initializationOptions;
}
1 change: 1 addition & 0 deletions packages/language-server/src/server.ts
Expand Up @@ -127,6 +127,7 @@ export function createCommonLanguageServer(
plugins,
ts,
configHost,
options,
);

for (const root of roots) {
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/src/types.ts
Expand Up @@ -119,4 +119,5 @@ export interface LanguageServerInitializationOptions {
*/
respectClientCapabilities?: boolean;
maxFileSize?: number;
configFilePath?: string;
}
4 changes: 2 additions & 2 deletions packages/language-server/src/utils/config.ts
@@ -1,9 +1,9 @@
import { LanguageServicePlugin } from '@volar/language-service';

export function loadCustomPlugins(dir: string) {
export function loadCustomPlugins(dir: string, configFile: string | undefined) {
let configPath: string | undefined;
try {
configPath = require.resolve('./volar.config.js', { paths: [dir] });
configPath = require.resolve(configFile ?? './volar.config.js', { paths: [dir] });
} catch { }

try {
Expand Down
5 changes: 3 additions & 2 deletions packages/language-server/src/utils/documentServiceHost.ts
@@ -1,4 +1,4 @@
import { LanguageServerPlugin, RuntimeEnvironment } from '../types';
import { LanguageServerInitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
import * as embedded from '@volar/language-service';
import { URI } from 'vscode-uri';
import { loadCustomPlugins } from './config';
Expand All @@ -11,6 +11,7 @@ export function createDocumentServiceHost(
plugins: ReturnType<LanguageServerPlugin>[],
ts: typeof import('typescript/lib/tsserverlibrary'),
configHost: embedded.ConfigurationHost | undefined,
initOptions: LanguageServerInitializationOptions,
) {

const workspaceServices = new Map<string, embedded.DocumentService>();
Expand Down Expand Up @@ -53,7 +54,7 @@ export function createDocumentServiceHost(
},
getPlugins() {
return [
...loadCustomPlugins(rootUri.fsPath),
...loadCustomPlugins(rootUri.fsPath, initOptions.configFilePath),
...plugins.map(plugin => plugin.syntacticService?.getServicePlugins?.(serviceContext) ?? []).flat(),
];
},
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/utils/project.ts
Expand Up @@ -80,7 +80,7 @@ export async function createProject(
context: languageContext,
getPlugins() {
return [
...loadCustomPlugins(languageServiceHost.getCurrentDirectory()),
...loadCustomPlugins(languageServiceHost.getCurrentDirectory(), serverOptions.configFilePath),
...plugins.map(plugin => plugin.semanticService?.getServicePlugins?.(languageServiceHost, vueLs!) ?? []).flat(),
];
},
Expand Down

0 comments on commit 09dbada

Please sign in to comment.