@volar/typescript 2.0.0-alpha.8 → 2.0.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 (40) hide show
  1. package/lib/documentRegistry.d.ts +2 -2
  2. package/lib/node/decorateLanguageService.d.ts +3 -3
  3. package/lib/node/decorateLanguageService.js +47 -42
  4. package/lib/node/decorateLanguageServiceHost.d.ts +4 -4
  5. package/lib/node/decorateLanguageServiceHost.js +15 -15
  6. package/lib/node/decorateProgram.d.ts +3 -3
  7. package/lib/node/decorateProgram.js +1 -1
  8. package/lib/node/dedupe.d.ts +1 -1
  9. package/lib/node/proxyCreateProgram.d.ts +2 -2
  10. package/lib/node/proxyCreateProgram.js +10 -13
  11. package/lib/node/transform.d.ts +7 -7
  12. package/lib/node/transform.js +12 -10
  13. package/lib/node/utils.d.ts +6 -2
  14. package/lib/node/utils.js +7 -10
  15. package/lib/protocol/createProject.d.ts +6 -3
  16. package/lib/protocol/createProject.js +95 -119
  17. package/lib/protocol/createSys.d.ts +3 -3
  18. package/lib/protocol/createSys.js +11 -11
  19. package/lib/quickstart/createAsyncLanguageServicePlugin.d.ts +3 -0
  20. package/lib/quickstart/createAsyncLanguageServicePlugin.js +89 -0
  21. package/lib/quickstart/createAsyncTSServerPlugin.d.ts +3 -0
  22. package/lib/quickstart/createAsyncTSServerPlugin.js +89 -0
  23. package/lib/quickstart/createLanguageServicePlugin.d.ts +4 -0
  24. package/lib/quickstart/createLanguageServicePlugin.js +70 -0
  25. package/lib/quickstart/createTSServerPlugin.d.ts +4 -0
  26. package/lib/quickstart/createTSServerPlugin.js +70 -0
  27. package/lib/{starters → quickstart}/runTsc.d.ts +2 -2
  28. package/lib/typescript/core.js +16 -8
  29. package/lib/typescript/path.js +42 -21
  30. package/lib/typescript/utilities.js +6 -3
  31. package/lib/utils/resolveModuleName.d.ts +3 -0
  32. package/lib/utils/resolveModuleName.js +47 -0
  33. package/package.json +4 -4
  34. package/lib/protocol/getProgram.d.ts +0 -3
  35. package/lib/protocol/getProgram.js +0 -146
  36. package/lib/starters/createAsyncTSServerPlugin.d.ts +0 -3
  37. package/lib/starters/createAsyncTSServerPlugin.js +0 -82
  38. package/lib/starters/createTSServerPlugin.d.ts +0 -7
  39. package/lib/starters/createTSServerPlugin.js +0 -60
  40. /package/lib/{starters → quickstart}/runTsc.js +0 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arrayItemsEqual = exports.createLanguageServicePlugin = void 0;
4
+ const decorateLanguageService_1 = require("../node/decorateLanguageService");
5
+ const decorateLanguageServiceHost_1 = require("../node/decorateLanguageServiceHost");
6
+ const language_core_1 = require("@volar/language-core");
7
+ const externalFiles = new WeakMap();
8
+ const projectExternalFileExtensions = new WeakMap();
9
+ const decoratedLanguageServices = new WeakSet();
10
+ const decoratedLanguageServiceHosts = new WeakSet();
11
+ function createLanguageServicePlugin(loadLanguagePlugins) {
12
+ return modules => {
13
+ const { typescript: ts } = modules;
14
+ const pluginModule = {
15
+ create(info) {
16
+ if (!decoratedLanguageServices.has(info.languageService)
17
+ && !decoratedLanguageServiceHosts.has(info.languageServiceHost)) {
18
+ decoratedLanguageServices.add(info.languageService);
19
+ decoratedLanguageServiceHosts.add(info.languageServiceHost);
20
+ const languagePlugins = loadLanguagePlugins(ts, info);
21
+ const extensions = languagePlugins
22
+ .map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])
23
+ .flat();
24
+ projectExternalFileExtensions.set(info.project, extensions);
25
+ const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
26
+ const files = (0, language_core_1.createFileRegistry)(languagePlugins, ts.sys.useCaseSensitiveFileNames, fileName => {
27
+ const snapshot = getScriptSnapshot(fileName);
28
+ if (snapshot) {
29
+ files.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
30
+ }
31
+ else {
32
+ files.delete(fileName);
33
+ }
34
+ });
35
+ (0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
36
+ (0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts);
37
+ }
38
+ return info.languageService;
39
+ },
40
+ getExternalFiles(project, updateLevel = 0) {
41
+ if (updateLevel >= (1)
42
+ || !externalFiles.has(project)) {
43
+ const oldFiles = externalFiles.get(project);
44
+ const newFiles = (0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, projectExternalFileExtensions.get(project));
45
+ externalFiles.set(project, newFiles);
46
+ if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) {
47
+ project.refreshDiagnostics();
48
+ }
49
+ }
50
+ return externalFiles.get(project);
51
+ },
52
+ };
53
+ return pluginModule;
54
+ };
55
+ }
56
+ exports.createLanguageServicePlugin = createLanguageServicePlugin;
57
+ function arrayItemsEqual(a, b) {
58
+ if (a.length !== b.length) {
59
+ return false;
60
+ }
61
+ const set = new Set(a);
62
+ for (const file of b) {
63
+ if (!set.has(file)) {
64
+ return false;
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+ exports.arrayItemsEqual = arrayItemsEqual;
70
+ //# sourceMappingURL=createLanguageServicePlugin.js.map
@@ -0,0 +1,4 @@
1
+ import type * as ts from 'typescript';
2
+ import { LanguagePlugin } from '@volar/language-core';
3
+ export declare function createTSServerPlugin(init: (ts: typeof import('typescript'), info: ts.server.PluginCreateInfo) => LanguagePlugin[]): ts.server.PluginModuleFactory;
4
+ export declare function arrayItemsEqual(a: string[], b: string[]): boolean;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arrayItemsEqual = exports.createTSServerPlugin = void 0;
4
+ const decorateLanguageService_1 = require("../node/decorateLanguageService");
5
+ const decorateLanguageServiceHost_1 = require("../node/decorateLanguageServiceHost");
6
+ const language_core_1 = require("@volar/language-core");
7
+ const externalFiles = new WeakMap();
8
+ const projectExternalFileExtensions = new WeakMap();
9
+ const decoratedLanguageServices = new WeakSet();
10
+ const decoratedLanguageServiceHosts = new WeakSet();
11
+ function createTSServerPlugin(init) {
12
+ return modules => {
13
+ const { typescript: ts } = modules;
14
+ const pluginModule = {
15
+ create(info) {
16
+ if (!decoratedLanguageServices.has(info.languageService)
17
+ && !decoratedLanguageServiceHosts.has(info.languageServiceHost)) {
18
+ decoratedLanguageServices.add(info.languageService);
19
+ decoratedLanguageServiceHosts.add(info.languageServiceHost);
20
+ const languagePlugins = init(ts, info);
21
+ const extensions = languagePlugins
22
+ .map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [])
23
+ .flat();
24
+ projectExternalFileExtensions.set(info.project, extensions);
25
+ const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
26
+ const files = (0, language_core_1.createFileRegistry)(languagePlugins, ts.sys.useCaseSensitiveFileNames, fileName => {
27
+ const snapshot = getScriptSnapshot(fileName);
28
+ if (snapshot) {
29
+ files.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
30
+ }
31
+ else {
32
+ files.delete(fileName);
33
+ }
34
+ });
35
+ (0, decorateLanguageService_1.decorateLanguageService)(files, info.languageService);
36
+ (0, decorateLanguageServiceHost_1.decorateLanguageServiceHost)(files, info.languageServiceHost, ts);
37
+ }
38
+ return info.languageService;
39
+ },
40
+ getExternalFiles(project, updateLevel = 0) {
41
+ if (updateLevel >= (1)
42
+ || !externalFiles.has(project)) {
43
+ const oldFiles = externalFiles.get(project);
44
+ const newFiles = (0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, projectExternalFileExtensions.get(project));
45
+ externalFiles.set(project, newFiles);
46
+ if (oldFiles && !arrayItemsEqual(oldFiles, newFiles)) {
47
+ project.refreshDiagnostics();
48
+ }
49
+ }
50
+ return externalFiles.get(project);
51
+ },
52
+ };
53
+ return pluginModule;
54
+ };
55
+ }
56
+ exports.createTSServerPlugin = createTSServerPlugin;
57
+ function arrayItemsEqual(a, b) {
58
+ if (a.length !== b.length) {
59
+ return false;
60
+ }
61
+ const set = new Set(a);
62
+ for (const file of b) {
63
+ if (!set.has(file)) {
64
+ return false;
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+ exports.arrayItemsEqual = arrayItemsEqual;
70
+ //# sourceMappingURL=createTSServerPlugin.js.map
@@ -1,4 +1,4 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
1
+ import type * as ts from 'typescript';
2
2
  import type { LanguagePlugin } from '@volar/language-core';
3
- export declare let getLanguagePlugins: (ts: typeof import('typescript/lib/tsserverlibrary'), options: ts.CreateProgramOptions) => LanguagePlugin[];
3
+ export declare let getLanguagePlugins: (ts: typeof import('typescript'), options: ts.CreateProgramOptions) => LanguagePlugin[];
4
4
  export declare function runTsc(tscPath: string, extensions: string[], _getLanguagePlugins: typeof getLanguagePlugins): void;
@@ -21,8 +21,9 @@ function every(array, callback) {
21
21
  exports.every = every;
22
22
  /** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
23
23
  function findIndex(array, predicate, startIndex) {
24
- if (array === undefined)
24
+ if (array === undefined) {
25
25
  return -1;
26
+ }
26
27
  for (let i = startIndex ?? 0; i < array.length; i++) {
27
28
  if (predicate(array[i], i)) {
28
29
  return i;
@@ -125,10 +126,12 @@ exports.some = some;
125
126
  // function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined;
126
127
  // function append<T>(to: Push<T>, value: T | undefined): void;
127
128
  function append(to, value) {
128
- if (value === undefined)
129
+ if (value === undefined) {
129
130
  return to;
130
- if (to === undefined)
131
+ }
132
+ if (to === undefined) {
131
133
  return [value];
134
+ }
132
135
  to.push(value);
133
136
  return to;
134
137
  }
@@ -140,10 +143,12 @@ function toOffset(array, offset) {
140
143
  return offset < 0 ? array.length + offset : offset;
141
144
  }
142
145
  function addRange(to, from, start, end) {
143
- if (from === undefined || from.length === 0)
146
+ if (from === undefined || from.length === 0) {
144
147
  return to;
145
- if (to === undefined)
148
+ }
149
+ if (to === undefined) {
146
150
  return from.slice(start, end);
151
+ }
147
152
  start = start === undefined ? 0 : toOffset(from, start);
148
153
  end = end === undefined ? from.length : toOffset(from, end);
149
154
  for (let i = start; i < end && i < from.length; i++) {
@@ -273,12 +278,15 @@ function compareComparableValues(a, b) {
273
278
  * lowercase (such as `ẞ` (German sharp capital s)).
274
279
  */
275
280
  function compareStringsCaseInsensitive(a, b) {
276
- if (a === b)
281
+ if (a === b) {
277
282
  return 0 /* Comparison.EqualTo */;
278
- if (a === undefined)
283
+ }
284
+ if (a === undefined) {
279
285
  return -1 /* Comparison.LessThan */;
280
- if (b === undefined)
286
+ }
287
+ if (b === undefined) {
281
288
  return 1 /* Comparison.GreaterThan */;
289
+ }
282
290
  a = a.toUpperCase();
283
291
  b = b.toUpperCase();
284
292
  return a < b ? -1 /* Comparison.LessThan */ : a > b ? 1 /* Comparison.GreaterThan */ : 0 /* Comparison.EqualTo */;
@@ -56,12 +56,14 @@ function isVolumeCharacter(charCode) {
56
56
  }
57
57
  function getFileUrlVolumeSeparatorEnd(url, start) {
58
58
  const ch0 = url.charCodeAt(start);
59
- if (ch0 === 58 /* CharacterCodes.colon */)
59
+ if (ch0 === 58 /* CharacterCodes.colon */) {
60
60
  return start + 1;
61
+ }
61
62
  if (ch0 === 37 /* CharacterCodes.percent */ && url.charCodeAt(start + 1) === 51 /* CharacterCodes._3 */) {
62
63
  const ch2 = url.charCodeAt(start + 2);
63
- if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */)
64
+ if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */) {
64
65
  return start + 3;
66
+ }
65
67
  }
66
68
  return -1;
67
69
  }
@@ -70,25 +72,30 @@ function getFileUrlVolumeSeparatorEnd(url, start) {
70
72
  * If the root is part of a URL, the twos-complement of the root length is returned.
71
73
  */
72
74
  function getEncodedRootLength(path) {
73
- if (!path)
75
+ if (!path) {
74
76
  return 0;
77
+ }
75
78
  const ch0 = path.charCodeAt(0);
76
79
  // POSIX or UNC
77
80
  if (ch0 === 47 /* CharacterCodes.slash */ || ch0 === 92 /* CharacterCodes.backslash */) {
78
- if (path.charCodeAt(1) !== ch0)
81
+ if (path.charCodeAt(1) !== ch0) {
79
82
  return 1; // POSIX: "/" (or non-normalized "\")
83
+ }
80
84
  const p1 = path.indexOf(ch0 === 47 /* CharacterCodes.slash */ ? exports.directorySeparator : altDirectorySeparator, 2);
81
- if (p1 < 0)
85
+ if (p1 < 0) {
82
86
  return path.length; // UNC: "//server" or "\\server"
87
+ }
83
88
  return p1 + 1; // UNC: "//server/" or "\\server\"
84
89
  }
85
90
  // DOS
86
91
  if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* CharacterCodes.colon */) {
87
92
  const ch2 = path.charCodeAt(2);
88
- if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */)
93
+ if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */) {
89
94
  return 3; // DOS: "c:/" or "c:\"
90
- if (path.length === 2)
95
+ }
96
+ if (path.length === 2) {
91
97
  return 2; // DOS: "c:" (but not "c:d")
98
+ }
92
99
  }
93
100
  // URL
94
101
  const schemeEnd = path.indexOf(urlSchemeSeparator);
@@ -156,8 +163,9 @@ function getDirectoryPath(path) {
156
163
  path = normalizeSlashes(path);
157
164
  // If the path provided is itself the root, then return it.
158
165
  const rootLength = getRootLength(path);
159
- if (rootLength === path.length)
166
+ if (rootLength === path.length) {
160
167
  return path;
168
+ }
161
169
  // return the leading portion of the path up to the last (non-terminal) directory separator
162
170
  // but not including any trailing directory separator.
163
171
  path = removeTrailingDirectorySeparator(path);
@@ -168,8 +176,9 @@ function getBaseFileName(path, extensions, ignoreCase) {
168
176
  path = normalizeSlashes(path);
169
177
  // if the path provided is itself the root, then it has not file name.
170
178
  const rootLength = getRootLength(path);
171
- if (rootLength === path.length)
179
+ if (rootLength === path.length) {
172
180
  return "";
181
+ }
173
182
  // return the trailing portion of the path starting after the last (non-terminal) directory
174
183
  // separator but not including any trailing directory separator.
175
184
  path = removeTrailingDirectorySeparator(path);
@@ -178,8 +187,9 @@ function getBaseFileName(path, extensions, ignoreCase) {
178
187
  return extension ? name.slice(0, name.length - extension.length) : name;
179
188
  }
180
189
  function tryGetExtensionFromPath(path, extension, stringEqualityComparer) {
181
- if (!(0, core_1.startsWith)(extension, "."))
190
+ if (!(0, core_1.startsWith)(extension, ".")) {
182
191
  extension = "." + extension;
192
+ }
183
193
  if (path.length >= extension.length && path.charCodeAt(path.length - extension.length) === 46 /* CharacterCodes.dot */) {
184
194
  const pathExtension = path.slice(path.length - extension.length);
185
195
  if (stringEqualityComparer(pathExtension, extension)) {
@@ -193,8 +203,9 @@ function getAnyExtensionFromPathWorker(path, extensions, stringEqualityComparer)
193
203
  }
194
204
  for (const extension of extensions) {
195
205
  const result = tryGetExtensionFromPath(path, extension, stringEqualityComparer);
196
- if (result)
206
+ if (result) {
197
207
  return result;
208
+ }
198
209
  }
199
210
  return "";
200
211
  }
@@ -214,8 +225,9 @@ function getAnyExtensionFromPath(path, extensions, ignoreCase) {
214
225
  function pathComponents(path, rootLength) {
215
226
  const root = path.substring(0, rootLength);
216
227
  const rest = path.substring(rootLength).split(exports.directorySeparator);
217
- if (rest.length && !(0, core_1.lastOrUndefined)(rest))
228
+ if (rest.length && !(0, core_1.lastOrUndefined)(rest)) {
218
229
  rest.pop();
230
+ }
219
231
  return [root, ...rest];
220
232
  }
221
233
  /**
@@ -262,8 +274,9 @@ function getPathComponents(path, currentDirectory = "") {
262
274
  * ```
263
275
  */
264
276
  function getPathFromPathComponents(pathComponents) {
265
- if (pathComponents.length === 0)
277
+ if (pathComponents.length === 0) {
266
278
  return "";
279
+ }
267
280
  const root = pathComponents[0] && ensureTrailingDirectorySeparator(pathComponents[0]);
268
281
  return root + pathComponents.slice(1).join(exports.directorySeparator);
269
282
  }
@@ -281,15 +294,18 @@ function normalizeSlashes(path) {
281
294
  * `"."` or `".."` entries in the path.
282
295
  */
283
296
  function reducePathComponents(components) {
284
- if (!(0, core_1.some)(components))
297
+ if (!(0, core_1.some)(components)) {
285
298
  return [];
299
+ }
286
300
  const reduced = [components[0]];
287
301
  for (let i = 1; i < components.length; i++) {
288
302
  const component = components[i];
289
- if (!component)
303
+ if (!component) {
290
304
  continue;
291
- if (component === ".")
305
+ }
306
+ if (component === ".") {
292
307
  continue;
308
+ }
293
309
  if (component === "..") {
294
310
  if (reduced.length > 1) {
295
311
  if (reduced[reduced.length - 1] !== "..") {
@@ -297,8 +313,9 @@ function reducePathComponents(components) {
297
313
  continue;
298
314
  }
299
315
  }
300
- else if (reduced[0])
316
+ else if (reduced[0]) {
301
317
  continue;
318
+ }
302
319
  }
303
320
  reduced.push(component);
304
321
  }
@@ -323,11 +340,13 @@ function reducePathComponents(components) {
323
340
  * ```
324
341
  */
325
342
  function combinePaths(path, ...paths) {
326
- if (path)
343
+ if (path) {
327
344
  path = normalizeSlashes(path);
345
+ }
328
346
  for (let relativePath of paths) {
329
- if (!relativePath)
347
+ if (!relativePath) {
330
348
  continue;
349
+ }
331
350
  relativePath = normalizeSlashes(relativePath);
332
351
  if (!path || getRootLength(relativePath) !== 0) {
333
352
  path = relativePath;
@@ -396,10 +415,12 @@ function containsPath(parent, child, currentDirectory, ignoreCase) {
396
415
  else if (typeof currentDirectory === "boolean") {
397
416
  ignoreCase = currentDirectory;
398
417
  }
399
- if (parent === undefined || child === undefined)
418
+ if (parent === undefined || child === undefined) {
400
419
  return false;
401
- if (parent === child)
420
+ }
421
+ if (parent === child) {
402
422
  return true;
423
+ }
403
424
  const parentComponents = reducePathComponents(getPathComponents(parent));
404
425
  const childComponents = reducePathComponents(getPathComponents(child));
405
426
  if (childComponents.length < parentComponents.length) {
@@ -172,17 +172,20 @@ function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNa
172
172
  return (0, core_1.flatten)(results);
173
173
  function visitDirectory(path, absolutePath, depth) {
174
174
  const canonicalPath = toCanonical(realpath(absolutePath));
175
- if (visited.has(canonicalPath))
175
+ if (visited.has(canonicalPath)) {
176
176
  return;
177
+ }
177
178
  visited.set(canonicalPath, true);
178
179
  const { files, directories } = getFileSystemEntries(path);
179
180
  for (const current of (0, core_1.sort)(files, core_1.compareStringsCaseSensitive)) {
180
181
  const name = (0, path_1.combinePaths)(path, current);
181
182
  const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
182
- if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions))
183
+ if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions)) {
183
184
  continue;
184
- if (excludeRegex && excludeRegex.test(absoluteName))
185
+ }
186
+ if (excludeRegex && excludeRegex.test(absoluteName)) {
185
187
  continue;
188
+ }
186
189
  if (!includeFileRegexes) {
187
190
  results[0].push(name);
188
191
  }
@@ -0,0 +1,3 @@
1
+ import type * as ts from 'typescript';
2
+ import type { FileRegistry } from '@volar/language-core';
3
+ export declare function resolveModuleName(ts: typeof import('typescript'), files: FileRegistry, fileNameToFileId: (fileName: string) => string, languageServiceHost: ts.LanguageServiceHost, moduleName: string, containingFile: string, options: ts.CompilerOptions, cache?: ts.ModuleResolutionCache, redirectedReference?: ts.ResolvedProjectReference, resolutionMode?: ts.ResolutionMode): ts.ResolvedModuleWithFailedLookupLocations;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveModuleName = void 0;
4
+ function resolveModuleName(ts, files, fileNameToFileId, languageServiceHost, moduleName, containingFile, options, cache, redirectedReference, resolutionMode) {
5
+ let extraFileExtension;
6
+ let isPatchResult = false;
7
+ for (const language of files.languagePlugins) {
8
+ extraFileExtension = language.typescript?.extraFileExtensions.find(ext => moduleName.endsWith('.' + ext.extension))?.extension;
9
+ if (extraFileExtension) {
10
+ break;
11
+ }
12
+ }
13
+ const result = ts.resolveModuleName(moduleName, containingFile, options, {
14
+ ...languageServiceHost,
15
+ fileExists(fileName) {
16
+ if (extraFileExtension && fileName.endsWith('.d.ts')) {
17
+ const patchResult = fileExists(fileName.slice(0, -5));
18
+ if (patchResult) {
19
+ isPatchResult = true;
20
+ return true;
21
+ }
22
+ }
23
+ return fileExists(fileName);
24
+ },
25
+ }, cache, redirectedReference, resolutionMode);
26
+ if (isPatchResult && result.resolvedModule) {
27
+ result.resolvedModule.resolvedFileName = result.resolvedModule.resolvedFileName.slice(0, -5);
28
+ const sourceFile = files.get(fileNameToFileId(result.resolvedModule.resolvedFileName));
29
+ if (sourceFile?.generated) {
30
+ const tsCode = sourceFile.generated.languagePlugin.typescript?.getLanguageServiceCode(sourceFile.generated.code);
31
+ if (tsCode) {
32
+ result.resolvedModule.extension = tsCode.extension;
33
+ }
34
+ }
35
+ }
36
+ return result;
37
+ // fix https://github.com/vuejs/language-tools/issues/3332
38
+ function fileExists(fileName) {
39
+ if (languageServiceHost.fileExists(fileName)) {
40
+ const fileSize = ts.sys.getFileSize?.(fileName) ?? languageServiceHost.readFile(fileName)?.length ?? 0;
41
+ return fileSize < 4 * 1024 * 1024;
42
+ }
43
+ return false;
44
+ }
45
+ }
46
+ exports.resolveModuleName = resolveModuleName;
47
+ //# sourceMappingURL=resolveModuleName.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,13 +12,13 @@
12
12
  "directory": "packages/typescript"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.0.0-alpha.8",
15
+ "@volar/language-core": "2.0.0",
16
16
  "path-browserify": "^1.0.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "latest",
20
20
  "@types/path-browserify": "latest",
21
- "@volar/language-service": "2.0.0-alpha.8"
21
+ "@volar/language-service": "2.0.0"
22
22
  },
23
- "gitHead": "4573af5545a28a90f3d2b1b30cf6ad74ae0851b1"
23
+ "gitHead": "95217136d2727bb7304443d91cfde3dbe711369c"
24
24
  }
@@ -1,3 +0,0 @@
1
- import { type FileProvider } from '@volar/language-core';
2
- import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider, ls: ts.LanguageService, sys: ts.System): ts.Program;
@@ -1,146 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProgram = void 0;
4
- const language_core_1 = require("@volar/language-core");
5
- function getProgram(ts, files, ls, sys) {
6
- const proxy = {
7
- getRootFileNames,
8
- emit,
9
- getSyntacticDiagnostics,
10
- getSemanticDiagnostics,
11
- getGlobalDiagnostics,
12
- // @ts-expect-error
13
- getBindAndCheckDiagnostics,
14
- };
15
- return new Proxy({}, {
16
- get: (target, property) => {
17
- if (property in proxy) {
18
- return proxy[property];
19
- }
20
- const program = getProgram();
21
- if (property in program) {
22
- return program[property];
23
- }
24
- return target[property];
25
- },
26
- // #17
27
- // notice: https://github.com/vuejs/language-tools/issues/2403
28
- set: (target, property, newValue) => {
29
- const program = getProgram();
30
- target[property] = program[property] = newValue;
31
- return true;
32
- },
33
- });
34
- function getProgram() {
35
- return ls.getProgram();
36
- }
37
- function getRootFileNames() {
38
- return getProgram().getRootFileNames().filter(fileName => sys.fileExists?.(fileName));
39
- }
40
- // for vue-tsc --noEmit --watch
41
- function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
42
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
43
- }
44
- // for vue-tsc --noEmit
45
- function getSyntacticDiagnostics(sourceFile, cancellationToken) {
46
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
47
- }
48
- function getSemanticDiagnostics(sourceFile, cancellationToken) {
49
- return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
50
- }
51
- function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
52
- if (sourceFile) {
53
- const [virtualFile, source] = files.getVirtualFile(sourceFile.fileName);
54
- if (virtualFile && source) {
55
- if (!virtualFile.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)))
56
- return [];
57
- const errors = transformDiagnostics(ls.getProgram()?.[api](sourceFile, cancellationToken) ?? []);
58
- return errors;
59
- }
60
- }
61
- return transformDiagnostics(getProgram()[api](sourceFile, cancellationToken) ?? []);
62
- }
63
- function getGlobalDiagnostics(cancellationToken) {
64
- return transformDiagnostics(getProgram().getGlobalDiagnostics(cancellationToken) ?? []);
65
- }
66
- function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
67
- const scriptResult = getProgram().emit(targetSourceFile, (sys.writeFile ?? ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
68
- return {
69
- emitSkipped: scriptResult.emitSkipped,
70
- emittedFiles: scriptResult.emittedFiles,
71
- diagnostics: transformDiagnostics(scriptResult.diagnostics),
72
- };
73
- }
74
- // transform
75
- function transformDiagnostics(diagnostics) {
76
- const result = [];
77
- for (const diagnostic of diagnostics) {
78
- if (diagnostic.file !== undefined
79
- && diagnostic.start !== undefined
80
- && diagnostic.length !== undefined) {
81
- const [virtualFile, source] = files.getVirtualFile(diagnostic.file.fileName);
82
- if (virtualFile && source) {
83
- if (sys.fileExists?.(source.fileName) === false)
84
- continue;
85
- for (const [_, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
86
- if (sourceSnapshot !== source.snapshot)
87
- continue;
88
- for (const start of map.getSourceOffsets(diagnostic.start)) {
89
- if (!(0, language_core_1.shouldReportDiagnostics)(start[1].data))
90
- continue;
91
- for (const end of map.getSourceOffsets(diagnostic.start + diagnostic.length)) {
92
- if (!(0, language_core_1.shouldReportDiagnostics)(end[1].data))
93
- continue;
94
- onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
95
- break;
96
- }
97
- break;
98
- }
99
- }
100
- }
101
- else {
102
- if (sys.fileExists?.(diagnostic.file.fileName) === false)
103
- continue;
104
- onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
105
- }
106
- }
107
- else if (diagnostic.file === undefined) {
108
- result.push(diagnostic);
109
- }
110
- }
111
- return result;
112
- function onMapping(diagnostic, fileName, start, end, docText) {
113
- let file = fileName === diagnostic.file?.fileName
114
- ? diagnostic.file
115
- : undefined;
116
- if (!file) {
117
- if (docText === undefined) {
118
- const snapshot = files.getSourceFile(fileName)?.snapshot;
119
- if (snapshot) {
120
- docText = snapshot.getText(0, snapshot.getLength());
121
- }
122
- }
123
- else {
124
- file = ts.createSourceFile(fileName, docText, ts.ScriptTarget.Latest, undefined, ts.ScriptKind.Deferred);
125
- // fix https://github.com/vuejs/language-tools/issues/2622 for TS 5.0
126
- file.originalFileName = fileName;
127
- file.path = fileName.toLowerCase();
128
- file.resolvedPath = fileName.toLowerCase();
129
- }
130
- }
131
- const newDiagnostic = {
132
- ...diagnostic,
133
- file,
134
- start: start,
135
- length: end - start,
136
- };
137
- const relatedInformation = diagnostic.relatedInformation;
138
- if (relatedInformation) {
139
- newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
140
- }
141
- result.push(newDiagnostic);
142
- }
143
- }
144
- }
145
- exports.getProgram = getProgram;
146
- //# sourceMappingURL=getProgram.js.map
@@ -1,3 +0,0 @@
1
- import type * as ts from 'typescript/lib/tsserverlibrary';
2
- import { LanguagePlugin } from '@volar/language-core';
3
- export declare function createAsyncTSServerPlugin(extensions: string[], scriptKind: ts.ScriptKind, loadLanguagePlugins: (ts: typeof import('typescript/lib/tsserverlibrary'), info: ts.server.PluginCreateInfo) => Promise<LanguagePlugin[]>): ts.server.PluginModuleFactory;