@volar/typescript 1.0.0-rc.4
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.
- package/LICENSE +21 -0
- package/out/getProgram.d.ts +3 -0
- package/out/getProgram.js +121 -0
- package/out/index.d.ts +2 -0
- package/out/index.js +250 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Johnson Chu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.getProgram = void 0;
|
|
3
|
+
function getProgram(ts, core, ls) {
|
|
4
|
+
const proxy = {
|
|
5
|
+
getRootFileNames,
|
|
6
|
+
emit,
|
|
7
|
+
getSyntacticDiagnostics,
|
|
8
|
+
getSemanticDiagnostics,
|
|
9
|
+
getGlobalDiagnostics,
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
getBindAndCheckDiagnostics,
|
|
12
|
+
};
|
|
13
|
+
return new Proxy({}, {
|
|
14
|
+
get: (target, property) => {
|
|
15
|
+
if (property in proxy) {
|
|
16
|
+
return proxy[property];
|
|
17
|
+
}
|
|
18
|
+
const program = getProgram();
|
|
19
|
+
if (property in program) {
|
|
20
|
+
return program[property];
|
|
21
|
+
}
|
|
22
|
+
return target[property];
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
function getProgram() {
|
|
26
|
+
return ls.getProgram();
|
|
27
|
+
}
|
|
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); });
|
|
30
|
+
}
|
|
31
|
+
// for vue-tsc --noEmit --watch
|
|
32
|
+
function getBindAndCheckDiagnostics(sourceFile, cancellationToken) {
|
|
33
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getBindAndCheckDiagnostics');
|
|
34
|
+
}
|
|
35
|
+
// for vue-tsc --noEmit
|
|
36
|
+
function getSyntacticDiagnostics(sourceFile, cancellationToken) {
|
|
37
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSyntacticDiagnostics');
|
|
38
|
+
}
|
|
39
|
+
function getSemanticDiagnostics(sourceFile, cancellationToken) {
|
|
40
|
+
return getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, 'getSemanticDiagnostics');
|
|
41
|
+
}
|
|
42
|
+
function getSourceFileDiagnosticsWorker(sourceFile, cancellationToken, api) {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
if (sourceFile) {
|
|
45
|
+
const mapped = core.mapper.fromEmbeddedFileName(sourceFile.fileName);
|
|
46
|
+
if (mapped) {
|
|
47
|
+
if (!mapped.embedded.capabilities.diagnostic)
|
|
48
|
+
return [];
|
|
49
|
+
const errors = transformDiagnostics((_b = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a[api](sourceFile, cancellationToken)) !== null && _b !== void 0 ? _b : []);
|
|
50
|
+
return errors;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return transformDiagnostics((_c = getProgram()[api](sourceFile, cancellationToken)) !== null && _c !== void 0 ? _c : []);
|
|
54
|
+
}
|
|
55
|
+
function getGlobalDiagnostics(cancellationToken) {
|
|
56
|
+
var _a;
|
|
57
|
+
return transformDiagnostics((_a = getProgram().getGlobalDiagnostics(cancellationToken)) !== null && _a !== void 0 ? _a : []);
|
|
58
|
+
}
|
|
59
|
+
function emit(targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) {
|
|
60
|
+
var _a;
|
|
61
|
+
const scriptResult = getProgram().emit(targetSourceFile, ((_a = core.typescriptLanguageServiceHost.writeFile) !== null && _a !== void 0 ? _a : ts.sys.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
62
|
+
return {
|
|
63
|
+
emitSkipped: scriptResult.emitSkipped,
|
|
64
|
+
emittedFiles: scriptResult.emittedFiles,
|
|
65
|
+
diagnostics: transformDiagnostics(scriptResult.diagnostics),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// transform
|
|
69
|
+
function transformDiagnostics(diagnostics) {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
const result = [];
|
|
72
|
+
for (const diagnostic of diagnostics) {
|
|
73
|
+
if (diagnostic.file !== undefined
|
|
74
|
+
&& diagnostic.start !== undefined
|
|
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)))
|
|
80
|
+
continue;
|
|
81
|
+
for (const end of core.mapper.fromEmbeddedLocation(diagnostic.file.fileName, diagnostic.start + diagnostic.length)) {
|
|
82
|
+
if (end.mapping && !end.mapping.data.diagnostic)
|
|
83
|
+
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;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (diagnostic.file === undefined) {
|
|
91
|
+
result.push(diagnostic);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
function onMapping(diagnostic, fileName, start, end, docText) {
|
|
96
|
+
var _a;
|
|
97
|
+
let file = fileName === ((_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.fileName)
|
|
98
|
+
? diagnostic.file
|
|
99
|
+
: undefined;
|
|
100
|
+
if (!file) {
|
|
101
|
+
if (docText === undefined) {
|
|
102
|
+
const snapshot = core.typescriptLanguageServiceHost.getScriptSnapshot(fileName);
|
|
103
|
+
if (snapshot) {
|
|
104
|
+
docText = snapshot.getText(0, snapshot.getLength());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
file = ts.createSourceFile(fileName, docText, fileName.endsWith('.vue') || fileName.endsWith('.md') || fileName.endsWith('.html') ? ts.ScriptTarget.JSON : ts.ScriptTarget.Latest);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const newDiagnostic = Object.assign(Object.assign({}, diagnostic), { file, start: start, length: end - start });
|
|
112
|
+
const relatedInformation = diagnostic.relatedInformation;
|
|
113
|
+
if (relatedInformation) {
|
|
114
|
+
newDiagnostic.relatedInformation = transformDiagnostics(relatedInformation);
|
|
115
|
+
}
|
|
116
|
+
result.push(newDiagnostic);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.getProgram = getProgram;
|
|
121
|
+
//# sourceMappingURL=getProgram.js.map
|
package/out/index.d.ts
ADDED
package/out/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.createLanguageService = void 0;
|
|
3
|
+
const tsFaster = require("@volar/typescript-faster");
|
|
4
|
+
const vue = require("@volar/vue-language-core");
|
|
5
|
+
const getProgram_1 = require("./getProgram");
|
|
6
|
+
const embedded = require("@volar/language-core");
|
|
7
|
+
function createLanguageService(host) {
|
|
8
|
+
const mods = [vue.createEmbeddedLanguageModule(host.getTypeScriptModule(), host.getCurrentDirectory(), host.getCompilationSettings(), host.getVueCompilationSettings(), ['.vue'])];
|
|
9
|
+
return create(host, mods);
|
|
10
|
+
}
|
|
11
|
+
exports.createLanguageService = createLanguageService;
|
|
12
|
+
function create(host, mods) {
|
|
13
|
+
const core = embedded.createEmbeddedLanguageServiceHost(host, mods);
|
|
14
|
+
const ts = host.getTypeScriptModule();
|
|
15
|
+
const ls = ts.createLanguageService(core.typescriptLanguageServiceHost);
|
|
16
|
+
tsFaster.decorate(ts, core.typescriptLanguageServiceHost, ls);
|
|
17
|
+
const proxy = {
|
|
18
|
+
organizeImports,
|
|
19
|
+
// only support for .ts for now, not support for .vue
|
|
20
|
+
getCompletionsAtPosition,
|
|
21
|
+
getDefinitionAtPosition,
|
|
22
|
+
getDefinitionAndBoundSpan,
|
|
23
|
+
getTypeDefinitionAtPosition,
|
|
24
|
+
getImplementationAtPosition,
|
|
25
|
+
findRenameLocations,
|
|
26
|
+
getReferencesAtPosition,
|
|
27
|
+
findReferences,
|
|
28
|
+
// TODO: now is handled by vue server
|
|
29
|
+
// prepareCallHierarchy: tsLanguageService.rawLs.prepareCallHierarchy,
|
|
30
|
+
// provideCallHierarchyIncomingCalls: tsLanguageService.rawLs.provideCallHierarchyIncomingCalls,
|
|
31
|
+
// provideCallHierarchyOutgoingCalls: tsLanguageService.rawLs.provideCallHierarchyOutgoingCalls,
|
|
32
|
+
// getEditsForFileRename: tsLanguageService.rawLs.getEditsForFileRename,
|
|
33
|
+
// TODO
|
|
34
|
+
// getCodeFixesAtPosition: tsLanguageService.rawLs.getCodeFixesAtPosition,
|
|
35
|
+
// getCombinedCodeFix: tsLanguageService.rawLs.getCombinedCodeFix,
|
|
36
|
+
// applyCodeActionCommand: tsLanguageService.rawLs.applyCodeActionCommand,
|
|
37
|
+
// getApplicableRefactors: tsLanguageService.rawLs.getApplicableRefactors,
|
|
38
|
+
// getEditsForRefactor: tsLanguageService.rawLs.getEditsForRefactor,
|
|
39
|
+
getProgram: () => (0, getProgram_1.getProgram)(ts, core, ls),
|
|
40
|
+
};
|
|
41
|
+
return new Proxy(ls, {
|
|
42
|
+
get: (target, property) => {
|
|
43
|
+
if (property in proxy) {
|
|
44
|
+
return proxy[property];
|
|
45
|
+
}
|
|
46
|
+
return target[property];
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
// apis
|
|
50
|
+
function organizeImports(args, formatOptions, preferences) {
|
|
51
|
+
const file = core.mapper.get(args.fileName);
|
|
52
|
+
let edits = [];
|
|
53
|
+
if (file) {
|
|
54
|
+
embedded.forEachEmbeddeds(file[0].embeddeds, embedded => {
|
|
55
|
+
if (embedded.kind && embedded.capabilities.codeAction) {
|
|
56
|
+
edits = edits.concat(ls.organizeImports(Object.assign(Object.assign({}, args), { fileName: embedded.fileName }), formatOptions, preferences));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return ls.organizeImports(args, formatOptions, preferences);
|
|
62
|
+
}
|
|
63
|
+
return edits.map(transformFileTextChanges).filter(notEmpty);
|
|
64
|
+
}
|
|
65
|
+
function getCompletionsAtPosition(fileName, position, options) {
|
|
66
|
+
const finalResult = ls.getCompletionsAtPosition(fileName, position, options);
|
|
67
|
+
if (finalResult) {
|
|
68
|
+
finalResult.entries = finalResult.entries.filter(entry => entry.name.indexOf('__VLS_') === -1);
|
|
69
|
+
}
|
|
70
|
+
return finalResult;
|
|
71
|
+
}
|
|
72
|
+
function getReferencesAtPosition(fileName, position) {
|
|
73
|
+
return findLocations(fileName, position, 'references');
|
|
74
|
+
}
|
|
75
|
+
function getDefinitionAtPosition(fileName, position) {
|
|
76
|
+
return findLocations(fileName, position, 'definition');
|
|
77
|
+
}
|
|
78
|
+
function getTypeDefinitionAtPosition(fileName, position) {
|
|
79
|
+
return findLocations(fileName, position, 'typeDefinition');
|
|
80
|
+
}
|
|
81
|
+
function getImplementationAtPosition(fileName, position) {
|
|
82
|
+
return findLocations(fileName, position, 'implementation');
|
|
83
|
+
}
|
|
84
|
+
function findRenameLocations(fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename) {
|
|
85
|
+
return findLocations(fileName, position, 'rename', findInStrings, findInComments, providePrefixAndSuffixTextForRename);
|
|
86
|
+
}
|
|
87
|
+
function findLocations(fileName, position, mode, findInStrings = false, findInComments = false, providePrefixAndSuffixTextForRename) {
|
|
88
|
+
const loopChecker = new Set();
|
|
89
|
+
let symbols = [];
|
|
90
|
+
withTeleports(fileName, position);
|
|
91
|
+
return symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty);
|
|
92
|
+
function withTeleports(fileName, position) {
|
|
93
|
+
if (loopChecker.has(fileName + ':' + position))
|
|
94
|
+
return;
|
|
95
|
+
loopChecker.add(fileName + ':' + position);
|
|
96
|
+
const _symbols = mode === 'definition' ? ls.getDefinitionAtPosition(fileName, position)
|
|
97
|
+
: mode === 'typeDefinition' ? ls.getTypeDefinitionAtPosition(fileName, position)
|
|
98
|
+
: mode === 'references' ? ls.getReferencesAtPosition(fileName, position)
|
|
99
|
+
: mode === 'implementation' ? ls.getImplementationAtPosition(fileName, position)
|
|
100
|
+
: mode === 'rename' ? ls.findRenameLocations(fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename)
|
|
101
|
+
: undefined;
|
|
102
|
+
if (!_symbols)
|
|
103
|
+
return;
|
|
104
|
+
symbols = symbols.concat(_symbols);
|
|
105
|
+
for (const ref of _symbols) {
|
|
106
|
+
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
107
|
+
const teleport = core.mapper.getTeleport(ref.fileName);
|
|
108
|
+
if (!teleport)
|
|
109
|
+
continue;
|
|
110
|
+
for (const teleOffset of teleport.findTeleports(ref.textSpan.start, data => {
|
|
111
|
+
if ((mode === 'definition' || mode === 'typeDefinition' || mode === 'implementation') && !data.definition)
|
|
112
|
+
return false;
|
|
113
|
+
if ((mode === 'references') && !data.references)
|
|
114
|
+
return false;
|
|
115
|
+
if ((mode === 'rename') && !data.rename)
|
|
116
|
+
return false;
|
|
117
|
+
return true;
|
|
118
|
+
})) {
|
|
119
|
+
if (loopChecker.has(ref.fileName + ':' + teleOffset))
|
|
120
|
+
continue;
|
|
121
|
+
withTeleports(ref.fileName, teleOffset);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function getDefinitionAndBoundSpan(fileName, position) {
|
|
127
|
+
const loopChecker = new Set();
|
|
128
|
+
let textSpan;
|
|
129
|
+
let symbols = [];
|
|
130
|
+
withTeleports(fileName, position);
|
|
131
|
+
if (!textSpan)
|
|
132
|
+
return;
|
|
133
|
+
return {
|
|
134
|
+
textSpan: textSpan,
|
|
135
|
+
definitions: symbols === null || symbols === void 0 ? void 0 : symbols.map(s => transformDocumentSpanLike(s)).filter(notEmpty),
|
|
136
|
+
};
|
|
137
|
+
function withTeleports(fileName, position) {
|
|
138
|
+
if (loopChecker.has(fileName + ':' + position))
|
|
139
|
+
return;
|
|
140
|
+
loopChecker.add(fileName + ':' + position);
|
|
141
|
+
const _symbols = ls.getDefinitionAndBoundSpan(fileName, position);
|
|
142
|
+
if (!_symbols)
|
|
143
|
+
return;
|
|
144
|
+
if (!textSpan) {
|
|
145
|
+
textSpan = _symbols.textSpan;
|
|
146
|
+
}
|
|
147
|
+
if (!_symbols.definitions)
|
|
148
|
+
return;
|
|
149
|
+
symbols = symbols.concat(_symbols.definitions);
|
|
150
|
+
for (const ref of _symbols.definitions) {
|
|
151
|
+
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
152
|
+
const teleport = core.mapper.getTeleport(ref.fileName);
|
|
153
|
+
if (!teleport)
|
|
154
|
+
continue;
|
|
155
|
+
for (const teleOffset of teleport.findTeleports(ref.textSpan.start, data => !!data.definition)) {
|
|
156
|
+
if (loopChecker.has(ref.fileName + ':' + teleOffset))
|
|
157
|
+
continue;
|
|
158
|
+
withTeleports(ref.fileName, teleOffset);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function findReferences(fileName, position) {
|
|
164
|
+
const loopChecker = new Set();
|
|
165
|
+
let symbols = [];
|
|
166
|
+
withTeleports(fileName, position);
|
|
167
|
+
return symbols.map(s => transformReferencedSymbol(s)).filter(notEmpty);
|
|
168
|
+
function withTeleports(fileName, position) {
|
|
169
|
+
if (loopChecker.has(fileName + ':' + position))
|
|
170
|
+
return;
|
|
171
|
+
loopChecker.add(fileName + ':' + position);
|
|
172
|
+
const _symbols = ls.findReferences(fileName, position);
|
|
173
|
+
if (!_symbols)
|
|
174
|
+
return;
|
|
175
|
+
symbols = symbols.concat(_symbols);
|
|
176
|
+
for (const symbol of _symbols) {
|
|
177
|
+
for (const ref of symbol.references) {
|
|
178
|
+
loopChecker.add(ref.fileName + ':' + ref.textSpan.start);
|
|
179
|
+
const teleport = core.mapper.getTeleport(ref.fileName);
|
|
180
|
+
if (!teleport)
|
|
181
|
+
continue;
|
|
182
|
+
for (const telePos of teleport.findTeleports(ref.textSpan.start, data => !!data.references)) {
|
|
183
|
+
if (loopChecker.has(ref.fileName + ':' + telePos))
|
|
184
|
+
continue;
|
|
185
|
+
withTeleports(ref.fileName, telePos);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// transforms
|
|
192
|
+
function transformFileTextChanges(changes) {
|
|
193
|
+
const sourceFile = core.mapper.fromEmbeddedFileName(changes.fileName);
|
|
194
|
+
if (sourceFile) {
|
|
195
|
+
return Object.assign(Object.assign({}, changes), { fileName: sourceFile.sourceFile.fileName, textChanges: changes.textChanges.map(c => {
|
|
196
|
+
const span = transformSpan(changes.fileName, c.span);
|
|
197
|
+
if (span) {
|
|
198
|
+
return Object.assign(Object.assign({}, c), { span: span.textSpan });
|
|
199
|
+
}
|
|
200
|
+
}).filter(notEmpty) });
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return changes;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function transformReferencedSymbol(symbol) {
|
|
207
|
+
const definition = transformDocumentSpanLike(symbol.definition);
|
|
208
|
+
const references = symbol.references.map(r => transformDocumentSpanLike(r)).filter(notEmpty);
|
|
209
|
+
if (definition) {
|
|
210
|
+
return {
|
|
211
|
+
definition,
|
|
212
|
+
references,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
else if (references.length) { // TODO: remove patching
|
|
216
|
+
return {
|
|
217
|
+
definition: Object.assign(Object.assign({}, symbol.definition), { fileName: references[0].fileName, textSpan: references[0].textSpan }),
|
|
218
|
+
references,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function transformDocumentSpanLike(documentSpan) {
|
|
223
|
+
const textSpan = transformSpan(documentSpan.fileName, documentSpan.textSpan);
|
|
224
|
+
if (!textSpan)
|
|
225
|
+
return;
|
|
226
|
+
const contextSpan = transformSpan(documentSpan.fileName, documentSpan.contextSpan);
|
|
227
|
+
const originalTextSpan = transformSpan(documentSpan.originalFileName, documentSpan.originalTextSpan);
|
|
228
|
+
const originalContextSpan = transformSpan(documentSpan.originalFileName, documentSpan.originalContextSpan);
|
|
229
|
+
return Object.assign(Object.assign({}, documentSpan), { fileName: textSpan.fileName, textSpan: textSpan.textSpan, contextSpan: contextSpan === null || contextSpan === void 0 ? void 0 : contextSpan.textSpan, originalFileName: originalTextSpan === null || originalTextSpan === void 0 ? void 0 : originalTextSpan.fileName, originalTextSpan: originalTextSpan === null || originalTextSpan === void 0 ? void 0 : originalTextSpan.textSpan, originalContextSpan: originalContextSpan === null || originalContextSpan === void 0 ? void 0 : originalContextSpan.textSpan });
|
|
230
|
+
}
|
|
231
|
+
function transformSpan(fileName, textSpan) {
|
|
232
|
+
if (!fileName)
|
|
233
|
+
return;
|
|
234
|
+
if (!textSpan)
|
|
235
|
+
return;
|
|
236
|
+
for (const sourceLoc of core.mapper.fromEmbeddedLocation(fileName, textSpan.start)) {
|
|
237
|
+
return {
|
|
238
|
+
fileName: sourceLoc.fileName,
|
|
239
|
+
textSpan: {
|
|
240
|
+
start: sourceLoc.offset,
|
|
241
|
+
length: textSpan.length,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function notEmpty(value) {
|
|
248
|
+
return value !== null && value !== undefined;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volar/typescript",
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
|
+
"main": "out/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"out/**/*.js",
|
|
8
|
+
"out/**/*.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/johnsoncodehk/volar.git",
|
|
13
|
+
"directory": "packages/typescript"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@volar/language-core": "1.0.0-rc.4",
|
|
17
|
+
"@volar/typescript-faster": "1.0.0-rc.4"
|
|
18
|
+
}
|
|
19
|
+
}
|