volar-service-typescript 0.0.64 → 0.0.66
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/lib/configs/getFormatCodeSettings.js +6 -3
- package/lib/configs/getUserPreferences.d.ts +1 -1
- package/lib/configs/getUserPreferences.js +48 -24
- package/lib/plugins/directiveComment.js +11 -8
- package/lib/plugins/docCommentTemplate.js +4 -1
- package/lib/plugins/semantic.js +11 -9
- package/lib/semanticFeatures/codeAction.js +3 -2
- package/lib/semanticFeatures/codeActionResolve.d.ts +1 -1
- package/lib/semanticFeatures/codeActionResolve.js +1 -1
- package/lib/semanticFeatures/semanticTokens.d.ts +3 -1
- package/lib/semanticFeatures/semanticTokens.js +55 -51
- package/lib/shared.js +6 -6
- package/lib/utils/lspConverters.js +83 -40
- package/lib/utils/snippetForFunctionCall.js +4 -1
- package/lib/utils/typeConverters.js +46 -23
- package/package.json +3 -2
|
@@ -15,12 +15,15 @@ async function getFormatCodeSettings(ctx, document, options) {
|
|
|
15
15
|
insertSpaceAfterSemicolonInForStatements: config.insertSpaceAfterSemicolonInForStatements ?? true,
|
|
16
16
|
insertSpaceBeforeAndAfterBinaryOperators: config.insertSpaceBeforeAndAfterBinaryOperators ?? true,
|
|
17
17
|
insertSpaceAfterKeywordsInControlFlowStatements: config.insertSpaceAfterKeywordsInControlFlowStatements ?? true,
|
|
18
|
-
insertSpaceAfterFunctionKeywordForAnonymousFunctions: config.insertSpaceAfterFunctionKeywordForAnonymousFunctions
|
|
18
|
+
insertSpaceAfterFunctionKeywordForAnonymousFunctions: config.insertSpaceAfterFunctionKeywordForAnonymousFunctions
|
|
19
|
+
?? true,
|
|
19
20
|
insertSpaceBeforeFunctionParenthesis: config.insertSpaceBeforeFunctionParenthesis ?? false,
|
|
20
21
|
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ?? false,
|
|
21
22
|
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ?? false,
|
|
22
|
-
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces
|
|
23
|
-
|
|
23
|
+
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces
|
|
24
|
+
?? true,
|
|
25
|
+
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: config.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces
|
|
26
|
+
?? true,
|
|
24
27
|
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: config.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces ?? false,
|
|
25
28
|
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: config.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces ?? false,
|
|
26
29
|
insertSpaceAfterTypeAssertion: config.insertSpaceAfterTypeAssertion ?? false,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { LanguageServiceContext } from '@volar/language-service';
|
|
1
2
|
import type * as ts from 'typescript';
|
|
2
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
-
import type { LanguageServiceContext } from '@volar/language-service';
|
|
4
4
|
export declare function getUserPreferences(ctx: LanguageServiceContext, document: TextDocument): Promise<ts.UserPreferences>;
|
|
5
5
|
//# sourceMappingURL=getUserPreferences.d.ts.map
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUserPreferences = getUserPreferences;
|
|
4
4
|
const path = require("path-browserify");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
6
|
+
const shared_1 = require("../shared");
|
|
7
7
|
async function getUserPreferences(ctx, document) {
|
|
8
8
|
let currentDirectory = '';
|
|
9
9
|
if (ctx.project.typescript) {
|
|
@@ -20,7 +20,9 @@ async function getUserPreferences(ctx, document) {
|
|
|
20
20
|
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
|
|
21
21
|
jsxAttributeCompletionStyle: getJsxAttributeCompletionStyle(preferencesConfig),
|
|
22
22
|
allowTextChangesInNewFiles: documentUri.scheme === 'file',
|
|
23
|
-
providePrefixAndSuffixTextForRename: (preferencesConfig.renameShorthandProperties ?? true) === false
|
|
23
|
+
providePrefixAndSuffixTextForRename: (preferencesConfig.renameShorthandProperties ?? true) === false
|
|
24
|
+
? false
|
|
25
|
+
: (preferencesConfig.useAliasesForRenames ?? true),
|
|
24
26
|
allowRenameOfImportPath: true,
|
|
25
27
|
includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true,
|
|
26
28
|
provideRefactorNotApplicableReason: true,
|
|
@@ -52,9 +54,12 @@ async function getUserPreferences(ctx, document) {
|
|
|
52
54
|
}
|
|
53
55
|
function getQuoteStylePreference(config) {
|
|
54
56
|
switch (config.quoteStyle) {
|
|
55
|
-
case 'single':
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
case 'single':
|
|
58
|
+
return 'single';
|
|
59
|
+
case 'double':
|
|
60
|
+
return 'double';
|
|
61
|
+
default:
|
|
62
|
+
return 'auto';
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
function getAutoImportFileExcludePatternsPreference(config, workspacePath) {
|
|
@@ -62,42 +67,61 @@ function getAutoImportFileExcludePatternsPreference(config, workspacePath) {
|
|
|
62
67
|
// Normalization rules: https://github.com/microsoft/TypeScript/pull/49578
|
|
63
68
|
const slashNormalized = p.replace(/\\/g, '/');
|
|
64
69
|
const isRelative = /^\.\.?($|\/)/.test(slashNormalized);
|
|
65
|
-
return path.isAbsolute(p)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
return path.isAbsolute(p)
|
|
71
|
+
? p
|
|
72
|
+
: p.startsWith('*')
|
|
73
|
+
? '/' + slashNormalized
|
|
74
|
+
: isRelative
|
|
75
|
+
? path.join(workspacePath, p)
|
|
76
|
+
: '/**/' + slashNormalized;
|
|
69
77
|
});
|
|
70
78
|
}
|
|
71
79
|
function getImportModuleSpecifierPreference(config) {
|
|
72
80
|
switch (config.importModuleSpecifier) {
|
|
73
|
-
case 'project-relative':
|
|
74
|
-
|
|
75
|
-
case '
|
|
76
|
-
|
|
81
|
+
case 'project-relative':
|
|
82
|
+
return 'project-relative';
|
|
83
|
+
case 'relative':
|
|
84
|
+
return 'relative';
|
|
85
|
+
case 'non-relative':
|
|
86
|
+
return 'non-relative';
|
|
87
|
+
default:
|
|
88
|
+
return undefined;
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
91
|
function getImportModuleSpecifierEndingPreference(config) {
|
|
80
92
|
switch (config.importModuleSpecifierEnding) {
|
|
81
|
-
case 'minimal':
|
|
82
|
-
|
|
83
|
-
case '
|
|
84
|
-
|
|
93
|
+
case 'minimal':
|
|
94
|
+
return 'minimal';
|
|
95
|
+
case 'index':
|
|
96
|
+
return 'index';
|
|
97
|
+
case 'js':
|
|
98
|
+
return 'js';
|
|
99
|
+
default:
|
|
100
|
+
return 'minimal';
|
|
85
101
|
// default: return 'auto';
|
|
102
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1667
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
105
|
function getJsxAttributeCompletionStyle(config) {
|
|
89
106
|
switch (config.jsxAttributeCompletionStyle) {
|
|
90
|
-
case 'braces':
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
case 'braces':
|
|
108
|
+
return 'braces';
|
|
109
|
+
case 'none':
|
|
110
|
+
return 'none';
|
|
111
|
+
default:
|
|
112
|
+
return 'auto';
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
115
|
function getInlayParameterNameHintsPreference(config) {
|
|
96
116
|
switch (config.inlayHints?.parameterNames?.enabled) {
|
|
97
|
-
case 'none':
|
|
98
|
-
|
|
99
|
-
case '
|
|
100
|
-
|
|
117
|
+
case 'none':
|
|
118
|
+
return 'none';
|
|
119
|
+
case 'literals':
|
|
120
|
+
return 'literals';
|
|
121
|
+
case 'all':
|
|
122
|
+
return 'all';
|
|
123
|
+
default:
|
|
124
|
+
return undefined;
|
|
101
125
|
}
|
|
102
126
|
}
|
|
103
127
|
//# sourceMappingURL=getUserPreferences.js.map
|
|
@@ -7,17 +7,20 @@ const localize = nls.loadMessageBundle(); // TODO: not working
|
|
|
7
7
|
const directives = [
|
|
8
8
|
{
|
|
9
9
|
value: '@ts-check',
|
|
10
|
-
description: localize('ts-check',
|
|
11
|
-
},
|
|
10
|
+
description: localize('ts-check', 'Enables semantic checking in a JavaScript file. Must be at the top of a file.'),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
12
13
|
value: '@ts-nocheck',
|
|
13
|
-
description: localize('ts-nocheck',
|
|
14
|
-
},
|
|
14
|
+
description: localize('ts-nocheck', 'Disables semantic checking in a JavaScript file. Must be at the top of a file.'),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
15
17
|
value: '@ts-ignore',
|
|
16
|
-
description: localize('ts-ignore',
|
|
17
|
-
},
|
|
18
|
+
description: localize('ts-ignore', 'Suppresses @ts-check errors on the next line of a file.'),
|
|
19
|
+
},
|
|
20
|
+
{
|
|
18
21
|
value: '@ts-expect-error',
|
|
19
|
-
description: localize('ts-expect-error',
|
|
20
|
-
}
|
|
22
|
+
description: localize('ts-expect-error', 'Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.'),
|
|
23
|
+
},
|
|
21
24
|
];
|
|
22
25
|
function create() {
|
|
23
26
|
return {
|
|
@@ -59,7 +59,10 @@ function createCompletionItem(document, position, insertText) {
|
|
|
59
59
|
const line = (0, lspConverters_1.getLineText)(document, position.line);
|
|
60
60
|
const prefix = line.slice(0, position.character).match(/\/\**\s*$/);
|
|
61
61
|
const suffix = line.slice(position.character).match(/^\s*\**\//);
|
|
62
|
-
const start = {
|
|
62
|
+
const start = {
|
|
63
|
+
line: position.line,
|
|
64
|
+
character: position.character + (prefix ? -prefix[0].length : 0),
|
|
65
|
+
};
|
|
63
66
|
const end = { line: position.line, character: position.character + (suffix ? suffix[0].length : 0) };
|
|
64
67
|
const range = { start, end };
|
|
65
68
|
item.textEdit = { range, newText: insertText };
|
package/lib/plugins/semantic.js
CHANGED
|
@@ -283,7 +283,8 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
283
283
|
Object.assign(item.labelDetails, data.originalItem.labelDetails);
|
|
284
284
|
}
|
|
285
285
|
(0, lspConverters_1.applyCompletionEntryDetails)(ts, item, details, document, ctx.fileNameToUri, ctx.getTextDocument);
|
|
286
|
-
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls')
|
|
286
|
+
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls')
|
|
287
|
+
?? false;
|
|
287
288
|
const useCodeSnippet = useCodeSnippetsOnMethodSuggest
|
|
288
289
|
&& (item.kind === 3
|
|
289
290
|
|| item.kind === 2);
|
|
@@ -302,8 +303,8 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
302
303
|
}
|
|
303
304
|
item.insertTextFormat = 2;
|
|
304
305
|
if (parameterCount > 0) {
|
|
305
|
-
//Fix for https://github.com/microsoft/vscode/issues/104059
|
|
306
|
-
//Don't show parameter hints if "editor.parameterHints.enabled": false
|
|
306
|
+
// Fix for https://github.com/microsoft/vscode/issues/104059
|
|
307
|
+
// Don't show parameter hints if "editor.parameterHints.enabled": false
|
|
307
308
|
// if (await getConfiguration('editor.parameterHints.enabled', document.uri)) {
|
|
308
309
|
// item.command = {
|
|
309
310
|
// title: 'triggerParameterHints',
|
|
@@ -680,7 +681,7 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
680
681
|
const options = {};
|
|
681
682
|
if (context?.triggerKind === 1) {
|
|
682
683
|
options.triggerReason = {
|
|
683
|
-
kind: 'invoked'
|
|
684
|
+
kind: 'invoked',
|
|
684
685
|
};
|
|
685
686
|
}
|
|
686
687
|
else if (context?.triggerKind === 2) {
|
|
@@ -708,14 +709,14 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
708
709
|
const signature = {
|
|
709
710
|
label: '',
|
|
710
711
|
documentation: undefined,
|
|
711
|
-
parameters: []
|
|
712
|
+
parameters: [],
|
|
712
713
|
};
|
|
713
714
|
signature.label += ts.displayPartsToString(item.prefixDisplayParts);
|
|
714
715
|
item.parameters.forEach((p, i, a) => {
|
|
715
716
|
const label = ts.displayPartsToString(p.displayParts);
|
|
716
717
|
const parameter = {
|
|
717
718
|
label,
|
|
718
|
-
documentation: ts.displayPartsToString(p.documentation)
|
|
719
|
+
documentation: ts.displayPartsToString(p.documentation),
|
|
719
720
|
};
|
|
720
721
|
signature.label += label;
|
|
721
722
|
signature.parameters.push(parameter);
|
|
@@ -748,7 +749,8 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
748
749
|
}
|
|
749
750
|
const tsToken = {
|
|
750
751
|
isCancellationRequested() {
|
|
751
|
-
return ctx.project.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()
|
|
752
|
+
return ctx.project.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()
|
|
753
|
+
?? false;
|
|
752
754
|
},
|
|
753
755
|
throwIfCancellationRequested() { },
|
|
754
756
|
};
|
|
@@ -816,7 +818,7 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
816
818
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
817
819
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
818
820
|
if (virtualCode && sourceScript?.generated?.languagePlugin.typescript) {
|
|
819
|
-
const { getServiceScript, getExtraServiceScripts } = sourceScript.generated
|
|
821
|
+
const { getServiceScript, getExtraServiceScripts } = sourceScript.generated.languagePlugin.typescript;
|
|
820
822
|
const sourceFileName = uriConverter.asFileName(sourceScript.id);
|
|
821
823
|
if (getServiceScript(sourceScript.generated.root)?.code === virtualCode) {
|
|
822
824
|
return {
|
|
@@ -835,7 +837,7 @@ function create(ts, { disableAutoImportCache = false, isValidationEnabled = asyn
|
|
|
835
837
|
};
|
|
836
838
|
}
|
|
837
839
|
function getBasicTriggerCharacters(tsVersion) {
|
|
838
|
-
const triggerCharacters = ['.', '"', '
|
|
840
|
+
const triggerCharacters = ['.', '"', "'", '`', '/', '<'];
|
|
839
841
|
// https://github.com/microsoft/vscode/blob/8e65ae28d5fb8b3c931135da1a41edb9c80ae46f/extensions/typescript-language-features/src/languageFeatures/completions.ts#L811-L833
|
|
840
842
|
if (semver.lt(tsVersion, '3.1.0') || semver.gte(tsVersion, '3.2.0')) {
|
|
841
843
|
triggerCharacters.push('@');
|
|
@@ -16,7 +16,8 @@ const renameCommandRefactors = new Set([
|
|
|
16
16
|
'refactor.extract.function',
|
|
17
17
|
]);
|
|
18
18
|
function register(ctx) {
|
|
19
|
-
let resolveCommandSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties
|
|
19
|
+
let resolveCommandSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties
|
|
20
|
+
?.includes('command');
|
|
20
21
|
let resolveEditSupport = ctx.env.clientCapabilities?.textDocument?.codeAction?.resolveSupport?.properties?.includes('edit');
|
|
21
22
|
let loged = false;
|
|
22
23
|
const wranUnsupportResolve = () => {
|
|
@@ -178,7 +179,7 @@ function register(ctx) {
|
|
|
178
179
|
if (a.length <= b.length) {
|
|
179
180
|
let matchNums = 0;
|
|
180
181
|
for (let i = 0; i < a.length; i++) {
|
|
181
|
-
if (a[i]
|
|
182
|
+
if (a[i] === b[i]) {
|
|
182
183
|
matchNums++;
|
|
183
184
|
}
|
|
184
185
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
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 './types';
|
|
5
4
|
import type { Data, FixAllData, RefactorData } from './codeAction';
|
|
5
|
+
import type { SharedContext } from './types';
|
|
6
6
|
export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction, formattingOptions: vscode.FormattingOptions | undefined) => Promise<vscode.CodeAction>;
|
|
7
7
|
export declare function resolveFixAllCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: FixAllData, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
|
|
8
8
|
export declare function resolveRefactorCodeAction(ctx: SharedContext, codeAction: vscode.CodeAction, data: RefactorData, document: TextDocument, formatOptions: ts.FormatCodeSettings, preferences: ts.UserPreferences): void;
|
|
@@ -4,11 +4,11 @@ exports.register = register;
|
|
|
4
4
|
exports.resolveFixAllCodeAction = resolveFixAllCodeAction;
|
|
5
5
|
exports.resolveRefactorCodeAction = resolveRefactorCodeAction;
|
|
6
6
|
exports.resolveOrganizeImportsCodeAction = resolveOrganizeImportsCodeAction;
|
|
7
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
7
8
|
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
8
9
|
const getUserPreferences_1 = require("../configs/getUserPreferences");
|
|
9
10
|
const shared_1 = require("../shared");
|
|
10
11
|
const lspConverters_1 = require("../utils/lspConverters");
|
|
11
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
12
12
|
function register(ctx) {
|
|
13
13
|
return async (codeAction, formattingOptions) => {
|
|
14
14
|
const data = codeAction.data;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type * as vscode from '@volar/language-service';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
2
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
-
import type { SharedContext } from './types';
|
|
4
4
|
import type { URI } from 'vscode-uri';
|
|
5
|
+
import type { SharedContext } from './types';
|
|
5
6
|
export declare function register(ts: typeof import('typescript'), ctx: SharedContext): (uri: URI, document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend) => [number, number, number, number, number][] | undefined;
|
|
7
|
+
export declare function convertClassificationsToSemanticTokens(document: TextDocument, { start, length }: ts.TextSpan, legend: vscode.SemanticTokensLegend, response: ts.Classifications): [number, number, number, number, number][];
|
|
6
8
|
//# sourceMappingURL=semanticTokens.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = register;
|
|
4
|
+
exports.convertClassificationsToSemanticTokens = convertClassificationsToSemanticTokens;
|
|
4
5
|
const shared_1 = require("../shared");
|
|
5
6
|
function register(ts, ctx) {
|
|
6
7
|
return (uri, document, range, legend) => {
|
|
@@ -14,61 +15,64 @@ function register(ts, ctx) {
|
|
|
14
15
|
if (!response) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (tokenType === undefined) {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const tokenModifiers = getTokenModifierFromClassification(tsClassification);
|
|
41
|
-
// we can use the document's range conversion methods because the result is at the same version as the document
|
|
42
|
-
const startPos = document.positionAt(offset);
|
|
43
|
-
const endPos = document.positionAt(offset + length);
|
|
44
|
-
const serverToken = tsTokenTypeToServerTokenType(tokenType);
|
|
45
|
-
if (serverToken === undefined) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const serverTokenModifiers = tsTokenModifierToServerTokenModifier(tokenModifiers);
|
|
49
|
-
for (let line = startPos.line; line <= endPos.line; line++) {
|
|
50
|
-
const startCharacter = (line === startPos.line ? startPos.character : 0);
|
|
51
|
-
const endCharacter = (line === endPos.line ? endPos.character : docLineLength(document, line));
|
|
52
|
-
tokens.push([line, startCharacter, endCharacter - startCharacter, serverToken, serverTokenModifiers]);
|
|
53
|
-
}
|
|
18
|
+
return convertClassificationsToSemanticTokens(document, { start, length }, legend, response);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function convertClassificationsToSemanticTokens(document, { start, length }, legend, response) {
|
|
22
|
+
let tokenModifiersTable = [];
|
|
23
|
+
tokenModifiersTable[2 /* TokenModifier.async */] = 1 << legend.tokenModifiers.indexOf('async');
|
|
24
|
+
tokenModifiersTable[0 /* TokenModifier.declaration */] = 1 << legend.tokenModifiers.indexOf('declaration');
|
|
25
|
+
tokenModifiersTable[3 /* TokenModifier.readonly */] = 1 << legend.tokenModifiers.indexOf('readonly');
|
|
26
|
+
tokenModifiersTable[1 /* TokenModifier.static */] = 1 << legend.tokenModifiers.indexOf('static');
|
|
27
|
+
tokenModifiersTable[5 /* TokenModifier.local */] = 1 << legend.tokenModifiers.indexOf('local');
|
|
28
|
+
tokenModifiersTable[4 /* TokenModifier.defaultLibrary */] = 1 << legend.tokenModifiers.indexOf('defaultLibrary');
|
|
29
|
+
tokenModifiersTable = tokenModifiersTable.map(mod => Math.max(mod, 0));
|
|
30
|
+
const end = start + length;
|
|
31
|
+
const tokenSpan = response.spans;
|
|
32
|
+
const tokens = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < tokenSpan.length) {
|
|
35
|
+
const offset = tokenSpan[i++];
|
|
36
|
+
if (offset >= end) {
|
|
37
|
+
break;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
const length = tokenSpan[i++];
|
|
40
|
+
const tsClassification = tokenSpan[i++];
|
|
41
|
+
const tokenType = getTokenTypeFromClassification(tsClassification);
|
|
42
|
+
if (tokenType === undefined) {
|
|
43
|
+
continue;
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
const tokenModifiers = getTokenModifierFromClassification(tsClassification);
|
|
46
|
+
// we can use the document's range conversion methods because the result is at the same version as the document
|
|
47
|
+
const startPos = document.positionAt(offset);
|
|
48
|
+
const endPos = document.positionAt(offset + length);
|
|
49
|
+
const serverToken = tsTokenTypeToServerTokenType(tokenType);
|
|
50
|
+
if (serverToken === undefined) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const serverTokenModifiers = tsTokenModifierToServerTokenModifier(tokenModifiers);
|
|
54
|
+
for (let line = startPos.line; line <= endPos.line; line++) {
|
|
55
|
+
const startCharacter = line === startPos.line ? startPos.character : 0;
|
|
56
|
+
const endCharacter = line === endPos.line ? endPos.character : docLineLength(document, line);
|
|
57
|
+
tokens.push([line, startCharacter, endCharacter - startCharacter, serverToken, serverTokenModifiers]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return tokens;
|
|
61
|
+
function tsTokenTypeToServerTokenType(tokenType) {
|
|
62
|
+
return legend.tokenTypes.indexOf(tokenTypes[tokenType]);
|
|
63
|
+
}
|
|
64
|
+
function tsTokenModifierToServerTokenModifier(input) {
|
|
65
|
+
let m = 0;
|
|
66
|
+
let i = 0;
|
|
67
|
+
while (input) {
|
|
68
|
+
if (input & 1) {
|
|
69
|
+
m |= tokenModifiersTable[i];
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
input = input >> 1;
|
|
72
|
+
i++;
|
|
70
73
|
}
|
|
71
|
-
|
|
74
|
+
return m;
|
|
75
|
+
}
|
|
72
76
|
}
|
|
73
77
|
function docLineLength(document, line) {
|
|
74
78
|
const currentLineOffset = document.offsetAt({ line, character: 0 });
|
package/lib/shared.js
CHANGED
|
@@ -14,14 +14,14 @@ function getConfigTitle(document) {
|
|
|
14
14
|
return document.languageId;
|
|
15
15
|
}
|
|
16
16
|
function isTsDocument(document) {
|
|
17
|
-
return document.languageId === 'javascript'
|
|
18
|
-
document.languageId === 'typescript'
|
|
19
|
-
document.languageId === 'javascriptreact'
|
|
20
|
-
document.languageId === 'typescriptreact';
|
|
17
|
+
return document.languageId === 'javascript'
|
|
18
|
+
|| document.languageId === 'typescript'
|
|
19
|
+
|| document.languageId === 'javascriptreact'
|
|
20
|
+
|| document.languageId === 'typescriptreact';
|
|
21
21
|
}
|
|
22
22
|
function isJsonDocument(document) {
|
|
23
|
-
return document.languageId === 'json'
|
|
24
|
-
document.languageId === 'jsonc';
|
|
23
|
+
return document.languageId === 'json'
|
|
24
|
+
|| document.languageId === 'jsonc';
|
|
25
25
|
}
|
|
26
26
|
function safeCall(cb) {
|
|
27
27
|
try {
|
|
@@ -93,10 +93,14 @@ function convertDiagnosticRelatedInformation(diag, fileNameToUri, getTextDocumen
|
|
|
93
93
|
}
|
|
94
94
|
function convertDiagnosticCategory(input) {
|
|
95
95
|
switch (input) {
|
|
96
|
-
case 0:
|
|
97
|
-
|
|
98
|
-
case
|
|
99
|
-
|
|
96
|
+
case 0:
|
|
97
|
+
return 2;
|
|
98
|
+
case 1:
|
|
99
|
+
return 1;
|
|
100
|
+
case 2:
|
|
101
|
+
return 4;
|
|
102
|
+
case 3:
|
|
103
|
+
return 3;
|
|
100
104
|
}
|
|
101
105
|
return 1;
|
|
102
106
|
}
|
|
@@ -205,7 +209,9 @@ function convertCompletionInfo(ts, completionContext, document, position, create
|
|
|
205
209
|
enableCallCompletions: true, // TODO: suggest.completeFunctionCalls
|
|
206
210
|
});
|
|
207
211
|
item.insertText = tsEntry.insertText;
|
|
208
|
-
item.insertTextFormat = isSnippet
|
|
212
|
+
item.insertTextFormat = isSnippet
|
|
213
|
+
? 2
|
|
214
|
+
: 1;
|
|
209
215
|
item.filterText = getFilterText(tsEntry, wordRange, line, tsEntry.insertText);
|
|
210
216
|
if (completionContext?.isMemberCompletion && dotAccessorContext && !isSnippet) {
|
|
211
217
|
item.filterText = dotAccessorContext.text + (item.insertText || item.label);
|
|
@@ -440,8 +446,12 @@ function handleKindModifiers(item, tsEntry) {
|
|
|
440
446
|
}
|
|
441
447
|
}
|
|
442
448
|
function rangeUnion(a, b) {
|
|
443
|
-
const start = (a.start.line < b.start.line || (a.start.line === b.start.line && a.start.character < b.start.character))
|
|
444
|
-
|
|
449
|
+
const start = (a.start.line < b.start.line || (a.start.line === b.start.line && a.start.character < b.start.character))
|
|
450
|
+
? a.start
|
|
451
|
+
: b.start;
|
|
452
|
+
const end = (a.end.line > b.end.line || (a.end.line === b.end.line && a.end.character > b.end.character))
|
|
453
|
+
? a.end
|
|
454
|
+
: b.end;
|
|
445
455
|
return { start, end };
|
|
446
456
|
}
|
|
447
457
|
function getLineText(document, line) {
|
|
@@ -478,18 +488,30 @@ function getLabel(item) {
|
|
|
478
488
|
}
|
|
479
489
|
function convertScriptElementKind(kind) {
|
|
480
490
|
switch (kind) {
|
|
481
|
-
case PConst.Kind.method:
|
|
482
|
-
|
|
483
|
-
case PConst.Kind.
|
|
484
|
-
|
|
485
|
-
case PConst.Kind.
|
|
486
|
-
|
|
487
|
-
case PConst.Kind.
|
|
488
|
-
|
|
489
|
-
case PConst.Kind.
|
|
490
|
-
|
|
491
|
-
case PConst.Kind.
|
|
492
|
-
|
|
491
|
+
case PConst.Kind.method:
|
|
492
|
+
return 6;
|
|
493
|
+
case PConst.Kind.enum:
|
|
494
|
+
return 10;
|
|
495
|
+
case PConst.Kind.enumMember:
|
|
496
|
+
return 22;
|
|
497
|
+
case PConst.Kind.function:
|
|
498
|
+
return 12;
|
|
499
|
+
case PConst.Kind.class:
|
|
500
|
+
return 5;
|
|
501
|
+
case PConst.Kind.interface:
|
|
502
|
+
return 11;
|
|
503
|
+
case PConst.Kind.type:
|
|
504
|
+
return 5;
|
|
505
|
+
case PConst.Kind.memberVariable:
|
|
506
|
+
return 8;
|
|
507
|
+
case PConst.Kind.memberGetAccessor:
|
|
508
|
+
return 8;
|
|
509
|
+
case PConst.Kind.memberSetAccessor:
|
|
510
|
+
return 8;
|
|
511
|
+
case PConst.Kind.variable:
|
|
512
|
+
return 13;
|
|
513
|
+
default:
|
|
514
|
+
return 13;
|
|
493
515
|
}
|
|
494
516
|
}
|
|
495
517
|
// inlayHints
|
|
@@ -497,8 +519,10 @@ function convertInlayHint(hint, document) {
|
|
|
497
519
|
const result = {
|
|
498
520
|
position: document.positionAt(hint.position),
|
|
499
521
|
label: hint.text,
|
|
500
|
-
kind: hint.kind === 'Type'
|
|
501
|
-
|
|
522
|
+
kind: hint.kind === 'Type'
|
|
523
|
+
? 1
|
|
524
|
+
: hint.kind === 'Parameter'
|
|
525
|
+
? 2
|
|
502
526
|
: undefined,
|
|
503
527
|
};
|
|
504
528
|
result.paddingLeft = hint.whitespaceBefore;
|
|
@@ -651,21 +675,36 @@ function convertNavTree(item, document) {
|
|
|
651
675
|
}
|
|
652
676
|
const getSymbolKind = (kind) => {
|
|
653
677
|
switch (kind) {
|
|
654
|
-
case PConst.Kind.module:
|
|
655
|
-
|
|
656
|
-
case PConst.Kind.
|
|
657
|
-
|
|
658
|
-
case PConst.Kind.
|
|
659
|
-
|
|
660
|
-
case PConst.Kind.
|
|
661
|
-
|
|
662
|
-
case PConst.Kind.
|
|
663
|
-
|
|
664
|
-
case PConst.Kind.
|
|
665
|
-
|
|
666
|
-
case PConst.Kind.
|
|
667
|
-
|
|
668
|
-
case PConst.Kind.
|
|
678
|
+
case PConst.Kind.module:
|
|
679
|
+
return 2;
|
|
680
|
+
case PConst.Kind.class:
|
|
681
|
+
return 5;
|
|
682
|
+
case PConst.Kind.enum:
|
|
683
|
+
return 10;
|
|
684
|
+
case PConst.Kind.interface:
|
|
685
|
+
return 11;
|
|
686
|
+
case PConst.Kind.method:
|
|
687
|
+
return 6;
|
|
688
|
+
case PConst.Kind.memberVariable:
|
|
689
|
+
return 7;
|
|
690
|
+
case PConst.Kind.memberGetAccessor:
|
|
691
|
+
return 7;
|
|
692
|
+
case PConst.Kind.memberSetAccessor:
|
|
693
|
+
return 7;
|
|
694
|
+
case PConst.Kind.variable:
|
|
695
|
+
return 13;
|
|
696
|
+
case PConst.Kind.const:
|
|
697
|
+
return 13;
|
|
698
|
+
case PConst.Kind.localVariable:
|
|
699
|
+
return 13;
|
|
700
|
+
case PConst.Kind.function:
|
|
701
|
+
return 12;
|
|
702
|
+
case PConst.Kind.localFunction:
|
|
703
|
+
return 12;
|
|
704
|
+
case PConst.Kind.constructSignature:
|
|
705
|
+
return 9;
|
|
706
|
+
case PConst.Kind.constructorImplementation:
|
|
707
|
+
return 9;
|
|
669
708
|
}
|
|
670
709
|
return 13;
|
|
671
710
|
};
|
|
@@ -689,11 +728,15 @@ function convertOutliningSpan(outliningSpan, document) {
|
|
|
689
728
|
}
|
|
690
729
|
function convertOutliningSpanKind(kind) {
|
|
691
730
|
switch (kind) {
|
|
692
|
-
case 'comment':
|
|
693
|
-
|
|
694
|
-
case '
|
|
731
|
+
case 'comment':
|
|
732
|
+
return 'comment';
|
|
733
|
+
case 'region':
|
|
734
|
+
return 'region';
|
|
735
|
+
case 'imports':
|
|
736
|
+
return 'imports';
|
|
695
737
|
case 'code':
|
|
696
|
-
default:
|
|
738
|
+
default:
|
|
739
|
+
return undefined;
|
|
697
740
|
}
|
|
698
741
|
}
|
|
699
742
|
const foldEndPairCharacters = ['}', ']', ')', '`'];
|
|
@@ -16,7 +16,10 @@ function snippetForFunctionCall(item, displayParts) {
|
|
|
16
16
|
}
|
|
17
17
|
snippet += ')';
|
|
18
18
|
snippet += '$' + _tabstop++;
|
|
19
|
-
return {
|
|
19
|
+
return {
|
|
20
|
+
snippet,
|
|
21
|
+
parameterCount: parameterListParts.parts.length + (parameterListParts.hasOptionalParameters ? 1 : 0),
|
|
22
|
+
};
|
|
20
23
|
function appendJoinedPlaceholders(snippet, parts, joiner) {
|
|
21
24
|
for (let i = 0; i < parts.length; ++i) {
|
|
22
25
|
const paramterPart = parts[i];
|
|
@@ -10,29 +10,52 @@ var SymbolKind;
|
|
|
10
10
|
(function (SymbolKind) {
|
|
11
11
|
function fromProtocolScriptElementKind(kind) {
|
|
12
12
|
switch (kind) {
|
|
13
|
-
case PConst.Kind.module:
|
|
14
|
-
|
|
15
|
-
case PConst.Kind.
|
|
16
|
-
|
|
17
|
-
case PConst.Kind.
|
|
18
|
-
|
|
19
|
-
case PConst.Kind.
|
|
20
|
-
|
|
21
|
-
case PConst.Kind.
|
|
22
|
-
|
|
23
|
-
case PConst.Kind.
|
|
24
|
-
|
|
25
|
-
case PConst.Kind.
|
|
26
|
-
|
|
27
|
-
case PConst.Kind.
|
|
28
|
-
|
|
29
|
-
case PConst.Kind.
|
|
30
|
-
|
|
31
|
-
case PConst.Kind.
|
|
32
|
-
|
|
33
|
-
case PConst.Kind.
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
case PConst.Kind.module:
|
|
14
|
+
return 2;
|
|
15
|
+
case PConst.Kind.class:
|
|
16
|
+
return 5;
|
|
17
|
+
case PConst.Kind.enum:
|
|
18
|
+
return 10;
|
|
19
|
+
case PConst.Kind.enumMember:
|
|
20
|
+
return 22;
|
|
21
|
+
case PConst.Kind.interface:
|
|
22
|
+
return 11;
|
|
23
|
+
case PConst.Kind.indexSignature:
|
|
24
|
+
return 6;
|
|
25
|
+
case PConst.Kind.callSignature:
|
|
26
|
+
return 6;
|
|
27
|
+
case PConst.Kind.method:
|
|
28
|
+
return 6;
|
|
29
|
+
case PConst.Kind.memberVariable:
|
|
30
|
+
return 7;
|
|
31
|
+
case PConst.Kind.memberGetAccessor:
|
|
32
|
+
return 7;
|
|
33
|
+
case PConst.Kind.memberSetAccessor:
|
|
34
|
+
return 7;
|
|
35
|
+
case PConst.Kind.variable:
|
|
36
|
+
return 13;
|
|
37
|
+
case PConst.Kind.let:
|
|
38
|
+
return 13;
|
|
39
|
+
case PConst.Kind.const:
|
|
40
|
+
return 13;
|
|
41
|
+
case PConst.Kind.localVariable:
|
|
42
|
+
return 13;
|
|
43
|
+
case PConst.Kind.alias:
|
|
44
|
+
return 13;
|
|
45
|
+
case PConst.Kind.function:
|
|
46
|
+
return 12;
|
|
47
|
+
case PConst.Kind.localFunction:
|
|
48
|
+
return 12;
|
|
49
|
+
case PConst.Kind.constructSignature:
|
|
50
|
+
return 9;
|
|
51
|
+
case PConst.Kind.constructorImplementation:
|
|
52
|
+
return 9;
|
|
53
|
+
case PConst.Kind.typeParameter:
|
|
54
|
+
return 26;
|
|
55
|
+
case PConst.Kind.string:
|
|
56
|
+
return 15;
|
|
57
|
+
default:
|
|
58
|
+
return 13;
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
SymbolKind.fromProtocolScriptElementKind = fromProtocolScriptElementKind;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.66",
|
|
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",
|
|
@@ -43,5 +43,6 @@
|
|
|
43
43
|
"@volar/language-service": {
|
|
44
44
|
"optional": true
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "7113cd822bff8839f54ec8dfb3cb9c0486716230"
|
|
47
48
|
}
|