@volar/language-service 2.3.0 → 2.3.2
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 +0 -1
- package/index.js +0 -1
- package/lib/features/provideAutoInsertSnippet.js +4 -5
- package/lib/features/provideCallHierarchyItems.d.ts +1 -1
- package/lib/features/provideCallHierarchyItems.js +18 -17
- package/lib/features/provideCodeActions.js +7 -8
- package/lib/features/provideCodeLenses.js +6 -8
- package/lib/features/provideColorPresentations.js +8 -10
- package/lib/features/provideCompletionItems.js +32 -21
- package/lib/features/provideDefinition.js +22 -20
- package/lib/features/provideDiagnostics.d.ts +2 -2
- package/lib/features/provideDiagnostics.js +38 -30
- package/lib/features/provideDocumentColors.js +6 -8
- package/lib/features/provideDocumentDropEdits.js +3 -4
- package/lib/features/provideDocumentFormattingEdits.js +51 -30
- package/lib/features/provideDocumentHighlights.js +12 -13
- package/lib/features/provideDocumentLinks.js +6 -8
- package/lib/features/provideDocumentSemanticTokens.js +9 -10
- package/lib/features/provideDocumentSymbols.js +6 -7
- package/lib/features/provideFileReferences.d.ts +1 -1
- package/lib/features/provideFileReferences.js +9 -8
- package/lib/features/provideFileRenameEdits.js +1 -2
- package/lib/features/provideFoldingRanges.js +5 -6
- package/lib/features/provideHover.js +5 -6
- package/lib/features/provideInlayHints.js +11 -13
- package/lib/features/provideLinkedEditingRanges.js +7 -9
- package/lib/features/provideReferences.js +15 -12
- package/lib/features/provideRenameEdits.js +10 -10
- package/lib/features/provideRenameRange.js +5 -6
- package/lib/features/provideSelectionRanges.js +18 -10
- package/lib/features/provideSignatureHelp.js +2 -3
- package/lib/features/provideWorkspaceDiagnostics.js +12 -9
- package/lib/features/provideWorkspaceSymbols.js +14 -10
- package/lib/features/resolveCodeAction.js +1 -2
- package/lib/features/resolveCodeLens.js +1 -2
- package/lib/features/resolveCompletionItem.js +9 -6
- package/lib/features/resolveDocumentLink.js +1 -2
- package/lib/features/resolveInlayHint.js +1 -2
- package/lib/languageService.d.ts +11 -5
- package/lib/languageService.js +25 -51
- package/lib/types.d.ts +0 -4
- package/lib/utils/common.d.ts +2 -3
- package/lib/utils/common.js +7 -12
- package/lib/utils/dedupe.js +10 -11
- package/lib/utils/featureWorkers.d.ts +30 -7
- package/lib/utils/featureWorkers.js +103 -55
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +61 -48
- package/lib/utils/uriMap.js +1 -2
- package/package.json +3 -3
- package/lib/documents.d.ts +0 -31
- package/lib/documents.js +0 -117
package/lib/languageService.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.embeddedContentScheme = void 0;
|
|
4
|
+
exports.createLanguageService = createLanguageService;
|
|
5
|
+
exports.decodeEmbeddedDocumentUri = decodeEmbeddedDocumentUri;
|
|
6
|
+
exports.encodeEmbeddedDocumentUri = encodeEmbeddedDocumentUri;
|
|
4
7
|
const language_core_1 = require("@volar/language-core");
|
|
5
8
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
9
|
const vscode_uri_1 = require("vscode-uri");
|
|
7
|
-
const documents_1 = require("./documents");
|
|
8
10
|
const autoInsert = require("./features/provideAutoInsertSnippet");
|
|
9
11
|
const callHierarchy = require("./features/provideCallHierarchyItems");
|
|
10
12
|
const codeActions = require("./features/provideCodeActions");
|
|
@@ -13,7 +15,6 @@ const colorPresentations = require("./features/provideColorPresentations");
|
|
|
13
15
|
const completions = require("./features/provideCompletionItems");
|
|
14
16
|
const definition = require("./features/provideDefinition");
|
|
15
17
|
const diagnostics = require("./features/provideDiagnostics");
|
|
16
|
-
const workspaceDiagnostics = require("./features/provideWorkspaceDiagnostics");
|
|
17
18
|
const documentColors = require("./features/provideDocumentColors");
|
|
18
19
|
const documentDrop = require("./features/provideDocumentDropEdits");
|
|
19
20
|
const format = require("./features/provideDocumentFormattingEdits");
|
|
@@ -32,6 +33,7 @@ const rename = require("./features/provideRenameEdits");
|
|
|
32
33
|
const renamePrepare = require("./features/provideRenameRange");
|
|
33
34
|
const selectionRanges = require("./features/provideSelectionRanges");
|
|
34
35
|
const signatureHelp = require("./features/provideSignatureHelp");
|
|
36
|
+
const workspaceDiagnostics = require("./features/provideWorkspaceDiagnostics");
|
|
35
37
|
const workspaceSymbol = require("./features/provideWorkspaceSymbols");
|
|
36
38
|
const codeActionResolve = require("./features/resolveCodeAction");
|
|
37
39
|
const codeLensResolve = require("./features/resolveCodeLens");
|
|
@@ -39,12 +41,10 @@ const completionResolve = require("./features/resolveCompletionItem");
|
|
|
39
41
|
const documentLinkResolve = require("./features/resolveDocumentLink");
|
|
40
42
|
const inlayHintResolve = require("./features/resolveInlayHint");
|
|
41
43
|
const uriMap_1 = require("./utils/uriMap");
|
|
44
|
+
exports.embeddedContentScheme = 'volar-embedded-content';
|
|
42
45
|
function createLanguageService(language, plugins, env) {
|
|
43
46
|
const documentVersions = (0, uriMap_1.createUriMap)();
|
|
44
|
-
const map2DocMap = new WeakMap();
|
|
45
|
-
const mirrorMap2DocMirrorMap = new WeakMap();
|
|
46
47
|
const snapshot2Doc = new WeakMap();
|
|
47
|
-
const embeddedContentScheme = 'volar-embedded-content';
|
|
48
48
|
const context = {
|
|
49
49
|
language,
|
|
50
50
|
getLanguageService: () => langaugeService,
|
|
@@ -61,33 +61,6 @@ function createLanguageService(language, plugins, env) {
|
|
|
61
61
|
}
|
|
62
62
|
return map.get(uri);
|
|
63
63
|
},
|
|
64
|
-
getMap(virtualCode, sourceScript) {
|
|
65
|
-
const map = context.language.maps.get(virtualCode, sourceScript);
|
|
66
|
-
if (!map2DocMap.has(map)) {
|
|
67
|
-
const embeddedUri = context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
|
|
68
|
-
map2DocMap.set(map, new documents_1.SourceMapWithDocuments(this.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
|
|
69
|
-
}
|
|
70
|
-
return map2DocMap.get(map);
|
|
71
|
-
},
|
|
72
|
-
*getMaps(virtualCode) {
|
|
73
|
-
for (const [uri, snapshot, map] of context.language.maps.forEach(virtualCode)) {
|
|
74
|
-
if (!map2DocMap.has(map)) {
|
|
75
|
-
const embeddedUri = context.encodeEmbeddedDocumentUri(uri, virtualCode.id);
|
|
76
|
-
map2DocMap.set(map, new documents_1.SourceMapWithDocuments(this.get(uri, context.language.scripts.get(uri).languageId, snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
|
|
77
|
-
}
|
|
78
|
-
yield map2DocMap.get(map);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
getLinkedCodeMap(virtualCode, documentUri) {
|
|
82
|
-
const map = context.language.linkedCodeMaps.get(virtualCode);
|
|
83
|
-
if (map) {
|
|
84
|
-
if (!mirrorMap2DocMirrorMap.has(map)) {
|
|
85
|
-
const embeddedUri = context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id);
|
|
86
|
-
mirrorMap2DocMirrorMap.set(map, new documents_1.LinkedCodeMapWithDocument(this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
|
|
87
|
-
}
|
|
88
|
-
return mirrorMap2DocMirrorMap.get(map);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
64
|
},
|
|
92
65
|
env,
|
|
93
66
|
inject: (key, ...args) => {
|
|
@@ -156,23 +129,8 @@ function createLanguageService(language, plugins, env) {
|
|
|
156
129
|
},
|
|
157
130
|
disabledEmbeddedDocumentUris: (0, uriMap_1.createUriMap)(),
|
|
158
131
|
disabledServicePlugins: new WeakSet(),
|
|
159
|
-
decodeEmbeddedDocumentUri
|
|
160
|
-
|
|
161
|
-
const embeddedCodeId = decodeURIComponent(maybeEmbeddedContentUri.authority);
|
|
162
|
-
const documentUri = decodeURIComponent(maybeEmbeddedContentUri.path.substring(1));
|
|
163
|
-
return [
|
|
164
|
-
vscode_uri_1.URI.parse(documentUri),
|
|
165
|
-
embeddedCodeId,
|
|
166
|
-
];
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
encodeEmbeddedDocumentUri(documentUri, embeddedContentId) {
|
|
170
|
-
return vscode_uri_1.URI.from({
|
|
171
|
-
scheme: embeddedContentScheme,
|
|
172
|
-
authority: encodeURIComponent(embeddedContentId),
|
|
173
|
-
path: '/' + encodeURIComponent(documentUri.toString()),
|
|
174
|
-
});
|
|
175
|
-
},
|
|
132
|
+
decodeEmbeddedDocumentUri,
|
|
133
|
+
encodeEmbeddedDocumentUri,
|
|
176
134
|
};
|
|
177
135
|
for (const plugin of plugins) {
|
|
178
136
|
context.plugins.push([plugin, plugin.create(context)]);
|
|
@@ -180,7 +138,23 @@ function createLanguageService(language, plugins, env) {
|
|
|
180
138
|
const langaugeService = createLanguageServiceBase(plugins, context);
|
|
181
139
|
return langaugeService;
|
|
182
140
|
}
|
|
183
|
-
|
|
141
|
+
function decodeEmbeddedDocumentUri(maybeEmbeddedContentUri) {
|
|
142
|
+
if (maybeEmbeddedContentUri.scheme === exports.embeddedContentScheme) {
|
|
143
|
+
const embeddedCodeId = decodeURIComponent(maybeEmbeddedContentUri.authority);
|
|
144
|
+
const documentUri = decodeURIComponent(maybeEmbeddedContentUri.path.substring(1));
|
|
145
|
+
return [
|
|
146
|
+
vscode_uri_1.URI.parse(documentUri),
|
|
147
|
+
embeddedCodeId,
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function encodeEmbeddedDocumentUri(documentUri, embeddedContentId) {
|
|
152
|
+
return vscode_uri_1.URI.from({
|
|
153
|
+
scheme: exports.embeddedContentScheme,
|
|
154
|
+
authority: encodeURIComponent(embeddedContentId),
|
|
155
|
+
path: '/' + encodeURIComponent(documentUri.toString()),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
184
158
|
function createLanguageServiceBase(plugins, context) {
|
|
185
159
|
return {
|
|
186
160
|
getSemanticTokenLegend: () => {
|
package/lib/types.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Language, SourceScript, VirtualCode } from '@volar/language-core';
|
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import type * as ts from 'typescript';
|
|
5
|
-
import type { LinkedCodeMapWithDocument, SourceMapWithDocuments } from './documents';
|
|
6
5
|
import type { LanguageService } from './languageService';
|
|
7
6
|
import type { URI } from 'vscode-uri';
|
|
8
7
|
import type { UriMap } from './utils/uriMap';
|
|
@@ -50,9 +49,6 @@ export interface LanguageServiceContext {
|
|
|
50
49
|
};
|
|
51
50
|
documents: {
|
|
52
51
|
get(uri: URI, languageId: string, snapshot: ts.IScriptSnapshot): TextDocument;
|
|
53
|
-
getMap(virtualCode: VirtualCode, sourceScript: SourceScript<URI>): SourceMapWithDocuments;
|
|
54
|
-
getMaps(virtualCode: VirtualCode): Generator<SourceMapWithDocuments>;
|
|
55
|
-
getLinkedCodeMap(virtualCode: VirtualCode, documentUri: URI): LinkedCodeMapWithDocument | undefined;
|
|
56
52
|
};
|
|
57
53
|
plugins: [LanguageServicePlugin, LanguageServicePluginInstance][];
|
|
58
54
|
disabledEmbeddedDocumentUris: UriMap<boolean>;
|
package/lib/utils/common.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { CodeInformation, Mapper } from '@volar/language-core';
|
|
1
2
|
import type * as ts from 'typescript';
|
|
2
3
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
|
|
4
|
-
export declare function findOverlapCodeRange(start: number, end: number, map: SourceMap<CodeInformation>, filter: (data: CodeInformation) => boolean): {
|
|
4
|
+
export declare function findOverlapCodeRange(start: number, end: number, map: Mapper, filter: (data: CodeInformation) => boolean): {
|
|
5
5
|
start: number;
|
|
6
6
|
end: number;
|
|
7
7
|
} | undefined;
|
|
@@ -9,4 +9,3 @@ export declare function isInsideRange(parent: vscode.Range, child: vscode.Range)
|
|
|
9
9
|
export declare function isEqualRange(a: vscode.Range, b: vscode.Range): boolean;
|
|
10
10
|
export declare function stringToSnapshot(str: string): ts.IScriptSnapshot;
|
|
11
11
|
export declare function sleep(ms: number): Promise<unknown>;
|
|
12
|
-
export declare function notEmpty<T>(value: T | null | undefined): value is T;
|
package/lib/utils/common.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.findOverlapCodeRange = findOverlapCodeRange;
|
|
4
|
+
exports.isInsideRange = isInsideRange;
|
|
5
|
+
exports.isEqualRange = isEqualRange;
|
|
6
|
+
exports.stringToSnapshot = stringToSnapshot;
|
|
7
|
+
exports.sleep = sleep;
|
|
4
8
|
function findOverlapCodeRange(start, end, map, filter) {
|
|
5
9
|
let mappedStart;
|
|
6
10
|
let mappedEnd;
|
|
7
|
-
for (const [mapped, mapping] of map.
|
|
11
|
+
for (const [mapped, mapping] of map.toGeneratedLocation(start)) {
|
|
8
12
|
if (filter(mapping.data)) {
|
|
9
13
|
mappedStart = mapped;
|
|
10
14
|
break;
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
|
-
for (const [mapped, mapping] of map.
|
|
17
|
+
for (const [mapped, mapping] of map.toGeneratedLocation(end)) {
|
|
14
18
|
if (filter(mapping.data)) {
|
|
15
19
|
mappedEnd = mapped;
|
|
16
20
|
break;
|
|
@@ -40,7 +44,6 @@ function findOverlapCodeRange(start, end, map, filter) {
|
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
exports.findOverlapCodeRange = findOverlapCodeRange;
|
|
44
47
|
function getOverlapRange(range1Start, range1End, range2Start, range2End) {
|
|
45
48
|
const start = Math.max(range1Start, range2Start);
|
|
46
49
|
const end = Math.min(range1End, range2End);
|
|
@@ -67,14 +70,12 @@ function isInsideRange(parent, child) {
|
|
|
67
70
|
}
|
|
68
71
|
return true;
|
|
69
72
|
}
|
|
70
|
-
exports.isInsideRange = isInsideRange;
|
|
71
73
|
function isEqualRange(a, b) {
|
|
72
74
|
return a.start.line === b.start.line
|
|
73
75
|
&& a.start.character === b.start.character
|
|
74
76
|
&& a.end.line === b.end.line
|
|
75
77
|
&& a.end.character === b.end.character;
|
|
76
78
|
}
|
|
77
|
-
exports.isEqualRange = isEqualRange;
|
|
78
79
|
function stringToSnapshot(str) {
|
|
79
80
|
return {
|
|
80
81
|
getText: (start, end) => str.substring(start, end),
|
|
@@ -82,13 +83,7 @@ function stringToSnapshot(str) {
|
|
|
82
83
|
getChangeRange: () => undefined,
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
|
-
exports.stringToSnapshot = stringToSnapshot;
|
|
86
86
|
function sleep(ms) {
|
|
87
87
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
88
88
|
}
|
|
89
|
-
exports.sleep = sleep;
|
|
90
|
-
function notEmpty(value) {
|
|
91
|
-
return value !== null && value !== undefined;
|
|
92
|
-
}
|
|
93
|
-
exports.notEmpty = notEmpty;
|
|
94
89
|
//# sourceMappingURL=common.js.map
|
package/lib/utils/dedupe.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createLocationSet = createLocationSet;
|
|
4
|
+
exports.withCodeAction = withCodeAction;
|
|
5
|
+
exports.withTextEdits = withTextEdits;
|
|
6
|
+
exports.withDocumentChanges = withDocumentChanges;
|
|
7
|
+
exports.withDiagnostics = withDiagnostics;
|
|
8
|
+
exports.withLocations = withLocations;
|
|
9
|
+
exports.withLocationLinks = withLocationLinks;
|
|
10
|
+
exports.withCallHierarchyIncomingCalls = withCallHierarchyIncomingCalls;
|
|
11
|
+
exports.withCallHierarchyOutgoingCalls = withCallHierarchyOutgoingCalls;
|
|
12
|
+
exports.withRanges = withRanges;
|
|
4
13
|
function createLocationSet() {
|
|
5
14
|
const set = new Set();
|
|
6
15
|
return {
|
|
@@ -27,13 +36,11 @@ function createLocationSet() {
|
|
|
27
36
|
].join(':');
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
|
-
exports.createLocationSet = createLocationSet;
|
|
31
39
|
function withCodeAction(items) {
|
|
32
40
|
return dedupe(items, item => [
|
|
33
41
|
item.title
|
|
34
42
|
].join(':'));
|
|
35
43
|
}
|
|
36
|
-
exports.withCodeAction = withCodeAction;
|
|
37
44
|
function withTextEdits(items) {
|
|
38
45
|
return dedupe(items, item => [
|
|
39
46
|
item.range.start.line,
|
|
@@ -43,11 +50,9 @@ function withTextEdits(items) {
|
|
|
43
50
|
item.newText,
|
|
44
51
|
].join(':'));
|
|
45
52
|
}
|
|
46
|
-
exports.withTextEdits = withTextEdits;
|
|
47
53
|
function withDocumentChanges(items) {
|
|
48
54
|
return dedupe(items, item => JSON.stringify(item)); // TODO: improve this
|
|
49
55
|
}
|
|
50
|
-
exports.withDocumentChanges = withDocumentChanges;
|
|
51
56
|
function withDiagnostics(items) {
|
|
52
57
|
return dedupe(items, item => [
|
|
53
58
|
item.range.start.line,
|
|
@@ -60,7 +65,6 @@ function withDiagnostics(items) {
|
|
|
60
65
|
item.message,
|
|
61
66
|
].join(':'));
|
|
62
67
|
}
|
|
63
|
-
exports.withDiagnostics = withDiagnostics;
|
|
64
68
|
function withLocations(items) {
|
|
65
69
|
return dedupe(items, item => [
|
|
66
70
|
item.uri,
|
|
@@ -70,7 +74,6 @@ function withLocations(items) {
|
|
|
70
74
|
item.range.end.character,
|
|
71
75
|
].join(':'));
|
|
72
76
|
}
|
|
73
|
-
exports.withLocations = withLocations;
|
|
74
77
|
function withLocationLinks(items) {
|
|
75
78
|
return dedupe(items, item => [
|
|
76
79
|
item.targetUri,
|
|
@@ -81,7 +84,6 @@ function withLocationLinks(items) {
|
|
|
81
84
|
// ignore difference targetRange
|
|
82
85
|
].join(':'));
|
|
83
86
|
}
|
|
84
|
-
exports.withLocationLinks = withLocationLinks;
|
|
85
87
|
function withCallHierarchyIncomingCalls(items) {
|
|
86
88
|
return dedupe(items, item => [
|
|
87
89
|
item.from.uri,
|
|
@@ -91,7 +93,6 @@ function withCallHierarchyIncomingCalls(items) {
|
|
|
91
93
|
item.from.range.end.character,
|
|
92
94
|
].join(':'));
|
|
93
95
|
}
|
|
94
|
-
exports.withCallHierarchyIncomingCalls = withCallHierarchyIncomingCalls;
|
|
95
96
|
function withCallHierarchyOutgoingCalls(items) {
|
|
96
97
|
return dedupe(items, item => [
|
|
97
98
|
item.to.uri,
|
|
@@ -101,7 +102,6 @@ function withCallHierarchyOutgoingCalls(items) {
|
|
|
101
102
|
item.to.range.end.character,
|
|
102
103
|
].join(':'));
|
|
103
104
|
}
|
|
104
|
-
exports.withCallHierarchyOutgoingCalls = withCallHierarchyOutgoingCalls;
|
|
105
105
|
function withRanges(items) {
|
|
106
106
|
return dedupe(items, item => [
|
|
107
107
|
item.start.line,
|
|
@@ -110,7 +110,6 @@ function withRanges(items) {
|
|
|
110
110
|
item.end.character,
|
|
111
111
|
].join(':'));
|
|
112
112
|
}
|
|
113
|
-
exports.withRanges = withRanges;
|
|
114
113
|
function dedupe(items, getKey) {
|
|
115
114
|
const map = new Map();
|
|
116
115
|
for (const item of items.reverse()) {
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import type { VirtualCode } from '@volar/language-core';
|
|
1
|
+
import type { CodeInformation, LinkedCodeMap, Mapper, SourceScript, VirtualCode } from '@volar/language-core';
|
|
2
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
4
|
import type { URI } from 'vscode-uri';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import type { LanguageServiceContext, LanguageServicePlugin, LanguageServicePluginInstance } from '../types';
|
|
6
|
+
export type DocumentsAndMap = [
|
|
7
|
+
sourceDocument: TextDocument,
|
|
8
|
+
embeddedDocument: TextDocument,
|
|
9
|
+
map: Mapper
|
|
10
|
+
];
|
|
11
|
+
export declare function documentFeatureWorker<T>(context: LanguageServiceContext, uri: URI, valid: (info: DocumentsAndMap) => boolean, worker: (plugin: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: DocumentsAndMap) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
12
|
+
export declare function languageFeatureWorker<T, K>(context: LanguageServiceContext, uri: URI, getRealDocParams: () => K, eachVirtualDocParams: (map: DocumentsAndMap) => Generator<K>, worker: (plugin: [LanguageServicePlugin, LanguageServicePluginInstance], document: TextDocument, params: K, map?: DocumentsAndMap) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: DocumentsAndMap) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
8
13
|
export declare function safeCall<T>(cb: () => Thenable<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
9
|
-
export declare function forEachEmbeddedDocument(context: LanguageServiceContext,
|
|
10
|
-
export declare function
|
|
14
|
+
export declare function forEachEmbeddedDocument(context: LanguageServiceContext, sourceScript: SourceScript<URI>, current: VirtualCode): Generator<DocumentsAndMap>;
|
|
15
|
+
export declare function getSourceRange(docs: DocumentsAndMap, range: vscode.Range, filter?: (data: CodeInformation) => boolean): {
|
|
16
|
+
start: import("vscode-languageserver-textdocument").Position;
|
|
17
|
+
end: import("vscode-languageserver-textdocument").Position;
|
|
18
|
+
} | undefined;
|
|
19
|
+
export declare function getGeneratedRange(docs: DocumentsAndMap, range: vscode.Range, filter?: (data: CodeInformation) => boolean): {
|
|
20
|
+
start: import("vscode-languageserver-textdocument").Position;
|
|
21
|
+
end: import("vscode-languageserver-textdocument").Position;
|
|
22
|
+
} | undefined;
|
|
23
|
+
export declare function getSourceRanges([sourceDocument, embeddedDocument, map]: DocumentsAndMap, range: vscode.Range, filter?: (data: CodeInformation) => boolean): Generator<{
|
|
24
|
+
start: import("vscode-languageserver-textdocument").Position;
|
|
25
|
+
end: import("vscode-languageserver-textdocument").Position;
|
|
26
|
+
}, void, unknown>;
|
|
27
|
+
export declare function getGeneratedRanges([sourceDocument, embeddedDocument, map]: DocumentsAndMap, range: vscode.Range, filter?: (data: CodeInformation) => boolean): Generator<{
|
|
28
|
+
start: import("vscode-languageserver-textdocument").Position;
|
|
29
|
+
end: import("vscode-languageserver-textdocument").Position;
|
|
30
|
+
}, void, unknown>;
|
|
31
|
+
export declare function getSourcePositions([sourceDocument, embeddedDocument, map]: DocumentsAndMap, position: vscode.Position, filter?: (data: CodeInformation) => boolean): Generator<import("vscode-languageserver-textdocument").Position, void, unknown>;
|
|
32
|
+
export declare function getGeneratedPositions([sourceDocument, embeddedDocument, map]: DocumentsAndMap, position: vscode.Position, filter?: (data: CodeInformation) => boolean): Generator<import("vscode-languageserver-textdocument").Position, void, unknown>;
|
|
33
|
+
export declare function getLinkedCodePositions(document: TextDocument, linkedMap: LinkedCodeMap, posotion: vscode.Position): Generator<import("vscode-languageserver-textdocument").Position, void, unknown>;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.documentFeatureWorker = documentFeatureWorker;
|
|
4
|
+
exports.languageFeatureWorker = languageFeatureWorker;
|
|
5
|
+
exports.safeCall = safeCall;
|
|
6
|
+
exports.forEachEmbeddedDocument = forEachEmbeddedDocument;
|
|
7
|
+
exports.getSourceRange = getSourceRange;
|
|
8
|
+
exports.getGeneratedRange = getGeneratedRange;
|
|
9
|
+
exports.getSourceRanges = getSourceRanges;
|
|
10
|
+
exports.getGeneratedRanges = getGeneratedRanges;
|
|
11
|
+
exports.getSourcePositions = getSourcePositions;
|
|
12
|
+
exports.getGeneratedPositions = getGeneratedPositions;
|
|
13
|
+
exports.getLinkedCodePositions = getLinkedCodePositions;
|
|
4
14
|
function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
|
|
5
15
|
return languageFeatureWorker(context, uri, () => void 0, function* (map) {
|
|
6
16
|
if (valid(map)) {
|
|
@@ -8,40 +18,36 @@ function documentFeatureWorker(context, uri, valid, worker, transformResult, com
|
|
|
8
18
|
}
|
|
9
19
|
}, worker, transformResult, combineResult);
|
|
10
20
|
}
|
|
11
|
-
exports.documentFeatureWorker = documentFeatureWorker;
|
|
12
21
|
async function languageFeatureWorker(context, uri, getRealDocParams, eachVirtualDocParams, worker, transformResult, combineResult) {
|
|
13
|
-
|
|
22
|
+
let sourceScript;
|
|
23
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
24
|
+
if (decoded) {
|
|
25
|
+
sourceScript = context.language.scripts.get(decoded[0]);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
sourceScript = context.language.scripts.get(uri);
|
|
29
|
+
}
|
|
14
30
|
if (!sourceScript) {
|
|
15
31
|
return;
|
|
16
32
|
}
|
|
17
33
|
let results = [];
|
|
18
|
-
if (
|
|
19
|
-
|
|
34
|
+
if (decoded) {
|
|
35
|
+
const virtualCode = sourceScript.generated?.embeddedCodes.get(decoded[1]);
|
|
36
|
+
if (virtualCode) {
|
|
37
|
+
const docs = [
|
|
38
|
+
context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot),
|
|
39
|
+
context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot),
|
|
40
|
+
context.language.maps.get(virtualCode, sourceScript),
|
|
41
|
+
];
|
|
42
|
+
await docsWorker(docs, false);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (sourceScript.generated) {
|
|
46
|
+
for (const docs of forEachEmbeddedDocument(context, sourceScript, sourceScript.generated.root)) {
|
|
20
47
|
if (results.length && !combineResult) {
|
|
21
48
|
continue;
|
|
22
49
|
}
|
|
23
|
-
|
|
24
|
-
if (results.length && !combineResult) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
for (const [pluginIndex, plugin] of Object.entries(context.plugins)) {
|
|
28
|
-
if (context.disabledServicePlugins.has(plugin[1])) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (results.length && !combineResult) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const rawResult = await safeCall(() => worker(plugin, map.embeddedDocument, mappedArg, map), `Language service plugin "${plugin[0].name}" (${pluginIndex}) failed to provide document feature for ${map.embeddedDocument.uri}.`);
|
|
35
|
-
if (!rawResult) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const mappedResult = transformResult(rawResult, map);
|
|
39
|
-
if (!mappedResult) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
results.push(mappedResult);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
50
|
+
await docsWorker(docs, true);
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
else {
|
|
@@ -72,8 +78,35 @@ async function languageFeatureWorker(context, uri, getRealDocParams, eachVirtual
|
|
|
72
78
|
else if (results.length > 0) {
|
|
73
79
|
return results[0];
|
|
74
80
|
}
|
|
81
|
+
async function docsWorker(docs, transform) {
|
|
82
|
+
for (const mappedArg of eachVirtualDocParams(docs)) {
|
|
83
|
+
if (results.length && !combineResult) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const [pluginIndex, plugin] of Object.entries(context.plugins)) {
|
|
87
|
+
if (context.disabledServicePlugins.has(plugin[1])) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (results.length && !combineResult) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const embeddedResult = await safeCall(() => worker(plugin, docs[1], mappedArg, docs), `Language service plugin "${plugin[0].name}" (${pluginIndex}) failed to provide document feature for ${docs[1].uri}.`);
|
|
94
|
+
if (!embeddedResult) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (transform) {
|
|
98
|
+
const mappedResult = transformResult(embeddedResult, docs);
|
|
99
|
+
if (mappedResult) {
|
|
100
|
+
results.push(mappedResult);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
results.push(embeddedResult);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
75
109
|
}
|
|
76
|
-
exports.languageFeatureWorker = languageFeatureWorker;
|
|
77
110
|
async function safeCall(cb, errorMsg) {
|
|
78
111
|
try {
|
|
79
112
|
return await cb();
|
|
@@ -82,39 +115,54 @@ async function safeCall(cb, errorMsg) {
|
|
|
82
115
|
console.warn(errorMsg, err);
|
|
83
116
|
}
|
|
84
117
|
}
|
|
85
|
-
|
|
86
|
-
function* forEachEmbeddedDocument(context, sourceScriptId, current) {
|
|
118
|
+
function* forEachEmbeddedDocument(context, sourceScript, current) {
|
|
87
119
|
if (current.embeddedCodes) {
|
|
88
120
|
for (const embeddedCode of current.embeddedCodes) {
|
|
89
|
-
yield* forEachEmbeddedDocument(context,
|
|
121
|
+
yield* forEachEmbeddedDocument(context, sourceScript, embeddedCode);
|
|
90
122
|
}
|
|
91
123
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
124
|
+
const embeddedDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, current.id);
|
|
125
|
+
if (!context.disabledEmbeddedDocumentUris.get(embeddedDocumentUri)) {
|
|
126
|
+
yield [
|
|
127
|
+
context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot),
|
|
128
|
+
context.documents.get(embeddedDocumentUri, current.languageId, current.snapshot),
|
|
129
|
+
context.language.maps.get(current, sourceScript),
|
|
130
|
+
];
|
|
97
131
|
}
|
|
98
132
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
function getSourceRange(docs, range, filter) {
|
|
134
|
+
for (const result of getSourceRanges(docs, range, filter)) {
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function getGeneratedRange(docs, range, filter) {
|
|
139
|
+
for (const result of getGeneratedRanges(docs, range, filter)) {
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function* getSourceRanges([sourceDocument, embeddedDocument, map], range, filter) {
|
|
144
|
+
for (const [mappedStart, mappedEnd] of map.toSourceRange(embeddedDocument.offsetAt(range.start), embeddedDocument.offsetAt(range.end), true, filter)) {
|
|
145
|
+
yield { start: sourceDocument.positionAt(mappedStart), end: sourceDocument.positionAt(mappedEnd) };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function* getGeneratedRanges([sourceDocument, embeddedDocument, map], range, filter) {
|
|
149
|
+
for (const [mappedStart, mappedEnd] of map.toGeneratedRange(sourceDocument.offsetAt(range.start), sourceDocument.offsetAt(range.end), true, filter)) {
|
|
150
|
+
yield { start: embeddedDocument.positionAt(mappedStart), end: embeddedDocument.positionAt(mappedEnd) };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function* getSourcePositions([sourceDocument, embeddedDocument, map], position, filter = () => true) {
|
|
154
|
+
for (const mapped of map.toSourceLocation(embeddedDocument.offsetAt(position), filter)) {
|
|
155
|
+
yield sourceDocument.positionAt(mapped[0]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function* getGeneratedPositions([sourceDocument, embeddedDocument, map], position, filter = () => true) {
|
|
159
|
+
for (const mapped of map.toGeneratedLocation(sourceDocument.offsetAt(position), filter)) {
|
|
160
|
+
yield embeddedDocument.positionAt(mapped[0]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function* getLinkedCodePositions(document, linkedMap, posotion) {
|
|
164
|
+
for (const linkedPosition of linkedMap.getLinkedOffsets(document.offsetAt(posotion))) {
|
|
165
|
+
yield document.positionAt(linkedPosition);
|
|
117
166
|
}
|
|
118
167
|
}
|
|
119
|
-
exports.getEmbeddedFilesByLevel = getEmbeddedFilesByLevel;
|
|
120
168
|
//# sourceMappingURL=featureWorkers.js.map
|
package/lib/utils/transform.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import { URI } from 'vscode-uri';
|
|
3
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import { URI } from 'vscode-uri';
|
|
4
4
|
import type { LanguageServiceContext } from '../types';
|
|
5
5
|
export declare function transformDocumentLinkTarget(_target: string, context: LanguageServiceContext): URI;
|
|
6
6
|
export declare function transformMarkdown(content: string, context: LanguageServiceContext): string;
|