volar-service-typescript 0.0.24 → 0.0.26
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/index.d.ts +3 -4
- package/index.js +74 -59
- package/lib/configs/getFormatCodeSettings.d.ts +1 -1
- package/lib/configs/getUserPreferences.d.ts +1 -1
- package/lib/configs/getUserPreferences.js +1 -1
- package/lib/features/callHierarchy.js +10 -10
- package/lib/features/codeAction.js +4 -4
- package/lib/features/codeActionResolve.d.ts +1 -1
- package/lib/features/codeActionResolve.js +3 -3
- package/lib/features/completions/basic.d.ts +1 -1
- package/lib/features/completions/basic.js +2 -2
- package/lib/features/completions/jsDoc.js +2 -2
- package/lib/features/completions/resolve.js +3 -3
- package/lib/features/definition.js +2 -2
- package/lib/features/diagnostics.d.ts +1 -1
- package/lib/features/diagnostics.js +4 -4
- package/lib/features/documentHighlight.js +2 -2
- package/lib/features/documentSymbol.js +2 -2
- package/lib/features/fileReferences.js +2 -2
- package/lib/features/fileRename.js +3 -3
- package/lib/features/foldingRanges.js +2 -2
- package/lib/features/formatting.js +5 -5
- package/lib/features/hover.js +3 -3
- package/lib/features/implementation.js +2 -2
- package/lib/features/inlayHints.js +3 -3
- package/lib/features/prepareRename.js +2 -2
- package/lib/features/references.js +2 -2
- package/lib/features/rename.d.ts +1 -1
- package/lib/features/rename.js +8 -8
- package/lib/features/selectionRanges.js +2 -2
- package/lib/features/semanticTokens.js +3 -3
- package/lib/features/signatureHelp.js +2 -2
- package/lib/features/typeDefinition.js +2 -2
- package/lib/features/workspaceSymbol.js +2 -2
- package/lib/types.d.ts +6 -6
- package/lib/utils/previewer.d.ts +1 -1
- package/lib/utils/previewer.js +1 -1
- package/lib/utils/snippetForFunctionCall.d.ts +1 -1
- package/lib/utils/transforms.d.ts +1 -1
- package/lib/utils/transforms.js +3 -3
- package/lib/utils/typeConverters.d.ts +1 -1
- package/package.json +4 -4
- package/lib/protocol.d.ts +0 -2
- package/lib/protocol.js +0 -3
package/index.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { ServicePlugin } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
export * from '@volar/typescript';
|
|
4
4
|
export interface Provide {
|
|
5
|
-
'typescript/typescript': () => typeof import('typescript
|
|
6
|
-
'typescript/sys': () => ts.System;
|
|
5
|
+
'typescript/typescript': () => typeof import('typescript');
|
|
7
6
|
'typescript/languageService': () => ts.LanguageService;
|
|
8
7
|
'typescript/languageServiceHost': () => ts.LanguageServiceHost;
|
|
9
8
|
'typescript/syntacticLanguageService': () => ts.LanguageService;
|
|
10
9
|
'typescript/syntacticLanguageServiceHost': () => ts.LanguageServiceHost;
|
|
11
10
|
}
|
|
12
|
-
export declare function create(ts: typeof import('typescript
|
|
11
|
+
export declare function create(ts: typeof import('typescript')): ServicePlugin;
|
|
13
12
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.create = void 0;
|
|
18
18
|
const semver = require("semver");
|
|
19
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
20
19
|
const shared_1 = require("./lib/shared");
|
|
20
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
21
21
|
const typescript_1 = require("@volar/typescript");
|
|
22
22
|
const tsFaster = require("typescript-auto-import-cache");
|
|
23
23
|
const _callHierarchy = require("./lib/features/callHierarchy");
|
|
@@ -77,30 +77,26 @@ function create(ts) {
|
|
|
77
77
|
};
|
|
78
78
|
const syntacticCtx = {
|
|
79
79
|
...context,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
languageService: ts.createLanguageService(syntacticServiceHost, undefined, 2),
|
|
83
|
-
},
|
|
80
|
+
languageServiceHost: syntacticServiceHost,
|
|
81
|
+
languageService: ts.createLanguageService(syntacticServiceHost, undefined, 2),
|
|
84
82
|
ts,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (virtualFile) {
|
|
89
|
-
return context.documents.get(uri, virtualFile.languageId, virtualFile.snapshot);
|
|
83
|
+
uriToFileName: uri => {
|
|
84
|
+
if (uri !== syntacticHostCtx.document?.uri) {
|
|
85
|
+
throw new Error(`uriToFileName: uri not found: ${uri}`);
|
|
90
86
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
return syntacticHostCtx.fileName;
|
|
88
|
+
},
|
|
89
|
+
fileNameToUri: fileName => {
|
|
90
|
+
if (fileName !== syntacticHostCtx.fileName) {
|
|
91
|
+
throw new Error(`fileNameToUri: fileName not found: ${fileName}`);
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
documents.set(snapshot, document);
|
|
101
|
-
}
|
|
102
|
-
return document;
|
|
93
|
+
return syntacticHostCtx.document.uri;
|
|
94
|
+
},
|
|
95
|
+
getTextDocument(uri) {
|
|
96
|
+
if (uri !== syntacticHostCtx.document?.uri) {
|
|
97
|
+
throw new Error(`getTextDocument: uri not found: ${uri}`);
|
|
103
98
|
}
|
|
99
|
+
return syntacticHostCtx.document;
|
|
104
100
|
},
|
|
105
101
|
};
|
|
106
102
|
const findDocumentSymbols = documentSymbol.register(syntacticCtx);
|
|
@@ -109,19 +105,18 @@ function create(ts) {
|
|
|
109
105
|
const syntacticService = {
|
|
110
106
|
provide: {
|
|
111
107
|
'typescript/typescript': () => ts,
|
|
112
|
-
'typescript/
|
|
113
|
-
'typescript/
|
|
114
|
-
'typescript/
|
|
115
|
-
'typescript/
|
|
116
|
-
'typescript/syntacticLanguageServiceHost': () => syntacticCtx.typescript.languageServiceHost,
|
|
108
|
+
'typescript/languageService': () => syntacticCtx.languageService,
|
|
109
|
+
'typescript/languageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
110
|
+
'typescript/syntacticLanguageService': () => syntacticCtx.languageService,
|
|
111
|
+
'typescript/syntacticLanguageServiceHost': () => syntacticCtx.languageServiceHost,
|
|
117
112
|
},
|
|
118
113
|
provideAutoInsertionEdit(document, position, lastChange) {
|
|
119
114
|
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
120
115
|
&& lastChange.text.endsWith('>')) {
|
|
121
116
|
const config = context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.autoClosingTags') ?? true;
|
|
122
117
|
if (config) {
|
|
123
|
-
prepareSyntacticService(document);
|
|
124
|
-
const close = syntacticCtx.
|
|
118
|
+
const ctx = prepareSyntacticService(document);
|
|
119
|
+
const close = syntacticCtx.languageService.getJsxClosingTagAtPosition(ctx.fileName, document.offsetAt(position));
|
|
125
120
|
if (close) {
|
|
126
121
|
return '$0' + close.newText;
|
|
127
122
|
}
|
|
@@ -163,7 +158,8 @@ function create(ts) {
|
|
|
163
158
|
provideFormattingIndentSensitiveLines(document) {
|
|
164
159
|
if (!(0, shared_1.isTsDocument)(document))
|
|
165
160
|
return;
|
|
166
|
-
const
|
|
161
|
+
const ctx = prepareSyntacticService(document);
|
|
162
|
+
const sourceFile = ts.createSourceFile(ctx.fileName, document.getText(), ts.ScriptTarget.ESNext);
|
|
167
163
|
if (sourceFile) {
|
|
168
164
|
const lines = [];
|
|
169
165
|
sourceFile.forEachChild(function walk(node) {
|
|
@@ -189,10 +185,10 @@ function create(ts) {
|
|
|
189
185
|
fileVersion: 0,
|
|
190
186
|
snapshot: ts.ScriptSnapshot.fromString(''),
|
|
191
187
|
};
|
|
192
|
-
if (!context.
|
|
188
|
+
if (!context.typescript) {
|
|
193
189
|
return syntacticService;
|
|
194
190
|
}
|
|
195
|
-
const { sys, languageServiceHost
|
|
191
|
+
const { sys, languageServiceHost } = context.typescript;
|
|
196
192
|
const created = tsFaster.createLanguageService(ts, sys, languageServiceHost, proxiedHost => ts.createLanguageService(proxiedHost, (0, typescript_1.getDocumentRegistry)(ts, sys.useCaseSensitiveFileNames, languageServiceHost.getCurrentDirectory())));
|
|
197
193
|
const { languageService } = created;
|
|
198
194
|
if (created.setPreferences && context.env.getConfiguration) {
|
|
@@ -217,7 +213,7 @@ function create(ts) {
|
|
|
217
213
|
updateSourceScriptFileNames();
|
|
218
214
|
}
|
|
219
215
|
for (const change of params.changes) {
|
|
220
|
-
const fileName = context.env.uriToFileName(change.uri);
|
|
216
|
+
const fileName = context.env.typescript.uriToFileName(change.uri);
|
|
221
217
|
if (sourceScriptNames.has(normalizeFileName(fileName))) {
|
|
222
218
|
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
|
|
223
219
|
}
|
|
@@ -226,34 +222,52 @@ function create(ts) {
|
|
|
226
222
|
function updateSourceScriptFileNames() {
|
|
227
223
|
sourceScriptNames.clear();
|
|
228
224
|
for (const fileName of languageServiceHost.getScriptFileNames()) {
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
226
|
+
const sourceFile = context.files.get(uri);
|
|
227
|
+
if (sourceFile?.generated) {
|
|
228
|
+
const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code);
|
|
229
|
+
if (tsCode) {
|
|
230
|
+
sourceScriptNames.add(normalizeFileName(fileName));
|
|
231
|
+
}
|
|
233
232
|
}
|
|
234
|
-
|
|
235
|
-
if (sourceFile && !sourceFile.virtualFile) {
|
|
233
|
+
else if (sourceFile) {
|
|
236
234
|
sourceScriptNames.add(normalizeFileName(fileName));
|
|
237
|
-
continue;
|
|
238
235
|
}
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
|
-
const documents = new WeakMap();
|
|
243
239
|
const semanticCtx = {
|
|
244
|
-
...
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
...context,
|
|
241
|
+
languageServiceHost,
|
|
242
|
+
languageService,
|
|
243
|
+
ts,
|
|
244
|
+
uriToFileName: uri => {
|
|
245
|
+
const [_virtualCode, file] = context.documents.getVirtualCodeByUri(uri);
|
|
246
|
+
if (file) {
|
|
247
|
+
return context.env.typescript.uriToFileName(file.id);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return context.env.typescript.uriToFileName(uri);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
fileNameToUri: fileName => {
|
|
254
|
+
const uri = context.env.typescript.fileNameToUri(fileName);
|
|
255
|
+
const file = context.files.get(uri);
|
|
256
|
+
if (file?.generated) {
|
|
257
|
+
const script = file.generated.languagePlugin.typescript?.getScript(file.generated.code);
|
|
258
|
+
if (script) {
|
|
259
|
+
return context.documents.getVirtualCodeUri(uri, script.code.id);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return uri;
|
|
248
263
|
},
|
|
249
264
|
getTextDocument(uri) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return context.documents.get(uri, virtualFile.languageId, virtualFile.snapshot);
|
|
265
|
+
const virtualCode = context.documents.getVirtualCodeByUri(uri)[0];
|
|
266
|
+
if (virtualCode) {
|
|
267
|
+
return context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot);
|
|
254
268
|
}
|
|
255
|
-
const sourceFile = context.
|
|
256
|
-
if (sourceFile
|
|
269
|
+
const sourceFile = context.files.get(uri);
|
|
270
|
+
if (sourceFile) {
|
|
257
271
|
return context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
258
272
|
}
|
|
259
273
|
},
|
|
@@ -483,24 +497,25 @@ function create(ts) {
|
|
|
483
497
|
},
|
|
484
498
|
};
|
|
485
499
|
async function worker(token, callback) {
|
|
486
|
-
let oldSysVersion = await
|
|
500
|
+
let oldSysVersion = await sys.sync?.();
|
|
487
501
|
let result = await callback();
|
|
488
|
-
let newSysVersion = await
|
|
502
|
+
let newSysVersion = await sys.sync?.();
|
|
489
503
|
while (newSysVersion !== oldSysVersion && !token.isCancellationRequested) {
|
|
490
504
|
oldSysVersion = newSysVersion;
|
|
491
505
|
result = await callback();
|
|
492
|
-
newSysVersion = await
|
|
506
|
+
newSysVersion = await sys.sync?.();
|
|
493
507
|
}
|
|
494
508
|
return result;
|
|
495
509
|
}
|
|
496
510
|
function prepareSyntacticService(document) {
|
|
497
|
-
if (syntacticHostCtx.document
|
|
498
|
-
|
|
511
|
+
if (syntacticHostCtx.document !== document || syntacticHostCtx.fileVersion !== document.version) {
|
|
512
|
+
syntacticHostCtx.document = document;
|
|
513
|
+
syntacticHostCtx.fileName = vscode_uri_1.URI.parse(document.uri).fsPath.replace(/\\/g, '/');
|
|
514
|
+
syntacticHostCtx.fileVersion = document.version;
|
|
515
|
+
syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
516
|
+
syntacticHostCtx.projectVersion++;
|
|
499
517
|
}
|
|
500
|
-
syntacticHostCtx
|
|
501
|
-
syntacticHostCtx.fileVersion = document.version;
|
|
502
|
-
syntacticHostCtx.snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
503
|
-
syntacticHostCtx.projectVersion++;
|
|
518
|
+
return syntacticHostCtx;
|
|
504
519
|
}
|
|
505
520
|
},
|
|
506
521
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FormattingOptions } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import type { SharedContext } from '../types';
|
|
5
5
|
export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as ts from 'typescript
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
import type { SharedContext } from '../types';
|
|
4
4
|
export declare function getUserPreferences(ctx: SharedContext, document: TextDocument): Promise<ts.UserPreferences>;
|
|
@@ -22,7 +22,7 @@ async function getUserPreferences(ctx, document) {
|
|
|
22
22
|
includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
|
|
23
23
|
includeCompletionsWithClassMemberSnippets: config.suggest?.classMemberSnippets?.enabled ?? true,
|
|
24
24
|
includeCompletionsWithObjectLiteralMethodSnippets: config.suggest?.objectLiteralMethodSnippets?.enabled ?? true,
|
|
25
|
-
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.
|
|
25
|
+
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.languageServiceHost.getCurrentDirectory()),
|
|
26
26
|
useLabelDetailsInCompletionEntries: true,
|
|
27
27
|
allowIncompleteCompletions: true,
|
|
28
28
|
displayPartsForJSDoc: true,
|
|
@@ -11,9 +11,9 @@ function register(ctx) {
|
|
|
11
11
|
const document = ctx.getTextDocument(uri);
|
|
12
12
|
if (!document)
|
|
13
13
|
return [];
|
|
14
|
-
const fileName = ctx.
|
|
14
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
15
15
|
const offset = document.offsetAt(position);
|
|
16
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.prepareCallHierarchy(fileName, offset));
|
|
17
17
|
if (!calls)
|
|
18
18
|
return [];
|
|
19
19
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -23,9 +23,9 @@ function register(ctx) {
|
|
|
23
23
|
const document = ctx.getTextDocument(item.uri);
|
|
24
24
|
if (!document)
|
|
25
25
|
return [];
|
|
26
|
-
const fileName = ctx.
|
|
26
|
+
const fileName = ctx.uriToFileName(item.uri);
|
|
27
27
|
const offset = document.offsetAt(item.selectionRange.start);
|
|
28
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
28
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
|
|
29
29
|
if (!calls)
|
|
30
30
|
return [];
|
|
31
31
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -35,9 +35,9 @@ function register(ctx) {
|
|
|
35
35
|
const document = ctx.getTextDocument(item.uri);
|
|
36
36
|
if (!document)
|
|
37
37
|
return [];
|
|
38
|
-
const fileName = ctx.
|
|
38
|
+
const fileName = ctx.uriToFileName(item.uri);
|
|
39
39
|
const offset = document.offsetAt(item.selectionRange.start);
|
|
40
|
-
const calls = (0, shared_1.safeCall)(() => ctx.
|
|
40
|
+
const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
|
|
41
41
|
if (!calls)
|
|
42
42
|
return [];
|
|
43
43
|
const items = Array.isArray(calls) ? calls : [calls];
|
|
@@ -52,8 +52,8 @@ function register(ctx) {
|
|
|
52
52
|
return item.kind === PConst.Kind.script || item.kind === PConst.Kind.module && item.selectionSpan.start === 0;
|
|
53
53
|
}
|
|
54
54
|
function fromProtocolCallHierarchyItem(item) {
|
|
55
|
-
const rootPath = ctx.
|
|
56
|
-
const document = ctx.getTextDocument(ctx.
|
|
55
|
+
const rootPath = ctx.languageService.getProgram()?.getCompilerOptions().rootDir ?? '';
|
|
56
|
+
const document = ctx.getTextDocument(ctx.fileNameToUri(item.file)); // TODO
|
|
57
57
|
const useFileName = isSourceFileItem(item);
|
|
58
58
|
const name = useFileName ? path.basename(item.file) : item.name;
|
|
59
59
|
const detail = useFileName ? path.relative(rootPath, path.dirname(item.file)) : item.containerName ?? '';
|
|
@@ -61,7 +61,7 @@ function register(ctx) {
|
|
|
61
61
|
kind: typeConverters.SymbolKind.fromProtocolScriptElementKind(item.kind),
|
|
62
62
|
name,
|
|
63
63
|
detail,
|
|
64
|
-
uri: ctx.
|
|
64
|
+
uri: ctx.fileNameToUri(item.file),
|
|
65
65
|
range: {
|
|
66
66
|
start: document.positionAt(item.span.start),
|
|
67
67
|
end: document.positionAt(item.span.start + item.span.length),
|
|
@@ -78,7 +78,7 @@ function register(ctx) {
|
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
80
|
function fromProtocolCallHierarchyIncomingCall(item) {
|
|
81
|
-
const document = ctx.getTextDocument(ctx.
|
|
81
|
+
const document = ctx.getTextDocument(ctx.fileNameToUri(item.from.file));
|
|
82
82
|
return {
|
|
83
83
|
from: fromProtocolCallHierarchyItem(item.from),
|
|
84
84
|
fromRanges: item.fromSpans.map(fromSpan => ({
|
|
@@ -22,14 +22,14 @@ function register(ctx) {
|
|
|
22
22
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
23
23
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
24
24
|
]);
|
|
25
|
-
const fileName = ctx.
|
|
25
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
26
26
|
const start = document.offsetAt(range.start);
|
|
27
27
|
const end = document.offsetAt(range.end);
|
|
28
28
|
let result = [];
|
|
29
29
|
const onlyQuickFix = matchOnlyKind(`${'quickfix'}.ts`);
|
|
30
30
|
if (!context.only || onlyQuickFix) {
|
|
31
31
|
for (const error of context.diagnostics) {
|
|
32
|
-
const codeFixes = (0, shared_1.safeCall)(() => ctx.
|
|
32
|
+
const codeFixes = (0, shared_1.safeCall)(() => ctx.languageService.getCodeFixesAtPosition(fileName, document.offsetAt(error.range.start), document.offsetAt(error.range.end), [Number(error.code)], formatOptions, preferences)) ?? [];
|
|
33
33
|
for (const codeFix of codeFixes) {
|
|
34
34
|
result = result.concat(transformCodeFix(codeFix, [error], onlyQuickFix ?? ''));
|
|
35
35
|
}
|
|
@@ -38,7 +38,7 @@ function register(ctx) {
|
|
|
38
38
|
if (context.only) {
|
|
39
39
|
for (const only of context.only) {
|
|
40
40
|
if (only.split('.')[0] === 'refactor') {
|
|
41
|
-
const refactors = (0, shared_1.safeCall)(() => ctx.
|
|
41
|
+
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, only)) ?? [];
|
|
42
42
|
for (const refactor of refactors) {
|
|
43
43
|
result = result.concat(transformRefactor(refactor));
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ function register(ctx) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
const refactors = (0, shared_1.safeCall)(() => ctx.
|
|
49
|
+
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, undefined)) ?? [];
|
|
50
50
|
for (const refactor of refactors) {
|
|
51
51
|
result = result.concat(transformRefactor(refactor));
|
|
52
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import type { SharedContext } from '../types';
|
|
5
5
|
import type { Data, FixAllData, RefactorData } from './codeAction';
|
|
@@ -27,13 +27,13 @@ function register(ctx) {
|
|
|
27
27
|
}
|
|
28
28
|
exports.register = register;
|
|
29
29
|
function resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
30
|
-
const fixes = data.fixIds.map(fixId => (0, shared_1.safeCall)(() => ctx.
|
|
30
|
+
const fixes = data.fixIds.map(fixId => (0, shared_1.safeCall)(() => ctx.languageService.getCombinedCodeFix({ type: 'file', fileName: data.fileName }, fixId, formatOptions, preferences)));
|
|
31
31
|
const changes = fixes.map(fix => fix?.changes ?? []).flat();
|
|
32
32
|
codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes, ctx);
|
|
33
33
|
}
|
|
34
34
|
exports.resolveFixAllCodeAction = resolveFixAllCodeAction;
|
|
35
35
|
function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences) {
|
|
36
|
-
const editInfo = (0, shared_1.safeCall)(() => ctx.
|
|
36
|
+
const editInfo = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForRefactor(data.fileName, formatOptions, data.range, data.refactorName, data.actionName, preferences));
|
|
37
37
|
if (!editInfo) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -44,7 +44,7 @@ function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOption
|
|
|
44
44
|
}
|
|
45
45
|
exports.resolveRefactorCodeAction = resolveRefactorCodeAction;
|
|
46
46
|
function resolveOrganizeImportsCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
47
|
-
const changes = (0, shared_1.safeCall)(() => ctx.
|
|
47
|
+
const changes = (0, shared_1.safeCall)(() => ctx.languageService.organizeImports({ type: 'file', fileName: data.fileName }, formatOptions, preferences));
|
|
48
48
|
codeAction.edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(changes ?? [], ctx);
|
|
49
49
|
}
|
|
50
50
|
exports.resolveOrganizeImportsCodeAction = resolveOrganizeImportsCodeAction;
|
|
@@ -15,9 +15,9 @@ function register(ctx) {
|
|
|
15
15
|
if (!document)
|
|
16
16
|
return;
|
|
17
17
|
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
18
|
-
const fileName = ctx.
|
|
18
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
19
19
|
const offset = document.offsetAt(position);
|
|
20
|
-
const completionContext = (0, shared_1.safeCall)(() => ctx.
|
|
20
|
+
const completionContext = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionsAtPosition(fileName, offset, {
|
|
21
21
|
...preferences,
|
|
22
22
|
...options,
|
|
23
23
|
}));
|
|
@@ -12,9 +12,9 @@ function register(ctx) {
|
|
|
12
12
|
return;
|
|
13
13
|
if (!isPotentiallyValidDocCompletionPosition(document, position))
|
|
14
14
|
return;
|
|
15
|
-
const fileName = ctx.
|
|
15
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
16
16
|
const offset = document.offsetAt(position);
|
|
17
|
-
const docCommentTemplate = ctx.
|
|
17
|
+
const docCommentTemplate = ctx.languageService.getDocCommentTemplateAtPosition(fileName, offset);
|
|
18
18
|
if (!docCommentTemplate)
|
|
19
19
|
return;
|
|
20
20
|
let insertText;
|
|
@@ -26,7 +26,7 @@ function register(ctx) {
|
|
|
26
26
|
]) : [{}, {}];
|
|
27
27
|
let details;
|
|
28
28
|
try {
|
|
29
|
-
details = ctx.
|
|
29
|
+
details = ctx.languageService.getCompletionEntryDetails(fileName, offset, data.originalItem.name, formatOptions, data.originalItem.source, preferences, data.originalItem.data);
|
|
30
30
|
}
|
|
31
31
|
catch (err) {
|
|
32
32
|
item.detail = `[TS Error]\n${err}\n${JSON.stringify(err, undefined, 2)}`;
|
|
@@ -76,7 +76,7 @@ function register(ctx) {
|
|
|
76
76
|
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls') ?? false;
|
|
77
77
|
const useCodeSnippet = useCodeSnippetsOnMethodSuggest && (item.kind === 3 || item.kind === 2);
|
|
78
78
|
if (useCodeSnippet) {
|
|
79
|
-
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.
|
|
79
|
+
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.languageService, fileName, offset, document);
|
|
80
80
|
if (shouldCompleteFunction) {
|
|
81
81
|
const { snippet, parameterCount } = (0, snippetForFunctionCall_1.snippetForFunctionCall)({
|
|
82
82
|
insertText: item.insertText ?? item.textEdit?.newText, // insertText is dropped by LSP in some case: https://github.com/microsoft/vscode-languageserver-node/blob/9b742021fb04ad081aa3676a9eecf4fa612084b4/client/src/common/codeConverter.ts#L659-L664
|
|
@@ -104,7 +104,7 @@ function register(ctx) {
|
|
|
104
104
|
}
|
|
105
105
|
return item;
|
|
106
106
|
function toResource(path) {
|
|
107
|
-
return ctx.
|
|
107
|
+
return ctx.fileNameToUri(path);
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
}
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const info = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getDefinitionAndBoundSpan(fileName, offset));
|
|
14
14
|
if (!info)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.boundSpanToLocationLinks)(info, document, ctx);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { SharedContext } from '../types';
|
|
4
4
|
export declare function register(ctx: SharedContext): (uri: string, options: {
|
|
5
5
|
semantic?: boolean;
|
|
@@ -8,8 +8,8 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const program = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const program = ctx.languageService.getProgram();
|
|
13
13
|
const sourceFile = program?.getSourceFile(fileName);
|
|
14
14
|
if (!program || !sourceFile)
|
|
15
15
|
return [];
|
|
@@ -22,7 +22,7 @@ function register(ctx) {
|
|
|
22
22
|
let errors = (0, shared_1.safeCall)(() => [
|
|
23
23
|
...options.semantic ? program.getSemanticDiagnostics(sourceFile, token) : [],
|
|
24
24
|
...options.syntactic ? program.getSyntacticDiagnostics(sourceFile, token) : [],
|
|
25
|
-
...options.suggestion ? ctx.
|
|
25
|
+
...options.suggestion ? ctx.languageService.getSuggestionDiagnostics(fileName) : [],
|
|
26
26
|
]) ?? [];
|
|
27
27
|
if (options.declaration && getEmitDeclarations(program.getCompilerOptions())) {
|
|
28
28
|
errors = errors.concat(program.getDeclarationDiagnostics(sourceFile, token));
|
|
@@ -70,7 +70,7 @@ function register(ctx) {
|
|
|
70
70
|
return;
|
|
71
71
|
let document;
|
|
72
72
|
if (diag.file) {
|
|
73
|
-
document = ctx.getTextDocument(ctx.
|
|
73
|
+
document = ctx.getTextDocument(ctx.fileNameToUri(diag.file.fileName));
|
|
74
74
|
}
|
|
75
75
|
if (!document)
|
|
76
76
|
return;
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const highlights = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const highlights = (0, shared_1.safeCall)(() => ctx.languageService.getDocumentHighlights(fileName, offset, [fileName]));
|
|
14
14
|
if (!highlights)
|
|
15
15
|
return [];
|
|
16
16
|
const results = [];
|
|
@@ -29,8 +29,8 @@ function register(ctx) {
|
|
|
29
29
|
const document = ctx.getTextDocument(uri);
|
|
30
30
|
if (!document)
|
|
31
31
|
return [];
|
|
32
|
-
const fileName = ctx.
|
|
33
|
-
const barItems = (0, shared_1.safeCall)(() => ctx.
|
|
32
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
33
|
+
const barItems = (0, shared_1.safeCall)(() => ctx.languageService.getNavigationTree(fileName));
|
|
34
34
|
if (!barItems)
|
|
35
35
|
return [];
|
|
36
36
|
// The root represents the file. Ignore this when showing in the UI
|
|
@@ -8,8 +8,8 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getFileReferences(fileName));
|
|
13
13
|
if (!entries)
|
|
14
14
|
return [];
|
|
15
15
|
return (0, transforms_1.entriesToLocations)([...entries], ctx);
|
|
@@ -12,9 +12,9 @@ function register(ctx) {
|
|
|
12
12
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
13
13
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
14
14
|
]) : [{}, {}];
|
|
15
|
-
const fileToRename = ctx.
|
|
16
|
-
const newFilePath = ctx.
|
|
17
|
-
const response = (0, shared_1.safeCall)(() => ctx.
|
|
15
|
+
const fileToRename = ctx.uriToFileName(oldUri);
|
|
16
|
+
const newFilePath = ctx.uriToFileName(newUri);
|
|
17
|
+
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences));
|
|
18
18
|
if (!response?.length)
|
|
19
19
|
return;
|
|
20
20
|
const edits = (0, rename_1.fileTextChangesToWorkspaceEdit)(response, ctx);
|
|
@@ -8,8 +8,8 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
12
|
-
const outliningSpans = (0, shared_1.safeCall)(() => ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
|
+
const outliningSpans = (0, shared_1.safeCall)(() => ctx.languageService.getOutliningSpans(fileName));
|
|
13
13
|
if (!outliningSpans)
|
|
14
14
|
return [];
|
|
15
15
|
const foldingRanges = [];
|
|
@@ -6,14 +6,14 @@ const shared_1 = require("../shared");
|
|
|
6
6
|
function register(ctx) {
|
|
7
7
|
return {
|
|
8
8
|
onRange: async (document, range, options) => {
|
|
9
|
-
const fileName = ctx.
|
|
9
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
10
10
|
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
11
11
|
if (typeof (tsOptions.indentSize) === "boolean" || typeof (tsOptions.indentSize) === "string") {
|
|
12
12
|
tsOptions.indentSize = undefined;
|
|
13
13
|
}
|
|
14
14
|
const scriptEdits = range
|
|
15
|
-
? (0, shared_1.safeCall)(() => ctx.
|
|
16
|
-
: (0, shared_1.safeCall)(() => ctx.
|
|
15
|
+
? (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsForRange(fileName, document.offsetAt(range.start), document.offsetAt(range.end), tsOptions))
|
|
16
|
+
: (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsForDocument(fileName, tsOptions));
|
|
17
17
|
if (!scriptEdits)
|
|
18
18
|
return [];
|
|
19
19
|
const result = [];
|
|
@@ -29,9 +29,9 @@ function register(ctx) {
|
|
|
29
29
|
return result;
|
|
30
30
|
},
|
|
31
31
|
onType: async (document, options, position, key) => {
|
|
32
|
-
const fileName = ctx.
|
|
32
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
33
33
|
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
34
|
-
const scriptEdits = (0, shared_1.safeCall)(() => ctx.
|
|
34
|
+
const scriptEdits = (0, shared_1.safeCall)(() => ctx.languageService.getFormattingEditsAfterKeystroke(fileName, document.offsetAt(position), key, tsOptions));
|
|
35
35
|
if (!scriptEdits)
|
|
36
36
|
return [];
|
|
37
37
|
const result = [];
|
package/lib/features/hover.js
CHANGED
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
const document = ctx.getTextDocument(uri);
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const info = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const info = (0, shared_1.safeCall)(() => ctx.languageService.getQuickInfoAtPosition(fileName, offset));
|
|
15
15
|
if (!info)
|
|
16
16
|
return;
|
|
17
17
|
const parts = [];
|
|
@@ -35,7 +35,7 @@ function register(ctx) {
|
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
37
|
function toResource(path) {
|
|
38
|
-
return ctx.
|
|
38
|
+
return ctx.fileNameToUri(path);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getImplementationAtPosition(fileName, offset));
|
|
14
14
|
if (!entries)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.entriesToLocationLinks)([...entries], ctx);
|
|
@@ -10,11 +10,11 @@ function register(ctx) {
|
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
12
|
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
13
|
-
const fileName = ctx.
|
|
13
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
14
14
|
const start = document.offsetAt(range.start);
|
|
15
15
|
const end = document.offsetAt(range.end);
|
|
16
|
-
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.
|
|
17
|
-
? ctx.
|
|
16
|
+
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.languageService
|
|
17
|
+
? ctx.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
|
|
18
18
|
: []) ?? [];
|
|
19
19
|
return inlayHints.map(inlayHint => {
|
|
20
20
|
const result = {
|
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
const document = ctx.getTextDocument(uri);
|
|
10
10
|
if (!document)
|
|
11
11
|
return;
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const renameInfo = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, exports.renameInfoOptions));
|
|
15
15
|
if (!renameInfo)
|
|
16
16
|
return;
|
|
17
17
|
if (!renameInfo.canRename) {
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const references = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const references = (0, shared_1.safeCall)(() => ctx.languageService.findReferences(fileName, offset));
|
|
14
14
|
if (!references)
|
|
15
15
|
return [];
|
|
16
16
|
const result = [];
|
package/lib/features/rename.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { SharedContext } from '../types';
|
|
4
4
|
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
5
5
|
export declare function fileTextChangesToWorkspaceEdit(changes: readonly ts.FileTextChanges[], ctx: SharedContext): vscode.WorkspaceEdit;
|
package/lib/features/rename.js
CHANGED
|
@@ -11,9 +11,9 @@ function register(ctx) {
|
|
|
11
11
|
const document = ctx.getTextDocument(uri);
|
|
12
12
|
if (!document)
|
|
13
13
|
return;
|
|
14
|
-
const fileName = ctx.
|
|
14
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
15
15
|
const offset = document.offsetAt(position);
|
|
16
|
-
const renameInfo = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.languageService.getRenameInfo(fileName, offset, prepareRename_1.renameInfoOptions));
|
|
17
17
|
if (!renameInfo?.canRename)
|
|
18
18
|
return;
|
|
19
19
|
if (renameInfo.fileToRename) {
|
|
@@ -24,7 +24,7 @@ function register(ctx) {
|
|
|
24
24
|
return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
|
|
25
25
|
}
|
|
26
26
|
const { providePrefixAndSuffixTextForRename } = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
27
|
-
const entries = ctx.
|
|
27
|
+
const entries = ctx.languageService.findRenameLocations(fileName, offset, false, false, providePrefixAndSuffixTextForRename);
|
|
28
28
|
if (!entries)
|
|
29
29
|
return;
|
|
30
30
|
const locations = locationsToWorkspaceEdit(newName, entries, ctx);
|
|
@@ -37,15 +37,15 @@ function register(ctx) {
|
|
|
37
37
|
}
|
|
38
38
|
const dirname = path.dirname(fileToRename);
|
|
39
39
|
const newFilePath = path.join(dirname, newName);
|
|
40
|
-
const response = ctx.
|
|
40
|
+
const response = ctx.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences);
|
|
41
41
|
const edits = fileTextChangesToWorkspaceEdit(response, ctx);
|
|
42
42
|
if (!edits.documentChanges) {
|
|
43
43
|
edits.documentChanges = [];
|
|
44
44
|
}
|
|
45
45
|
edits.documentChanges.push({
|
|
46
46
|
kind: 'rename',
|
|
47
|
-
oldUri: ctx.
|
|
48
|
-
newUri: ctx.
|
|
47
|
+
oldUri: ctx.fileNameToUri(fileToRename),
|
|
48
|
+
newUri: ctx.fileNameToUri(newFilePath),
|
|
49
49
|
});
|
|
50
50
|
return edits;
|
|
51
51
|
}
|
|
@@ -57,7 +57,7 @@ function fileTextChangesToWorkspaceEdit(changes, ctx) {
|
|
|
57
57
|
if (!workspaceEdit.documentChanges) {
|
|
58
58
|
workspaceEdit.documentChanges = [];
|
|
59
59
|
}
|
|
60
|
-
const uri = ctx.
|
|
60
|
+
const uri = ctx.fileNameToUri(change.fileName);
|
|
61
61
|
let doc = ctx.getTextDocument(uri);
|
|
62
62
|
if (change.isNewFile) {
|
|
63
63
|
workspaceEdit.documentChanges.push({ kind: 'create', uri });
|
|
@@ -91,7 +91,7 @@ function locationsToWorkspaceEdit(newText, locations, ctx) {
|
|
|
91
91
|
if (!workspaceEdit.changes) {
|
|
92
92
|
workspaceEdit.changes = {};
|
|
93
93
|
}
|
|
94
|
-
const uri = ctx.
|
|
94
|
+
const uri = ctx.fileNameToUri(location.fileName);
|
|
95
95
|
const doc = ctx.getTextDocument(uri);
|
|
96
96
|
if (!doc)
|
|
97
97
|
continue;
|
|
@@ -9,9 +9,9 @@ function register(ctx) {
|
|
|
9
9
|
return [];
|
|
10
10
|
const result = [];
|
|
11
11
|
for (const position of positions) {
|
|
12
|
-
const fileName = ctx.
|
|
12
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
13
13
|
const offset = document.offsetAt(position);
|
|
14
|
-
const range = (0, shared_1.safeCall)(() => ctx.
|
|
14
|
+
const range = (0, shared_1.safeCall)(() => ctx.languageService.getSmartSelectionRange(fileName, offset));
|
|
15
15
|
if (!range)
|
|
16
16
|
continue;
|
|
17
17
|
result.push(transformSelectionRange(range, document));
|
|
@@ -8,17 +8,17 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return;
|
|
11
|
-
const file = ctx.
|
|
11
|
+
const file = ctx.uriToFileName(uri);
|
|
12
12
|
const start = range ? document.offsetAt(range.start) : 0;
|
|
13
13
|
const length = range ? (document.offsetAt(range.end) - start) : document.getText().length;
|
|
14
14
|
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
15
15
|
return;
|
|
16
|
-
const response2 = (0, shared_1.safeCall)(() => ctx.
|
|
16
|
+
const response2 = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSyntacticClassifications(file, { start, length }));
|
|
17
17
|
if (!response2)
|
|
18
18
|
return;
|
|
19
19
|
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
20
20
|
return;
|
|
21
|
-
const response1 = (0, shared_1.safeCall)(() => ctx.
|
|
21
|
+
const response1 = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSemanticClassifications(file, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty));
|
|
22
22
|
if (!response1)
|
|
23
23
|
return;
|
|
24
24
|
let tokenModifiersTable = [];
|
|
@@ -26,9 +26,9 @@ function register(ctx) {
|
|
|
26
26
|
triggerCharacter: context.triggerCharacter,
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
const fileName = ctx.
|
|
29
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
30
30
|
const offset = document.offsetAt(position);
|
|
31
|
-
const helpItems = (0, shared_1.safeCall)(() => ctx.
|
|
31
|
+
const helpItems = (0, shared_1.safeCall)(() => ctx.languageService.getSignatureHelpItems(fileName, offset, options));
|
|
32
32
|
if (!helpItems)
|
|
33
33
|
return;
|
|
34
34
|
return {
|
|
@@ -8,9 +8,9 @@ function register(ctx) {
|
|
|
8
8
|
const document = ctx.getTextDocument(uri);
|
|
9
9
|
if (!document)
|
|
10
10
|
return [];
|
|
11
|
-
const fileName = ctx.
|
|
11
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
12
|
const offset = document.offsetAt(position);
|
|
13
|
-
const entries = (0, shared_1.safeCall)(() => ctx.
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.languageService.getTypeDefinitionAtPosition(fileName, offset));
|
|
14
14
|
if (!entries)
|
|
15
15
|
return [];
|
|
16
16
|
return (0, transforms_1.entriesToLocationLinks)([...entries], ctx);
|
|
@@ -22,7 +22,7 @@ function getSymbolKind(item) {
|
|
|
22
22
|
}
|
|
23
23
|
function register(ctx) {
|
|
24
24
|
return (query) => {
|
|
25
|
-
const items = (0, shared_1.safeCall)(() => ctx.
|
|
25
|
+
const items = (0, shared_1.safeCall)(() => ctx.languageService.getNavigateToItems(query));
|
|
26
26
|
if (!items)
|
|
27
27
|
return [];
|
|
28
28
|
return items
|
|
@@ -31,7 +31,7 @@ function register(ctx) {
|
|
|
31
31
|
.filter((v) => !!v);
|
|
32
32
|
function toWorkspaceSymbol(item) {
|
|
33
33
|
const label = getLabel(item);
|
|
34
|
-
const uri = ctx.
|
|
34
|
+
const uri = ctx.fileNameToUri(item.fileName);
|
|
35
35
|
const document = ctx.getTextDocument(uri);
|
|
36
36
|
if (document) {
|
|
37
37
|
const range = {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ServiceContext } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export type SharedContext = ServiceContext & {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
ts: typeof import('typescript/lib/tsserverlibrary');
|
|
5
|
+
ts: typeof import('typescript');
|
|
6
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
+
languageService: ts.LanguageService;
|
|
10
8
|
getTextDocument: (uri: string) => TextDocument | undefined;
|
|
9
|
+
uriToFileName: (uri: string) => string;
|
|
10
|
+
fileNameToUri: (fileName: string) => string;
|
|
11
11
|
};
|
|
12
12
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/utils/previewer.d.ts
CHANGED
package/lib/utils/previewer.js
CHANGED
|
@@ -105,7 +105,7 @@ function convertLinkTags(parts, filePathConverter, ctx) {
|
|
|
105
105
|
let target = currentLink.target;
|
|
106
106
|
if (typeof currentLink.target === 'object' && 'fileName' in currentLink.target) {
|
|
107
107
|
const _target = currentLink.target;
|
|
108
|
-
const fileDoc = ctx.getTextDocument(ctx.
|
|
108
|
+
const fileDoc = ctx.getTextDocument(ctx.uriToFileName(_target.fileName));
|
|
109
109
|
if (fileDoc) {
|
|
110
110
|
const start = fileDoc.positionAt(_target.textSpan.start);
|
|
111
111
|
const end = fileDoc.positionAt(_target.textSpan.start + _target.textSpan.length);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import type { SharedContext } from '../types';
|
|
5
5
|
export declare function entriesToLocations(entries: {
|
package/lib/utils/transforms.js
CHANGED
|
@@ -8,7 +8,7 @@ function entriesToLocations(entries, ctx) {
|
|
|
8
8
|
}
|
|
9
9
|
exports.entriesToLocations = entriesToLocations;
|
|
10
10
|
function entryToLocation(entry, ctx) {
|
|
11
|
-
const entryUri = ctx.
|
|
11
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
12
12
|
const doc = ctx.getTextDocument(entryUri);
|
|
13
13
|
if (!doc)
|
|
14
14
|
return;
|
|
@@ -23,7 +23,7 @@ exports.entryToLocation = entryToLocation;
|
|
|
23
23
|
function entriesToLocationLinks(entries, ctx) {
|
|
24
24
|
const locations = [];
|
|
25
25
|
for (const entry of entries) {
|
|
26
|
-
const entryUri = ctx.
|
|
26
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
27
27
|
const doc = ctx.getTextDocument(entryUri);
|
|
28
28
|
if (!doc)
|
|
29
29
|
continue;
|
|
@@ -59,7 +59,7 @@ function boundSpanToLocationLinks(info, originalDoc, ctx) {
|
|
|
59
59
|
end: originalDoc.positionAt(info.textSpan.start + info.textSpan.length),
|
|
60
60
|
};
|
|
61
61
|
for (const entry of info.definitions) {
|
|
62
|
-
const entryUri = ctx.
|
|
62
|
+
const entryUri = ctx.fileNameToUri(entry.fileName);
|
|
63
63
|
const doc = ctx.getTextDocument(entryUri);
|
|
64
64
|
if (!doc)
|
|
65
65
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "Integrate TypeScript into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/path-browserify": "latest",
|
|
28
|
-
"@types/semver": "
|
|
28
|
+
"@types/semver": "latest",
|
|
29
29
|
"@volar/typescript": "latest"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"path-browserify": "^1.0.1",
|
|
33
33
|
"semver": "^7.5.4",
|
|
34
|
-
"typescript-auto-import-cache": "^0.3.
|
|
34
|
+
"typescript-auto-import-cache": "^0.3.1",
|
|
35
35
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
36
36
|
"vscode-nls": "^5.2.0",
|
|
37
37
|
"vscode-uri": "^3.0.8"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"optional": true
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "876051c97aedf04531033784019b4344cdd48881"
|
|
49
49
|
}
|
package/lib/protocol.d.ts
DELETED
package/lib/protocol.js
DELETED