@volar/language-server 2.4.0-alpha.9 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/browser.d.ts +39 -21
  2. package/browser.js +12 -33
  3. package/lib/features/configurations.d.ts +8 -0
  4. package/lib/features/configurations.js +49 -0
  5. package/lib/features/editorFeatures.d.ts +2 -0
  6. package/lib/features/editorFeatures.js +186 -0
  7. package/lib/features/fileSystem.d.ts +8 -0
  8. package/lib/features/fileSystem.js +61 -0
  9. package/lib/features/fileWatcher.d.ts +9 -0
  10. package/lib/features/fileWatcher.js +63 -0
  11. package/lib/features/languageFeatures.d.ts +4 -0
  12. package/lib/features/languageFeatures.js +730 -0
  13. package/lib/features/textDocuments.d.ts +12 -0
  14. package/lib/features/textDocuments.js +54 -0
  15. package/lib/features/workspaceFolders.d.ts +6 -0
  16. package/lib/features/workspaceFolders.js +50 -0
  17. package/lib/fileSystemProviders/http.d.ts +6 -0
  18. package/lib/fileSystemProviders/http.js +46 -0
  19. package/lib/fileSystemProviders/node.d.ts +2 -0
  20. package/lib/fileSystemProviders/node.js +49 -0
  21. package/lib/project/inferredCompilerOptions.js +2 -2
  22. package/lib/project/simpleProject.js +7 -8
  23. package/lib/project/typescriptProject.d.ts +7 -4
  24. package/lib/project/typescriptProject.js +35 -26
  25. package/lib/project/typescriptProjectLs.d.ts +7 -6
  26. package/lib/project/typescriptProjectLs.js +14 -33
  27. package/lib/server.d.ts +42 -27
  28. package/lib/server.js +58 -479
  29. package/lib/types.d.ts +14 -5
  30. package/lib/types.js +1 -0
  31. package/lib/utils/combineChangeRanges.d.ts +2 -0
  32. package/lib/utils/combineChangeRanges.js +28 -0
  33. package/lib/utils/snapshotDocument.d.ts +28 -0
  34. package/lib/utils/snapshotDocument.js +138 -0
  35. package/node.d.ts +39 -23
  36. package/node.js +12 -58
  37. package/package.json +5 -6
  38. package/protocol.d.ts +1 -13
  39. package/protocol.js +1 -16
  40. package/lib/register/registerEditorFeatures.d.ts +0 -2
  41. package/lib/register/registerEditorFeatures.js +0 -208
  42. package/lib/register/registerLanguageFeatures.d.ts +0 -3
  43. package/lib/register/registerLanguageFeatures.js +0 -435
  44. package/lib/schemaRequestHandlers/http.d.ts +0 -2
  45. package/lib/schemaRequestHandlers/http.js +0 -16
package/browser.d.ts CHANGED
@@ -7,31 +7,49 @@ export * from './lib/project/typescriptProject';
7
7
  export * from './lib/server';
8
8
  export declare function createConnection(): vscode.Connection;
9
9
  export declare function createServer(connection: vscode.Connection): {
10
- connection: vscode.Connection;
11
- fs: import("@volar/language-service").FileSystem;
12
10
  initializeParams: vscode.InitializeParams;
13
- initializeResult: import("./index").VolarInitializeResult;
14
- languageServicePlugins: import("@volar/language-service").LanguageServicePlugin[];
15
11
  project: import("./index").LanguageServerProject;
16
- pullModelDiagnostics: boolean;
17
- documents: vscode.TextDocuments<import("@volar/snapshot-document/lib/snapshotDocument").SnapshotDocument>;
18
- workspaceFolders: Map<URI, boolean>;
19
- getSyncedDocumentKey: (uri: URI) => string | undefined;
20
- initialize: (initializeParams: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service").LanguageServicePlugin[], options?: {
21
- pullModelDiagnostics?: boolean;
22
- }) => import("./index").VolarInitializeResult;
23
- initialized: () => void;
24
- shutdown: () => void;
25
- watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
26
- getConfiguration: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
27
- onDidChangeConfiguration: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
28
- dispose(): void;
12
+ languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin<any>[];
13
+ initialize(params: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin[]): vscode.InitializeResult<import("./index").ExperimentalFeatures>;
14
+ initialized(): void;
15
+ shutdown(): void;
16
+ configurations: {
17
+ get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
18
+ onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
19
+ dispose(): void;
20
+ };
21
+ };
22
+ editorFeatures: void;
23
+ documents: {
24
+ all: () => import("./lib/utils/snapshotDocument").SnapshotDocument[];
25
+ onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
26
+ onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
27
+ onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
28
+ onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
29
+ get(uri: URI): import("./lib/utils/snapshotDocument").SnapshotDocument | undefined;
30
+ };
31
+ workspaceFolders: {
32
+ readonly all: URI[];
33
+ has(uri: URI): boolean;
29
34
  };
30
- onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
31
- dispose: () => void;
35
+ fileWatcher: {
36
+ watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
37
+ onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
38
+ dispose: () => void;
39
+ };
32
40
  };
33
- clearPushDiagnostics: () => void;
34
- refresh: (project: import("./index").LanguageServerProject) => Promise<void>;
41
+ languageFeatures: {
42
+ requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
43
+ };
44
+ fileSystem: {
45
+ readFile(uri: URI): string | Thenable<string | undefined>;
46
+ stat(uri: URI): import("@volar/language-service/lib/types").FileStat | Thenable<import("@volar/language-service/lib/types").FileStat | undefined>;
47
+ readDirectory(uri: URI): import("@volar/language-service/lib/types").ProviderResult<[string, import("@volar/language-service/lib/types").FileType][]>;
48
+ install(scheme: string, provider: import("@volar/language-service/lib/types").FileSystem): void;
49
+ };
50
+ connection: vscode.Connection;
51
+ onInitialize(callback: (serverCapabilities: vscode.ServerCapabilities<import("./index").ExperimentalFeatures>) => void): void;
52
+ onInitialized(callback: () => void): void;
35
53
  };
36
54
  export declare function loadTsdkByUrl(tsdkUrl: string, locale: string | undefined): Promise<{
37
55
  typescript: typeof import("typescript");
package/browser.js CHANGED
@@ -17,12 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createConnection = createConnection;
18
18
  exports.createServer = createServer;
19
19
  exports.loadTsdkByUrl = loadTsdkByUrl;
20
- const language_service_1 = require("@volar/language-service");
21
20
  const vscode = require("vscode-languageserver/browser");
22
21
  const vscode_uri_1 = require("vscode-uri");
23
- const http_1 = require("./lib/schemaRequestHandlers/http");
22
+ const http_1 = require("./lib/fileSystemProviders/http");
24
23
  const server_1 = require("./lib/server");
25
- const protocol_1 = require("./protocol");
24
+ const http_2 = require("./lib/fileSystemProviders/http");
26
25
  __exportStar(require("vscode-languageserver/browser"), exports);
27
26
  __exportStar(require("./index"), exports);
28
27
  __exportStar(require("./lib/project/simpleProject"), exports);
@@ -35,37 +34,14 @@ function createConnection() {
35
34
  return connection;
36
35
  }
37
36
  function createServer(connection) {
38
- return (0, server_1.createServerBase)(connection, {
39
- async stat(uri) {
40
- if (uri.scheme === 'http' || uri.scheme === 'https') { // perf
41
- const text = await this.readFile(uri);
42
- if (text !== undefined) {
43
- return {
44
- type: language_service_1.FileType.File,
45
- size: text.length,
46
- ctime: -1,
47
- mtime: -1,
48
- };
49
- }
50
- return undefined;
51
- }
52
- return await connection.sendRequest(protocol_1.FsStatRequest.type, uri.toString());
53
- },
54
- async readFile(uri) {
55
- if (uri.scheme === 'http' || uri.scheme === 'https') { // perf
56
- return await (0, http_1.default)(uri);
57
- }
58
- return await connection.sendRequest(protocol_1.FsReadFileRequest.type, uri.toString()) ?? undefined;
59
- },
60
- async readDirectory(uri) {
61
- if (uri.scheme === 'http' || uri.scheme === 'https') { // perf
62
- return [];
63
- }
64
- return await connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri.toString());
65
- },
66
- });
37
+ const server = (0, server_1.createServerBase)(connection);
38
+ server.fileSystem.install('http', http_2.provider);
39
+ server.fileSystem.install('https', http_2.provider);
40
+ server.onInitialized(() => (0, http_2.listenEditorSettings)(server));
41
+ return server;
67
42
  }
68
43
  async function loadTsdkByUrl(tsdkUrl, locale) {
44
+ locale = locale?.toLowerCase();
69
45
  return {
70
46
  typescript: await loadLib(),
71
47
  diagnosticMessages: await loadLocalizedDiagnosticMessages(),
@@ -82,8 +58,11 @@ async function loadTsdkByUrl(tsdkUrl, locale) {
82
58
  }
83
59
  }
84
60
  async function loadLocalizedDiagnosticMessages() {
61
+ if (locale === 'en') {
62
+ return;
63
+ }
85
64
  try {
86
- const json = await (0, http_1.default)(vscode_uri_1.URI.parse(`${tsdkUrl}/${locale}/diagnosticMessages.generated.json`));
65
+ const json = await (0, http_1.handler)(vscode_uri_1.URI.parse(`${tsdkUrl}/${locale}/diagnosticMessages.generated.json`));
87
66
  if (json) {
88
67
  return JSON.parse(json);
89
68
  }
@@ -0,0 +1,8 @@
1
+ import * as vscode from 'vscode-languageserver';
2
+ import { LanguageServerState } from '../types';
3
+ export declare function register(server: LanguageServerState): {
4
+ get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
5
+ onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
6
+ dispose(): void;
7
+ };
8
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = register;
4
+ const vscode = require("vscode-languageserver");
5
+ function register(server) {
6
+ const configurations = new Map();
7
+ const didChangeCallbacks = new Set();
8
+ server.onInitialized(() => {
9
+ server.connection.onDidChangeConfiguration(params => {
10
+ configurations.clear(); // TODO: clear only the configurations that changed
11
+ for (const cb of didChangeCallbacks) {
12
+ cb(params);
13
+ }
14
+ });
15
+ const didChangeConfiguration = server.initializeParams.capabilities.workspace?.didChangeConfiguration;
16
+ if (didChangeConfiguration?.dynamicRegistration) {
17
+ server.connection.client.register(vscode.DidChangeConfigurationNotification.type);
18
+ }
19
+ });
20
+ return {
21
+ get,
22
+ onDidChange,
23
+ };
24
+ function get(section, scopeUri) {
25
+ if (!server.initializeParams.capabilities.workspace?.configuration) {
26
+ return Promise.resolve(undefined);
27
+ }
28
+ const didChangeConfiguration = server.initializeParams.capabilities.workspace?.didChangeConfiguration;
29
+ if (!scopeUri && didChangeConfiguration) {
30
+ if (!configurations.has(section)) {
31
+ configurations.set(section, getConfigurationWorker(section, scopeUri));
32
+ }
33
+ return configurations.get(section);
34
+ }
35
+ return getConfigurationWorker(section, scopeUri);
36
+ }
37
+ function onDidChange(cb) {
38
+ didChangeCallbacks.add(cb);
39
+ return {
40
+ dispose() {
41
+ didChangeCallbacks.delete(cb);
42
+ },
43
+ };
44
+ }
45
+ async function getConfigurationWorker(section, scopeUri) {
46
+ return (await server.connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
47
+ }
48
+ }
49
+ //# sourceMappingURL=configurations.js.map
@@ -0,0 +1,2 @@
1
+ import type { LanguageServerState } from '../types';
2
+ export declare function register(server: LanguageServerState): void;
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = register;
4
+ const language_service_1 = require("@volar/language-service");
5
+ const vscode_uri_1 = require("vscode-uri");
6
+ const protocol_1 = require("../../protocol");
7
+ function register(server) {
8
+ server.onInitialize(() => {
9
+ const { project } = server;
10
+ const scriptVersions = (0, language_service_1.createUriMap)();
11
+ const scriptVersionSnapshots = new WeakSet();
12
+ server.connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
13
+ const uri = vscode_uri_1.URI.parse(params.uri);
14
+ const languageService = (await project.getLanguageService(uri));
15
+ const tsProject = languageService.context.project.typescript;
16
+ if (tsProject?.configFileName) {
17
+ const { configFileName, uriConverter } = tsProject;
18
+ return { uri: uriConverter.asUri(configFileName).toString() };
19
+ }
20
+ });
21
+ server.connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (document) => {
22
+ const uri = vscode_uri_1.URI.parse(document.uri);
23
+ const languageService = (await project.getLanguageService(uri));
24
+ const documentUri = vscode_uri_1.URI.parse(document.uri);
25
+ const sourceScript = languageService.context.language.scripts.get(documentUri);
26
+ if (sourceScript?.generated) {
27
+ return prune(sourceScript.generated.root);
28
+ }
29
+ function prune(virtualCode) {
30
+ const uri = languageService.context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
31
+ let version = scriptVersions.get(uri) ?? 0;
32
+ if (!scriptVersionSnapshots.has(virtualCode.snapshot)) {
33
+ version++;
34
+ scriptVersions.set(uri, version);
35
+ scriptVersionSnapshots.add(virtualCode.snapshot);
36
+ }
37
+ return {
38
+ fileUri: sourceScript.id.toString(),
39
+ virtualCodeId: virtualCode.id,
40
+ languageId: virtualCode.languageId,
41
+ embeddedCodes: virtualCode.embeddedCodes?.map(prune) || [],
42
+ version,
43
+ disabled: languageService.context.disabledEmbeddedDocumentUris.has(uri),
44
+ };
45
+ }
46
+ });
47
+ server.connection.onRequest(protocol_1.GetVirtualCodeRequest.type, async (params) => {
48
+ const uri = vscode_uri_1.URI.parse(params.fileUri);
49
+ const languageService = (await project.getLanguageService(uri));
50
+ const sourceScript = languageService.context.language.scripts.get(vscode_uri_1.URI.parse(params.fileUri));
51
+ const virtualCode = sourceScript?.generated?.embeddedCodes.get(params.virtualCodeId);
52
+ if (virtualCode) {
53
+ const mappings = {};
54
+ for (const [sourceScript, map] of languageService.context.language.maps.forEach(virtualCode)) {
55
+ mappings[sourceScript.id.toString()] = map.mappings;
56
+ }
57
+ return {
58
+ content: virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength()),
59
+ mappings,
60
+ };
61
+ }
62
+ });
63
+ server.connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
64
+ // webpack compatibility
65
+ const _require = eval('require');
66
+ const fs = _require('fs');
67
+ const uri = vscode_uri_1.URI.parse(params.uri);
68
+ const languageService = (await project.getLanguageService(uri));
69
+ const tsProject = languageService.context.project.typescript;
70
+ if (tsProject) {
71
+ const { languageServiceHost } = tsProject;
72
+ for (const fileName of languageServiceHost.getScriptFileNames()) {
73
+ if (!fs.existsSync(fileName)) {
74
+ // global virtual files
75
+ const snapshot = languageServiceHost.getScriptSnapshot(fileName);
76
+ if (snapshot) {
77
+ fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
78
+ }
79
+ }
80
+ else {
81
+ const uri = tsProject.uriConverter.asUri(fileName);
82
+ const sourceScript = languageService.context.language.scripts.get(uri);
83
+ if (sourceScript?.generated) {
84
+ const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
85
+ if (serviceScript) {
86
+ const { snapshot } = serviceScript.code;
87
+ fs.writeFile(fileName + serviceScript.extension, snapshot.getText(0, snapshot.getLength()), () => { });
88
+ }
89
+ if (sourceScript.generated.languagePlugin.typescript?.getExtraServiceScripts) {
90
+ for (const extraServiceScript of sourceScript.generated.languagePlugin.typescript.getExtraServiceScripts(uri.toString(), sourceScript.generated.root)) {
91
+ const { snapshot } = extraServiceScript.code;
92
+ fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
99
+ });
100
+ server.connection.onRequest(protocol_1.LoadedTSFilesMetaRequest.type, async () => {
101
+ const sourceFilesData = new Map();
102
+ for (const languageService of await project.getExistingLanguageServices()) {
103
+ const tsLanguageService = languageService.context.inject('typescript/languageService');
104
+ const program = tsLanguageService?.getProgram();
105
+ const tsProject = languageService.context.project.typescript;
106
+ if (program && tsProject) {
107
+ const { languageServiceHost, configFileName } = tsProject;
108
+ const projectName = configFileName ?? (languageServiceHost.getCurrentDirectory() + '(inferred)');
109
+ const sourceFiles = program.getSourceFiles() ?? [];
110
+ for (const sourceFile of sourceFiles) {
111
+ if (!sourceFilesData.has(sourceFile)) {
112
+ let nodes = 0;
113
+ sourceFile.forEachChild(function walk(node) {
114
+ nodes++;
115
+ node.forEachChild(walk);
116
+ });
117
+ sourceFilesData.set(sourceFile, {
118
+ projectNames: [],
119
+ size: nodes * 128,
120
+ });
121
+ }
122
+ sourceFilesData.get(sourceFile).projectNames.push(projectName);
123
+ }
124
+ ;
125
+ }
126
+ }
127
+ const result = {
128
+ inputs: {},
129
+ outputs: {},
130
+ };
131
+ for (const [sourceFile, fileData] of sourceFilesData) {
132
+ let key = fileData.projectNames.sort().join(', ');
133
+ if (fileData.projectNames.length >= 2) {
134
+ key = `Shared in ${fileData.projectNames.length} projects (${key})`;
135
+ }
136
+ result.outputs[key] ??= {
137
+ imports: [],
138
+ exports: [],
139
+ entryPoint: '',
140
+ inputs: {},
141
+ bytes: 0,
142
+ };
143
+ result.outputs[key].inputs[sourceFile.fileName] = { bytesInOutput: fileData.size };
144
+ }
145
+ return result;
146
+ });
147
+ server.connection.onNotification(protocol_1.UpdateVirtualCodeStateNotification.type, async (params) => {
148
+ const uri = vscode_uri_1.URI.parse(params.fileUri);
149
+ const languageService = await project.getLanguageService(uri);
150
+ const virtualFileUri = languageService.context.encodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(params.fileUri), params.virtualCodeId);
151
+ if (params.disabled) {
152
+ languageService.context.disabledEmbeddedDocumentUris.set(virtualFileUri, true);
153
+ }
154
+ else {
155
+ languageService.context.disabledEmbeddedDocumentUris.delete(virtualFileUri);
156
+ }
157
+ });
158
+ server.connection.onNotification(protocol_1.UpdateServicePluginStateNotification.type, async (params) => {
159
+ const uri = vscode_uri_1.URI.parse(params.uri);
160
+ const languageService = await project.getLanguageService(uri);
161
+ const plugin = languageService.context.plugins[params.serviceId][1];
162
+ if (params.disabled) {
163
+ languageService.context.disabledServicePlugins.add(plugin);
164
+ }
165
+ else {
166
+ languageService.context.disabledServicePlugins.delete(plugin);
167
+ }
168
+ });
169
+ server.connection.onRequest(protocol_1.GetServicePluginsRequest.type, async (params) => {
170
+ const uri = vscode_uri_1.URI.parse(params.uri);
171
+ const languageService = await project.getLanguageService(uri);
172
+ const result = [];
173
+ for (let pluginIndex = 0; pluginIndex < languageService.context.plugins.length; pluginIndex++) {
174
+ const plugin = languageService.context.plugins[pluginIndex];
175
+ result.push({
176
+ id: pluginIndex,
177
+ name: plugin[0].name,
178
+ disabled: languageService.context.disabledServicePlugins.has(plugin[1]),
179
+ features: Object.keys(plugin[1]),
180
+ });
181
+ }
182
+ return result;
183
+ });
184
+ });
185
+ }
186
+ //# sourceMappingURL=editorFeatures.js.map
@@ -0,0 +1,8 @@
1
+ import { FileSystem } from '@volar/language-service';
2
+ import { URI } from 'vscode-uri';
3
+ export declare function register(documents: ReturnType<typeof import('./textDocuments').register>, fileWatcher: ReturnType<typeof import('./fileWatcher').register>): {
4
+ readFile(uri: URI): string | Thenable<string | undefined>;
5
+ stat(uri: URI): import("@volar/language-service").FileStat | Thenable<import("@volar/language-service").FileStat | undefined>;
6
+ readDirectory(uri: URI): import("@volar/language-service").ProviderResult<[string, import("@volar/language-service").FileType][]>;
7
+ install(scheme: string, provider: FileSystem): void;
8
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = register;
4
+ const language_service_1 = require("@volar/language-service");
5
+ const vscode = require("vscode-languageserver");
6
+ const vscode_uri_1 = require("vscode-uri");
7
+ function register(documents, fileWatcher) {
8
+ const providers = new Map();
9
+ const readFileCache = (0, language_service_1.createUriMap)();
10
+ const statCache = (0, language_service_1.createUriMap)();
11
+ const readDirectoryCache = (0, language_service_1.createUriMap)();
12
+ documents.onDidSave(({ document }) => {
13
+ const uri = vscode_uri_1.URI.parse(document.uri);
14
+ readFileCache.set(uri, document.getText());
15
+ statCache.delete(uri);
16
+ });
17
+ fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
18
+ for (const change of changes) {
19
+ const changeUri = vscode_uri_1.URI.parse(change.uri);
20
+ const dir = vscode_uri_1.URI.parse(change.uri.substring(0, change.uri.lastIndexOf('/')));
21
+ if (change.type === vscode.FileChangeType.Deleted) {
22
+ readFileCache.set(changeUri, undefined);
23
+ statCache.set(changeUri, undefined);
24
+ readDirectoryCache.delete(dir);
25
+ }
26
+ else if (change.type === vscode.FileChangeType.Changed) {
27
+ readFileCache.delete(changeUri);
28
+ statCache.delete(changeUri);
29
+ }
30
+ else if (change.type === vscode.FileChangeType.Created) {
31
+ readFileCache.delete(changeUri);
32
+ statCache.delete(changeUri);
33
+ readDirectoryCache.delete(dir);
34
+ }
35
+ }
36
+ });
37
+ return {
38
+ readFile(uri) {
39
+ if (!readFileCache.has(uri)) {
40
+ readFileCache.set(uri, providers.get(uri.scheme)?.readFile(uri));
41
+ }
42
+ return readFileCache.get(uri);
43
+ },
44
+ stat(uri) {
45
+ if (!statCache.has(uri)) {
46
+ statCache.set(uri, providers.get(uri.scheme)?.stat(uri));
47
+ }
48
+ return statCache.get(uri);
49
+ },
50
+ readDirectory(uri) {
51
+ if (!readDirectoryCache.has(uri)) {
52
+ readDirectoryCache.set(uri, providers.get(uri.scheme)?.readDirectory(uri) ?? []);
53
+ }
54
+ return readDirectoryCache.get(uri);
55
+ },
56
+ install(scheme, provider) {
57
+ providers.set(scheme, provider);
58
+ },
59
+ };
60
+ }
61
+ //# sourceMappingURL=fileSystem.js.map
@@ -0,0 +1,9 @@
1
+ import { Disposable } from '@volar/language-service';
2
+ import * as vscode from 'vscode-languageserver';
3
+ import { LanguageServerState } from '../types';
4
+ export declare function register(server: LanguageServerState): {
5
+ watchFiles: (patterns: string[]) => Promise<Disposable>;
6
+ onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
7
+ dispose: () => void;
8
+ };
9
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.register = register;
4
+ const vscode = require("vscode-languageserver");
5
+ function register(server) {
6
+ let watchFilesDisposableCounter = 0;
7
+ let watchFilesDisposable;
8
+ const didChangeWatchedFilesCallbacks = new Set();
9
+ return {
10
+ watchFiles,
11
+ onDidChangeWatchedFiles,
12
+ };
13
+ async function watchFiles(patterns) {
14
+ const disposables = [];
15
+ const didChangeWatchedFiles = server.initializeParams.capabilities.workspace?.didChangeWatchedFiles;
16
+ const fileOperations = server.initializeParams.capabilities.workspace?.fileOperations;
17
+ if (didChangeWatchedFiles) {
18
+ if (watchFilesDisposableCounter === 0) {
19
+ watchFilesDisposable = server.connection.onDidChangeWatchedFiles(e => {
20
+ for (const cb of didChangeWatchedFilesCallbacks) {
21
+ cb(e);
22
+ }
23
+ });
24
+ }
25
+ watchFilesDisposableCounter++;
26
+ disposables.push({
27
+ dispose() {
28
+ watchFilesDisposableCounter--;
29
+ if (watchFilesDisposableCounter === 0) {
30
+ watchFilesDisposable?.dispose();
31
+ }
32
+ }
33
+ });
34
+ }
35
+ if (didChangeWatchedFiles?.dynamicRegistration) {
36
+ disposables.push(await server.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
37
+ watchers: patterns.map(pattern => ({ globPattern: pattern })),
38
+ }));
39
+ }
40
+ if (fileOperations?.dynamicRegistration && fileOperations.willRename) {
41
+ disposables.push(await server.connection.client.register(vscode.WillRenameFilesRequest.type, {
42
+ filters: patterns.map(pattern => ({ pattern: { glob: pattern } })),
43
+ }));
44
+ }
45
+ return {
46
+ dispose() {
47
+ for (const disposable of disposables) {
48
+ disposable.dispose();
49
+ }
50
+ disposables.length = 0;
51
+ },
52
+ };
53
+ }
54
+ function onDidChangeWatchedFiles(cb) {
55
+ didChangeWatchedFilesCallbacks.add(cb);
56
+ return {
57
+ dispose: () => {
58
+ didChangeWatchedFilesCallbacks.delete(cb);
59
+ },
60
+ };
61
+ }
62
+ }
63
+ //# sourceMappingURL=fileWatcher.js.map
@@ -0,0 +1,4 @@
1
+ import type { LanguageServerState } from '../types.js';
2
+ export declare function register(server: LanguageServerState, documents: ReturnType<typeof import('./textDocuments')['register']>, configurations: ReturnType<typeof import('./configurations')['register']>): {
3
+ requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
4
+ };