volar-service-typescript 0.0.52 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServiceContext, LanguageServicePlugin, ProviderResult } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import { URI } from 'vscode-uri';
|
package/lib/plugins/semantic.js
CHANGED
|
@@ -4,15 +4,15 @@ exports.create = create;
|
|
|
4
4
|
const path = require("path-browserify");
|
|
5
5
|
const semver = require("semver");
|
|
6
6
|
const tsWithImportCache = require("typescript-auto-import-cache");
|
|
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
|
-
const shared_1 = require("../shared");
|
|
10
|
-
const lspConverters_1 = require("../utils/lspConverters");
|
|
11
|
-
const snippetForFunctionCall_1 = require("../utils/snippetForFunctionCall");
|
|
12
10
|
const codeActions = require("../semanticFeatures/codeAction");
|
|
13
11
|
const codeActionResolve = require("../semanticFeatures/codeActionResolve");
|
|
14
12
|
const semanticTokens = require("../semanticFeatures/semanticTokens");
|
|
15
|
-
const
|
|
13
|
+
const shared_1 = require("../shared");
|
|
14
|
+
const lspConverters_1 = require("../utils/lspConverters");
|
|
15
|
+
const snippetForFunctionCall_1 = require("../utils/snippetForFunctionCall");
|
|
16
16
|
const documentRegistries = [];
|
|
17
17
|
function getDocumentRegistry(ts, useCaseSensitiveFileNames, currentDirectory) {
|
|
18
18
|
let documentRegistry = documentRegistries.find(item => item[0] === useCaseSensitiveFileNames && item[1] === currentDirectory)?.[2];
|
|
@@ -69,43 +69,27 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
69
69
|
'class',
|
|
70
70
|
'enum',
|
|
71
71
|
'interface',
|
|
72
|
-
'struct',
|
|
73
72
|
'typeParameter',
|
|
74
73
|
'type',
|
|
75
74
|
'parameter',
|
|
76
75
|
'variable',
|
|
77
76
|
'property',
|
|
78
77
|
'enumMember',
|
|
79
|
-
'decorator',
|
|
80
|
-
'event',
|
|
81
78
|
'function',
|
|
82
79
|
'method',
|
|
83
|
-
'macro',
|
|
84
|
-
'label',
|
|
85
|
-
'comment',
|
|
86
|
-
'string',
|
|
87
|
-
'keyword',
|
|
88
|
-
'number',
|
|
89
|
-
'regexp',
|
|
90
|
-
'operator',
|
|
91
80
|
],
|
|
92
81
|
tokenModifiers: [
|
|
93
82
|
'declaration',
|
|
94
|
-
'definition',
|
|
95
83
|
'readonly',
|
|
96
84
|
'static',
|
|
97
|
-
'deprecated',
|
|
98
|
-
'abstract',
|
|
99
85
|
'async',
|
|
100
|
-
'modification',
|
|
101
|
-
'documentation',
|
|
102
86
|
'defaultLibrary',
|
|
87
|
+
'local', // additional
|
|
103
88
|
],
|
|
104
89
|
},
|
|
105
90
|
},
|
|
106
91
|
workspaceSymbolProvider: true,
|
|
107
92
|
// fileRenameEdits: true,
|
|
108
|
-
selectionRangeProvider: true,
|
|
109
93
|
signatureHelpProvider: {
|
|
110
94
|
triggerCharacters: ['(', ',', '<'],
|
|
111
95
|
retriggerCharacters: [')'],
|
|
@@ -197,7 +181,9 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
197
181
|
function updateSourceScriptFileNames() {
|
|
198
182
|
sourceScriptNames.clear();
|
|
199
183
|
for (const fileName of languageServiceHost.getScriptFileNames()) {
|
|
200
|
-
const
|
|
184
|
+
const maybeEmbeddedUri = ctx.fileNameToUri(fileName);
|
|
185
|
+
const decoded = context.decodeEmbeddedDocumentUri(maybeEmbeddedUri);
|
|
186
|
+
const uri = decoded ? decoded[0] : maybeEmbeddedUri;
|
|
201
187
|
const sourceScript = context.language.scripts.get(uri);
|
|
202
188
|
if (sourceScript?.generated) {
|
|
203
189
|
const tsCode = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
@@ -652,25 +638,6 @@ function create(ts, { isValidationEnabled = async (document, context) => {
|
|
|
652
638
|
return (0, lspConverters_1.convertFileTextChanges)(response, ctx.fileNameToUri, ctx.getTextDocument);
|
|
653
639
|
});
|
|
654
640
|
},
|
|
655
|
-
provideSelectionRanges(document, positions, token) {
|
|
656
|
-
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
657
|
-
if (!isSemanticDocument(uri, document)) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
return worker(token, () => {
|
|
661
|
-
return positions
|
|
662
|
-
.map(position => {
|
|
663
|
-
const fileName = ctx.uriToFileName(uri);
|
|
664
|
-
const offset = document.offsetAt(position);
|
|
665
|
-
const range = (0, shared_1.safeCall)(() => ctx.languageService.getSmartSelectionRange(fileName, offset));
|
|
666
|
-
if (!range) {
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
return (0, lspConverters_1.convertSelectionRange)(range, document);
|
|
670
|
-
})
|
|
671
|
-
.filter(position => !!position);
|
|
672
|
-
});
|
|
673
|
-
},
|
|
674
641
|
provideSignatureHelp(document, position, context, token) {
|
|
675
642
|
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
676
643
|
if (!isSemanticDocument(uri, document)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
1
|
+
import type { LanguageServiceContext, LanguageServicePlugin, ProviderResult } from '@volar/language-service';
|
|
3
2
|
import type * as ts from 'typescript';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export declare function getLanguageServiceByDocument(ts: typeof import('typescript'), document: TextDocument): {
|
|
5
5
|
languageService: ts.LanguageService;
|
|
6
6
|
fileName: string;
|
package/lib/plugins/syntactic.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.getLanguageServiceByDocument = getLanguageServiceByDocument;
|
|
|
4
4
|
exports.create = create;
|
|
5
5
|
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
6
6
|
const shared_1 = require("../shared");
|
|
7
|
-
const lspConverters_1 = require("../utils/lspConverters");
|
|
8
7
|
const syntaxOnlyService_1 = require("../syntaxOnlyService");
|
|
8
|
+
const lspConverters_1 = require("../utils/lspConverters");
|
|
9
9
|
const snapshots = new WeakMap();
|
|
10
10
|
let created;
|
|
11
11
|
function getLanguageServiceByDocument(ts, document) {
|
|
@@ -41,6 +41,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
41
41
|
configurationSections: ['javascript.autoClosingTags', 'typescript.autoClosingTags'],
|
|
42
42
|
},
|
|
43
43
|
foldingRangeProvider: true,
|
|
44
|
+
selectionRangeProvider: true,
|
|
44
45
|
documentSymbolProvider: true,
|
|
45
46
|
documentFormattingProvider: true,
|
|
46
47
|
documentOnTypeFormattingProvider: {
|
|
@@ -76,6 +77,24 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
76
77
|
}
|
|
77
78
|
return outliningSpans.map(span => (0, lspConverters_1.convertOutliningSpan)(span, document));
|
|
78
79
|
},
|
|
80
|
+
provideSelectionRanges(document, positions) {
|
|
81
|
+
if (!(0, shared_1.isTsDocument)(document)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
85
|
+
const ranges = positions
|
|
86
|
+
.map(position => {
|
|
87
|
+
const offset = document.offsetAt(position);
|
|
88
|
+
const range = (0, shared_1.safeCall)(() => languageService.getSmartSelectionRange(fileName, offset));
|
|
89
|
+
if (!range) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return (0, lspConverters_1.convertSelectionRange)(range, document);
|
|
93
|
+
});
|
|
94
|
+
if (ranges.every(range => !!range)) {
|
|
95
|
+
return ranges;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
79
98
|
provideDocumentSymbols(document) {
|
|
80
99
|
if (!(0, shared_1.isTsDocument)(document)) {
|
|
81
100
|
return;
|
|
@@ -19,14 +19,18 @@ function register(ts, ctx) {
|
|
|
19
19
|
tokenModifiersTable[0 /* TokenModifier.declaration */] = 1 << legend.tokenModifiers.indexOf('declaration');
|
|
20
20
|
tokenModifiersTable[3 /* TokenModifier.readonly */] = 1 << legend.tokenModifiers.indexOf('readonly');
|
|
21
21
|
tokenModifiersTable[1 /* TokenModifier.static */] = 1 << legend.tokenModifiers.indexOf('static');
|
|
22
|
-
tokenModifiersTable[5 /* TokenModifier.local */] = 1 << legend.tokenModifiers.indexOf('local');
|
|
22
|
+
tokenModifiersTable[5 /* TokenModifier.local */] = 1 << legend.tokenModifiers.indexOf('local');
|
|
23
23
|
tokenModifiersTable[4 /* TokenModifier.defaultLibrary */] = 1 << legend.tokenModifiers.indexOf('defaultLibrary');
|
|
24
24
|
tokenModifiersTable = tokenModifiersTable.map(mod => Math.max(mod, 0));
|
|
25
|
+
const end = start + length;
|
|
25
26
|
const tokenSpan = response.spans;
|
|
26
27
|
const tokens = [];
|
|
27
28
|
let i = 0;
|
|
28
29
|
while (i < tokenSpan.length) {
|
|
29
30
|
const offset = tokenSpan[i++];
|
|
31
|
+
if (offset >= end) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
30
34
|
const length = tokenSpan[i++];
|
|
31
35
|
const tsClassification = tokenSpan[i++];
|
|
32
36
|
const tokenType = getTokenTypeFromClassification(tsClassification);
|
|
@@ -98,7 +102,7 @@ tokenModifiers[2 /* TokenModifier.async */] = 'async';
|
|
|
98
102
|
tokenModifiers[0 /* TokenModifier.declaration */] = 'declaration';
|
|
99
103
|
tokenModifiers[3 /* TokenModifier.readonly */] = 'readonly';
|
|
100
104
|
tokenModifiers[1 /* TokenModifier.static */] = 'static';
|
|
101
|
-
tokenModifiers[5 /* TokenModifier.local */] = 'local';
|
|
105
|
+
tokenModifiers[5 /* TokenModifier.local */] = 'local';
|
|
102
106
|
tokenModifiers[4 /* TokenModifier.defaultLibrary */] = 'defaultLibrary';
|
|
103
107
|
// mapping for the original ExperimentalProtocol.ClassificationType from TypeScript (only used when plugin is not available)
|
|
104
108
|
const tokenTypeMap = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"path-browserify": "^1.0.1",
|
|
32
|
-
"semver": "^7.
|
|
32
|
+
"semver": "^7.6.2",
|
|
33
33
|
"typescript-auto-import-cache": "^0.3.3",
|
|
34
34
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
35
35
|
"vscode-nls": "^5.2.0",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"optional": true
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3b2f1593c15ea8e7f2ee02cd881c91342eeebe4e"
|
|
47
47
|
}
|