Skip to content

Commit

Permalink
feat: add volar.vueserver.disableFileWatcher setting
Browse files Browse the repository at this point in the history
close #2027
  • Loading branch information
johnsoncodehk committed Nov 28, 2022
1 parent 2694088 commit 74227ae
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions extensions/vscode-vue-language-features/package.json
Expand Up @@ -348,6 +348,11 @@
"default": false,
"description": "Reverse priority for tsconfig pickup."
},
"volar.vueserver.disableFileWatcher": {
"type": "boolean",
"default": false,
"description": "Disable file watcher in language server for better performance."
},
"volar.vueserver.additionalExtensions": {
"type": "array",
"items": {
Expand Down
6 changes: 6 additions & 0 deletions extensions/vscode-vue-language-features/src/common.ts
Expand Up @@ -127,6 +127,7 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
|| e.affectsConfiguration('volar.vueserver.diagnosticModel')
|| e.affectsConfiguration('volar.vueserver.noProjectReferences')
|| e.affectsConfiguration('volar.vueserver.reverseConfigFilePriority')
|| e.affectsConfiguration('volar.vueserver.disableFileWatcher')
|| e.affectsConfiguration('volar.vueserver.petiteVue.processHtmlFile')
|| e.affectsConfiguration('volar.vueserver.vitePress.processMdFile')
|| e.affectsConfiguration('volar.vueserver.additionalExtensions')
Expand Down Expand Up @@ -209,6 +210,10 @@ export function reverseConfigFilePriority() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.reverseConfigFilePriority');
}

export function disableFileWatcher() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.disableFileWatcher');
}

export function diagnosticModel() {
return vscode.workspace.getConfiguration('volar').get<'push' | 'pull'>('vueserver.diagnosticModel');
}
Expand Down Expand Up @@ -289,6 +294,7 @@ function getInitializationOptions(
},
noProjectReferences: noProjectReferences(),
reverseConfigFilePriority: reverseConfigFilePriority(),
disableFileWatcher: disableFileWatcher(),
additionalExtensions: additionalExtensions()
};
return initializationOptions;
Expand Down
32 changes: 19 additions & 13 deletions packages/language-server/src/server.ts
Expand Up @@ -90,22 +90,28 @@ export function createCommonLanguageServer(
});
}

if (options.serverMode !== ServerMode.Syntactic && params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration) {
if (
options.serverMode !== ServerMode.Syntactic
&& !options.disableFileWatcher
&& params.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration
) {
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
watchers: [
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ globPattern: `**/*.${ext.extension}` }))).flat(),
{ globPattern: `**/*.{${[
'js',
'cjs',
'mjs',
'ts',
'cts',
'mts',
'jsx',
'tsx',
'json',
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ext.extension)).flat(),
].join(',')}}` },
{
globPattern: `**/*.{${[
'js',
'cjs',
'mjs',
'ts',
'cts',
'mts',
'jsx',
'tsx',
'json',
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ext.extension)).flat(),
].join(',')}}`
},
]
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/src/types.ts
Expand Up @@ -113,6 +113,7 @@ export interface LanguageServerInitializationOptions {
cancellationPipeName?: string;
noProjectReferences?: boolean;
reverseConfigFilePriority?: boolean;
disableFileWatcher?: boolean;
/**
* Enable this option to make language server setup server capabilities based on client capabilities to support multiple servers.
*/
Expand Down

0 comments on commit 74227ae

Please sign in to comment.