@volar/typescript 1.8.2 → 1.9.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.
@@ -8,6 +8,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
8
8
  const _getDefinitionAndBoundSpan = languageService.getDefinitionAndBoundSpan.bind(languageService);
9
9
  const _getTypeDefinitionAtPosition = languageService.getTypeDefinitionAtPosition.bind(languageService);
10
10
  const _getImplementationAtPosition = languageService.getImplementationAtPosition.bind(languageService);
11
+ const _getFileReferences = languageService.getFileReferences.bind(languageService);
11
12
  const _findRenameLocations = languageService.findRenameLocations.bind(languageService);
12
13
  const _getReferencesAtPosition = languageService.getReferencesAtPosition.bind(languageService);
13
14
  const _findReferences = languageService.findReferences.bind(languageService);
@@ -18,6 +19,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
18
19
  languageService.getImplementationAtPosition = getImplementationAtPosition;
19
20
  languageService.findRenameLocations = findRenameLocations;
20
21
  languageService.getReferencesAtPosition = getReferencesAtPosition;
22
+ languageService.getFileReferences = getFileReferences;
21
23
  languageService.findReferences = findReferences;
22
24
  // apis
23
25
  function organizeImports(args, formatOptions, preferences) {
@@ -41,6 +43,9 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
41
43
  function getReferencesAtPosition(fileName, position) {
42
44
  return findLocations(fileName, position, 'references');
43
45
  }
46
+ function getFileReferences(fileName) {
47
+ return findLocations(fileName, -1, 'fileReferences');
48
+ }
44
49
  function getDefinitionAtPosition(fileName, position) {
45
50
  return findLocations(fileName, position, 'definition');
46
51
  }
@@ -65,9 +70,10 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
65
70
  const _symbols = mode === 'definition' ? _getDefinitionAtPosition(fileName, position)
66
71
  : mode === 'typeDefinition' ? _getTypeDefinitionAtPosition(fileName, position)
67
72
  : mode === 'references' ? _getReferencesAtPosition(fileName, position)
68
- : mode === 'implementation' ? _getImplementationAtPosition(fileName, position)
69
- : mode === 'rename' && preferences ? _findRenameLocations(fileName, position, findInStrings, findInComments, preferences)
70
- : undefined;
73
+ : mode === 'fileReferences' ? _getFileReferences(fileName)
74
+ : mode === 'implementation' ? _getImplementationAtPosition(fileName, position)
75
+ : mode === 'rename' && preferences ? _findRenameLocations(fileName, position, findInStrings, findInComments, preferences)
76
+ : undefined;
71
77
  if (!_symbols)
72
78
  return;
73
79
  symbols = symbols.concat(_symbols);
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLanguageServiceHost = void 0;
4
4
  const path_1 = require("path");
5
5
  const utilities_1 = require("./typescript/utilities");
6
+ const fileVersions = new Map();
6
7
  function createLanguageServiceHost(ctx, ts, sys) {
7
8
  let lastProjectVersion;
8
9
  let tsProjectVersion = 0;
9
10
  let tsFileNames = [];
10
11
  const _tsHost = {
11
12
  ...sys,
12
- getCurrentDirectory: () => ctx.host.getCurrentDirectory(),
13
+ getCurrentDirectory: () => ctx.host.workspacePath,
13
14
  getCompilationSettings: () => ctx.host.getCompilationSettings(),
14
15
  getCancellationToken: ctx.host.getCancellationToken ? () => ctx.host.getCancellationToken() : undefined,
15
16
  getLocalizedDiagnosticMessages: ctx.host.getLocalizedDiagnosticMessages ? () => ctx.host.getLocalizedDiagnosticMessages() : undefined,
@@ -67,7 +68,6 @@ function createLanguageServiceHost(ctx, ts, sys) {
67
68
  },
68
69
  };
69
70
  const fsFileSnapshots = new Map();
70
- const fileVersions = new Map();
71
71
  let oldTsVirtualFileSnapshots = new Set();
72
72
  let oldOtherVirtualFileSnapshots = new Set();
73
73
  return new Proxy(_tsHost, {
@@ -119,7 +119,7 @@ function createLanguageServiceHost(ctx, ts, sys) {
119
119
  tsFileNames = [...tsFileNamesSet];
120
120
  }
121
121
  function readDirectory(dirName, extensions, excludes, includes, depth) {
122
- let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.getCurrentDirectory(), depth, (dirPath) => {
122
+ let matches = (0, utilities_1.matchFiles)(dirName, extensions, excludes, includes, sys?.useCaseSensitiveFileNames ?? false, ctx.host.workspacePath, depth, (dirPath) => {
123
123
  const files = [];
124
124
  for (const fileName of tsFileNames) {
125
125
  if (fileName.toLowerCase().startsWith(dirPath.toLowerCase())) {
@@ -196,14 +196,13 @@ function createLanguageServiceHost(ctx, ts, sys) {
196
196
  const snapshot = virtualFile?.snapshot ?? ctx.host.getScriptSnapshot(fileName);
197
197
  if (snapshot) {
198
198
  if (!fileVersions.has(fileName)) {
199
- fileVersions.set(fileName, { value: 0, snapshot });
199
+ fileVersions.set(fileName, { lastVersion: 0, snapshotVersions: new WeakMap() });
200
200
  }
201
201
  const version = fileVersions.get(fileName);
202
- if (version.snapshot !== snapshot) {
203
- version.value++;
204
- version.snapshot = snapshot;
202
+ if (!version.snapshotVersions.has(snapshot)) {
203
+ version.snapshotVersions.set(snapshot, version.lastVersion++);
205
204
  }
206
- return version.value.toString();
205
+ return version.snapshotVersions.get(snapshot).toString();
207
206
  }
208
207
  // fs files
209
208
  return sys.getModifiedTime?.(fileName)?.valueOf().toString() ?? '';
package/out/sys.js CHANGED
@@ -83,16 +83,6 @@ function createSys(ts, env) {
83
83
  }
84
84
  return path_1.posix.resolve(fsPath).replace(/\\/g, '/');
85
85
  }
86
- function getModifiedTime(fileName) {
87
- fileName = resolvePath(fileName);
88
- const dirPath = path_1.posix.dirname(fileName);
89
- const dir = getDir(dirPath);
90
- const name = path_1.posix.basename(fileName);
91
- const modifiedTime = dir.files[name]?.modifiedTime;
92
- if (modifiedTime !== undefined) {
93
- return new Date(modifiedTime);
94
- }
95
- }
96
86
  function readFile(fileName, encoding) {
97
87
  fileName = resolvePath(fileName);
98
88
  const dirPath = path_1.posix.dirname(fileName);
@@ -124,33 +114,55 @@ function createSys(ts, env) {
124
114
  }
125
115
  return dir.exists;
126
116
  }
117
+ function getModifiedTime(fileName) {
118
+ fileName = resolvePath(fileName);
119
+ const file = getFile(fileName);
120
+ if (file.modifiedTime === undefined) {
121
+ file.modifiedTime = new Date(0);
122
+ handleStat(fileName, file);
123
+ }
124
+ return file.modifiedTime;
125
+ }
127
126
  function fileExists(fileName) {
128
127
  fileName = resolvePath(fileName);
129
- const dirPath = path_1.posix.dirname(fileName);
130
- const baseName = path_1.posix.basename(fileName);
131
- const dir = getDir(dirPath);
132
- const file = dir.files[baseName] ??= {};
128
+ const file = getFile(fileName);
133
129
  if (file.exists === undefined) {
134
130
  file.exists = false;
135
- const result = env.fs?.stat(env.fileNameToUri(fileName));
136
- if (typeof result === 'object' && 'then' in result) {
137
- const promise = result;
138
- promises.add(promise);
139
- result.then(result => {
140
- promises.delete(promise);
141
- file.exists = result?.type === 1;
142
- if (file.exists) {
143
- const time = Date.now();
144
- file.modifiedTime = time !== file.modifiedTime ? time : file.modifiedTime + 1;
145
- version++;
146
- }
147
- });
148
- }
149
- else {
131
+ handleStat(fileName, file);
132
+ }
133
+ return file.exists;
134
+ }
135
+ function handleStat(fileName, file) {
136
+ const result = env.fs?.stat(env.fileNameToUri(fileName));
137
+ if (typeof result === 'object' && 'then' in result) {
138
+ const promise = result;
139
+ promises.add(promise);
140
+ result.then(result => {
141
+ promises.delete(promise);
150
142
  file.exists = result?.type === 1;
143
+ if (result) {
144
+ file.modifiedTime = new Date(result.mtime);
145
+ }
146
+ if (file.exists) {
147
+ file.requested = false;
148
+ version++;
149
+ }
150
+ });
151
+ }
152
+ else {
153
+ file.exists = result?.type === 1;
154
+ if (result) {
155
+ file.modifiedTime = new Date(result.mtime);
151
156
  }
152
157
  }
153
- return file.exists;
158
+ }
159
+ function getFile(fileName) {
160
+ fileName = resolvePath(fileName);
161
+ const dirPath = path_1.posix.dirname(fileName);
162
+ const baseName = path_1.posix.basename(fileName);
163
+ const dir = getDir(dirPath);
164
+ const file = dir.files[baseName] ??= {};
165
+ return file;
154
166
  }
155
167
  // for import path completion
156
168
  function getDirectories(dirName) {
@@ -190,8 +202,6 @@ function createSys(ts, env) {
190
202
  if (result !== undefined) {
191
203
  file.exists = true;
192
204
  file.text = result;
193
- const time = Date.now();
194
- file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
195
205
  version++;
196
206
  }
197
207
  else {
@@ -202,8 +212,6 @@ function createSys(ts, env) {
202
212
  else if (result !== undefined) {
203
213
  file.exists = true;
204
214
  file.text = result;
205
- const time = Date.now();
206
- file.modifiedTime = time !== file.modifiedTime ? time : time + 1;
207
215
  }
208
216
  else {
209
217
  file.exists = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
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.8.2"
16
+ "@volar/language-core": "1.9.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@volar/language-service": "1.8.2"
19
+ "@volar/language-service": "1.9.0"
20
20
  },
21
- "gitHead": "b552c1f827294da5d36cbe4e7c1f7f2729b2b82e"
21
+ "gitHead": "37453f868329df9c666e6ee44919a55b36484b93"
22
22
  }