@volar/typescript 1.10.3 → 1.10.5

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.
@@ -73,10 +73,10 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
73
73
  const watching = !!env?.onDidChangeWatchedFiles?.(() => {
74
74
  moduleCache.clear();
75
75
  });
76
- let lastProjectVersion = ctx.host.getProjectVersion();
76
+ let lastSysVersion = sys.version;
77
77
  _tsHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, sourceFile) => {
78
- if (!watching && lastProjectVersion !== ctx.host.getProjectVersion()) {
79
- lastProjectVersion = ctx.host.getProjectVersion();
78
+ if (!watching && lastSysVersion !== sys.version) {
79
+ lastSysVersion = sys.version;
80
80
  moduleCache.clear();
81
81
  }
82
82
  return moduleLiterals.map((moduleLiteral) => {
@@ -86,8 +86,8 @@ function createLanguageServiceHost(ctx, ts, sys, env) {
86
86
  });
87
87
  };
88
88
  _tsHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options, sourceFile) => {
89
- if (!watching && lastProjectVersion !== ctx.host.getProjectVersion()) {
90
- lastProjectVersion = ctx.host.getProjectVersion();
89
+ if (!watching && lastSysVersion !== sys.version) {
90
+ lastSysVersion = sys.version;
91
91
  moduleCache.clear();
92
92
  }
93
93
  return moduleNames.map((moduleName) => {
@@ -0,0 +1,4 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ import type * as embedded from '@volar/language-core';
3
+ export declare function decorateProgram({ createSourceFile }: Pick<typeof import('typescript/lib/tsserverlibrary'), 'createSourceFile'>, options: ts.CreateProgramOptions, core: embedded.LanguageContext, program: ts.Program): void;
4
+ //# sourceMappingURL=program.d.ts.map
package/out/program.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decorateProgram = void 0;
4
+ function decorateProgram({ createSourceFile }, options, core, program) {
5
+ const _getRootFileNames = program.getRootFileNames.bind(program);
6
+ const _getSyntacticDiagnostics = program.getSyntacticDiagnostics.bind(program);
7
+ const _getSemanticDiagnostics = program.getSemanticDiagnostics.bind(program);
8
+ const _getGlobalDiagnostics = program.getGlobalDiagnostics.bind(program);
9
+ const _emit = program.emit.bind(program);
10
+ // @ts-expect-error
11
+ const _getBindAndCheckDiagnostics = program.getBindAndCheckDiagnostics.bind(program);
12
+ program.getRootFileNames = getRootFileNames;
13
+ program.getSyntacticDiagnostics = getSyntacticDiagnostics;
14
+ program.getSemanticDiagnostics = getSemanticDiagnostics;
15
+ program.getGlobalDiagnostics = getGlobalDiagnostics;
16
+ program.emit = emit;
17
+ // @ts-expect-error
18
+ program.getBindAndCheckDiagnostics = getBindAndCheckDiagnostics;
19
+ // TODO
20
+ function getRootFileNames() {
21
+ return _getRootFileNames().filter(fileName => options.host?.fileExists?.(fileName));
22
+ }
23
+ // for vue-tsc --noEmit --watch
24
+ function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
25
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getBindAndCheckDiagnostics);
26
+ }
27
+ // for vue-tsc --noEmit
28
+ function getSyntacticDiagnostics(sourceFile, cancellationToken) {
29
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getSyntacticDiagnostics);
30
+ }
31
+ function getSemanticDiagnostics(sourceFile, cancellationToken) {
32
+ return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, _getSemanticDiagnostics);
33
+ }
34
+ function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
35
+ if (sourceFile) {
36
+ const [virtualFile, source] = core.virtualFiles.getVirtualFile(sourceFile.fileName);
37
+ if (virtualFile && source) {
38
+ if (!virtualFile.capabilities.diagnostic)
39
+ return [];
40
+ const errors = transformDiagnostics(api(sourceFile, cancellationToken) ?? []);
41
+ return errors;
42
+ }
43
+ }
44
+ return transformDiagnostics(api(sourceFile, cancellationToken) ?? []);
45
+ }
46
+ function getGlobalDiagnostics(cancellationToken) {
47
+ return transformDiagnostics(_getGlobalDiagnostics(cancellationToken) ?? []);
48
+ }
49
+ function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
50
+ const scriptResult = _emit(targetSourceFile, options.host?.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
51
+ return {
52
+ emitSkipped: scriptResult.emitSkipped,
53
+ emittedFiles: scriptResult.emittedFiles,
54
+ diagnostics: transformDiagnostics(scriptResult.diagnostics),
55
+ };
56
+ }
57
+ // transform
58
+ function transformDiagnostics(diagnostics) {
59
+ const result = [];
60
+ for (const diagnostic of diagnostics) {
61
+ if (diagnostic.file !== undefined
62
+ && diagnostic.start !== undefined
63
+ && diagnostic.length !== undefined) {
64
+ const [virtualFile, source] = core.virtualFiles.getVirtualFile(diagnostic.file.fileName);
65
+ if (virtualFile && source) {
66
+ if (options.host?.fileExists?.(source.fileName) === false)
67
+ continue;
68
+ for (const [_, [sourceSnapshot, map]] of core.virtualFiles.getMaps(virtualFile)) {
69
+ if (sourceSnapshot !== source.snapshot)
70
+ continue;
71
+ for (const start of map.toSourceOffsets(diagnostic.start)) {
72
+ const reportStart = typeof start[1].data.diagnostic === 'object' ? start[1].data.diagnostic.shouldReport() : !!start[1].data.diagnostic;
73
+ if (!reportStart)
74
+ continue;
75
+ for (const end of map.toSourceOffsets(diagnostic.start + diagnostic.length, true)) {
76
+ const reportEnd = typeof end[1].data.diagnostic === 'object' ? end[1].data.diagnostic.shouldReport() : !!end[1].data.diagnostic;
77
+ if (!reportEnd)
78
+ continue;
79
+ onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
80
+ break;
81
+ }
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ else {
87
+ if (options.host?.fileExists?.(diagnostic.file.fileName) === false)
88
+ continue;
89
+ onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
90
+ }
91
+ }
92
+ else if (diagnostic.file === undefined) {
93
+ result.push(diagnostic);
94
+ }
95
+ }
96
+ return result;
97
+ function onMapping(diagnostic, fileName, start, end, docText) {
98
+ let file = fileName === diagnostic.file?.fileName
99
+ ? diagnostic.file
100
+ : undefined;
101
+ if (!file) {
102
+ if (docText === undefined) {
103
+ const snapshot = core.host.getScriptSnapshot(fileName);
104
+ if (snapshot) {
105
+ docText = snapshot.getText(0, snapshot.getLength());
106
+ }
107
+ }
108
+ else {
109
+ file = createSourceFile(fileName, docText, 99, undefined, 7);
110
+ // fix https://github.com/vuejs/language-tools/issues/2622 for TS 5.0
111
+ file.originalFileName = fileName;
112
+ file.path = fileName.toLowerCase();
113
+ file.resolvedPath = fileName.toLowerCase();
114
+ }
115
+ }
116
+ const newDiagnostic = {
117
+ ...diagnostic,
118
+ file,
119
+ start: start,
120
+ length: end - start,
121
+ };
122
+ const relatedInformation = diagnostic.relatedInformation;
123
+ if (relatedInformation) {
124
+ newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
125
+ }
126
+ result.push(newDiagnostic);
127
+ }
128
+ }
129
+ }
130
+ exports.decorateProgram = decorateProgram;
131
+ //# sourceMappingURL=program.js.map
@@ -1,5 +1,9 @@
1
1
  import { VirtualFiles } from '@volar/language-core';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
3
  export declare function decorateLanguageServiceHost(virtualFiles: VirtualFiles, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript/lib/tsserverlibrary'), exts: string[]): void;
4
- export declare function getExternalFiles(ts: typeof import('typescript/lib/tsserverlibrary'), project: ts.server.Project, exts: string[]): string[];
4
+ export declare function searchExternalFiles(ts: typeof import('typescript/lib/tsserverlibrary'), project: ts.server.Project, exts: string[]): string[];
5
+ /**
6
+ * @deprecated use `searchExternalFiles` instead
7
+ */
8
+ export declare const getExternalFiles: typeof searchExternalFiles;
5
9
  //# sourceMappingURL=serverPlugin.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExternalFiles = exports.decorateLanguageServiceHost = void 0;
3
+ exports.getExternalFiles = exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts) {
6
6
  let extraProjectVersion = 0;
@@ -129,7 +129,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
129
129
  if (virtualFile) {
130
130
  let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
131
131
  (0, language_core_1.forEachEmbeddedFile)(virtualFile, file => {
132
- const ext = file.fileName.replace(fileName, '');
132
+ const ext = file.fileName.substring(fileName.length);
133
133
  if (file.kind === language_core_1.FileKind.TypeScriptHostFile && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
134
134
  extension = ext;
135
135
  patchedText += file.snapshot.getText(0, file.snapshot.getLength());
@@ -152,7 +152,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
152
152
  }
153
153
  }
154
154
  exports.decorateLanguageServiceHost = decorateLanguageServiceHost;
155
- function getExternalFiles(ts, project, exts) {
155
+ function searchExternalFiles(ts, project, exts) {
156
156
  if (project.projectKind !== ts.server.ProjectKind.Configured) {
157
157
  return [];
158
158
  }
@@ -170,5 +170,9 @@ function getExternalFiles(ts, project, exts) {
170
170
  const parsed = ts.parseJsonSourceFileConfigFileContent(config, parseHost, project.getCurrentDirectory());
171
171
  return parsed.fileNames;
172
172
  }
173
- exports.getExternalFiles = getExternalFiles;
173
+ exports.searchExternalFiles = searchExternalFiles;
174
+ /**
175
+ * @deprecated use `searchExternalFiles` instead
176
+ */
177
+ exports.getExternalFiles = searchExternalFiles;
174
178
  //# sourceMappingURL=serverPlugin.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.10.3",
3
+ "version": "1.10.5",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,10 +13,10 @@
13
13
  "directory": "packages/typescript"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.10.3"
16
+ "@volar/language-core": "1.10.5"
17
17
  },
18
18
  "devDependencies": {
19
- "@volar/language-service": "1.10.3"
19
+ "@volar/language-service": "1.10.5"
20
20
  },
21
- "gitHead": "5dd492d94d3e5aa620448e0b951dead341676dac"
21
+ "gitHead": "f087b2cb990108e71ed66727588b3e19c421b4c2"
22
22
  }