@volar/typescript 1.7.8 → 1.7.10

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.
@@ -6,6 +6,7 @@ const utilities_1 = require("./typescript/utilities");
6
6
  function createLanguageServiceHost(ctx, ts, sys) {
7
7
  let lastProjectVersion;
8
8
  let tsProjectVersion = 0;
9
+ let tsFileNames = [];
9
10
  const _tsHost = {
10
11
  ...sys,
11
12
  getCurrentDirectory: () => ctx.host.getCurrentDirectory(),
@@ -42,7 +43,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
42
43
  getTypeRootsVersion: () => {
43
44
  return sys.version ?? -1; // TODO: only update for /node_modules changes?
44
45
  },
45
- getScriptFileNames,
46
+ getScriptFileNames: () => tsFileNames,
46
47
  getScriptVersion,
47
48
  getScriptSnapshot,
48
49
  getScriptKind(fileName) {
@@ -102,11 +103,25 @@ function createLanguageServiceHost(ctx, ts, sys) {
102
103
  }
103
104
  oldTsVirtualFileSnapshots = newTsVirtualFileSnapshots;
104
105
  oldOtherVirtualFileSnapshots = newOtherVirtualFileSnapshots;
106
+ const tsFileNamesSet = new Set();
107
+ for (const { root } of ctx.virtualFiles.allSources()) {
108
+ forEachEmbeddedFile(root, embedded => {
109
+ if (embedded.kind === 1) {
110
+ tsFileNamesSet.add(embedded.fileName); // virtual .ts
111
+ }
112
+ });
113
+ }
114
+ for (const fileName of ctx.host.getScriptFileNames()) {
115
+ if (!ctx.virtualFiles.hasSource(fileName)) {
116
+ tsFileNamesSet.add(fileName); // .ts
117
+ }
118
+ }
119
+ tsFileNames = [...tsFileNamesSet];
105
120
  }
106
121
  function readDirectory(dirName, extensions, excludes, includes, depth) {
107
122
  let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.getCurrentDirectory(), depth, (dirPath) => {
108
123
  const files = [];
109
- for (const fileName of getScriptFileNames()) {
124
+ for (const fileName of tsFileNames) {
110
125
  if (fileName.toLowerCase().startsWith(dirPath.toLowerCase())) {
111
126
  const baseName = fileName.substring(dirPath.length);
112
127
  if (baseName.indexOf('/') === -1) {
@@ -141,7 +156,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
141
156
  }
142
157
  function getVirtualFileDirectories(dirName) {
143
158
  const names = new Set();
144
- for (const fileName of getScriptFileNames()) {
159
+ for (const fileName of tsFileNames) {
145
160
  if (fileName.toLowerCase().startsWith(dirName.toLowerCase())) {
146
161
  const path = fileName.substring(dirName.length);
147
162
  if (path.indexOf('/') >= 0) {
@@ -151,22 +166,6 @@ function createLanguageServiceHost(ctx, ts, sys) {
151
166
  }
152
167
  return [...names];
153
168
  }
154
- function getScriptFileNames() {
155
- const tsFileNames = new Set();
156
- for (const { root } of ctx.virtualFiles.allSources()) {
157
- forEachEmbeddedFile(root, embedded => {
158
- if (embedded.kind === 1) {
159
- tsFileNames.add(embedded.fileName); // virtual .ts
160
- }
161
- });
162
- }
163
- for (const fileName of ctx.host.getScriptFileNames()) {
164
- if (!ctx.virtualFiles.hasSource(fileName)) {
165
- tsFileNames.add(fileName); // .ts
166
- }
167
- }
168
- return [...tsFileNames];
169
- }
170
169
  function getScriptSnapshot(fileName) {
171
170
  // virtual files
172
171
  const [virtualFile] = ctx.virtualFiles.getVirtualFile(fileName);
@@ -212,33 +211,10 @@ function createLanguageServiceHost(ctx, ts, sys) {
212
211
  return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '';
213
212
  }
214
213
  function directoryExists(dirName) {
215
- if (getScriptFileNames().some(fileName => fileName.toLowerCase().startsWith(dirName.toLowerCase()))) {
216
- return true;
217
- }
218
- return sys.directoryExists(dirName);
214
+ return sys.directoryExists(dirName)
215
+ || tsFileNames.some(fileName => fileName.toLowerCase().startsWith(dirName.toLowerCase()));
219
216
  }
220
217
  function fileExists(fileName) {
221
- // fill external virtual files
222
- const ext = fileName.substring(fileName.lastIndexOf('.'));
223
- if (ext === '.js'
224
- || ext === '.ts'
225
- || ext === '.jsx'
226
- || ext === '.tsx') {
227
- /**
228
- * If try to access a external .vue file that outside of the project,
229
- * the file will not process by language service host,
230
- * so virtual file will not be created.
231
- *
232
- * We try to create virtual file here.
233
- */
234
- const sourceFileName = fileName.substring(0, fileName.lastIndexOf('.'));
235
- if (!ctx.virtualFiles.hasSource(sourceFileName)) {
236
- const scriptSnapshot = getScriptSnapshot(sourceFileName);
237
- if (scriptSnapshot) {
238
- ctx.virtualFiles.updateSource(sourceFileName, scriptSnapshot, ctx.host.getLanguageId?.(sourceFileName));
239
- }
240
- }
241
- }
242
218
  // virtual files
243
219
  if (ctx.virtualFiles.hasVirtualFile(fileName)) {
244
220
  return true;
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decorateLanguageServiceHost = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
5
  function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts) {
6
+ let extraProjectVersion = 0;
6
7
  const scripts = new Map();
7
8
  const resolveModuleNameLiterals = languageServiceHost.resolveModuleNameLiterals?.bind(languageServiceHost);
8
9
  const resolveModuleNames = languageServiceHost.resolveModuleNames?.bind(languageServiceHost);
10
+ const getProjectVersion = languageServiceHost.getProjectVersion?.bind(languageServiceHost);
11
+ const getScriptFileNames = languageServiceHost.getScriptFileNames.bind(languageServiceHost);
9
12
  const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
10
13
  if (resolveModuleNameLiterals) {
11
14
  languageServiceHost.resolveModuleNameLiterals = (moduleNames, containingFile, redirectedReference, options, ...rest) => {
@@ -29,6 +32,22 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
29
32
  });
30
33
  };
31
34
  }
35
+ if (getProjectVersion) {
36
+ languageServiceHost.getProjectVersion = () => {
37
+ return getProjectVersion() + ':' + extraProjectVersion;
38
+ };
39
+ }
40
+ languageServiceHost.getScriptFileNames = () => {
41
+ if (languageServiceHost.getCompilationSettings().composite) {
42
+ return [
43
+ ...getScriptFileNames(),
44
+ ...virtualFiles.allSources().map(source => source.fileName),
45
+ ];
46
+ }
47
+ else {
48
+ return getScriptFileNames();
49
+ }
50
+ };
32
51
  languageServiceHost.getScriptSnapshot = (fileName) => {
33
52
  if (scripts.has(fileName)) {
34
53
  updateScript(fileName);
@@ -42,7 +61,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
42
61
  },
43
62
  fileExists(fileName) {
44
63
  if (exts.some(ext => fileName.endsWith(ext + '.d.ts'))) {
45
- return languageServiceHost.fileExists(fileName.slice(0, -'.d.ts'.length));
64
+ return fileExists(fileName.slice(0, -'.d.ts'.length));
46
65
  }
47
66
  return languageServiceHost.fileExists(fileName);
48
67
  },
@@ -56,6 +75,14 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
56
75
  }
57
76
  return resolved;
58
77
  }
78
+ // fix https://github.com/vuejs/language-tools/issues/3332
79
+ function fileExists(fileName) {
80
+ if (languageServiceHost.fileExists(fileName)) {
81
+ const fileSize = ts.sys.getFileSize?.(fileName) ?? languageServiceHost.readFile(fileName)?.length ?? 0;
82
+ return fileSize < 4 * 1024 * 1024;
83
+ }
84
+ return false;
85
+ }
59
86
  function updateScript(fileName) {
60
87
  const version = languageServiceHost.getScriptVersion(fileName);
61
88
  if (version !== scripts.get(fileName)?.version) {
@@ -63,6 +90,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
63
90
  let snapshot;
64
91
  let extension = '.ts';
65
92
  if (text !== undefined) {
93
+ extraProjectVersion++;
66
94
  const virtualFile = virtualFiles.updateSource(fileName, ts.ScriptSnapshot.fromString(text), undefined);
67
95
  if (virtualFile) {
68
96
  let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
@@ -76,7 +104,8 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
76
104
  snapshot = ts.ScriptSnapshot.fromString(patchedText);
77
105
  }
78
106
  }
79
- else {
107
+ else if (virtualFiles.hasSource(fileName)) {
108
+ extraProjectVersion++;
80
109
  virtualFiles.deleteSource(fileName);
81
110
  }
82
111
  scripts.set(fileName, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.7.8",
3
+ "version": "1.7.10",
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.7.8"
16
+ "@volar/language-core": "1.7.10"
17
17
  },
18
18
  "devDependencies": {
19
- "@volar/language-service": "1.7.8"
19
+ "@volar/language-service": "1.7.10"
20
20
  },
21
- "gitHead": "e7c1b16e5c78702de6986eafa17ae96000ffe0cb"
21
+ "gitHead": "53c67c3fd1d11be3dba0ef199c282e605c980638"
22
22
  }