@volar/typescript 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
@@ -5,6 +5,29 @@ const language_core_1 = require("@volar/language-core");
5
5
  const dedupe_1 = require("./dedupe");
6
6
  function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
7
7
  const transformedDiagnostics = new WeakMap();
8
+ // ignored methods
9
+ const { getNavigationTree, getOutliningSpans, } = languageService;
10
+ languageService.getNavigationTree = (fileName) => {
11
+ const [virtualFile] = getVirtualFileAndMap(fileName);
12
+ if (virtualFile) {
13
+ const tree = getNavigationTree(fileName);
14
+ tree.childItems = undefined;
15
+ return tree;
16
+ }
17
+ else {
18
+ return getNavigationTree(fileName);
19
+ }
20
+ };
21
+ languageService.getOutliningSpans = (fileName) => {
22
+ const [virtualFile] = getVirtualFileAndMap(fileName);
23
+ if (virtualFile) {
24
+ return [];
25
+ }
26
+ else {
27
+ return getOutliningSpans(fileName);
28
+ }
29
+ };
30
+ // methods
8
31
  const { findReferences, findRenameLocations, getCompletionEntryDetails, getCompletionsAtPosition, getDefinitionAndBoundSpan, getDefinitionAtPosition, getFileReferences, getImplementationAtPosition, getQuickInfoAtPosition, getReferencesAtPosition, getSemanticDiagnostics, getSyntacticDiagnostics, getSuggestionDiagnostics, getTypeDefinitionAtPosition, getEncodedSemanticClassifications, getDocumentHighlights, getApplicableRefactors, getEditsForRefactor, getRenameInfo, getCodeFixesAtPosition, prepareCallHierarchy, provideCallHierarchyIncomingCalls, provideCallHierarchyOutgoingCalls, provideInlayHints, organizeImports, } = languageService;
9
32
  languageService.prepareCallHierarchy = (fileName, position) => {
10
33
  const [virtualFile, sourceFile, map] = getVirtualFileAndMap(fileName);
@@ -554,7 +577,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
554
577
  if (source) {
555
578
  return {
556
579
  ...changes,
557
- fileName: source.id,
580
+ fileName: source.fileName,
558
581
  textChanges: changes.textChanges.map(c => {
559
582
  const span = transformSpan(changes.fileName, c.span, filter);
560
583
  if (span) {
@@ -576,7 +599,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
576
599
  const [virtualFile, source] = getVirtualFileAndMap(documentSpan.fileName);
577
600
  if (virtualFile) {
578
601
  textSpan = {
579
- fileName: source.id,
602
+ fileName: source.fileName,
580
603
  textSpan: { start: 0, length: 0 },
581
604
  };
582
605
  }
@@ -608,7 +631,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
608
631
  for (const sourceEnd of map.getSourceOffsets(textSpan.start + textSpan.length - (isTsPlugin ? sourceFile.snapshot.getLength() : 0))) {
609
632
  if (filter(sourceEnd[1].data)) {
610
633
  return {
611
- fileName: sourceFile.id,
634
+ fileName: sourceFile.fileName,
612
635
  textSpan: {
613
636
  start: sourceStart[0],
614
637
  length: sourceEnd[0] - sourceStart[0],
@@ -631,7 +654,7 @@ function decorateLanguageService(virtualFiles, languageService, isTsPlugin) {
631
654
  const sourceFile = virtualFiles.getSourceFile(fileName);
632
655
  if (sourceFile?.virtualFile) {
633
656
  for (const virtualFile of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
634
- const ext = virtualFile.id.substring(fileName.length);
657
+ const ext = virtualFile.fileName.substring(fileName.length);
635
658
  if (virtualFile.typescript && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
636
659
  for (const map of virtualFiles.getMaps(virtualFile)) {
637
660
  if (map[1][0] === sourceFile.snapshot) {
@@ -121,7 +121,7 @@ function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts, exts
121
121
  const text = snapshot.getText(0, snapshot.getLength());
122
122
  let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n');
123
123
  for (const file of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
124
- const ext = file.id.substring(fileName.length);
124
+ const ext = file.fileName.substring(fileName.length);
125
125
  if (file.typescript && (ext === '.d.ts' || ext.match(/^\.(js|ts)x?$/))) {
126
126
  extension = ext;
127
127
  scriptKind = file.typescript.scriptKind;
@@ -8,8 +8,7 @@ const utilities_1 = require("../typescript/utilities");
8
8
  const scriptVersions = new Map();
9
9
  const fsFileSnapshots = new Map();
10
10
  function createLanguage(ts, sys, languages, configFileName, projectHost) {
11
- const files = (0, language_core_1.createFileProvider)(languages, sys.useCaseSensitiveFileNames, (id) => {
12
- const fileName = projectHost.getFileName(id);
11
+ const files = (0, language_core_1.createFileProvider)(languages, sys.useCaseSensitiveFileNames, fileName => {
13
12
  // opened files
14
13
  let snapshot = projectHost.getScriptSnapshot(fileName);
15
14
  if (!snapshot) {
@@ -29,10 +28,10 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
29
28
  snapshot = fsFileSnapshots.get(fileName)?.[1];
30
29
  }
31
30
  if (snapshot) {
32
- files.updateSourceFile(id, projectHost.getLanguageId(id), snapshot);
31
+ files.updateSourceFile(fileName, projectHost.getLanguageId(fileName), snapshot);
33
32
  }
34
33
  else {
35
- files.deleteSourceFile(id);
34
+ files.deleteSourceFile(fileName);
36
35
  }
37
36
  });
38
37
  let languageServiceHost = createLanguageServiceHost();
@@ -95,7 +94,6 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
95
94
  ...sys,
96
95
  getCurrentDirectory: projectHost.getCurrentDirectory,
97
96
  getCompilationSettings: projectHost.getCompilationSettings,
98
- getCancellationToken: projectHost.getCancellationToken,
99
97
  getLocalizedDiagnosticMessages: projectHost.getLocalizedDiagnosticMessages,
100
98
  getProjectReferences: projectHost.getProjectReferences,
101
99
  getDefaultLibFileName: (options) => {
@@ -153,9 +151,9 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
153
151
  };
154
152
  }, sys?.realpath ? (path => sys.realpath(path)) : (path => path));
155
153
  matches = matches.map(match => {
156
- const [_, source] = files.getVirtualFile(projectHost.getFileId(match));
154
+ const [_, source] = files.getVirtualFile(match);
157
155
  if (source) {
158
- return projectHost.getFileName(source.id);
156
+ return source.fileName;
159
157
  }
160
158
  return match;
161
159
  });
@@ -174,11 +172,11 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
174
172
  },
175
173
  getScriptKind(fileName) {
176
174
  syncSourceFile(fileName);
177
- const virtualFile = files.getVirtualFile(projectHost.getFileId(fileName))[0];
175
+ const virtualFile = files.getVirtualFile(fileName)[0];
178
176
  if (virtualFile?.typescript) {
179
177
  return virtualFile.typescript.scriptKind;
180
178
  }
181
- const sourceFile = files.getSourceFile(projectHost.getFileId(fileName));
179
+ const sourceFile = files.getSourceFile(fileName);
182
180
  if (sourceFile?.virtualFile) {
183
181
  return ts.ScriptKind.Deferred;
184
182
  }
@@ -209,7 +207,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
209
207
  for (const language of languages) {
210
208
  const sourceFileName = language.typescript?.resolveSourceFileName(tsFileName);
211
209
  if (sourceFileName) {
212
- files.getSourceFile(projectHost.getFileId(sourceFileName)); // trigger sync
210
+ files.getSourceFile(sourceFileName); // trigger sync
213
211
  }
214
212
  }
215
213
  }
@@ -223,13 +221,12 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
223
221
  const newOtherVirtualFileSnapshots = new Set();
224
222
  const tsFileNamesSet = new Set();
225
223
  for (const fileName of projectHost.getScriptFileNames()) {
226
- const uri = projectHost.getFileId(fileName);
227
- const sourceFile = files.getSourceFile(uri);
224
+ const sourceFile = files.getSourceFile(fileName);
228
225
  if (sourceFile?.virtualFile) {
229
226
  for (const file of (0, language_core_2.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
230
227
  if (file.typescript) {
231
228
  newTsVirtualFileSnapshots.add(file.snapshot);
232
- tsFileNamesSet.add(projectHost.getFileName(file.id)); // virtual .ts
229
+ tsFileNamesSet.add(file.fileName); // virtual .ts
233
230
  }
234
231
  else {
235
232
  newOtherVirtualFileSnapshots.add(file.snapshot);
@@ -256,12 +253,11 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
256
253
  }
257
254
  function getScriptSnapshot(fileName) {
258
255
  syncSourceFile(fileName);
259
- const uri = projectHost.getFileId(fileName);
260
- const virtualFile = files.getVirtualFile(uri)[0];
256
+ const virtualFile = files.getVirtualFile(fileName)[0];
261
257
  if (virtualFile) {
262
258
  return virtualFile.snapshot;
263
259
  }
264
- const sourceFile = files.getSourceFile(uri);
260
+ const sourceFile = files.getSourceFile(fileName);
265
261
  if (sourceFile && !sourceFile.virtualFile) {
266
262
  return sourceFile.snapshot;
267
263
  }
@@ -272,7 +268,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
272
268
  scriptVersions.set(fileName, { lastVersion: 0, map: new WeakMap() });
273
269
  }
274
270
  const version = scriptVersions.get(fileName);
275
- const virtualFile = files.getVirtualFile(projectHost.getFileId(fileName))[0];
271
+ const virtualFile = files.getVirtualFile(fileName)[0];
276
272
  if (virtualFile) {
277
273
  if (!version.map.has(virtualFile.snapshot)) {
278
274
  version.map.set(virtualFile.snapshot, version.lastVersion++);
@@ -281,7 +277,7 @@ function createLanguage(ts, sys, languages, configFileName, projectHost) {
281
277
  }
282
278
  const isOpenedFile = !!projectHost.getScriptSnapshot(fileName);
283
279
  if (isOpenedFile) {
284
- const sourceFile = files.getSourceFile(projectHost.getFileId(fileName));
280
+ const sourceFile = files.getSourceFile(fileName);
285
281
  if (sourceFile && !sourceFile.virtualFile) {
286
282
  if (!version.map.has(sourceFile.snapshot)) {
287
283
  version.map.set(sourceFile.snapshot, version.lastVersion++);
@@ -1,6 +1,3 @@
1
1
  import { type FileProvider } from '@volar/language-core';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider, { getFileId, getFileName }: {
4
- getFileId(fileName: string): string;
5
- getFileName(id: string): string;
6
- }, ls: ts.LanguageService, sys: ts.System): ts.Program;
3
+ export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), files: FileProvider, ls: ts.LanguageService, sys: ts.System): ts.Program;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProgram = void 0;
4
4
  const language_core_1 = require("@volar/language-core");
5
- function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
5
+ function getProgram(ts, files, ls, sys) {
6
6
  const proxy = {
7
7
  getRootFileNames,
8
8
  emit,
@@ -50,8 +50,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
50
50
  }
51
51
  function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
52
52
  if (sourceFile) {
53
- const uri = getFileId(sourceFile.fileName);
54
- const [virtualFile, source] = files.getVirtualFile(uri);
53
+ const [virtualFile, source] = files.getVirtualFile(sourceFile.fileName);
55
54
  if (virtualFile && source) {
56
55
  if (!virtualFile.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)))
57
56
  return [];
@@ -79,11 +78,9 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
79
78
  if (diagnostic.file !== undefined
80
79
  && diagnostic.start !== undefined
81
80
  && diagnostic.length !== undefined) {
82
- const uri = getFileId(diagnostic.file.fileName);
83
- const [virtualFile, source] = files.getVirtualFile(uri);
81
+ const [virtualFile, source] = files.getVirtualFile(diagnostic.file.fileName);
84
82
  if (virtualFile && source) {
85
- const sourceFileName = getFileName(source.id);
86
- if (sys.fileExists?.(sourceFileName) === false)
83
+ if (sys.fileExists?.(source.fileName) === false)
87
84
  continue;
88
85
  for (const [_, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
89
86
  if (sourceSnapshot !== source.snapshot)
@@ -94,7 +91,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
94
91
  for (const end of map.getSourceOffsets(diagnostic.start + diagnostic.length)) {
95
92
  if (!(0, language_core_1.shouldReportDiagnostics)(end[1].data))
96
93
  continue;
97
- onMapping(diagnostic, sourceFileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
94
+ onMapping(diagnostic, source.fileName, start[0], end[0], source.snapshot.getText(0, source.snapshot.getLength()));
98
95
  break;
99
96
  }
100
97
  break;
@@ -118,8 +115,7 @@ function getProgram(ts, files, { getFileId, getFileName }, ls, sys) {
118
115
  : undefined;
119
116
  if (!file) {
120
117
  if (docText === undefined) {
121
- const uri = getFileId(fileName);
122
- const snapshot = files.getSourceFile(uri)?.snapshot;
118
+ const snapshot = files.getSourceFile(fileName)?.snapshot;
123
119
  if (snapshot) {
124
120
  docText = snapshot.getText(0, snapshot.getLength());
125
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,12 +12,12 @@
12
12
  "directory": "packages/typescript"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.0.0-alpha.1",
15
+ "@volar/language-core": "2.0.0-alpha.3",
16
16
  "path-browserify": "^1.0.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/path-browserify": "latest",
20
- "@volar/language-service": "2.0.0-alpha.1"
20
+ "@volar/language-service": "2.0.0-alpha.3"
21
21
  },
22
- "gitHead": "3af80b55081397c58cc5c0b6ed44d1810aa0dea1"
22
+ "gitHead": "0bb685a72cff180bb9b3420aaf3136c8e899c908"
23
23
  }