volar-service-typescript 0.0.31-patch.1 → 0.0.32
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 +4 -17
- package/index.js +12 -545
- package/lib/configs/getFormatCodeSettings.d.ts +2 -3
- package/lib/configs/getUserPreferences.d.ts +1 -1
- package/lib/plugins/directiveComment.d.ts +3 -0
- package/lib/plugins/directiveComment.js +65 -0
- package/lib/plugins/docCommentTemplate.d.ts +3 -0
- package/lib/{features/completions/jsDoc.js → plugins/docCommentTemplate.js} +42 -30
- package/lib/plugins/semantic.d.ts +23 -0
- package/lib/plugins/semantic.js +706 -0
- package/lib/plugins/syntactic.d.ts +7 -0
- package/lib/plugins/syntactic.js +92 -0
- package/lib/{features → semanticFeatures}/codeAction.d.ts +3 -2
- package/lib/{features → semanticFeatures}/codeAction.js +14 -17
- package/lib/{features → semanticFeatures}/codeActionResolve.d.ts +1 -1
- package/lib/{features → semanticFeatures}/codeActionResolve.js +7 -7
- package/lib/semanticFeatures/semanticTokens.d.ts +5 -0
- package/lib/{features → semanticFeatures}/semanticTokens.js +4 -8
- package/lib/{types.d.ts → semanticFeatures/types.d.ts} +1 -2
- package/lib/shared.d.ts +1 -0
- package/lib/shared.js +5 -1
- package/lib/syntacticLanguageService.d.ts +7 -0
- package/lib/syntacticLanguageService.js +38 -0
- package/lib/utils/lspConverters.d.ts +27 -0
- package/lib/utils/lspConverters.js +782 -0
- package/lib/utils/previewer.d.ts +5 -11
- package/lib/utils/previewer.js +30 -35
- package/package.json +5 -6
- package/lib/features/callHierarchy.d.ts +0 -8
- package/lib/features/callHierarchy.js +0 -102
- package/lib/features/completions/basic.d.ts +0 -17
- package/lib/features/completions/basic.js +0 -326
- package/lib/features/completions/directiveComment.d.ts +0 -4
- package/lib/features/completions/directiveComment.js +0 -54
- package/lib/features/completions/jsDoc.d.ts +0 -4
- package/lib/features/completions/resolve.d.ts +0 -6
- package/lib/features/completions/resolve.js +0 -146
- package/lib/features/definition.d.ts +0 -4
- package/lib/features/definition.js +0 -20
- package/lib/features/diagnostics.d.ts +0 -11
- package/lib/features/diagnostics.js +0 -120
- package/lib/features/documentHighlight.d.ts +0 -4
- package/lib/features/documentHighlight.js +0 -32
- package/lib/features/documentSymbol.d.ts +0 -4
- package/lib/features/documentSymbol.js +0 -94
- package/lib/features/fileReferences.d.ts +0 -4
- package/lib/features/fileReferences.js +0 -19
- package/lib/features/fileRename.d.ts +0 -4
- package/lib/features/fileRename.js +0 -25
- package/lib/features/foldingRanges.d.ts +0 -4
- package/lib/features/foldingRanges.js +0 -55
- package/lib/features/formatting.d.ts +0 -8
- package/lib/features/formatting.js +0 -55
- package/lib/features/hover.d.ts +0 -4
- package/lib/features/hover.js +0 -43
- package/lib/features/implementation.d.ts +0 -4
- package/lib/features/implementation.js +0 -20
- package/lib/features/inlayHints.d.ts +0 -4
- package/lib/features/inlayHints.js +0 -34
- package/lib/features/prepareRename.d.ts +0 -9
- package/lib/features/prepareRename.js +0 -27
- package/lib/features/references.d.ts +0 -4
- package/lib/features/references.js +0 -35
- package/lib/features/rename.d.ts +0 -6
- package/lib/features/rename.js +0 -116
- package/lib/features/selectionRanges.d.ts +0 -4
- package/lib/features/selectionRanges.js +0 -32
- package/lib/features/semanticTokens.d.ts +0 -4
- package/lib/features/signatureHelp.d.ts +0 -4
- package/lib/features/signatureHelp.js +0 -63
- package/lib/features/typeDefinition.d.ts +0 -4
- package/lib/features/typeDefinition.js +0 -20
- package/lib/features/workspaceSymbol.d.ts +0 -4
- package/lib/features/workspaceSymbol.js +0 -63
- package/lib/utils/transforms.d.ts +0 -15
- package/lib/utils/transforms.js +0 -85
- /package/lib/{types.js → semanticFeatures/types.js} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Result, ServiceContext, ServicePlugin } from '@volar/language-service';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
export declare function create(ts: typeof import('typescript'), { isFormattingEnabled, isAutoClosingTagsEnabled, }?: {
|
|
4
|
+
isFormattingEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
5
|
+
isAutoClosingTagsEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
|
|
6
|
+
}): ServicePlugin;
|
|
7
|
+
//# sourceMappingURL=syntactic.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
5
|
+
const shared_1 = require("../shared");
|
|
6
|
+
const lspConverters_1 = require("../utils/lspConverters");
|
|
7
|
+
const syntacticLanguageService_1 = require("../syntacticLanguageService");
|
|
8
|
+
function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
9
|
+
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable') ?? true;
|
|
10
|
+
}, isAutoClosingTagsEnabled = async (document, context) => {
|
|
11
|
+
return await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.autoClosingTags') ?? true;
|
|
12
|
+
}, } = {}) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'typescript-syntactic',
|
|
15
|
+
// https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
|
|
16
|
+
autoFormatTriggerCharacters: [';', '}', '\n'],
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
async provideAutoInsertionEdit(document, position, lastChange) {
|
|
20
|
+
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
21
|
+
&& lastChange.text.endsWith('>')
|
|
22
|
+
&& await isAutoClosingTagsEnabled(document, context)) {
|
|
23
|
+
const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
|
|
24
|
+
const close = languageService.getJsxClosingTagAtPosition(fileName, document.offsetAt(position));
|
|
25
|
+
if (close) {
|
|
26
|
+
return '$0' + close.newText;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
provideFoldingRanges(document) {
|
|
31
|
+
if (!(0, shared_1.isTsDocument)(document))
|
|
32
|
+
return;
|
|
33
|
+
const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
|
|
34
|
+
const outliningSpans = (0, shared_1.safeCall)(() => languageService.getOutliningSpans(fileName));
|
|
35
|
+
if (!outliningSpans) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
return outliningSpans.map(span => (0, lspConverters_1.convertOutliningSpan)(span, document));
|
|
39
|
+
},
|
|
40
|
+
provideDocumentSymbols(document) {
|
|
41
|
+
if (!(0, shared_1.isTsDocument)(document))
|
|
42
|
+
return;
|
|
43
|
+
const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
|
|
44
|
+
const barItems = (0, shared_1.safeCall)(() => languageService.getNavigationTree(fileName));
|
|
45
|
+
if (!barItems)
|
|
46
|
+
return [];
|
|
47
|
+
// The root represents the file. Ignore this when showing in the UI
|
|
48
|
+
return barItems.childItems
|
|
49
|
+
?.map(item => (0, lspConverters_1.convertNavTree)(item, document))
|
|
50
|
+
.flat()
|
|
51
|
+
?? [];
|
|
52
|
+
},
|
|
53
|
+
async provideDocumentFormattingEdits(document, range, options, codeOptions) {
|
|
54
|
+
if (!(0, shared_1.isTsDocument)(document))
|
|
55
|
+
return;
|
|
56
|
+
if (!await isFormattingEnabled(document, context))
|
|
57
|
+
return;
|
|
58
|
+
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(context, document, options);
|
|
59
|
+
if (codeOptions) {
|
|
60
|
+
tsOptions.baseIndentSize = codeOptions.initialIndentLevel * options.tabSize;
|
|
61
|
+
}
|
|
62
|
+
const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
|
|
63
|
+
const scriptEdits = range
|
|
64
|
+
? (0, shared_1.safeCall)(() => languageService.getFormattingEditsForRange(fileName, document.offsetAt(range.start), document.offsetAt(range.end), tsOptions))
|
|
65
|
+
: (0, shared_1.safeCall)(() => languageService.getFormattingEditsForDocument(fileName, tsOptions));
|
|
66
|
+
if (!scriptEdits) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return scriptEdits.map(edit => (0, lspConverters_1.convertTextChange)(edit, document));
|
|
70
|
+
},
|
|
71
|
+
async provideOnTypeFormattingEdits(document, position, key, options, codeOptions) {
|
|
72
|
+
if (!(0, shared_1.isTsDocument)(document))
|
|
73
|
+
return;
|
|
74
|
+
if (!await isFormattingEnabled(document, context))
|
|
75
|
+
return;
|
|
76
|
+
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(context, document, options);
|
|
77
|
+
if (codeOptions) {
|
|
78
|
+
tsOptions.baseIndentSize = codeOptions.initialIndentLevel * options.tabSize;
|
|
79
|
+
}
|
|
80
|
+
const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
|
|
81
|
+
const scriptEdits = (0, shared_1.safeCall)(() => languageService.getFormattingEditsAfterKeystroke(fileName, document.offsetAt(position), key, tsOptions));
|
|
82
|
+
if (!scriptEdits) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return scriptEdits.map(edit => (0, lspConverters_1.convertTextChange)(edit, document));
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.create = create;
|
|
92
|
+
//# sourceMappingURL=syntactic.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
-
import type { SharedContext } from '
|
|
2
|
+
import type { SharedContext } from './types';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
4
|
export interface FixAllData {
|
|
4
5
|
type: 'fixAll';
|
|
5
6
|
uri: string;
|
|
@@ -23,5 +24,5 @@ export interface OrganizeImportsData {
|
|
|
23
24
|
fileName: string;
|
|
24
25
|
}
|
|
25
26
|
export type Data = FixAllData | RefactorData | OrganizeImportsData;
|
|
26
|
-
export declare function register(ctx: SharedContext): (
|
|
27
|
+
export declare function register(ctx: SharedContext): (document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext) => Promise<vscode.CodeAction[]>;
|
|
27
28
|
//# sourceMappingURL=codeAction.d.ts.map
|
|
@@ -6,7 +6,7 @@ const getUserPreferences_1 = require("../configs/getUserPreferences");
|
|
|
6
6
|
const shared_1 = require("../shared");
|
|
7
7
|
const fixNames = require("../utils/fixNames");
|
|
8
8
|
const codeActionResolve_1 = require("./codeActionResolve");
|
|
9
|
-
const
|
|
9
|
+
const lspConverters_1 = require("../utils/lspConverters");
|
|
10
10
|
function register(ctx) {
|
|
11
11
|
let resolveCommandSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('command');
|
|
12
12
|
let resolveEditSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('edit');
|
|
@@ -14,10 +14,7 @@ function register(ctx) {
|
|
|
14
14
|
resolveCommandSupport = true;
|
|
15
15
|
resolveEditSupport = true;
|
|
16
16
|
}
|
|
17
|
-
return async (
|
|
18
|
-
const document = ctx.getTextDocument(uri);
|
|
19
|
-
if (!document)
|
|
20
|
-
return;
|
|
17
|
+
return async (document, range, context) => {
|
|
21
18
|
const [formatOptions, preferences] = await Promise.all([
|
|
22
19
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
23
20
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
@@ -31,7 +28,7 @@ function register(ctx) {
|
|
|
31
28
|
for (const error of context.diagnostics) {
|
|
32
29
|
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
30
|
for (const codeFix of codeFixes) {
|
|
34
|
-
result = result.concat(
|
|
31
|
+
result = result.concat(convertCodeFixAction(codeFix, [error], onlyQuickFix ?? ''));
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
}
|
|
@@ -40,7 +37,7 @@ function register(ctx) {
|
|
|
40
37
|
if (only.split('.')[0] === 'refactor') {
|
|
41
38
|
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, only)) ?? [];
|
|
42
39
|
for (const refactor of refactors) {
|
|
43
|
-
result = result.concat(
|
|
40
|
+
result = result.concat(convertApplicableRefactorInfo(refactor));
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
}
|
|
@@ -48,7 +45,7 @@ function register(ctx) {
|
|
|
48
45
|
else {
|
|
49
46
|
const refactors = (0, shared_1.safeCall)(() => ctx.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, undefined)) ?? [];
|
|
50
47
|
for (const refactor of refactors) {
|
|
51
|
-
result = result.concat(
|
|
48
|
+
result = result.concat(convertApplicableRefactorInfo(refactor));
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
const onlySourceOrganizeImports = matchOnlyKind(`${'source.organizeImports'}.ts`);
|
|
@@ -59,7 +56,7 @@ function register(ctx) {
|
|
|
59
56
|
};
|
|
60
57
|
const data = {
|
|
61
58
|
type: 'organizeImports',
|
|
62
|
-
uri,
|
|
59
|
+
uri: document.uri,
|
|
63
60
|
fileName,
|
|
64
61
|
};
|
|
65
62
|
if (resolveEditSupport) {
|
|
@@ -77,7 +74,7 @@ function register(ctx) {
|
|
|
77
74
|
kind: onlySourceFixAll,
|
|
78
75
|
};
|
|
79
76
|
const data = {
|
|
80
|
-
uri,
|
|
77
|
+
uri: document.uri,
|
|
81
78
|
type: 'fixAll',
|
|
82
79
|
fileName,
|
|
83
80
|
fixIds: [
|
|
@@ -101,7 +98,7 @@ function register(ctx) {
|
|
|
101
98
|
kind: onlyRemoveUnused,
|
|
102
99
|
};
|
|
103
100
|
const data = {
|
|
104
|
-
uri,
|
|
101
|
+
uri: document.uri,
|
|
105
102
|
type: 'fixAll',
|
|
106
103
|
fileName,
|
|
107
104
|
fixIds: [
|
|
@@ -129,7 +126,7 @@ function register(ctx) {
|
|
|
129
126
|
kind: onlyAddMissingImports,
|
|
130
127
|
};
|
|
131
128
|
const data = {
|
|
132
|
-
uri,
|
|
129
|
+
uri: document.uri,
|
|
133
130
|
type: 'fixAll',
|
|
134
131
|
fileName,
|
|
135
132
|
fixIds: [
|
|
@@ -171,8 +168,8 @@ function register(ctx) {
|
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
|
-
function
|
|
175
|
-
const edit = (0,
|
|
171
|
+
function convertCodeFixAction(codeFix, diagnostics, kind) {
|
|
172
|
+
const edit = (0, lspConverters_1.convertFileTextChanges)(codeFix.changes, ctx.fileNameToUri, ctx.getTextDocument);
|
|
176
173
|
const codeActions = [];
|
|
177
174
|
const fix = {
|
|
178
175
|
title: codeFix.description,
|
|
@@ -187,7 +184,7 @@ function register(ctx) {
|
|
|
187
184
|
kind,
|
|
188
185
|
};
|
|
189
186
|
const data = {
|
|
190
|
-
uri,
|
|
187
|
+
uri: document.uri,
|
|
191
188
|
type: 'fixAll',
|
|
192
189
|
fileName,
|
|
193
190
|
fixIds: [codeFix.fixId],
|
|
@@ -203,7 +200,7 @@ function register(ctx) {
|
|
|
203
200
|
}
|
|
204
201
|
return codeActions;
|
|
205
202
|
}
|
|
206
|
-
function
|
|
203
|
+
function convertApplicableRefactorInfo(refactor) {
|
|
207
204
|
const codeActions = [];
|
|
208
205
|
for (const action of refactor.actions) {
|
|
209
206
|
const codeAction = {
|
|
@@ -217,7 +214,7 @@ function register(ctx) {
|
|
|
217
214
|
codeAction.isPreferred = true;
|
|
218
215
|
}
|
|
219
216
|
const data = {
|
|
220
|
-
uri,
|
|
217
|
+
uri: document.uri,
|
|
221
218
|
type: 'refactor',
|
|
222
219
|
fileName,
|
|
223
220
|
range: { pos: start, end: end },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
import type { SharedContext } from '
|
|
4
|
+
import type { SharedContext } from './types';
|
|
5
5
|
import type { Data, FixAllData, RefactorData } from './codeAction';
|
|
6
6
|
export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
7
7
|
export declare function resolveFixAllCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: FixAllData, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
|
|
@@ -4,19 +4,19 @@ exports.resolveOrganizeImportsCodeAction = exports.resolveRefactorCodeAction = e
|
|
|
4
4
|
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
5
5
|
const getUserPreferences_1 = require("../configs/getUserPreferences");
|
|
6
6
|
const shared_1 = require("../shared");
|
|
7
|
-
const
|
|
7
|
+
const lspConverters_1 = require("../utils/lspConverters");
|
|
8
8
|
function register(ctx) {
|
|
9
9
|
return async (codeAction) => {
|
|
10
10
|
const data = codeAction.data;
|
|
11
11
|
const document = ctx.getTextDocument(data.uri);
|
|
12
|
-
const [formatOptions, preferences] =
|
|
12
|
+
const [formatOptions, preferences] = await Promise.all([
|
|
13
13
|
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
14
14
|
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
15
|
-
])
|
|
15
|
+
]);
|
|
16
16
|
if (data?.type === 'fixAll') {
|
|
17
17
|
resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences);
|
|
18
18
|
}
|
|
19
|
-
else if (data?.type === 'refactor'
|
|
19
|
+
else if (data?.type === 'refactor') {
|
|
20
20
|
resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences);
|
|
21
21
|
}
|
|
22
22
|
else if (data?.type === 'organizeImports') {
|
|
@@ -29,7 +29,7 @@ exports.register = register;
|
|
|
29
29
|
function resolveFixAllCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
30
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
|
-
codeAction.edit = (0,
|
|
32
|
+
codeAction.edit = (0, lspConverters_1.convertFileTextChanges)(changes, ctx.fileNameToUri, ctx.getTextDocument);
|
|
33
33
|
}
|
|
34
34
|
exports.resolveFixAllCodeAction = resolveFixAllCodeAction;
|
|
35
35
|
function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOptions, preferences) {
|
|
@@ -37,7 +37,7 @@ function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOption
|
|
|
37
37
|
if (!editInfo) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
codeAction.edit = (0,
|
|
40
|
+
codeAction.edit = (0, lspConverters_1.convertFileTextChanges)(editInfo.edits, ctx.fileNameToUri, ctx.getTextDocument);
|
|
41
41
|
if (editInfo.renameLocation !== undefined && editInfo.renameFilename !== undefined) {
|
|
42
42
|
codeAction.command = ctx.commands.rename.create(document.uri, document.positionAt(editInfo.renameLocation));
|
|
43
43
|
}
|
|
@@ -45,7 +45,7 @@ function resolveRefactorCodeAction(ctx, codeAction, data, document, formatOption
|
|
|
45
45
|
exports.resolveRefactorCodeAction = resolveRefactorCodeAction;
|
|
46
46
|
function resolveOrganizeImportsCodeAction(ctx, codeAction, data, formatOptions, preferences) {
|
|
47
47
|
const changes = (0, shared_1.safeCall)(() => ctx.languageService.organizeImports({ type: 'file', fileName: data.fileName }, formatOptions, preferences));
|
|
48
|
-
codeAction.edit = (0,
|
|
48
|
+
codeAction.edit = (0, lspConverters_1.convertFileTextChanges)(changes ?? [], ctx.fileNameToUri, ctx.getTextDocument);
|
|
49
49
|
}
|
|
50
50
|
exports.resolveOrganizeImportsCodeAction = resolveOrganizeImportsCodeAction;
|
|
51
51
|
//# sourceMappingURL=codeActionResolve.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import type { SharedContext } from './types';
|
|
4
|
+
export declare function register(ts: typeof import('typescript'), ctx: SharedContext): (document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend) => [number, number, number, number, number][] | undefined;
|
|
5
|
+
//# sourceMappingURL=semanticTokens.d.ts.map
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = void 0;
|
|
4
4
|
const shared_1 = require("../shared");
|
|
5
|
-
function register(ctx) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const document = ctx.getTextDocument(uri);
|
|
9
|
-
if (!document)
|
|
10
|
-
return;
|
|
11
|
-
const file = ctx.uriToFileName(uri);
|
|
5
|
+
function register(ts, ctx) {
|
|
6
|
+
return (document, range, legend) => {
|
|
7
|
+
const fileName = ctx.uriToFileName(document.uri);
|
|
12
8
|
const start = range ? document.offsetAt(range.start) : 0;
|
|
13
9
|
const length = range ? (document.offsetAt(range.end) - start) : document.getText().length;
|
|
14
10
|
if (ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
15
11
|
return;
|
|
16
|
-
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSemanticClassifications(
|
|
12
|
+
const response = (0, shared_1.safeCall)(() => ctx.languageService.getEncodedSemanticClassifications(fileName, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty));
|
|
17
13
|
if (!response)
|
|
18
14
|
return;
|
|
19
15
|
let tokenModifiersTable = [];
|
|
@@ -2,10 +2,9 @@ import type { ServiceContext } from '@volar/language-service';
|
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export type SharedContext = ServiceContext & {
|
|
5
|
-
ts: typeof import('typescript');
|
|
6
5
|
languageServiceHost: ts.LanguageServiceHost;
|
|
7
6
|
languageService: ts.LanguageService;
|
|
8
|
-
getTextDocument: (uri: string) => TextDocument
|
|
7
|
+
getTextDocument: (uri: string) => TextDocument;
|
|
9
8
|
uriToFileName: (uri: string) => string;
|
|
10
9
|
fileNameToUri: (fileName: string) => string;
|
|
11
10
|
};
|
package/lib/shared.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare function getConfigTitle(document: TextDocument): string;
|
|
|
3
3
|
export declare function isTsDocument(document: TextDocument): boolean;
|
|
4
4
|
export declare function isJsonDocument(document: TextDocument): boolean;
|
|
5
5
|
export declare function safeCall<T>(cb: () => T): T | undefined;
|
|
6
|
+
export declare function notEmpty(value: any): value is NonNullable<typeof value>;
|
|
6
7
|
//# sourceMappingURL=shared.d.ts.map
|
package/lib/shared.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeCall = exports.isJsonDocument = exports.isTsDocument = exports.getConfigTitle = void 0;
|
|
3
|
+
exports.notEmpty = exports.safeCall = exports.isJsonDocument = exports.isTsDocument = exports.getConfigTitle = void 0;
|
|
4
4
|
function getConfigTitle(document) {
|
|
5
5
|
if (document.languageId === 'javascriptreact') {
|
|
6
6
|
return 'javascript';
|
|
@@ -30,4 +30,8 @@ function safeCall(cb) {
|
|
|
30
30
|
catch { }
|
|
31
31
|
}
|
|
32
32
|
exports.safeCall = safeCall;
|
|
33
|
+
function notEmpty(value) {
|
|
34
|
+
return value !== null && value !== undefined;
|
|
35
|
+
}
|
|
36
|
+
exports.notEmpty = notEmpty;
|
|
33
37
|
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as ts from 'typescript';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
export declare function getLanguageService(ts: typeof import('typescript'), document: TextDocument): {
|
|
4
|
+
languageService: ts.LanguageService;
|
|
5
|
+
fileName: string;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=syntacticLanguageService.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLanguageService = void 0;
|
|
4
|
+
let currentProjectVersion = -1;
|
|
5
|
+
let currentDocument;
|
|
6
|
+
let currentDocumentVersion;
|
|
7
|
+
let currentFileName = '';
|
|
8
|
+
let currentSnapshot;
|
|
9
|
+
let languageService;
|
|
10
|
+
const host = {
|
|
11
|
+
getProjectVersion: () => currentProjectVersion.toString(),
|
|
12
|
+
getScriptFileNames: () => [currentFileName],
|
|
13
|
+
getScriptVersion: () => currentProjectVersion.toString(),
|
|
14
|
+
getScriptSnapshot: fileName => fileName === currentFileName ? currentSnapshot : undefined,
|
|
15
|
+
getCompilationSettings: () => ({}),
|
|
16
|
+
getCurrentDirectory: () => '',
|
|
17
|
+
getDefaultLibFileName: () => '',
|
|
18
|
+
readFile: () => undefined,
|
|
19
|
+
fileExists: fileName => fileName === currentFileName,
|
|
20
|
+
};
|
|
21
|
+
function getLanguageService(ts, document) {
|
|
22
|
+
if (currentDocument !== document || currentDocumentVersion !== document.version) {
|
|
23
|
+
currentDocument = document;
|
|
24
|
+
currentFileName = '/tmp.' + (document.languageId === 'javascript' ? 'js' :
|
|
25
|
+
document.languageId === 'typescriptreact' ? 'tsx' :
|
|
26
|
+
document.languageId === 'javascriptreact' ? 'jsx' :
|
|
27
|
+
'ts');
|
|
28
|
+
currentSnapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
29
|
+
currentProjectVersion++;
|
|
30
|
+
}
|
|
31
|
+
languageService ??= ts.createLanguageService(host, undefined, 2);
|
|
32
|
+
return {
|
|
33
|
+
languageService,
|
|
34
|
+
fileName: currentFileName,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.getLanguageService = getLanguageService;
|
|
38
|
+
//# sourceMappingURL=syntacticLanguageService.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
+
import type { SharedContext } from '../semanticFeatures/types';
|
|
5
|
+
export declare function convertDiagnostic(diag: ts.Diagnostic, document: TextDocument, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): vscode.Diagnostic | undefined;
|
|
6
|
+
export declare function applyCompletionEntryDetails(ts: typeof import('typescript'), item: vscode.CompletionItem, data: ts.CompletionEntryDetails, document: TextDocument, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): void;
|
|
7
|
+
export declare function convertCompletionInfo<T>(ts: typeof import('typescript'), completionContext: ts.CompletionInfo, document: TextDocument, position: vscode.Position, createData: (tsEntry: ts.CompletionEntry) => T): vscode.CompletionList;
|
|
8
|
+
export declare function getLineText(document: TextDocument, line: number): string;
|
|
9
|
+
export declare function convertNavigateToItem(item: ts.NavigateToItem, document: TextDocument): vscode.WorkspaceSymbol;
|
|
10
|
+
export declare function convertInlayHint(hint: ts.InlayHint, document: TextDocument): vscode.InlayHint;
|
|
11
|
+
export declare function convertHighlightSpan(span: ts.HighlightSpan, document: TextDocument): vscode.DocumentHighlight;
|
|
12
|
+
export declare function convertSelectionRange(range: ts.SelectionRange, document: TextDocument): vscode.SelectionRange;
|
|
13
|
+
export declare function convertFileTextChanges(changes: readonly ts.FileTextChanges[], fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): vscode.WorkspaceEdit;
|
|
14
|
+
export declare function convertRenameLocations(newText: string, locations: readonly ts.RenameLocation[], fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): vscode.WorkspaceEdit;
|
|
15
|
+
export declare function convertQuickInfo(ts: typeof import('typescript'), info: ts.QuickInfo, document: TextDocument, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): vscode.Hover;
|
|
16
|
+
export declare function convertNavTree(item: ts.NavigationTree, document: TextDocument): vscode.DocumentSymbol[];
|
|
17
|
+
export declare function convertOutliningSpan(outliningSpan: ts.OutliningSpan, document: TextDocument): vscode.FoldingRange;
|
|
18
|
+
export declare function convertOutliningSpanKind(kind: ts.OutliningSpanKind): vscode.FoldingRangeKind | undefined;
|
|
19
|
+
export declare function convertTextChange(edit: ts.TextChange, document: TextDocument): vscode.TextEdit;
|
|
20
|
+
export declare function convertCallHierarchyIncomingCall(item: ts.CallHierarchyIncomingCall, ctx: SharedContext): vscode.CallHierarchyIncomingCall;
|
|
21
|
+
export declare function convertCallHierarchyOutgoingCall(item: ts.CallHierarchyOutgoingCall, fromDocument: TextDocument, ctx: SharedContext): vscode.CallHierarchyOutgoingCall;
|
|
22
|
+
export declare function convertCallHierarchyItem(item: ts.CallHierarchyItem, ctx: SharedContext): vscode.CallHierarchyItem;
|
|
23
|
+
export declare function convertDocumentSpanToLocation(documentSpan: ts.DocumentSpan, ctx: SharedContext): vscode.Location;
|
|
24
|
+
export declare function convertDefinitionInfoAndBoundSpan(info: ts.DefinitionInfoAndBoundSpan, document: TextDocument, ctx: SharedContext): vscode.LocationLink[];
|
|
25
|
+
export declare function convertDocumentSpantoLocationLink(documentSpan: ts.DocumentSpan, ctx: SharedContext): vscode.LocationLink;
|
|
26
|
+
export declare function convertTextSpan(textSpan: ts.TextSpan, document: TextDocument): vscode.Range;
|
|
27
|
+
//# sourceMappingURL=lspConverters.d.ts.map
|