@volar/typescript 1.7.8 → 1.7.9

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(),
@@ -34,7 +35,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
34
35
  },
35
36
  readDirectory,
36
37
  getDirectories,
37
- directoryExists,
38
+ directoryExists: undefined,
38
39
  fileExists,
39
40
  getProjectVersion: () => {
40
41
  return tsProjectVersion + ':' + sys.version;
@@ -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);
@@ -211,34 +210,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
211
210
  // fs files
212
211
  return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '';
213
212
  }
214
- function directoryExists(dirName) {
215
- if (getScriptFileNames().some(fileName => fileName.toLowerCase().startsWith(dirName.toLowerCase()))) {
216
- return true;
217
- }
218
- return sys.directoryExists(dirName);
219
- }
220
213
  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
214
  // virtual files
243
215
  if (ctx.virtualFiles.hasVirtualFile(fileName)) {
244
216
  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);
@@ -63,6 +82,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
63
82
  let snapshot;
64
83
  let extension = '.ts';
65
84
  if (text !== undefined) {
85
+ extraProjectVersion++;
66
86
  const virtualFile = virtualFiles.updateSource(fileName, ts.ScriptSnapshot.fromString(text), undefined);
67
87
  if (virtualFile) {
68
88
  let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
@@ -76,7 +96,8 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
76
96
  snapshot = ts.ScriptSnapshot.fromString(patchedText);
77
97
  }
78
98
  }
79
- else {
99
+ else if (virtualFiles.hasSource(fileName)) {
100
+ extraProjectVersion++;
80
101
  virtualFiles.deleteSource(fileName);
81
102
  }
82
103
  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.9",
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.9"
17
17
  },
18
18
  "devDependencies": {
19
- "@volar/language-service": "1.7.8"
19
+ "@volar/language-service": "1.7.9"
20
20
  },
21
- "gitHead": "e7c1b16e5c78702de6986eafa17ae96000ffe0cb"
21
+ "gitHead": "c28b1b3fc725f38d335f4341179678c78828528f"
22
22
  }