volar-service-typescript 0.0.63 → 0.0.65
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,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 });
|
|
@@ -100,8 +100,8 @@ function convertDiagnosticCategory(input) {
|
|
|
100
100
|
}
|
|
101
101
|
return 1;
|
|
102
102
|
}
|
|
103
|
-
function getMessageText(diag
|
|
104
|
-
let messageText = '
|
|
103
|
+
function getMessageText(diag) {
|
|
104
|
+
let messageText = '';
|
|
105
105
|
if (typeof diag.messageText === 'string') {
|
|
106
106
|
messageText += diag.messageText;
|
|
107
107
|
}
|
|
@@ -109,12 +109,22 @@ function getMessageText(diag, level = 0) {
|
|
|
109
109
|
messageText += diag.messageText.messageText;
|
|
110
110
|
if (diag.messageText.next) {
|
|
111
111
|
for (const info of diag.messageText.next) {
|
|
112
|
-
messageText += '\n' +
|
|
112
|
+
messageText += '\n' + getNextMessageText(info, 1);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
return messageText;
|
|
117
117
|
}
|
|
118
|
+
function getNextMessageText(diag, level = 0) {
|
|
119
|
+
let messageText = ' '.repeat(level);
|
|
120
|
+
messageText += diag.messageText;
|
|
121
|
+
if (diag.next) {
|
|
122
|
+
for (const info of diag.next) {
|
|
123
|
+
messageText += '\n' + getNextMessageText(info, level + 1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return messageText;
|
|
127
|
+
}
|
|
118
128
|
// completion resolve
|
|
119
129
|
function applyCompletionEntryDetails(ts, item, data, document, fileNameToUri, getTextDocument) {
|
|
120
130
|
const { sourceDisplay } = data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
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",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"optional": true
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "f0253f4f3e3b0b0f1a453f99b354eb9feaec38cd"
|
|
48
48
|
}
|