@volar/typescript 1.7.5 → 1.7.7

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLanguageServiceHost = void 0;
4
4
  const path_1 = require("path");
5
+ const utilities_1 = require("./typescript/utilities");
5
6
  function createLanguageServiceHost(ctx, ts, sys) {
6
7
  let lastProjectVersion;
7
8
  let tsProjectVersion = 0;
@@ -31,9 +32,12 @@ function createLanguageServiceHost(ctx, ts, sys) {
31
32
  return snapshot.getText(0, snapshot.getLength());
32
33
  }
33
34
  },
35
+ readDirectory,
36
+ getDirectories,
37
+ directoryExists,
34
38
  fileExists,
35
39
  getProjectVersion: () => {
36
- return tsProjectVersion.toString() + ':' + sys.version;
40
+ return tsProjectVersion + ':' + sys.version;
37
41
  },
38
42
  getTypeRootsVersion: () => {
39
43
  return sys.version ?? -1; // TODO: only update for /node_modules changes?
@@ -99,6 +103,57 @@ function createLanguageServiceHost(ctx, ts, sys) {
99
103
  oldTsVirtualFileSnapshots = newTsVirtualFileSnapshots;
100
104
  oldOtherVirtualFileSnapshots = newOtherVirtualFileSnapshots;
101
105
  }
106
+ function readDirectory(dirName, extensions, excludes, includes, depth) {
107
+ let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.getCurrentDirectory(), depth, (dirPath) => {
108
+ const files = [];
109
+ for (const fileName of getScriptFileNames()) {
110
+ if (fileName.toLowerCase().startsWith(dirPath.toLowerCase())) {
111
+ const baseName = fileName.substring(dirPath.length);
112
+ if (baseName.indexOf('/') === -1) {
113
+ files.push(baseName);
114
+ }
115
+ }
116
+ }
117
+ return {
118
+ files,
119
+ directories: getVirtualFileDirectories(dirPath),
120
+ };
121
+ }, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
122
+ if (ctx) {
123
+ matches = matches.map(match => {
124
+ const [_, source] = ctx.virtualFiles.getVirtualFile(match);
125
+ if (source) {
126
+ return source.fileName;
127
+ }
128
+ return match;
129
+ });
130
+ }
131
+ return [...new Set([
132
+ ...matches,
133
+ ...sys.readDirectory(dirName, extensions, excludes, includes, depth),
134
+ ])];
135
+ }
136
+ function getDirectories(dirName) {
137
+ return [...new Set([
138
+ ...getVirtualFileDirectories(dirName),
139
+ ...sys.getDirectories(dirName),
140
+ ])];
141
+ }
142
+ function getVirtualFileDirectories(dirName) {
143
+ const names = new Set();
144
+ for (const fileName of getScriptFileNames()) {
145
+ if (fileName.toLowerCase().startsWith(dirName.toLowerCase())) {
146
+ const path = fileName.substring(dirName.length);
147
+ if (path.indexOf('/') >= 0) {
148
+ names.add(path.split('/')[0]);
149
+ }
150
+ }
151
+ }
152
+ for (const name of sys.getDirectories(dirName)) {
153
+ names.add(name);
154
+ }
155
+ return [...names];
156
+ }
102
157
  function getScriptFileNames() {
103
158
  const tsFileNames = new Set();
104
159
  for (const { root } of ctx.virtualFiles.allSources()) {
@@ -159,6 +214,12 @@ function createLanguageServiceHost(ctx, ts, sys) {
159
214
  // fs files
160
215
  return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '';
161
216
  }
217
+ function directoryExists(dirName) {
218
+ if (getScriptFileNames().some(fileName => fileName.toLowerCase().startsWith(dirName.toLowerCase()))) {
219
+ return true;
220
+ }
221
+ return sys.directoryExists(dirName);
222
+ }
162
223
  function fileExists(fileName) {
163
224
  // fill external virtual files
164
225
  const ext = fileName.substring(fileName.lastIndexOf('.'));
package/out/sys.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ServiceEnvironment, Disposable, LanguageContext } from '@volar/language-service';
1
+ import type { ServiceEnvironment, Disposable } from '@volar/language-service';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
3
  import { IDtsHost } from './dtsHost';
4
- export declare function createSys(ctx: LanguageContext | undefined, ts: typeof import('typescript/lib/tsserverlibrary'), env: ServiceEnvironment, dtsHost?: IDtsHost): ts.System & {
4
+ export declare function createSys(ts: typeof import('typescript/lib/tsserverlibrary'), env: ServiceEnvironment, dtsHost?: IDtsHost): ts.System & {
5
5
  version: number;
6
6
  sync(): Promise<number>;
7
7
  } & Disposable;
package/out/sys.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSys = void 0;
4
- const language_core_1 = require("@volar/language-core");
5
4
  const path_1 = require("path");
6
5
  const utilities_1 = require("./typescript/utilities");
7
6
  const dtsHost_1 = require("./dtsHost");
8
7
  let currentCwd = '';
9
- function createSys(ctx, ts, env, dtsHost) {
8
+ function createSys(ts, env, dtsHost) {
10
9
  let version = 0;
11
10
  const rootPath = env.uriToFileName(env.rootUri.toString());
12
11
  const sys = ts.sys;
@@ -153,7 +152,7 @@ function createSys(ctx, ts, env, dtsHost) {
153
152
  file.exists = result?.type === 1 || result?.type === 64;
154
153
  if (file.exists) {
155
154
  const time = Date.now();
156
- file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
155
+ file.modifiedTime = time !== file.modifiedTime ? time : file.modifiedTime + 1;
157
156
  version++;
158
157
  }
159
158
  });
@@ -173,40 +172,15 @@ function createSys(ctx, ts, env, dtsHost) {
173
172
  }
174
173
  function readDirectory(dirName, extensions, excludes, includes, depth) {
175
174
  dirName = resolvePath(dirName);
176
- let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, rootPath, depth, (dirPath) => {
175
+ const matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, rootPath, depth, (dirPath) => {
177
176
  dirPath = resolvePath(dirPath);
178
177
  readDirectoryWorker(dirPath);
179
178
  const dir = getDir(dirPath);
180
- const virtualFiles = [];
181
- if (ctx) {
182
- for (const { root } of ctx.virtualFiles.allSources()) {
183
- (0, language_core_1.forEachEmbeddedFile)(root, file => {
184
- if (file.kind === language_core_1.FileKind.TypeScriptHostFile) {
185
- const fileDirName = path_1.posix.dirname(file.fileName);
186
- if (fileDirName.toLowerCase() === dirPath.toLowerCase()) {
187
- virtualFiles.push(path_1.posix.basename(file.fileName));
188
- }
189
- }
190
- });
191
- }
192
- }
193
179
  return {
194
- files: [
195
- ...[...Object.entries(dir.files)].filter(([_, file]) => file.exists).map(([name]) => name),
196
- ...virtualFiles,
197
- ],
180
+ files: [...Object.entries(dir.files)].filter(([_, file]) => file.exists).map(([name]) => name),
198
181
  directories: [...Object.entries(dir.dirs)].filter(([_, dir]) => dir.exists).map(([name]) => name),
199
182
  };
200
183
  }, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
201
- if (ctx) {
202
- matches = matches.map(match => {
203
- const [_, source] = ctx.virtualFiles.getVirtualFile(match);
204
- if (source) {
205
- return source.fileName;
206
- }
207
- return match;
208
- });
209
- }
210
184
  return [...new Set(matches)];
211
185
  }
212
186
  function readFileWorker(fileName, encoding, dir) {
@@ -254,10 +228,9 @@ function createSys(ctx, ts, env, dtsHost) {
254
228
  return;
255
229
  }
256
230
  dir.requested = true;
257
- const uri = env.fileNameToUri(dirName);
258
231
  const result = dirName.startsWith('/node_modules/') && dtsHost
259
232
  ? dtsHost.readDirectory(dirName)
260
- : env.fs?.readDirectory(uri);
233
+ : env.fs?.readDirectory(env.fileNameToUri(dirName || '.'));
261
234
  if (typeof result === 'object' && 'then' in result) {
262
235
  const promise = result;
263
236
  promises.add(promise);
@@ -273,6 +246,8 @@ function createSys(ctx, ts, env, dtsHost) {
273
246
  }
274
247
  }
275
248
  function onReadDirectoryResult(dir, result) {
249
+ // See https://github.com/microsoft/TypeScript/blob/e1a9290051a3b0cbdfbadc3adbcc155a4641522a/src/compiler/sys.ts#L1853-L1857
250
+ result = result.filter(([name]) => name !== '.' && name !== '..');
276
251
  let updated = false;
277
252
  for (const [name, fileType] of result) {
278
253
  if (fileType === 1 || fileType === 64) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
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.5"
16
+ "@volar/language-core": "1.7.7"
17
17
  },
18
18
  "devDependencies": {
19
- "@volar/language-service": "1.7.5"
19
+ "@volar/language-service": "1.7.7"
20
20
  },
21
- "gitHead": "57fa4f05df4c593aa4a7b15c159f864d407bd1ac"
21
+ "gitHead": "ad13290da9f223f6d198d858faf5349933112200"
22
22
  }