@volar/language-server 1.7.5 → 1.7.6

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.
package/out/node/index.js CHANGED
@@ -78,7 +78,9 @@ function startLanguageServer(connection, ...plugins) {
78
78
  };
79
79
  }
80
80
  }
81
- catch { }
81
+ catch {
82
+ return undefined;
83
+ }
82
84
  }
83
85
  },
84
86
  readFile(uri, encoding) {
@@ -93,7 +95,9 @@ function startLanguageServer(connection, ...plugins) {
93
95
  }
94
96
  return fs.readFileSync(uriToFileName(uri), { encoding: encoding ?? 'utf-8' });
95
97
  }
96
- catch { }
98
+ catch {
99
+ return undefined;
100
+ }
97
101
  }
98
102
  if (uri.startsWith('http://') || uri.startsWith('https://')) {
99
103
  return (0, http_1.default)(uri);
@@ -101,14 +105,19 @@ function startLanguageServer(connection, ...plugins) {
101
105
  },
102
106
  readDirectory(uri) {
103
107
  if (uri.startsWith('file://')) {
104
- const dirName = uriToFileName(uri);
105
- const files = fs.existsSync(dirName) ? fs.readdirSync(dirName, { withFileTypes: true }) : [];
106
- return files.map(file => {
107
- return [file.name, file.isFile() ? language_service_1.FileType.File
108
- : file.isDirectory() ? language_service_1.FileType.Directory
109
- : file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
110
- : language_service_1.FileType.Unknown];
111
- });
108
+ try {
109
+ const dirName = uriToFileName(uri);
110
+ const files = fs.readdirSync(dirName, { withFileTypes: true });
111
+ return files.map(file => {
112
+ return [file.name, file.isFile() ? language_service_1.FileType.File
113
+ : file.isDirectory() ? language_service_1.FileType.Directory
114
+ : file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
115
+ : language_service_1.FileType.Unknown];
116
+ });
117
+ }
118
+ catch {
119
+ return [];
120
+ }
112
121
  }
113
122
  return [];
114
123
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,9 +15,9 @@
15
15
  "directory": "packages/language-server"
16
16
  },
17
17
  "dependencies": {
18
- "@volar/language-core": "1.7.5",
19
- "@volar/language-service": "1.7.5",
20
- "@volar/typescript": "1.7.5",
18
+ "@volar/language-core": "1.7.6",
19
+ "@volar/language-service": "1.7.6",
20
+ "@volar/typescript": "1.7.6",
21
21
  "@vscode/l10n": "^0.0.11",
22
22
  "request-light": "^0.7.0",
23
23
  "typesafe-path": "^0.2.2",
@@ -27,7 +27,7 @@
27
27
  "vscode-uri": "^3.0.7"
28
28
  },
29
29
  "devDependencies": {
30
- "@volar/source-map": "1.7.5"
30
+ "@volar/source-map": "1.7.6"
31
31
  },
32
- "gitHead": "57fa4f05df4c593aa4a7b15c159f864d407bd1ac"
32
+ "gitHead": "b2dbe05318c06658ae97a65f9bc6d1badc55a81b"
33
33
  }
@@ -1,2 +0,0 @@
1
- import { FileSystemHost, InitializationOptions, RuntimeEnvironment } from '../types';
2
- export declare function createWebFileSystemHost(_0: any, _1: any, env: RuntimeEnvironment, initOptions: InitializationOptions): FileSystemHost;
@@ -1,287 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWebFileSystemHost = void 0;
4
- const path = require("typesafe-path");
5
- const vscode_html_languageservice_1 = require("vscode-html-languageservice");
6
- const vscode = require("vscode-languageserver");
7
- const vscode_uri_1 = require("vscode-uri");
8
- const protocol_1 = require("../protocol");
9
- const utilities_1 = require("./typescript/utilities");
10
- const uriMap_1 = require("../common/utils/uriMap");
11
- function createWebFileSystemHost(_0, _1, env, initOptions) {
12
- const instances = (0, uriMap_1.createUriMap)(env.fileNameToUri);
13
- const onDidChangeWatchedFilesCb = new Set();
14
- const root = {
15
- dirs: new Map(),
16
- files: new Map(),
17
- requested: false,
18
- };
19
- const fetchTasks = [];
20
- const changes = [];
21
- const onReadyCb = [];
22
- let runningRead = false;
23
- let runningStat = false;
24
- let connection;
25
- return {
26
- ready(_connection) {
27
- connection = _connection;
28
- connection.onDidChangeWatchedFiles(params => {
29
- for (const change of params.changes) {
30
- const fsPath = env.uriToFileName(change.uri);
31
- const dir = getDir(path.dirname(fsPath));
32
- const name = path.basename(fsPath);
33
- if (!dir.files.has(name)) {
34
- dir.files.set(name, {});
35
- }
36
- if (change.type === vscode.FileChangeType.Created || change.type === vscode.FileChangeType.Changed) {
37
- dir.files.get(name).exists = true;
38
- }
39
- else if (change.type === vscode.FileChangeType.Deleted) {
40
- if (!dir.files.has(name)) {
41
- dir.files.set(name, {});
42
- }
43
- }
44
- }
45
- changes.push(...params.changes);
46
- fireChanges();
47
- });
48
- for (const cb of onReadyCb) {
49
- cb(connection);
50
- }
51
- onReadyCb.length = 0;
52
- },
53
- reload() {
54
- root.dirs.clear();
55
- root.files.clear();
56
- root.requested = false;
57
- },
58
- getWorkspaceFileSystem(rootUri) {
59
- let sys = instances.uriGet(rootUri.toString());
60
- if (!sys) {
61
- sys = createWorkspaceFileSystem(rootUri);
62
- instances.uriSet(rootUri.toString(), sys);
63
- }
64
- return sys;
65
- },
66
- onDidChangeWatchedFiles: cb => {
67
- onDidChangeWatchedFilesCb.add(cb);
68
- return () => onDidChangeWatchedFilesCb.delete(cb);
69
- },
70
- };
71
- function createWorkspaceFileSystem(rootUri) {
72
- const rootPath = env.uriToFileName(rootUri.toString());
73
- return {
74
- args: [],
75
- newLine: '\n',
76
- useCaseSensitiveFileNames: false,
77
- getCurrentDirectory: () => env.uriToFileName(rootUri.toString()),
78
- fileExists,
79
- readFile,
80
- readDirectory,
81
- getDirectories,
82
- resolvePath,
83
- // ignore
84
- write: () => { },
85
- writeFile: () => { },
86
- createDirectory: () => { },
87
- realpath: path => path,
88
- directoryExists: () => true,
89
- exit: () => { },
90
- getExecutingFilePath: () => rootPath + '/__fake__.js',
91
- };
92
- function resolvePath(fsPath) {
93
- return path.resolve(fsPath);
94
- }
95
- function fileExists(fsPath) {
96
- fsPath = resolvePath(fsPath);
97
- const uri = env.fileNameToUri(fsPath);
98
- const dirPath = path.dirname(fsPath);
99
- if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
100
- if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
101
- return false;
102
- }
103
- readFile(fsPath);
104
- const file = getDir(dirPath).files.get(path.basename(fsPath));
105
- return file?.exists ?? false;
106
- }
107
- readDirectory(dirPath);
108
- const file = getDir(path.dirname(fsPath)).files.get(path.basename(fsPath));
109
- return file?.exists ?? false;
110
- }
111
- function readFile(fsPath) {
112
- fsPath = resolvePath(fsPath);
113
- const uri = env.fileNameToUri(fsPath);
114
- const dirPath = path.dirname(fsPath);
115
- const dir = getDir(dirPath);
116
- const name = path.basename(fsPath);
117
- if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
118
- if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
119
- return dir.files.get(name)?.text || '';
120
- }
121
- readFileWorker();
122
- return dir.files.get(name)?.text || '';
123
- }
124
- readFileWorker();
125
- return dir.files.get(name)?.text || '';
126
- function readFileWorker() {
127
- if (connection) {
128
- fetch('load', fsPath, readFileAsync(connection, fsPath, dir));
129
- }
130
- else {
131
- onReadyCb.push((connection) => fetch('load', fsPath, readFileAsync(connection, fsPath, dir)));
132
- }
133
- }
134
- async function readFileAsync(connection, fsPath, dir) {
135
- const name = path.basename(fsPath);
136
- if (!dir.files.has(name)) {
137
- dir.files.set(name, {});
138
- }
139
- const file = dir.files.get(name);
140
- if (file.requested) {
141
- return;
142
- }
143
- file.requested = true;
144
- const uri = env.fileNameToUri(fsPath);
145
- const data = await connection.sendRequest(protocol_1.FsReadFileRequest.type, resolveRequestUrl(uri));
146
- const text = data ? new TextDecoder('utf8').decode(data) : undefined;
147
- if (text?.length) {
148
- file.exists = true;
149
- file.text = text;
150
- changes.push({ uri, type: vscode.FileChangeType.Changed });
151
- }
152
- }
153
- }
154
- function readDirectory(fsPath, extensions, exclude, include, depth) {
155
- fsPath = resolvePath(fsPath);
156
- return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootPath, depth, (dirPath) => {
157
- dirPath = resolvePath(dirPath);
158
- readDirectoryWorker(dirPath);
159
- const dir = getDir(dirPath);
160
- return {
161
- files: [...dir.files.entries()].filter(([_, file]) => file.exists).map(([name]) => name),
162
- directories: [...dir.dirs.entries()].filter(([_, dir]) => dir.exists).map(([name]) => name),
163
- };
164
- }, path => path);
165
- }
166
- // for import path completion
167
- function getDirectories(fsPath) {
168
- fsPath = resolvePath(fsPath);
169
- readDirectoryWorker(fsPath);
170
- const dir = getDir(fsPath);
171
- return [...dir.dirs.entries()].filter(([_, dir]) => dir.exists).map(([name]) => name);
172
- }
173
- function readDirectoryWorker(fsPath) {
174
- if (connection) {
175
- fetch('directory', fsPath, readDirectoryAsync(connection, fsPath));
176
- }
177
- else {
178
- onReadyCb.push((connection) => fetch('directory', fsPath, readDirectoryAsync(connection, fsPath)));
179
- }
180
- }
181
- async function readDirectoryAsync(connection, fsPath) {
182
- const dir = getDir(fsPath);
183
- if (dir.requested) {
184
- return;
185
- }
186
- dir.requested = true;
187
- const uri = env.fileNameToUri(fsPath);
188
- const result = await connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, resolveRequestUrl(uri));
189
- for (const [name, fileType] of result) {
190
- if (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink) {
191
- if (!dir.files.has(name)) {
192
- dir.files.set(name, {});
193
- }
194
- const file = dir.files.get(name);
195
- if (!file.exists) {
196
- file.exists = true;
197
- changes.push({
198
- uri: env.fileNameToUri(path.join(fsPath, name)),
199
- type: vscode.FileChangeType.Created,
200
- });
201
- }
202
- }
203
- else if (fileType === vscode_html_languageservice_1.FileType.Directory && !dir.dirs.has(name)) {
204
- const childDir = getDirFromDir(dir, name);
205
- childDir.exists = true;
206
- }
207
- }
208
- }
209
- }
210
- async function fetch(action, fileName, p) {
211
- fetchTasks.push([action, fileName, p]);
212
- if (runningRead === false) {
213
- let toUpdate;
214
- runningRead = true;
215
- const progress = await connection?.window.createWorkDoneProgress();
216
- progress?.begin('');
217
- while (fetchTasks.length) {
218
- const current = fetchTasks.shift();
219
- updateProgress(current[0] + ' ' + vscode_uri_1.URI.parse(env.fileNameToUri(current[1])).fsPath);
220
- await current[2];
221
- }
222
- progress?.done();
223
- runningRead = false;
224
- fireChanges();
225
- function updateProgress(text) {
226
- clearTimeout(toUpdate);
227
- toUpdate = setTimeout(() => {
228
- progress?.report(text);
229
- toUpdate = undefined;
230
- }, 0);
231
- }
232
- }
233
- }
234
- function resolveRequestUrl(uri) {
235
- if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
236
- let fileName = env.uriToFileName(uri);
237
- for (const [key, version] of Object.entries(initOptions.typescript.versions || {})) {
238
- if (fileName.startsWith(`/node_modules/${key}/`)) {
239
- fileName = fileName.replace(`/node_modules/${key}/`, `/node_modules/${key}@${version}/`);
240
- return env.fileNameToUri(fileName);
241
- }
242
- }
243
- }
244
- return uri;
245
- }
246
- async function fireChanges() {
247
- if (runningRead || runningStat) {
248
- return;
249
- }
250
- const _changes = [...changes];
251
- changes.length = 0;
252
- for (const cb of [...onDidChangeWatchedFilesCb]) {
253
- if (onDidChangeWatchedFilesCb.has(cb)) {
254
- await cb({ changes: _changes });
255
- }
256
- }
257
- }
258
- function getDir(dirPath) {
259
- const dirNames = [];
260
- let currentDirPath = dirPath;
261
- let currentDirName = path.basename(currentDirPath);
262
- while (currentDirName !== '') {
263
- dirNames.push(currentDirName);
264
- currentDirPath = path.dirname(currentDirPath);
265
- currentDirName = path.basename(currentDirPath);
266
- }
267
- let currentDir = root;
268
- for (let i = dirNames.length - 1; i >= 0; i--) {
269
- const nextDirName = dirNames[i];
270
- currentDir = getDirFromDir(currentDir, nextDirName);
271
- }
272
- return currentDir;
273
- }
274
- function getDirFromDir(dir, name) {
275
- let target = dir.dirs.get(name);
276
- if (!target) {
277
- target = {
278
- dirs: new Map(),
279
- files: new Map(),
280
- };
281
- dir.dirs.set(name, target);
282
- }
283
- return target;
284
- }
285
- }
286
- exports.createWebFileSystemHost = createWebFileSystemHost;
287
- //# sourceMappingURL=fileSystems.js.map
@@ -1,83 +0,0 @@
1
- import { Comparer, Comparison, SortedReadonlyArray } from "./corePublic";
2
- /**
3
- * Iterates through `array` by index and performs the callback on each element of array until the callback
4
- * returns a falsey value, then returns false.
5
- * If no such value is found, the callback is applied to each element of array and `true` is returned.
6
- */
7
- export declare function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean;
8
- /** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
9
- export declare function findIndex<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): number;
10
- export declare function indexOfAnyCharCode(text: string, charCodes: readonly number[], start?: number): number;
11
- export declare function map<T, U>(array: readonly T[], f: (x: T, i: number) => U): U[];
12
- export declare function map<T, U>(array: readonly T[] | undefined, f: (x: T, i: number) => U): U[] | undefined;
13
- /**
14
- * Flattens an array containing a mix of array or non-array elements.
15
- *
16
- * @param array The array to flatten.
17
- */
18
- export declare function flatten<T>(array: T[][] | readonly (T | readonly T[] | undefined)[]): T[];
19
- /**
20
- * Maps an array. If the mapped value is an array, it is spread into the result.
21
- *
22
- * @param array The array to map.
23
- * @param mapfn The callback used to map the result into one or more values.
24
- */
25
- export declare function flatMap<T, U>(array: readonly T[] | undefined, mapfn: (x: T, i: number) => U | readonly U[] | undefined): readonly U[];
26
- export declare function some<T>(array: readonly T[] | undefined): array is readonly T[];
27
- export declare function some<T>(array: readonly T[] | undefined, predicate: (value: T) => boolean): boolean;
28
- /**
29
- * Returns a new sorted array.
30
- */
31
- export declare function sort<T>(array: readonly T[], comparer?: Comparer<T>): SortedReadonlyArray<T>;
32
- /**
33
- * Returns the last element of an array if non-empty, `undefined` otherwise.
34
- */
35
- export declare function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefined;
36
- export declare function last<T>(array: readonly T[]): T;
37
- /**
38
- * Compare the equality of two strings using a case-sensitive ordinal comparison.
39
- *
40
- * Case-sensitive comparisons compare both strings one code-point at a time using the integer
41
- * value of each code-point after applying `toUpperCase` to each string. We always map both
42
- * strings to their upper-case form as some unicode characters do not properly round-trip to
43
- * lowercase (such as `ẞ` (German sharp capital s)).
44
- */
45
- export declare function equateStringsCaseInsensitive(a: string, b: string): boolean;
46
- /**
47
- * Compare the equality of two strings using a case-sensitive ordinal comparison.
48
- *
49
- * Case-sensitive comparisons compare both strings one code-point at a time using the
50
- * integer value of each code-point.
51
- */
52
- export declare function equateStringsCaseSensitive(a: string, b: string): boolean;
53
- /**
54
- * Compare two strings using a case-insensitive ordinal comparison.
55
- *
56
- * Ordinal comparisons are based on the difference between the unicode code points of both
57
- * strings. Characters with multiple unicode representations are considered unequal. Ordinal
58
- * comparisons provide predictable ordering, but place "a" after "B".
59
- *
60
- * Case-insensitive comparisons compare both strings one code-point at a time using the integer
61
- * value of each code-point after applying `toUpperCase` to each string. We always map both
62
- * strings to their upper-case form as some unicode characters do not properly round-trip to
63
- * lowercase (such as `ẞ` (German sharp capital s)).
64
- */
65
- declare function compareStringsCaseInsensitive(a: string, b: string): Comparison;
66
- /**
67
- * Compare two strings using a case-sensitive ordinal comparison.
68
- *
69
- * Ordinal comparisons are based on the difference between the unicode code points of both
70
- * strings. Characters with multiple unicode representations are considered unequal. Ordinal
71
- * comparisons provide predictable ordering, but place "a" after "B".
72
- *
73
- * Case-sensitive comparisons compare both strings one code-point at a time using the integer
74
- * value of each code-point.
75
- */
76
- export declare function compareStringsCaseSensitive(a: string | undefined, b: string | undefined): Comparison;
77
- export declare function getStringComparer(ignoreCase?: boolean): typeof compareStringsCaseInsensitive;
78
- export declare function endsWith(str: string, suffix: string): boolean;
79
- export declare function stringContains(str: string, substring: string): boolean;
80
- type GetCanonicalFileName = (fileName: string) => string;
81
- export declare function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName;
82
- export declare function startsWith(str: string, prefix: string): boolean;
83
- export {};