Skip to content

Commit

Permalink
refactor: register file watchers in language server
Browse files Browse the repository at this point in the history
close #2037
  • Loading branch information
johnsoncodehk committed Oct 23, 2022
1 parent 158ec1f commit 3c07cd2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/browser';
import { activate as commonActivate, deactivate as commonDeactivate, processHtml, processMd } from './common';
import { activate as commonActivate, deactivate as commonDeactivate } from './common';
import { middleware } from './middleware';

export function activate(context: vscode.ExtensionContext) {
Expand All @@ -24,9 +24,6 @@ export function activate(context: vscode.ExtensionContext) {
documentSelector: langs.map<lsp.DocumentFilter>(lang => ({ language: lang })),
initializationOptions: initOptions,
progressOnInitialization: true,
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher(`{**/*.vue,${processMd() ? '**/*.md,' : ''}${processHtml() ? '**/*.html,' : ''}**/*.js,**/*.ts,**/*.cjs,**/*.cts,**/*.mjs,**/*.mts,**/*.jsx,**/*.tsx,**/*.json}`)
},
middleware,
};
const client = new _LanguageClient(
Expand Down
Expand Up @@ -4,7 +4,7 @@ import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/node';
import { activate as commonActivate, deactivate as commonDeactivate, getDocumentSelector, processHtml, processMd } from './common';
import { activate as commonActivate, deactivate as commonDeactivate, getDocumentSelector } from './common';
import { middleware } from './middleware';

export function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -42,7 +42,6 @@ export function activate(context: vscode.ExtensionContext) {
}
}

const additionalExtensions = initOptions.additionalExtensions?.map(ext => `,**/*.${ext}`).join('') ?? '';
const serverModule = vscode.Uri.joinPath(context.extensionUri, 'server.js');
const maxOldSpaceSize = vscode.workspace.getConfiguration('volar').get<number | null>('vueserver.maxOldSpaceSize');
const runOptions = { execArgv: <string[]>[] };
Expand All @@ -67,9 +66,6 @@ export function activate(context: vscode.ExtensionContext) {
documentSelector: langs.map<lsp.DocumentFilter>(lang => ({ language: lang })),
initializationOptions: initOptions,
progressOnInitialization: true,
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher(`{**/*.vue,${processMd() ? '**/*.md,' : ''}${processHtml() ? '**/*.html,' : ''}**/*.js,**/*.ts,**/*.cjs,**/*.cts,**/*.mjs,**/*.mts,**/*.jsx,**/*.tsx,**/*.json${additionalExtensions}}`)
},
};
const client = new _LanguageClient(
id,
Expand Down
4 changes: 4 additions & 0 deletions packages/language-server/src/registerFeatures.ts
Expand Up @@ -114,7 +114,11 @@ export function setupSemanticCapabilities(
filters: [
...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ({ pattern: { glob: `**/*.${ext.extension}` } }))).flat(),
{ pattern: { glob: '**/*.js' } },
{ pattern: { glob: '**/*.cjs' } },
{ pattern: { glob: '**/*.mjs' } },
{ pattern: { glob: '**/*.ts' } },
{ pattern: { glob: '**/*.cts' } },
{ pattern: { glob: '**/*.mts' } },
{ pattern: { glob: '**/*.jsx' } },
{ pattern: { glob: '**/*.tsx' } },
{ pattern: { glob: '**/*.json' } },
Expand Down
17 changes: 17 additions & 0 deletions packages/language-server/src/server.ts
Expand Up @@ -89,6 +89,23 @@ export function createCommonLanguageServer(
}
});
}

if (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' },
{ globPattern: '**/*.cjs' },
{ globPattern: '**/*.mjs' },
{ globPattern: '**/*.ts' },
{ globPattern: '**/*.cts' },
{ globPattern: '**/*.mts' },
{ globPattern: '**/*.jsx' },
{ globPattern: '**/*.tsx' },
{ globPattern: '**/*.json' },
]
});
}
});
connection.listen();

Expand Down

0 comments on commit 3c07cd2

Please sign in to comment.