@volar/language-service 2.0.0-alpha.0 → 2.0.0-alpha.10
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/documents.d.ts +3 -2
- package/lib/documents.js +5 -5
- package/lib/features/provideCallHierarchyItems.js +3 -3
- package/lib/features/provideCodeActions.js +1 -1
- package/lib/features/provideCompletionItems.js +9 -5
- package/lib/features/provideDefinition.js +2 -2
- package/lib/features/provideDiagnostics.d.ts +1 -2
- package/lib/features/provideDiagnostics.js +14 -17
- package/lib/features/provideDocumentFormattingEdits.js +22 -30
- package/lib/features/provideDocumentHighlights.js +1 -1
- package/lib/features/provideDocumentSemanticTokens.js +1 -1
- package/lib/features/provideFileReferences.js +1 -1
- package/lib/features/provideFileRenameEdits.js +6 -3
- package/lib/features/provideInlayHints.js +1 -1
- package/lib/features/provideReferences.d.ts +1 -1
- package/lib/features/provideReferences.js +4 -4
- package/lib/features/provideRenameEdits.js +1 -1
- package/lib/features/provideWorkspaceSymbols.js +4 -1
- package/lib/features/resolveCodeLens.js +1 -14
- package/lib/features/resolveCompletionItem.js +1 -1
- package/lib/features/resolveDocumentLink.js +1 -1
- package/lib/languageService.d.ts +2 -2
- package/lib/languageService.js +6 -1
- package/lib/types.d.ts +7 -2
- package/lib/utils/dedupe.d.ts +1 -1
- package/lib/utils/featureWorkers.d.ts +1 -0
- package/lib/utils/featureWorkers.js +26 -7
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.js +6 -6
- package/package.json +3 -3
package/lib/documents.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CodeInformation, CodeRangeKey, FileProvider, LinkedCodeMap, Mapping, SourceFile, SourceMap, VirtualFile } from '@volar/language-core';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
4
4
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import type { RuntimeEnvironment } from '../lib/types';
|
|
5
6
|
export type DocumentProvider = ReturnType<typeof createDocumentProvider>;
|
|
6
7
|
export declare class SourceMapWithDocuments<Data = any> {
|
|
7
8
|
sourceFileDocument: TextDocument;
|
|
@@ -29,7 +30,7 @@ export declare class LinkedCodeMapWithDocument extends SourceMapWithDocuments {
|
|
|
29
30
|
constructor(document: TextDocument, linkedMap: LinkedCodeMap);
|
|
30
31
|
getLinkedCodePositions(posotion: vscode.Position): Generator<import("vscode-languageserver-textdocument").Position, void, unknown>;
|
|
31
32
|
}
|
|
32
|
-
export declare function createDocumentProvider(files: FileProvider): {
|
|
33
|
+
export declare function createDocumentProvider(env: RuntimeEnvironment, files: FileProvider): {
|
|
33
34
|
get: (uri: string, languageId: string, snapshot: ts.IScriptSnapshot) => TextDocument;
|
|
34
35
|
getSourceFileMaps(source: SourceFile): [VirtualFile, SourceMapWithDocuments<CodeInformation>][] | undefined;
|
|
35
36
|
getMaps(virtualFile: VirtualFile): Generator<SourceMapWithDocuments<CodeInformation>, void, unknown>;
|
package/lib/documents.js
CHANGED
|
@@ -113,7 +113,7 @@ class LinkedCodeMapWithDocument extends SourceMapWithDocuments {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
exports.LinkedCodeMapWithDocument = LinkedCodeMapWithDocument;
|
|
116
|
-
function createDocumentProvider(files) {
|
|
116
|
+
function createDocumentProvider(env, files) {
|
|
117
117
|
let version = 0;
|
|
118
118
|
const map2DocMap = new WeakMap();
|
|
119
119
|
const mirrorMap2DocMirrorMap = new WeakMap();
|
|
@@ -127,7 +127,7 @@ function createDocumentProvider(files) {
|
|
|
127
127
|
for (const [sourceUri, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
|
|
128
128
|
if (sourceSnapshot === source.snapshot) {
|
|
129
129
|
if (!map2DocMap.has(map)) {
|
|
130
|
-
map2DocMap.set(map, new SourceMapWithDocuments(get(sourceUri, source.languageId, sourceSnapshot), get(virtualFile.
|
|
130
|
+
map2DocMap.set(map, new SourceMapWithDocuments(get(sourceUri, source.languageId, sourceSnapshot), get(env.fileNameToUri(virtualFile.fileName), virtualFile.languageId, virtualFile.snapshot), map));
|
|
131
131
|
}
|
|
132
132
|
result.push([virtualFile, map2DocMap.get(map)]);
|
|
133
133
|
}
|
|
@@ -137,9 +137,9 @@ function createDocumentProvider(files) {
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
*getMaps(virtualFile) {
|
|
140
|
-
for (const [
|
|
140
|
+
for (const [sourceFileName, [sourceSnapshot, map]] of files.getMaps(virtualFile)) {
|
|
141
141
|
if (!map2DocMap.has(map)) {
|
|
142
|
-
map2DocMap.set(map, new SourceMapWithDocuments(get(
|
|
142
|
+
map2DocMap.set(map, new SourceMapWithDocuments(get(env.fileNameToUri(sourceFileName), files.getSourceFile(sourceFileName).languageId, sourceSnapshot), get(env.fileNameToUri(virtualFile.fileName), virtualFile.languageId, virtualFile.snapshot), map));
|
|
143
143
|
}
|
|
144
144
|
yield map2DocMap.get(map);
|
|
145
145
|
}
|
|
@@ -148,7 +148,7 @@ function createDocumentProvider(files) {
|
|
|
148
148
|
const map = files.getLinkedCodeMap(virtualFile);
|
|
149
149
|
if (map) {
|
|
150
150
|
if (!mirrorMap2DocMirrorMap.has(map)) {
|
|
151
|
-
mirrorMap2DocMirrorMap.set(map, new LinkedCodeMapWithDocument(get(virtualFile.
|
|
151
|
+
mirrorMap2DocMirrorMap.set(map, new LinkedCodeMapWithDocument(get(env.fileNameToUri(virtualFile.fileName), virtualFile.languageId, virtualFile.snapshot), map));
|
|
152
152
|
}
|
|
153
153
|
return mirrorMap2DocMirrorMap.get(map);
|
|
154
154
|
}
|
|
@@ -43,7 +43,7 @@ function register(context) {
|
|
|
43
43
|
return incomingItems;
|
|
44
44
|
Object.assign(item, data.original);
|
|
45
45
|
if (data.virtualDocumentUri) {
|
|
46
|
-
const [virtualFile] = context.language.files.getVirtualFile(data.virtualDocumentUri);
|
|
46
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(data.virtualDocumentUri));
|
|
47
47
|
if (virtualFile) {
|
|
48
48
|
const _calls = await service[1].provideCallHierarchyIncomingCalls(item, token);
|
|
49
49
|
for (const _call of _calls) {
|
|
@@ -81,7 +81,7 @@ function register(context) {
|
|
|
81
81
|
return items;
|
|
82
82
|
Object.assign(item, data.original);
|
|
83
83
|
if (data.virtualDocumentUri) {
|
|
84
|
-
const [virtualFile] = context.language.files.getVirtualFile(data.virtualDocumentUri);
|
|
84
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(data.virtualDocumentUri));
|
|
85
85
|
if (virtualFile) {
|
|
86
86
|
const _calls = await service[1].provideCallHierarchyOutgoingCalls(item, token);
|
|
87
87
|
for (const call of _calls) {
|
|
@@ -112,7 +112,7 @@ function register(context) {
|
|
|
112
112
|
},
|
|
113
113
|
};
|
|
114
114
|
function transformCallHierarchyItem(tsItem, tsRanges) {
|
|
115
|
-
const [virtualFile] = context.language.files.getVirtualFile(tsItem.uri);
|
|
115
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(tsItem.uri));
|
|
116
116
|
if (!virtualFile)
|
|
117
117
|
return [tsItem, tsRanges];
|
|
118
118
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
@@ -9,7 +9,7 @@ const transform_1 = require("../utils/transform");
|
|
|
9
9
|
const language_core_1 = require("@volar/language-core");
|
|
10
10
|
function register(context) {
|
|
11
11
|
return async (uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
12
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
13
13
|
if (!sourceFile)
|
|
14
14
|
return;
|
|
15
15
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
@@ -8,14 +8,14 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
8
8
|
function register(context) {
|
|
9
9
|
let cache;
|
|
10
10
|
return async (uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
|
|
11
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
11
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
12
12
|
if (completionContext?.triggerKind === 3
|
|
13
13
|
&& cache?.uri === uri) {
|
|
14
14
|
for (const cacheData of cache.data) {
|
|
15
15
|
if (!cacheData.list.isIncomplete)
|
|
16
16
|
continue;
|
|
17
17
|
if (cacheData.virtualDocumentUri) {
|
|
18
|
-
const [virtualFile] = context.language.files.getVirtualFile(cacheData.virtualDocumentUri);
|
|
18
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(cacheData.virtualDocumentUri));
|
|
19
19
|
if (!virtualFile)
|
|
20
20
|
continue;
|
|
21
21
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
@@ -65,7 +65,7 @@ function register(context) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
const rootVirtualFile = context.language.files.getSourceFile(uri)?.virtualFile?.[0];
|
|
68
|
+
const rootVirtualFile = context.language.files.getSourceFile(context.env.uriToFileName(uri))?.virtualFile?.[0];
|
|
69
69
|
cache = {
|
|
70
70
|
uri,
|
|
71
71
|
data: [],
|
|
@@ -75,7 +75,9 @@ function register(context) {
|
|
|
75
75
|
let isFirstMapping = true;
|
|
76
76
|
if (rootVirtualFile) {
|
|
77
77
|
await (0, featureWorkers_1.visitEmbedded)(context, rootVirtualFile, async (_, map) => {
|
|
78
|
-
const services = [...context.services]
|
|
78
|
+
const services = [...context.services]
|
|
79
|
+
.filter(service => !context.disabledServicePlugins.has(service[1]))
|
|
80
|
+
.sort((a, b) => sortServices(a[1], b[1]));
|
|
79
81
|
let _data;
|
|
80
82
|
for (const mapped of map.getGeneratedPositions(position, data => {
|
|
81
83
|
_data = data;
|
|
@@ -129,7 +131,9 @@ function register(context) {
|
|
|
129
131
|
}
|
|
130
132
|
if (sourceFile) {
|
|
131
133
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
132
|
-
const services = [...context.services]
|
|
134
|
+
const services = [...context.services]
|
|
135
|
+
.filter(service => !context.disabledServicePlugins.has(service[1]))
|
|
136
|
+
.sort((a, b) => sortServices(a[1], b[1]));
|
|
133
137
|
for (const service of services) {
|
|
134
138
|
if (token.isCancellationRequested)
|
|
135
139
|
break;
|
|
@@ -26,7 +26,7 @@ function register(context, apiName, isValidPosition) {
|
|
|
26
26
|
for (const definition of definitions) {
|
|
27
27
|
let foundMirrorPosition = false;
|
|
28
28
|
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
|
|
29
|
-
const [virtualFile] = context.language.files.getVirtualFile(definition.targetUri);
|
|
29
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(definition.targetUri));
|
|
30
30
|
const mirrorMap = virtualFile ? context.documents.getLinkedCodeMap(virtualFile) : undefined;
|
|
31
31
|
if (mirrorMap) {
|
|
32
32
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(definition.targetSelectionRange.start)) {
|
|
@@ -57,7 +57,7 @@ function register(context, apiName, isValidPosition) {
|
|
|
57
57
|
link.originSelectionRange = originSelectionRange;
|
|
58
58
|
}
|
|
59
59
|
let foundTargetSelectionRange = false;
|
|
60
|
-
const [targetVirtualFile] = context.language.files.getVirtualFile(link.targetUri);
|
|
60
|
+
const [targetVirtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(link.targetUri));
|
|
61
61
|
if (targetVirtualFile) {
|
|
62
62
|
for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
|
|
63
63
|
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
|
|
@@ -10,11 +10,10 @@ export interface ServiceDiagnosticData {
|
|
|
10
10
|
original: Pick<vscode.Diagnostic, 'data'>;
|
|
11
11
|
isFormat: boolean;
|
|
12
12
|
serviceIndex: number;
|
|
13
|
-
ruleFixIndex: number;
|
|
14
13
|
documentUri: string;
|
|
15
14
|
}
|
|
16
15
|
export declare const errorMarkups: Record<string, {
|
|
17
16
|
error: vscode.Diagnostic;
|
|
18
17
|
markup: vscode.MarkupContent;
|
|
19
18
|
}[]>;
|
|
20
|
-
export declare function register(context: ServiceContext): (uri: string,
|
|
19
|
+
export declare function register(context: ServiceContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -84,21 +84,20 @@ function register(context) {
|
|
|
84
84
|
const cacheMaps = {
|
|
85
85
|
semantic: new Map(),
|
|
86
86
|
syntactic: new Map(),
|
|
87
|
-
semantic_rules: new Map(),
|
|
88
|
-
syntax_rules: new Map(),
|
|
89
|
-
format_rules: new Map(),
|
|
90
87
|
};
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
context.env.onDidChangeConfiguration?.(() => {
|
|
89
|
+
lastResponses.clear();
|
|
90
|
+
cacheMaps.semantic.clear();
|
|
91
|
+
cacheMaps.syntactic.clear();
|
|
92
|
+
});
|
|
93
|
+
return async (uri, token = cancellation_1.NoneCancellationToken, response) => {
|
|
94
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
93
95
|
if (!sourceFile)
|
|
94
96
|
return [];
|
|
95
97
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
96
98
|
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, {
|
|
97
99
|
semantic: { errors: [] },
|
|
98
100
|
syntactic: { errors: [] },
|
|
99
|
-
semantic_rules: { errors: [] },
|
|
100
|
-
syntax_rules: { errors: [] },
|
|
101
|
-
format_rules: { errors: [] },
|
|
102
101
|
}).get(uri);
|
|
103
102
|
let updateCacheRangeFailed = false;
|
|
104
103
|
let errorsUpdated = false;
|
|
@@ -125,13 +124,9 @@ function register(context) {
|
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (mode === 'all' || mode === 'semantic') {
|
|
132
|
-
await doResponse();
|
|
133
|
-
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
|
|
134
|
-
}
|
|
127
|
+
await worker('provideDiagnostics', cacheMaps.syntactic, lastResponse.syntactic);
|
|
128
|
+
await doResponse();
|
|
129
|
+
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
|
|
135
130
|
return await collectErrors();
|
|
136
131
|
async function doResponse() {
|
|
137
132
|
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
@@ -144,6 +139,9 @@ function register(context) {
|
|
|
144
139
|
exports.errorMarkups[uri] = [];
|
|
145
140
|
for (const error of errors) {
|
|
146
141
|
for (const service of context.services) {
|
|
142
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
147
145
|
const markup = await service[1].provideDiagnosticMarkupContent?.(error, token);
|
|
148
146
|
if (markup) {
|
|
149
147
|
exports.errorMarkups[uri].push({ error, markup });
|
|
@@ -179,7 +177,6 @@ function register(context) {
|
|
|
179
177
|
original: {
|
|
180
178
|
data: error.data,
|
|
181
179
|
},
|
|
182
|
-
ruleFixIndex: 0,
|
|
183
180
|
documentUri: document.uri,
|
|
184
181
|
};
|
|
185
182
|
});
|
|
@@ -213,7 +210,7 @@ function register(context) {
|
|
|
213
210
|
if (_error.relatedInformation) {
|
|
214
211
|
const relatedInfos = [];
|
|
215
212
|
for (const info of _error.relatedInformation) {
|
|
216
|
-
const [virtualFile] = context.language.files.getVirtualFile(info.location.uri);
|
|
213
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(info.location.uri));
|
|
217
214
|
if (virtualFile) {
|
|
218
215
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
219
216
|
const range = map.getSourceRange(info.location.range, filter);
|
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.register = void 0;
|
|
4
4
|
const language_core_1 = require("@volar/language-core");
|
|
5
5
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const common_1 = require("../utils/common");
|
|
7
|
-
const cancellation_1 = require("../utils/cancellation");
|
|
8
6
|
const documents_1 = require("../documents");
|
|
7
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
8
|
+
const common_1 = require("../utils/common");
|
|
9
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
9
10
|
function register(context) {
|
|
10
11
|
let fakeVersion = 0;
|
|
11
12
|
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
13
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
13
14
|
if (!sourceFile)
|
|
14
15
|
return;
|
|
15
16
|
let document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
@@ -24,11 +25,11 @@ function register(context) {
|
|
|
24
25
|
}
|
|
25
26
|
const initialIndentLanguageId = await context.env.getConfiguration?.('volar.format.initialIndent') ?? { html: true };
|
|
26
27
|
let tempSourceSnapshot = sourceFile.snapshot;
|
|
27
|
-
const tempVirtualFile = sourceFile.virtualFile[1].createVirtualFile(sourceFile.
|
|
28
|
+
const tempVirtualFile = sourceFile.virtualFile[1].createVirtualFile(sourceFile.fileName, sourceFile.languageId, sourceFile.snapshot, context.language.files);
|
|
28
29
|
const originalDocument = document;
|
|
29
30
|
let level = 0;
|
|
30
31
|
while (true) {
|
|
31
|
-
const embeddedFiles = getEmbeddedFilesByLevel(tempVirtualFile, level++);
|
|
32
|
+
const embeddedFiles = (0, featureWorkers_1.getEmbeddedFilesByLevel)(context, tempVirtualFile, level++);
|
|
32
33
|
if (embeddedFiles.length === 0)
|
|
33
34
|
break;
|
|
34
35
|
let edits = [];
|
|
@@ -42,7 +43,7 @@ function register(context) {
|
|
|
42
43
|
&& file.mappings[0].lengths[0] === file.snapshot.getLength();
|
|
43
44
|
if (onTypeParams && !isCodeBlock)
|
|
44
45
|
continue;
|
|
45
|
-
const docMap = createDocMap(file, sourceFile.
|
|
46
|
+
const docMap = createDocMap(file, sourceFile.fileName, sourceFile.languageId, tempSourceSnapshot);
|
|
46
47
|
if (!docMap)
|
|
47
48
|
continue;
|
|
48
49
|
let embeddedCodeResult;
|
|
@@ -61,7 +62,7 @@ function register(context) {
|
|
|
61
62
|
if (!embeddedCodeResult)
|
|
62
63
|
continue;
|
|
63
64
|
toPatchIndent.push({
|
|
64
|
-
|
|
65
|
+
virtualFileName: file.fileName,
|
|
65
66
|
isCodeBlock,
|
|
66
67
|
service: embeddedCodeResult.service[1],
|
|
67
68
|
});
|
|
@@ -80,7 +81,7 @@ function register(context) {
|
|
|
80
81
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
81
82
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
82
83
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
83
|
-
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot);
|
|
84
|
+
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot, context.language.files);
|
|
84
85
|
}
|
|
85
86
|
if (level > 1) {
|
|
86
87
|
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
@@ -95,12 +96,12 @@ function register(context) {
|
|
|
95
96
|
for (const item of toPatchIndent) {
|
|
96
97
|
let virtualFile;
|
|
97
98
|
for (const file of (0, language_core_1.forEachEmbeddedFile)(tempVirtualFile)) {
|
|
98
|
-
if (file.
|
|
99
|
+
if (file.fileName === item.virtualFileName) {
|
|
99
100
|
virtualFile = file;
|
|
100
101
|
break;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
const docMap = createDocMap(virtualFile, sourceFile.
|
|
104
|
+
const docMap = createDocMap(virtualFile, context.env.fileNameToUri(sourceFile.fileName), sourceFile.languageId, tempSourceSnapshot);
|
|
104
105
|
if (!docMap)
|
|
105
106
|
continue;
|
|
106
107
|
const indentSensitiveLines = new Set();
|
|
@@ -138,7 +139,7 @@ function register(context) {
|
|
|
138
139
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
139
140
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
140
141
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
141
|
-
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot);
|
|
142
|
+
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot, context.language.files);
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
@@ -154,21 +155,12 @@ function register(context) {
|
|
|
154
155
|
newText: document.getText(),
|
|
155
156
|
};
|
|
156
157
|
return [textEdit];
|
|
157
|
-
function getEmbeddedFilesByLevel(rootFile, level) {
|
|
158
|
-
const embeddedFilesByLevel = [[rootFile]];
|
|
159
|
-
while (true) {
|
|
160
|
-
if (embeddedFilesByLevel.length > level)
|
|
161
|
-
return embeddedFilesByLevel[level];
|
|
162
|
-
let nextLevel = [];
|
|
163
|
-
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
164
|
-
nextLevel = nextLevel.concat(file.embeddedFiles);
|
|
165
|
-
}
|
|
166
|
-
embeddedFilesByLevel.push(nextLevel);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
158
|
async function tryFormat(document, range, ch) {
|
|
170
159
|
let formatRange = range;
|
|
171
160
|
for (const service of context.services) {
|
|
161
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
172
164
|
if (token.isCancellationRequested)
|
|
173
165
|
break;
|
|
174
166
|
let edits;
|
|
@@ -194,16 +186,16 @@ function register(context) {
|
|
|
194
186
|
}
|
|
195
187
|
}
|
|
196
188
|
};
|
|
197
|
-
function createDocMap(file,
|
|
198
|
-
const maps = (0, language_core_1.updateVirtualFileMaps)(file, (
|
|
199
|
-
if (!
|
|
200
|
-
return [
|
|
189
|
+
function createDocMap(file, sourceFileName, sourceLanguageId, _sourceSnapshot) {
|
|
190
|
+
const maps = (0, language_core_1.updateVirtualFileMaps)(file, (sourceFileName2) => {
|
|
191
|
+
if (!sourceFileName2) {
|
|
192
|
+
return [sourceFileName, _sourceSnapshot];
|
|
201
193
|
}
|
|
202
194
|
});
|
|
203
|
-
if (maps.has(
|
|
204
|
-
const map = maps.get(
|
|
195
|
+
if (maps.has(sourceFileName) && maps.get(sourceFileName)[0] === _sourceSnapshot) {
|
|
196
|
+
const map = maps.get(sourceFileName);
|
|
205
197
|
const version = fakeVersion++;
|
|
206
|
-
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(
|
|
198
|
+
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(context.env.fileNameToUri(sourceFileName), sourceLanguageId ?? (0, language_core_1.resolveCommonLanguageId)(sourceFileName), version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.env.fileNameToUri(file.fileName), file.languageId, version, file.snapshot.getText(0, file.snapshot.getLength())), map[1]);
|
|
207
199
|
}
|
|
208
200
|
}
|
|
209
201
|
}
|
|
@@ -26,7 +26,7 @@ function register(context) {
|
|
|
26
26
|
for (const reference of references) {
|
|
27
27
|
let foundMirrorPosition = false;
|
|
28
28
|
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
29
|
-
const [virtualFile] = context.language.files.getVirtualFile(document.uri);
|
|
29
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(document.uri));
|
|
30
30
|
const mirrorMap = virtualFile ? context.documents.getLinkedCodeMap(virtualFile) : undefined;
|
|
31
31
|
if (mirrorMap) {
|
|
32
32
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(reference.range.start)) {
|
|
@@ -8,7 +8,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
8
8
|
const language_core_1 = require("@volar/language-core");
|
|
9
9
|
function register(context) {
|
|
10
10
|
return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress) => {
|
|
11
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
11
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
12
12
|
if (!sourceFile)
|
|
13
13
|
return;
|
|
14
14
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
@@ -15,7 +15,7 @@ function register(context) {
|
|
|
15
15
|
return await service[1].provideFileReferences?.(document, token) ?? [];
|
|
16
16
|
}, (data) => data
|
|
17
17
|
.map(reference => {
|
|
18
|
-
const [virtualFile] = context.language.files.getVirtualFile(reference.uri);
|
|
18
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(reference.uri));
|
|
19
19
|
if (!virtualFile) {
|
|
20
20
|
return reference;
|
|
21
21
|
}
|
|
@@ -7,12 +7,12 @@ const language_core_1 = require("@volar/language-core");
|
|
|
7
7
|
const cancellation_1 = require("../utils/cancellation");
|
|
8
8
|
function register(context) {
|
|
9
9
|
return async (oldUri, newUri, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
-
const sourceFile = context.language.files.getSourceFile(oldUri);
|
|
10
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(oldUri));
|
|
11
11
|
if (sourceFile?.virtualFile) {
|
|
12
12
|
let tsExt;
|
|
13
13
|
for (const virtualFile of (0, language_core_1.forEachEmbeddedFile)(sourceFile.virtualFile[0])) {
|
|
14
|
-
if (virtualFile.typescript && virtualFile.
|
|
15
|
-
tsExt = virtualFile.
|
|
14
|
+
if (virtualFile.typescript && virtualFile.fileName.substring(sourceFile.fileName.length).match(/^\.(js|ts)x?$/)) {
|
|
15
|
+
tsExt = virtualFile.fileName.substring(virtualFile.fileName.lastIndexOf('.'));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
if (!tsExt) {
|
|
@@ -22,6 +22,9 @@ function register(context) {
|
|
|
22
22
|
newUri += tsExt;
|
|
23
23
|
}
|
|
24
24
|
for (const service of context.services) {
|
|
25
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
25
28
|
if (token.isCancellationRequested)
|
|
26
29
|
break;
|
|
27
30
|
if (!service[1].provideFileRenameEdits)
|
|
@@ -8,7 +8,7 @@ const transform_1 = require("../utils/transform");
|
|
|
8
8
|
const language_core_1 = require("@volar/language-core");
|
|
9
9
|
function register(context) {
|
|
10
10
|
return async (uri, range, token = cancellation_1.NoneCancellationToken) => {
|
|
11
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
11
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
12
12
|
if (!sourceFile)
|
|
13
13
|
return;
|
|
14
14
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
2
|
import type { ServiceContext } from '../types';
|
|
3
|
-
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>;
|
|
3
|
+
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, referenceContext: vscode.ReferenceContext, token?: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>;
|
|
@@ -6,7 +6,7 @@ const dedupe = require("../utils/dedupe");
|
|
|
6
6
|
const cancellation_1 = require("../utils/cancellation");
|
|
7
7
|
const language_core_1 = require("@volar/language-core");
|
|
8
8
|
function register(context) {
|
|
9
|
-
return (uri, position, token = cancellation_1.NoneCancellationToken) => {
|
|
9
|
+
return (uri, position, referenceContext, token = cancellation_1.NoneCancellationToken) => {
|
|
10
10
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, map => map.getGeneratedPositions(position, language_core_1.isReferencesEnabled), async (service, document, position) => {
|
|
11
11
|
if (token.isCancellationRequested)
|
|
12
12
|
return;
|
|
@@ -20,11 +20,11 @@ function register(context) {
|
|
|
20
20
|
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
|
|
21
21
|
return;
|
|
22
22
|
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
|
23
|
-
const references = await service[1].provideReferences(document, position, token) ?? [];
|
|
23
|
+
const references = await service[1].provideReferences(document, position, referenceContext, token) ?? [];
|
|
24
24
|
for (const reference of references) {
|
|
25
25
|
let foundMirrorPosition = false;
|
|
26
26
|
recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } });
|
|
27
|
-
const [virtualFile] = context.language.files.getVirtualFile(reference.uri);
|
|
27
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(reference.uri));
|
|
28
28
|
const mirrorMap = virtualFile ? context.documents.getLinkedCodeMap(virtualFile) : undefined;
|
|
29
29
|
if (mirrorMap) {
|
|
30
30
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(reference.range.start)) {
|
|
@@ -42,7 +42,7 @@ function register(context) {
|
|
|
42
42
|
}, (data) => {
|
|
43
43
|
const results = [];
|
|
44
44
|
for (const reference of data) {
|
|
45
|
-
const [virtualFile] = context.language.files.getVirtualFile(reference.uri);
|
|
45
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(reference.uri));
|
|
46
46
|
if (virtualFile) {
|
|
47
47
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
48
48
|
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
|
|
@@ -45,7 +45,7 @@ function register(context) {
|
|
|
45
45
|
for (const textEdit of textEdits) {
|
|
46
46
|
let foundMirrorPosition = false;
|
|
47
47
|
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
|
|
48
|
-
const [virtualFile] = context.language.files.getVirtualFile(editUri);
|
|
48
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(editUri));
|
|
49
49
|
const mirrorMap = virtualFile ? context.documents.getLinkedCodeMap(virtualFile) : undefined;
|
|
50
50
|
if (mirrorMap) {
|
|
51
51
|
for (const linkedPos of mirrorMap.getLinkedCodePositions(textEdit.range.start)) {
|
|
@@ -8,6 +8,9 @@ function register(context) {
|
|
|
8
8
|
return async (query, token = cancellation_1.NoneCancellationToken) => {
|
|
9
9
|
const symbolsList = [];
|
|
10
10
|
for (const service of context.services) {
|
|
11
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
11
14
|
if (token.isCancellationRequested) {
|
|
12
15
|
break;
|
|
13
16
|
}
|
|
@@ -19,7 +22,7 @@ function register(context) {
|
|
|
19
22
|
continue;
|
|
20
23
|
}
|
|
21
24
|
const symbols = embeddedSymbols.map(symbol => (0, transform_1.transformWorkspaceSymbol)(symbol, loc => {
|
|
22
|
-
const [virtualFile] = context.language.files.getVirtualFile(loc.uri);
|
|
25
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(loc.uri));
|
|
23
26
|
if (virtualFile) {
|
|
24
27
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
25
28
|
const range = map.getSourceRange(loc.range);
|
|
@@ -16,20 +16,7 @@ function register(context) {
|
|
|
16
16
|
// item.range already transformed in codeLens request
|
|
17
17
|
}
|
|
18
18
|
if (data?.kind === 'references') {
|
|
19
|
-
|
|
20
|
-
const service = context.services[data.serviceIndex];
|
|
21
|
-
if (service[1].resolveReferencesCodeLensLocations) {
|
|
22
|
-
const virtualFile = context.language.files.getVirtualFile(data.workerFileUri)[0];
|
|
23
|
-
const sourceFile = context.language.files.getSourceFile(data.workerFileUri);
|
|
24
|
-
if (virtualFile) {
|
|
25
|
-
const document = context.documents.get(virtualFile.id, virtualFile.languageId, virtualFile.snapshot);
|
|
26
|
-
references = await service[1].resolveReferencesCodeLensLocations(document, data.workerFileRange, references, token);
|
|
27
|
-
}
|
|
28
|
-
else if (sourceFile && !sourceFile?.virtualFile) {
|
|
29
|
-
const document = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
|
|
30
|
-
references = await service[1].resolveReferencesCodeLensLocations(document, data.workerFileRange, references, token);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
19
|
+
const references = await findReferences(data.sourceFileUri, item.range.start, { includeDeclaration: false }, token) ?? [];
|
|
33
20
|
item.command = context.commands.showReferences.create(data.sourceFileUri, item.range.start, references);
|
|
34
21
|
}
|
|
35
22
|
return item;
|
|
@@ -12,7 +12,7 @@ function register(context) {
|
|
|
12
12
|
return item;
|
|
13
13
|
item = Object.assign(item, data.original);
|
|
14
14
|
if (data.virtualDocumentUri) {
|
|
15
|
-
const [virtualFile] = context.language.files.getVirtualFile(data.virtualDocumentUri);
|
|
15
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(data.virtualDocumentUri));
|
|
16
16
|
if (virtualFile) {
|
|
17
17
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
18
18
|
item = await service[1].resolveCompletionItem(item, token);
|
|
@@ -24,7 +24,7 @@ exports.register = register;
|
|
|
24
24
|
function transformDocumentLinkTarget(target, context) {
|
|
25
25
|
const targetUri = vscode_uri_1.URI.parse(target);
|
|
26
26
|
const clearUri = targetUri.with({ fragment: '' }).toString();
|
|
27
|
-
const [virtualFile] = context.language.files.getVirtualFile(clearUri);
|
|
27
|
+
const [virtualFile] = context.language.files.getVirtualFile(context.env.uriToFileName(clearUri));
|
|
28
28
|
if (virtualFile) {
|
|
29
29
|
for (const map of context.documents.getMaps(virtualFile)) {
|
|
30
30
|
if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
|
package/lib/languageService.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export declare function createLanguageService(language: Language, servicePlugins
|
|
|
17
17
|
findDocumentSymbols: (uri: string, token?: vscode.CancellationToken) => Promise<vscode.DocumentSymbol[] | undefined>;
|
|
18
18
|
findDocumentColors: (uri: string, token?: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>;
|
|
19
19
|
getColorPresentations: (uri: string, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
|
|
20
|
-
doValidation: (uri: string,
|
|
21
|
-
findReferences: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>;
|
|
20
|
+
doValidation: (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
21
|
+
findReferences: (uri: string, position: vscode.Position, referenceContext: vscode.ReferenceContext, token?: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>;
|
|
22
22
|
findFileReferences: (uri: string, token?: vscode.CancellationToken) => import("./types").NullableResult<vscode.Location[]>;
|
|
23
23
|
findDefinition: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
|
24
24
|
findTypeDefinition: (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
package/lib/languageService.js
CHANGED
|
@@ -80,12 +80,15 @@ function createLanguageService(language, servicePlugins, env) {
|
|
|
80
80
|
context,
|
|
81
81
|
};
|
|
82
82
|
function createServiceContext() {
|
|
83
|
-
const documents = (0, documents_1.createDocumentProvider)(language.files);
|
|
83
|
+
const documents = (0, documents_1.createDocumentProvider)(env, language.files);
|
|
84
84
|
const context = {
|
|
85
85
|
env,
|
|
86
86
|
language: language,
|
|
87
87
|
inject: (key, ...args) => {
|
|
88
88
|
for (const service of context.services) {
|
|
89
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
89
92
|
const provide = service[1].provide?.[key];
|
|
90
93
|
if (provide) {
|
|
91
94
|
return provide(...args);
|
|
@@ -147,6 +150,8 @@ function createLanguageService(language, servicePlugins, env) {
|
|
|
147
150
|
}
|
|
148
151
|
},
|
|
149
152
|
},
|
|
153
|
+
disabledVirtualFiles: new Set(),
|
|
154
|
+
disabledServicePlugins: new WeakSet(),
|
|
150
155
|
};
|
|
151
156
|
for (const servicePlugin of servicePlugins) {
|
|
152
157
|
context.services.push([servicePlugin, servicePlugin.create(context)]);
|
package/lib/types.d.ts
CHANGED
|
@@ -59,11 +59,14 @@ export interface ServiceContext {
|
|
|
59
59
|
};
|
|
60
60
|
documents: DocumentProvider;
|
|
61
61
|
services: [ServicePlugin, ServicePluginInstance][];
|
|
62
|
+
disabledVirtualFiles: Set<string>;
|
|
63
|
+
disabledServicePlugins: WeakSet<ServicePluginInstance>;
|
|
62
64
|
}
|
|
63
65
|
export type Result<T> = T | Thenable<T>;
|
|
64
66
|
export type NullableResult<T> = Result<T | undefined | null>;
|
|
65
67
|
export type SemanticToken = [number, number, number, number, number];
|
|
66
68
|
export interface ServicePlugin {
|
|
69
|
+
name?: string;
|
|
67
70
|
triggerCharacters?: string[];
|
|
68
71
|
signatureHelpTriggerCharacters?: string[];
|
|
69
72
|
signatureHelpRetriggerCharacters?: string[];
|
|
@@ -97,7 +100,7 @@ export interface ServicePluginInstance<P = any> {
|
|
|
97
100
|
message: string;
|
|
98
101
|
}>;
|
|
99
102
|
provideRenameEdits?(document: TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceEdit>;
|
|
100
|
-
provideReferences?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Location[]>;
|
|
103
|
+
provideReferences?(document: TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): NullableResult<vscode.Location[]>;
|
|
101
104
|
provideSelectionRanges?(document: TextDocument, positions: vscode.Position[], token: vscode.CancellationToken): NullableResult<vscode.SelectionRange[]>;
|
|
102
105
|
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.InlayHint[]>;
|
|
103
106
|
provideCallHierarchyItems?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.CallHierarchyItem[]>;
|
|
@@ -122,7 +125,6 @@ export interface ServicePluginInstance<P = any> {
|
|
|
122
125
|
resolveCompletionItem?(item: vscode.CompletionItem, token: vscode.CancellationToken): Result<vscode.CompletionItem>;
|
|
123
126
|
resolveDocumentLink?(link: vscode.DocumentLink, token: vscode.CancellationToken): Result<vscode.DocumentLink>;
|
|
124
127
|
resolveInlayHint?(inlayHint: vscode.InlayHint, token: vscode.CancellationToken): Result<vscode.InlayHint>;
|
|
125
|
-
resolveReferencesCodeLensLocations?(document: TextDocument, range: vscode.Range, references: vscode.Location[], token: vscode.CancellationToken): Result<vscode.Location[]>;
|
|
126
128
|
transformCompletionItem?(item: vscode.CompletionItem): vscode.CompletionItem | undefined;
|
|
127
129
|
transformCodeAction?(item: vscode.CodeAction): vscode.CodeAction | undefined;
|
|
128
130
|
dispose?(): void;
|
|
@@ -131,6 +133,9 @@ export interface DocumentDropEdit {
|
|
|
131
133
|
insertText: string;
|
|
132
134
|
insertTextFormat: vscode.InsertTextFormat;
|
|
133
135
|
additionalEdit?: vscode.WorkspaceEdit;
|
|
136
|
+
createDataTransferFile?: (vscode.CreateFile & {
|
|
137
|
+
contentsMimeType: string;
|
|
138
|
+
})[];
|
|
134
139
|
}
|
|
135
140
|
export interface DataTransferItem {
|
|
136
141
|
value: any;
|
package/lib/utils/dedupe.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function createLocationSet(): {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]): T[];
|
|
7
7
|
export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
|
|
8
|
-
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.
|
|
8
|
+
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.CreateFile | vscode.TextDocumentEdit | vscode.RenameFile | vscode.DeleteFile)[];
|
|
9
9
|
export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];
|
|
10
10
|
export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
|
|
11
11
|
export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
|
|
@@ -6,3 +6,4 @@ export declare function documentFeatureWorker<T>(context: ServiceContext, uri: s
|
|
|
6
6
|
export declare function languageFeatureWorker<T, K>(context: ServiceContext, uri: string, getReadDocParams: () => K, eachVirtualDocParams: (map: SourceMapWithDocuments<CodeInformation>) => Generator<K>, worker: (service: [ServicePlugin, ServicePluginInstance], document: TextDocument, params: K, map?: SourceMapWithDocuments<CodeInformation>) => Thenable<T | null | undefined> | T | null | undefined, transformResult: (result: T, map?: SourceMapWithDocuments<CodeInformation>) => T | undefined, combineResult?: (results: T[]) => T): Promise<T | undefined>;
|
|
7
7
|
export declare function safeCall<T>(cb: () => Thenable<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
8
8
|
export declare function visitEmbedded(context: ServiceContext, current: VirtualFile, cb: (file: VirtualFile, sourceMap: SourceMapWithDocuments<CodeInformation>) => Promise<boolean>, rootFile?: VirtualFile): Promise<boolean>;
|
|
9
|
+
export declare function getEmbeddedFilesByLevel(context: ServiceContext, rootFile: VirtualFile, level: number): VirtualFile[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.visitEmbedded = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
3
|
+
exports.getEmbeddedFilesByLevel = exports.visitEmbedded = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
4
4
|
async function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
|
|
5
5
|
return languageFeatureWorker(context, uri, () => void 0, function* (map) {
|
|
6
6
|
if (valid(map)) {
|
|
@@ -10,7 +10,7 @@ async function documentFeatureWorker(context, uri, valid, worker, transformResul
|
|
|
10
10
|
}
|
|
11
11
|
exports.documentFeatureWorker = documentFeatureWorker;
|
|
12
12
|
async function languageFeatureWorker(context, uri, getReadDocParams, eachVirtualDocParams, worker, transformResult, combineResult) {
|
|
13
|
-
const sourceFile = context.language.files.getSourceFile(uri);
|
|
13
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(uri));
|
|
14
14
|
if (!sourceFile)
|
|
15
15
|
return;
|
|
16
16
|
let results = [];
|
|
@@ -18,6 +18,9 @@ async function languageFeatureWorker(context, uri, getReadDocParams, eachVirtual
|
|
|
18
18
|
await visitEmbedded(context, sourceFile.virtualFile[0], async (_file, map) => {
|
|
19
19
|
for (const mappedArg of eachVirtualDocParams(map)) {
|
|
20
20
|
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
21
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
21
24
|
const embeddedResult = await safeCall(() => worker(service, map.virtualFileDocument, mappedArg, map), 'service ' + serviceId + ' crashed on ' + map.virtualFileDocument.uri);
|
|
22
25
|
if (!embeddedResult)
|
|
23
26
|
continue;
|
|
@@ -36,6 +39,9 @@ async function languageFeatureWorker(context, uri, getReadDocParams, eachVirtual
|
|
|
36
39
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
37
40
|
const params = getReadDocParams();
|
|
38
41
|
for (const [serviceId, service] of Object.entries(context.services)) {
|
|
42
|
+
if (context.disabledServicePlugins.has(service[1])) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
39
45
|
const embeddedResult = await safeCall(() => worker(service, document, params, undefined), 'service ' + serviceId + ' crashed on ' + uri);
|
|
40
46
|
if (!embeddedResult)
|
|
41
47
|
continue;
|
|
@@ -71,14 +77,27 @@ async function visitEmbedded(context, current, cb, rootFile = current) {
|
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
for (const map of context.documents.getMaps(current)) {
|
|
74
|
-
const sourceFile = context.language.files.getSourceFile(map.sourceFileDocument.uri);
|
|
75
|
-
if (sourceFile?.virtualFile?.[0] === rootFile
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
const sourceFile = context.language.files.getSourceFile(context.env.uriToFileName(map.sourceFileDocument.uri));
|
|
81
|
+
if (sourceFile?.virtualFile?.[0] === rootFile
|
|
82
|
+
&& !context.disabledVirtualFiles.has(current.fileName)
|
|
83
|
+
&& !await cb(current, map)) {
|
|
84
|
+
return false;
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
return true;
|
|
82
88
|
}
|
|
83
89
|
exports.visitEmbedded = visitEmbedded;
|
|
90
|
+
function getEmbeddedFilesByLevel(context, rootFile, level) {
|
|
91
|
+
const embeddedFilesByLevel = [[rootFile]];
|
|
92
|
+
while (true) {
|
|
93
|
+
if (embeddedFilesByLevel.length > level)
|
|
94
|
+
return embeddedFilesByLevel[level];
|
|
95
|
+
let nextLevel = [];
|
|
96
|
+
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
97
|
+
nextLevel = nextLevel.concat(file.embeddedFiles.filter(file => !context.disabledVirtualFiles.has(file.fileName)));
|
|
98
|
+
}
|
|
99
|
+
embeddedFilesByLevel.push(nextLevel);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.getEmbeddedFilesByLevel = getEmbeddedFilesByLevel;
|
|
84
103
|
//# sourceMappingURL=featureWorkers.js.map
|
package/lib/utils/transform.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export declare function transformSelectionRange<T extends vscode.SelectionRange>
|
|
|
15
15
|
export declare function transformSelectionRanges<T extends vscode.SelectionRange>(locations: T[], getOtherRange: (range: vscode.Range) => vscode.Range | undefined): T[];
|
|
16
16
|
export declare function transformTextEdit<T extends vscode.TextEdit | vscode.InsertReplaceEdit>(textEdit: T, getOtherRange: (range: vscode.Range) => vscode.Range | undefined, document: vscode.TextDocument): T | undefined;
|
|
17
17
|
export declare function transformWorkspaceSymbol(symbol: vscode.WorkspaceSymbol, getOtherLocation: (location: vscode.Location) => vscode.Location | undefined): vscode.WorkspaceSymbol | undefined;
|
|
18
|
-
export declare function transformWorkspaceEdit(edit: vscode.WorkspaceEdit, { documents, language: project }: ServiceContext, mode: 'fileName' | 'rename' | 'codeAction' | undefined, versions?: Record<string, number>): vscode.WorkspaceEdit | undefined;
|
|
18
|
+
export declare function transformWorkspaceEdit(edit: vscode.WorkspaceEdit, { documents, language: project, env }: ServiceContext, mode: 'fileName' | 'rename' | 'codeAction' | undefined, versions?: Record<string, number>): vscode.WorkspaceEdit | undefined;
|
|
19
19
|
export declare function pushEditToDocumentChanges(arr: NonNullable<vscode.WorkspaceEdit['documentChanges']>, item: NonNullable<vscode.WorkspaceEdit['documentChanges']>[number]): void;
|
package/lib/utils/transform.js
CHANGED
|
@@ -204,13 +204,13 @@ function transformWorkspaceSymbol(symbol, getOtherLocation) {
|
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
exports.transformWorkspaceSymbol = transformWorkspaceSymbol;
|
|
207
|
-
function transformWorkspaceEdit(edit, { documents, language: project }, mode, versions = {}) {
|
|
207
|
+
function transformWorkspaceEdit(edit, { documents, language: project, env }, mode, versions = {}) {
|
|
208
208
|
const sourceResult = {};
|
|
209
209
|
let hasResult = false;
|
|
210
210
|
for (const tsUri in edit.changeAnnotations) {
|
|
211
211
|
sourceResult.changeAnnotations ??= {};
|
|
212
212
|
const tsAnno = edit.changeAnnotations[tsUri];
|
|
213
|
-
const [virtualFile] = project.files.getVirtualFile(tsUri);
|
|
213
|
+
const [virtualFile] = project.files.getVirtualFile(env.uriToFileName(tsUri));
|
|
214
214
|
if (virtualFile) {
|
|
215
215
|
for (const map of documents.getMaps(virtualFile)) {
|
|
216
216
|
// TODO: check capability?
|
|
@@ -224,7 +224,7 @@ function transformWorkspaceEdit(edit, { documents, language: project }, mode, ve
|
|
|
224
224
|
}
|
|
225
225
|
for (const tsUri in edit.changes) {
|
|
226
226
|
sourceResult.changes ??= {};
|
|
227
|
-
const [virtualFile] = project.files.getVirtualFile(tsUri);
|
|
227
|
+
const [virtualFile] = project.files.getVirtualFile(env.uriToFileName(tsUri));
|
|
228
228
|
if (virtualFile) {
|
|
229
229
|
for (const map of documents.getMaps(virtualFile)) {
|
|
230
230
|
const tsEdits = edit.changes[tsUri];
|
|
@@ -265,7 +265,7 @@ function transformWorkspaceEdit(edit, { documents, language: project }, mode, ve
|
|
|
265
265
|
sourceResult.documentChanges ??= [];
|
|
266
266
|
let sourceEdit;
|
|
267
267
|
if ('textDocument' in tsDocEdit) {
|
|
268
|
-
const [virtualFile] = project.files.getVirtualFile(tsDocEdit.textDocument.uri);
|
|
268
|
+
const [virtualFile] = project.files.getVirtualFile(env.fileNameToUri(tsDocEdit.textDocument.uri));
|
|
269
269
|
if (virtualFile) {
|
|
270
270
|
for (const map of documents.getMaps(virtualFile)) {
|
|
271
271
|
sourceEdit = {
|
|
@@ -315,7 +315,7 @@ function transformWorkspaceEdit(edit, { documents, language: project }, mode, ve
|
|
|
315
315
|
sourceEdit = tsDocEdit; // TODO: remove .ts?
|
|
316
316
|
}
|
|
317
317
|
else if (tsDocEdit.kind === 'rename') {
|
|
318
|
-
const [virtualFile] = project.files.getVirtualFile(tsDocEdit.oldUri);
|
|
318
|
+
const [virtualFile] = project.files.getVirtualFile(env.uriToFileName(tsDocEdit.oldUri));
|
|
319
319
|
if (virtualFile) {
|
|
320
320
|
for (const map of documents.getMaps(virtualFile)) {
|
|
321
321
|
// TODO: check capability?
|
|
@@ -333,7 +333,7 @@ function transformWorkspaceEdit(edit, { documents, language: project }, mode, ve
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
else if (tsDocEdit.kind === 'delete') {
|
|
336
|
-
const [virtualFile] = project.files.getVirtualFile(tsDocEdit.uri);
|
|
336
|
+
const [virtualFile] = project.files.getVirtualFile(env.uriToFileName(tsDocEdit.uri));
|
|
337
337
|
if (virtualFile) {
|
|
338
338
|
for (const map of documents.getMaps(virtualFile)) {
|
|
339
339
|
// TODO: check capability?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"directory": "packages/language-service"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-core": "2.0.0-alpha.
|
|
15
|
+
"@volar/language-core": "2.0.0-alpha.10",
|
|
16
16
|
"vscode-languageserver-protocol": "^3.17.5",
|
|
17
17
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
18
18
|
"vscode-uri": "^3.0.8"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "f320632bcffa06981de169ee3cdad79c29ecc1b5"
|
|
21
21
|
}
|