@volar/typescript 1.0.14 → 1.0.17

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.
@@ -1,3 +1,3 @@
1
1
  import type * as ts from 'typescript/lib/tsserverlibrary';
2
2
  import type * as embedded from '@volar/language-core';
3
- export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), core: embedded.EmbeddedLanguageContext, ls: ts.LanguageService): any;
3
+ export declare function getProgram(ts: typeof import('typescript/lib/tsserverlibrary'), core: embedded.LanguageContext, ls: ts.LanguageService): any;
package/out/getProgram.js CHANGED
@@ -26,7 +26,7 @@ function getProgram(ts, core, ls) {
26
26
  return ls.getProgram();
27
27
  }
28
28
  function getRootFileNames() {
29
- return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = core.typescriptLanguageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, fileName); });
29
+ return getProgram().getRootFileNames().filter(fileName => { var _a, _b; return (_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, fileName); });
30
30
  }
31
31
  // for vue-tsc --noEmit --watch
32
32
  function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
@@ -42,9 +42,9 @@ function getProgram(ts, core, ls) {
42
42
  function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
43
43
  var _a, _b, _c;
44
44
  if (sourceFile) {
45
- const mapped = core.mapper.fromEmbeddedFileName(sourceFile.fileName);
46
- if (mapped) {
47
- if (!mapped.embedded.capabilities.diagnostic)
45
+ const source = core.virtualFiles.getSourceByVirtualFileName(sourceFile.fileName);
46
+ if (source) {
47
+ if (!source[2].capabilities.diagnostic)
48
48
  return [];
49
49
  const errors = transformDiagnostics((_b = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a[api](sourceFile, cancellationToken)) !== null && _b !== void 0 ? _b : []);
50
50
  return errors;
@@ -58,7 +58,7 @@ function getProgram(ts, core, ls) {
58
58
  }
59
59
  function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
60
60
  var _a;
61
- const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.typescriptLanguageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
61
+ const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.typescript.languageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
62
62
  return {
63
63
  emitSkipped: scriptResult.emitSkipped,
64
64
  emittedFiles: scriptResult.emittedFiles,
@@ -67,24 +67,36 @@ function getProgram(ts, core, ls) {
67
67
  }
68
68
  // transform
69
69
  function transformDiagnostics(diagnostics) {
70
- var _a, _b, _c;
70
+ var _a, _b, _c, _d;
71
71
  const result = [];
72
72
  for (const diagnostic of diagnostics) {
73
73
  if (diagnostic.file !== undefined
74
74
  && diagnostic.start !== undefined
75
75
  && diagnostic.length !== undefined) {
76
- for (const start of core.mapper.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start)) {
77
- if (start.mapping && !start.mapping.data.diagnostic)
78
- continue;
79
- if (!((_b = (_a = core.typescriptLanguageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, start.fileName)))
76
+ const source = core.virtualFiles.getSourceByVirtualFileName(diagnostic.file.fileName);
77
+ if (source) {
78
+ if (((_b = (_a = core.typescript.languageServiceHost).fileExists) === null || _b === void 0 ? void 0 : _b.call(_a, source[0])) === false)
80
79
  continue;
81
- for (const end of core.mapper.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start + diagnostic.length, true)) {
82
- if (end.mapping && !end.mapping.data.diagnostic)
80
+ for (const [sourceFileName, map] of core.virtualFiles.getMaps(source[2])) {
81
+ if (sourceFileName !== source[0])
83
82
  continue;
84
- onMapping(diagnostic, start.fileName, start.offset, end.offset, (_c = core.mapper.get(start.fileName)) === null || _c === void 0 ? void 0 : _c[0].text);
85
- break;
83
+ for (const start of map.toSourceOffsets(diagnostic.start)) {
84
+ if (!start[1].data.diagnostic)
85
+ continue;
86
+ for (const end of map.toSourceOffsets(diagnostic.start + diagnostic.length, true)) {
87
+ if (!end[1].data.diagnostic)
88
+ continue;
89
+ onMapping(diagnostic, source[0], start[0], end[0], source[1].getText(0, source[1].getLength()));
90
+ break;
91
+ }
92
+ break;
93
+ }
86
94
  }
87
- break;
95
+ }
96
+ else {
97
+ if (((_d = (_c = core.typescript.languageServiceHost).fileExists) === null || _d === void 0 ? void 0 : _d.call(_c, diagnostic.file.fileName)) === false)
98
+ continue;
99
+ onMapping(diagnostic, diagnostic.file.fileName, diagnostic.start, diagnostic.start + diagnostic.length, diagnostic.file.text);
88
100
  }
89
101
  }
90
102
  else if (diagnostic.file === undefined) {
@@ -99,7 +111,7 @@ function getProgram(ts, core, ls) {
99
111
  : undefined;
100
112
  if (!file) {
101
113
  if (docText === undefined) {
102
- const snapshot = core.typescriptLanguageServiceHost.getScriptSnapshot(fileName);
114
+ const snapshot = core.typescript.languageServiceHost.getScriptSnapshot(fileName);
103
115
  if (snapshot) {
104
116
  docText = snapshot.getText(0, snapshot.getLength());
105
117
  }
package/out/index.d.ts CHANGED
@@ -3,6 +3,6 @@ import * as embedded from '@volar/language-core';
3
3
  export declare function createLanguageService(host: embedded.LanguageServiceHost, mods: embedded.LanguageModule[]): {
4
4
  __internal__: {
5
5
  languageService: ts.LanguageService;
6
- context: embedded.EmbeddedLanguageContext;
6
+ context: embedded.LanguageContext;
7
7
  };
8
8
  } & ts.LanguageService;
package/out/index.js CHANGED
@@ -3,9 +3,9 @@ exports.createLanguageService = void 0;
3
3
  const getProgram_1 = require("./getProgram");
4
4
  const embedded = require("@volar/language-core");
5
5
  function createLanguageService(host, mods) {
6
- const core = embedded.createEmbeddedLanguageServiceHost(host, mods);
6
+ const core = embedded.createLanguageContext(host, mods);
7
7
  const ts = host.getTypeScriptModule();
8
- const ls = ts.createLanguageService(core.typescriptLanguageServiceHost);
8
+ const ls = ts.createLanguageService(core.typescript.languageServiceHost);
9
9
  return new Proxy({
10
10
  organizeImports,
11
11
  // only support for .ts for now, not support for .vue
@@ -43,10 +43,11 @@ function createLanguageService(host, mods) {
43
43
  });
44
44
  // apis
45
45
  function organizeImports(args, formatOptions, preferences) {
46
- const file = core.mapper.get(args.fileName);
46
+ var _a;
47
47
  let edits = [];
48
+ const file = (_a = core.virtualFiles.get(args.fileName)) === null || _a === void 0 ? void 0 : _a[1];
48
49
  if (file) {
49
- embedded.forEachEmbeddeds(file[0], embedded => {
50
+ embedded.forEachEmbeddedFile(file, embedded => {
50
51
  if (embedded.kind && embedded.capabilities.codeAction) {
51
52
  edits = edits.concat(ls.organizeImports(Object.assign(Object.assign({}, args), { fileName: embedded.fileName }), formatOptions, preferences));
52
53
  }
@@ -82,9 +83,10 @@ function createLanguageService(host, mods) {
82
83
  function findLocations(fileName, position, mode, findInStrings = false, findInComments = false, providePrefixAndSuffixTextForRename) {
83
84
  const loopChecker = new Set();
84
85
  let symbols = [];
85
- withTeleports(fileName, position);
86
+ withMirrors(fileName, position);
86
87
  return symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty);
87
- function withTeleports(fileName, position) {
88
+ function withMirrors(fileName, position) {
89
+ var _a;
88
90
  if (loopChecker.has(fileName + ':' + position))
89
91
  return;
90
92
  loopChecker.add(fileName + ':' + position);
@@ -99,21 +101,22 @@ function createLanguageService(host, mods) {
99
101
  symbols = symbols.concat(_symbols);
100
102
  for (const ref of _symbols) {
101
103
  loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
102
- const teleport = core.mapper.getTeleport(ref.fileName);
103
- if (!teleport)
104
+ const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
105
+ if (!virtualFile)
104
106
  continue;
105
- for (const teleOffset of teleport.findTeleports(ref.textSpan.start, data => {
107
+ const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
108
+ if (!mirrorMap)
109
+ continue;
110
+ for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
106
111
  if ((mode === 'definition' || mode === 'typeDefinition' || mode === 'implementation') && !data.definition)
107
- return false;
112
+ continue;
108
113
  if ((mode === 'references') && !data.references)
109
- return false;
114
+ continue;
110
115
  if ((mode === 'rename') && !data.rename)
111
- return false;
112
- return true;
113
- })) {
114
- if (loopChecker.has(ref.fileName + ':' + teleOffset))
115
116
  continue;
116
- withTeleports(ref.fileName, teleOffset);
117
+ if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
118
+ continue;
119
+ withMirrors(ref.fileName, mirrorOffset);
117
120
  }
118
121
  }
119
122
  }
@@ -122,14 +125,15 @@ function createLanguageService(host, mods) {
122
125
  const loopChecker = new Set();
123
126
  let textSpan;
124
127
  let symbols = [];
125
- withTeleports(fileName, position);
128
+ withMirrors(fileName, position);
126
129
  if (!textSpan)
127
130
  return;
128
131
  return {
129
132
  textSpan: textSpan,
130
133
  definitions: symbols === null || symbols === void 0 ? void 0 : symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty),
131
134
  };
132
- function withTeleports(fileName, position) {
135
+ function withMirrors(fileName, position) {
136
+ var _a;
133
137
  if (loopChecker.has(fileName + ':' + position))
134
138
  return;
135
139
  loopChecker.add(fileName + ':' + position);
@@ -144,13 +148,18 @@ function createLanguageService(host, mods) {
144
148
  symbols = symbols.concat(_symbols.definitions);
145
149
  for (const ref of _symbols.definitions) {
146
150
  loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
147
- const teleport = core.mapper.getTeleport(ref.fileName);
148
- if (!teleport)
151
+ const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
152
+ if (!virtualFile)
149
153
  continue;
150
- for (const teleOffset of teleport.findTeleports(ref.textSpan.start, data => !!data.definition)) {
151
- if (loopChecker.has(ref.fileName + ':' + teleOffset))
154
+ const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
155
+ if (!mirrorMap)
156
+ continue;
157
+ for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
158
+ if (!data.definition)
159
+ continue;
160
+ if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
152
161
  continue;
153
- withTeleports(ref.fileName, teleOffset);
162
+ withMirrors(ref.fileName, mirrorOffset);
154
163
  }
155
164
  }
156
165
  }
@@ -158,9 +167,10 @@ function createLanguageService(host, mods) {
158
167
  function findReferences(fileName, position) {
159
168
  const loopChecker = new Set();
160
169
  let symbols = [];
161
- withTeleports(fileName, position);
170
+ withMirrors(fileName, position);
162
171
  return symbols.map(s => transformReferencedSymbol(s)).filter(notEmpty);
163
- function withTeleports(fileName, position) {
172
+ function withMirrors(fileName, position) {
173
+ var _a;
164
174
  if (loopChecker.has(fileName + ':' + position))
165
175
  return;
166
176
  loopChecker.add(fileName + ':' + position);
@@ -171,13 +181,18 @@ function createLanguageService(host, mods) {
171
181
  for (const symbol of _symbols) {
172
182
  for (const ref of symbol.references) {
173
183
  loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
174
- const teleport = core.mapper.getTeleport(ref.fileName);
175
- if (!teleport)
184
+ const virtualFile = (_a = core.virtualFiles.getSourceByVirtualFileName(ref.fileName)) === null || _a === void 0 ? void 0 : _a[2];
185
+ if (!virtualFile)
186
+ continue;
187
+ const mirrorMap = core.virtualFiles.getMirrorMap(virtualFile);
188
+ if (!mirrorMap)
176
189
  continue;
177
- for (const telePos of teleport.findTeleports(ref.textSpan.start, data => !!data.references)) {
178
- if (loopChecker.has(ref.fileName + ':' + telePos))
190
+ for (const [mirrorOffset, data] of mirrorMap.findMirrorOffsets(ref.textSpan.start)) {
191
+ if (!data.references)
179
192
  continue;
180
- withTeleports(ref.fileName, telePos);
193
+ if (loopChecker.has(ref.fileName + ':' + mirrorOffset))
194
+ continue;
195
+ withMirrors(ref.fileName, mirrorOffset);
181
196
  }
182
197
  }
183
198
  }
@@ -185,9 +200,9 @@ function createLanguageService(host, mods) {
185
200
  }
186
201
  // transforms
187
202
  function transformFileTextChanges(changes) {
188
- const sourceFile = core.mapper.fromEmbeddedFileName(changes.fileName);
189
- if (sourceFile) {
190
- return Object.assign(Object.assign({}, changes), { fileName: sourceFile.sourceFile.fileName, textChanges: changes.textChanges.map(c => {
203
+ const source = core.virtualFiles.getSourceByVirtualFileName(changes.fileName);
204
+ if (source) {
205
+ return Object.assign(Object.assign({}, changes), { fileName: source[0], textChanges: changes.textChanges.map(c => {
191
206
  const span = transformSpan(changes.fileName, c.span);
192
207
  if (span) {
193
208
  return Object.assign(Object.assign({}, c), { span: span.textSpan });
@@ -228,13 +243,27 @@ function createLanguageService(host, mods) {
228
243
  return;
229
244
  if (!textSpan)
230
245
  return;
231
- for (const sourceLoc of core.mapper.fromEmbeddedLocation(fileName, textSpan.start)) {
246
+ const source = core.virtualFiles.getSourceByVirtualFileName(fileName);
247
+ if (source) {
248
+ for (const [sourceFileName, map] of core.virtualFiles.getMaps(source[2])) {
249
+ if (source[0] !== sourceFileName)
250
+ continue;
251
+ const sourceLoc = map.toSourceOffset(textSpan.start);
252
+ if (sourceLoc) {
253
+ return {
254
+ fileName: source[0],
255
+ textSpan: {
256
+ start: sourceLoc[0],
257
+ length: textSpan.length,
258
+ },
259
+ };
260
+ }
261
+ }
262
+ }
263
+ else {
232
264
  return {
233
- fileName: sourceLoc.fileName,
234
- textSpan: {
235
- start: sourceLoc.offset,
236
- length: textSpan.length,
237
- },
265
+ fileName,
266
+ textSpan,
238
267
  };
239
268
  }
240
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.0.14",
3
+ "version": "1.0.17",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/typescript"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.0.14"
16
+ "@volar/language-core": "1.0.17"
17
17
  },
18
- "gitHead": "ce4d48b37db784400e15fe08282edc836e24d4cd"
18
+ "gitHead": "b66b64f579b5cafee9b8d70aa9f9303f39b6df49"
19
19
  }