@volar/language-service 1.11.1 → 2.0.0-alpha.0
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 +3 -4
- package/index.js +5 -5
- package/lib/documents.d.ts +26 -40
- package/lib/documents.js +66 -113
- package/lib/features/provideAutoInsertionEdit.d.ts +6 -0
- package/lib/features/provideAutoInsertionEdit.js +40 -0
- package/lib/{languageFeatures/callHierarchy.d.ts → features/provideCallHierarchyItems.d.ts} +1 -2
- package/lib/{languageFeatures/callHierarchy.js → features/provideCallHierarchyItems.js} +33 -23
- package/lib/{languageFeatures/codeActions.d.ts → features/provideCodeActions.d.ts} +1 -13
- package/lib/features/provideCodeActions.js +111 -0
- package/lib/{languageFeatures/codeLens.d.ts → features/provideCodeLenses.d.ts} +6 -6
- package/lib/features/provideCodeLenses.js +61 -0
- package/lib/{documentFeatures/colorPresentations.d.ts → features/provideColorPresentations.d.ts} +0 -1
- package/lib/features/provideColorPresentations.js +46 -0
- package/lib/{languageFeatures/complete.d.ts → features/provideCompletionItems.d.ts} +1 -2
- package/lib/{languageFeatures/complete.js → features/provideCompletionItems.js} +45 -37
- package/lib/features/provideDefinition.d.ts +4 -0
- package/lib/{languageFeatures/definition.js → features/provideDefinition.js} +48 -45
- package/lib/{languageFeatures/validation.d.ts → features/provideDiagnostics.d.ts} +2 -4
- package/lib/{languageFeatures/validation.js → features/provideDiagnostics.js} +30 -124
- package/lib/{documentFeatures/documentColors.d.ts → features/provideDocumentColors.d.ts} +1 -2
- package/lib/features/provideDocumentColors.js +34 -0
- package/lib/features/provideDocumentDropEdits.d.ts +3 -0
- package/lib/features/provideDocumentDropEdits.js +27 -0
- package/lib/{documentFeatures/format.d.ts → features/provideDocumentFormattingEdits.d.ts} +0 -1
- package/lib/{documentFeatures/format.js → features/provideDocumentFormattingEdits.js} +76 -71
- package/lib/{languageFeatures/documentHighlights.d.ts → features/provideDocumentHighlights.d.ts} +0 -1
- package/lib/{languageFeatures/documentHighlights.js → features/provideDocumentHighlights.js} +17 -16
- package/lib/{languageFeatures/documentLinks.d.ts → features/provideDocumentLinks.d.ts} +1 -2
- package/lib/features/provideDocumentLinks.js +50 -0
- package/lib/{languageFeatures/documentSemanticTokens.d.ts → features/provideDocumentSemanticTokens.d.ts} +1 -2
- package/lib/features/provideDocumentSemanticTokens.js +84 -0
- package/lib/{documentFeatures/documentSymbols.d.ts → features/provideDocumentSymbols.d.ts} +0 -1
- package/lib/{documentFeatures/documentSymbols.js → features/provideDocumentSymbols.js} +15 -10
- package/lib/{languageFeatures/fileReferences.d.ts → features/provideFileReferences.d.ts} +0 -1
- package/lib/features/provideFileReferences.js +35 -0
- package/lib/{languageFeatures/fileRename.d.ts → features/provideFileRenameEdits.d.ts} +0 -1
- package/lib/{languageFeatures/fileRename.js → features/provideFileRenameEdits.js} +12 -12
- package/lib/{documentFeatures/foldingRanges.d.ts → features/provideFoldingRanges.d.ts} +0 -1
- package/lib/features/provideFoldingRanges.js +24 -0
- package/lib/{languageFeatures/hover.d.ts → features/provideHover.d.ts} +0 -1
- package/lib/{languageFeatures/hover.js → features/provideHover.js} +11 -11
- package/lib/{languageFeatures/inlayHints.d.ts → features/provideInlayHints.d.ts} +1 -2
- package/lib/features/provideInlayHints.js +84 -0
- package/lib/{documentFeatures/linkedEditingRanges.d.ts → features/provideLinkedEditingRanges.d.ts} +0 -1
- package/lib/features/provideLinkedEditingRanges.js +32 -0
- package/lib/{languageFeatures/references.d.ts → features/provideReferences.d.ts} +0 -1
- package/lib/{languageFeatures/references.js → features/provideReferences.js} +14 -13
- package/lib/{languageFeatures/rename.d.ts → features/provideRenameEdits.d.ts} +0 -3
- package/lib/features/provideRenameEdits.js +126 -0
- package/lib/{languageFeatures/renamePrepare.d.ts → features/provideRenameRange.d.ts} +2 -3
- package/lib/{languageFeatures/renamePrepare.js → features/provideRenameRange.js} +7 -5
- package/lib/{documentFeatures/selectionRanges.d.ts → features/provideSelectionRanges.d.ts} +1 -2
- package/lib/{documentFeatures/selectionRanges.js → features/provideSelectionRanges.js} +18 -15
- package/lib/{languageFeatures/signatureHelp.d.ts → features/provideSignatureHelp.d.ts} +0 -1
- package/lib/{languageFeatures/signatureHelp.js → features/provideSignatureHelp.js} +8 -6
- package/lib/{languageFeatures/workspaceSymbols.d.ts → features/provideWorkspaceSymbols.d.ts} +0 -1
- package/lib/{languageFeatures/workspaceSymbols.js → features/provideWorkspaceSymbols.js} +15 -11
- package/lib/{languageFeatures/codeActionResolve.d.ts → features/resolveCodeAction.d.ts} +0 -1
- package/lib/features/resolveCodeAction.js +27 -0
- package/lib/{languageFeatures/codeLensResolve.d.ts → features/resolveCodeLens.d.ts} +0 -1
- package/lib/features/resolveCodeLens.js +39 -0
- package/lib/{languageFeatures/completeResolve.d.ts → features/resolveCompletionItem.d.ts} +0 -1
- package/lib/features/resolveCompletionItem.js +35 -0
- package/lib/{languageFeatures/documentLinkResolve.d.ts → features/resolveDocumentLink.d.ts} +0 -1
- package/lib/{languageFeatures/documentLinkResolve.js → features/resolveDocumentLink.js} +12 -10
- package/lib/{languageFeatures/inlayHintResolve.d.ts → features/resolveInlayHint.d.ts} +0 -1
- package/lib/{languageFeatures/inlayHintResolve.js → features/resolveInlayHint.js} +4 -4
- package/lib/languageService.d.ts +61 -0
- package/lib/languageService.js +158 -0
- package/lib/types.d.ts +88 -137
- package/lib/types.js +1 -8
- package/lib/utils/SemanticTokensBuilder.d.ts +0 -1
- package/lib/utils/cancellation.d.ts +0 -1
- package/lib/utils/common.d.ts +0 -2
- package/lib/utils/common.js +1 -18
- package/lib/utils/dedupe.d.ts +0 -1
- package/lib/utils/featureWorkers.d.ts +7 -8
- package/lib/utils/featureWorkers.js +37 -93
- package/lib/utils/transform.d.ts +19 -0
- package/lib/utils/transform.js +375 -0
- package/package.json +3 -4
- package/lib/baseLanguageService.d.ts +0 -112
- package/lib/baseLanguageService.js +0 -231
- package/lib/documentFeatures/colorPresentations.js +0 -37
- package/lib/documentFeatures/documentColors.js +0 -26
- package/lib/documentFeatures/foldingRanges.js +0 -17
- package/lib/documentFeatures/linkedEditingRanges.js +0 -20
- package/lib/languageFeatures/autoInsert.d.ts +0 -4
- package/lib/languageFeatures/autoInsert.js +0 -42
- package/lib/languageFeatures/codeActionResolve.js +0 -51
- package/lib/languageFeatures/codeActions.js +0 -177
- package/lib/languageFeatures/codeLens.js +0 -53
- package/lib/languageFeatures/codeLensResolve.js +0 -31
- package/lib/languageFeatures/completeResolve.js +0 -32
- package/lib/languageFeatures/definition.d.ts +0 -5
- package/lib/languageFeatures/documentLinks.js +0 -66
- package/lib/languageFeatures/documentSemanticTokens.js +0 -70
- package/lib/languageFeatures/fileReferences.js +0 -32
- package/lib/languageFeatures/inlayHints.js +0 -75
- package/lib/languageFeatures/rename.js +0 -291
- package/lib/transformer/completionItem.d.ts +0 -3
- package/lib/transformer/completionItem.js +0 -18
- package/lib/transformer/completionList.d.ts +0 -3
- package/lib/transformer/completionList.js +0 -27
- package/lib/transformer/documentSymbol.d.ts +0 -3
- package/lib/transformer/documentSymbol.js +0 -24
- package/lib/transformer/foldingRanges.d.ts +0 -3
- package/lib/transformer/foldingRanges.js +0 -24
- package/lib/transformer/hover.d.ts +0 -3
- package/lib/transformer/hover.js +0 -17
- package/lib/transformer/index.d.ts +0 -12
- package/lib/transformer/index.js +0 -26
- package/lib/transformer/locationLike.d.ts +0 -5
- package/lib/transformer/locationLike.js +0 -14
- package/lib/transformer/locationsLike.d.ts +0 -5
- package/lib/transformer/locationsLike.js +0 -12
- package/lib/transformer/selectionRange.d.ts +0 -3
- package/lib/transformer/selectionRange.js +0 -15
- package/lib/transformer/selectionRanges.d.ts +0 -3
- package/lib/transformer/selectionRanges.js +0 -12
- package/lib/transformer/textEdit.d.ts +0 -3
- package/lib/transformer/textEdit.js +0 -72
- package/lib/transformer/workspaceSymbol.d.ts +0 -3
- package/lib/transformer/workspaceSymbol.js +0 -18
- package/lib/utils/definePlugin.d.ts +0 -4
- package/lib/utils/definePlugin.js +0 -20
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
5
|
+
const common_1 = require("../utils/common");
|
|
6
|
+
const dedupe = require("../utils/dedupe");
|
|
7
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
8
|
+
const transform_1 = require("../utils/transform");
|
|
9
|
+
const language_core_1 = require("@volar/language-core");
|
|
10
|
+
function register(context) {
|
|
11
|
+
return async (uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
+
const sourceFile = context.language.files.getSourceFile(uri);
|
|
13
|
+
if (!sourceFile)
|
|
14
|
+
return;
|
|
15
|
+
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
16
|
+
const offsetRange = {
|
|
17
|
+
start: document.offsetAt(range.start),
|
|
18
|
+
end: document.offsetAt(range.end),
|
|
19
|
+
};
|
|
20
|
+
const transformedCodeActions = new WeakSet();
|
|
21
|
+
return await (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => ({ range, codeActionContext }), function* (map) {
|
|
22
|
+
if (map.map.mappings.some(mapping => (0, language_core_1.isCodeActionsEnabled)(mapping.data))) {
|
|
23
|
+
const _codeActionContext = {
|
|
24
|
+
diagnostics: (0, transform_1.transformLocations)(codeActionContext.diagnostics, range => map.getGeneratedRange(range)),
|
|
25
|
+
only: codeActionContext.only,
|
|
26
|
+
};
|
|
27
|
+
let minStart;
|
|
28
|
+
let maxEnd;
|
|
29
|
+
for (const mapping of map.map.mappings) {
|
|
30
|
+
const overlapRange = (0, common_1.getOverlapRange)(offsetRange.start, offsetRange.end, mapping.sourceOffsets[0], mapping.sourceOffsets[mapping.sourceOffsets.length - 1]
|
|
31
|
+
+ mapping.lengths[mapping.lengths.length - 1]);
|
|
32
|
+
if (overlapRange) {
|
|
33
|
+
const start = map.map.getGeneratedOffset(overlapRange.start)?.[0];
|
|
34
|
+
const end = map.map.getGeneratedOffset(overlapRange.end)?.[0];
|
|
35
|
+
if (start !== undefined && end !== undefined) {
|
|
36
|
+
minStart = minStart === undefined ? start : Math.min(start, minStart);
|
|
37
|
+
maxEnd = maxEnd === undefined ? end : Math.max(end, maxEnd);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (minStart !== undefined && maxEnd !== undefined) {
|
|
42
|
+
yield {
|
|
43
|
+
range: {
|
|
44
|
+
start: map.virtualFileDocument.positionAt(minStart),
|
|
45
|
+
end: map.virtualFileDocument.positionAt(maxEnd),
|
|
46
|
+
},
|
|
47
|
+
codeActionContext: _codeActionContext,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, async (service, document, { range, codeActionContext }) => {
|
|
52
|
+
if (token.isCancellationRequested) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const serviceIndex = context.services.indexOf(service);
|
|
56
|
+
const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
|
|
57
|
+
const data = diagnostic.data;
|
|
58
|
+
if (data && data.version !== document.version) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return data?.serviceIndex === serviceIndex;
|
|
62
|
+
}).map(diagnostic => {
|
|
63
|
+
const data = diagnostic.data;
|
|
64
|
+
return {
|
|
65
|
+
...diagnostic,
|
|
66
|
+
...data.original,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
const codeActions = await service[1].provideCodeActions?.(document, range, {
|
|
70
|
+
...codeActionContext,
|
|
71
|
+
diagnostics,
|
|
72
|
+
}, token);
|
|
73
|
+
codeActions?.forEach(codeAction => {
|
|
74
|
+
codeAction.data = {
|
|
75
|
+
uri,
|
|
76
|
+
version: document.version,
|
|
77
|
+
original: {
|
|
78
|
+
data: codeAction.data,
|
|
79
|
+
edit: codeAction.edit,
|
|
80
|
+
},
|
|
81
|
+
serviceIndex: context.services.indexOf(service),
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
if (codeActions && service[1].transformCodeAction) {
|
|
85
|
+
for (let i = 0; i < codeActions.length; i++) {
|
|
86
|
+
const transformed = service[1].transformCodeAction(codeActions[i]);
|
|
87
|
+
if (transformed) {
|
|
88
|
+
codeActions[i] = transformed;
|
|
89
|
+
transformedCodeActions.add(transformed);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return codeActions;
|
|
94
|
+
}, actions => actions
|
|
95
|
+
.map(action => {
|
|
96
|
+
if (transformedCodeActions.has(action))
|
|
97
|
+
return action;
|
|
98
|
+
if (action.edit) {
|
|
99
|
+
const edit = (0, transform_1.transformWorkspaceEdit)(action.edit, context, 'codeAction');
|
|
100
|
+
if (!edit) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
action.edit = edit;
|
|
104
|
+
}
|
|
105
|
+
return action;
|
|
106
|
+
})
|
|
107
|
+
.filter(common_1.notEmpty), arr => dedupe.withCodeAction(arr.flat()));
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.register = register;
|
|
111
|
+
//# sourceMappingURL=provideCodeActions.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { ServiceContext } from '../types';
|
|
2
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { ServiceContext } from '../types';
|
|
3
3
|
export interface ServiceCodeLensData {
|
|
4
4
|
kind: 'normal';
|
|
5
5
|
uri: string;
|
|
6
6
|
original: Pick<vscode.CodeLens, 'data'>;
|
|
7
|
-
|
|
7
|
+
serviceIndex: number;
|
|
8
8
|
}
|
|
9
9
|
export interface ServiceReferencesCodeLensData {
|
|
10
10
|
kind: 'references';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
sourceFileUri: string;
|
|
12
|
+
workerFileUri: string;
|
|
13
|
+
workerFileRange: vscode.Range;
|
|
14
|
+
serviceIndex: number;
|
|
14
15
|
}
|
|
15
16
|
export declare function register(context: ServiceContext): (uri: string, token?: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
|
|
16
|
-
//# sourceMappingURL=codeLens.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
5
|
+
const common_1 = require("../utils/common");
|
|
6
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
7
|
+
const language_core_1 = require("@volar/language-core");
|
|
8
|
+
function register(context) {
|
|
9
|
+
return async (uri, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
+
return await (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isCodeLensEnabled)(mapping.data)), async (service, document) => {
|
|
11
|
+
if (token.isCancellationRequested) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
let codeLens = await service[1].provideCodeLenses?.(document, token);
|
|
15
|
+
const serviceIndex = context.services.indexOf(service);
|
|
16
|
+
codeLens?.forEach(codeLens => {
|
|
17
|
+
codeLens.data = {
|
|
18
|
+
kind: 'normal',
|
|
19
|
+
uri,
|
|
20
|
+
original: {
|
|
21
|
+
data: codeLens.data,
|
|
22
|
+
},
|
|
23
|
+
serviceIndex,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
const ranges = await service[1].provideReferencesCodeLensRanges?.(document, token);
|
|
27
|
+
const referencesCodeLens = ranges?.map(range => ({
|
|
28
|
+
range,
|
|
29
|
+
data: {
|
|
30
|
+
kind: 'references',
|
|
31
|
+
sourceFileUri: uri,
|
|
32
|
+
workerFileUri: document.uri,
|
|
33
|
+
workerFileRange: range,
|
|
34
|
+
serviceIndex,
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
codeLens = [
|
|
38
|
+
...codeLens ?? [],
|
|
39
|
+
...referencesCodeLens ?? [],
|
|
40
|
+
];
|
|
41
|
+
return codeLens;
|
|
42
|
+
}, (data, map) => {
|
|
43
|
+
if (!map) {
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
return data
|
|
47
|
+
.map(codeLens => {
|
|
48
|
+
const range = map.getSourceRange(codeLens.range, language_core_1.isCodeLensEnabled);
|
|
49
|
+
if (range) {
|
|
50
|
+
return {
|
|
51
|
+
...codeLens,
|
|
52
|
+
range,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.filter(common_1.notEmpty);
|
|
57
|
+
}, arr => arr.flat()) ?? [];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.register = register;
|
|
61
|
+
//# sourceMappingURL=provideCodeLenses.js.map
|
package/lib/{documentFeatures/colorPresentations.d.ts → features/provideColorPresentations.d.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ServiceContext } from '../types';
|
|
2
2
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
3
|
export declare function register(context: ServiceContext): (uri: string, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
|
|
4
|
-
//# sourceMappingURL=colorPresentations.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
5
|
+
const common_1 = require("../utils/common");
|
|
6
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
7
|
+
const language_core_1 = require("@volar/language-core");
|
|
8
|
+
function register(context) {
|
|
9
|
+
return (uri, color, range, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => range, function* (map) {
|
|
11
|
+
for (const mappedRange of map.getGeneratedRanges(range, language_core_1.isColorEnabled)) {
|
|
12
|
+
yield mappedRange;
|
|
13
|
+
}
|
|
14
|
+
}, (service, document, range) => {
|
|
15
|
+
if (token.isCancellationRequested) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return service[1].provideColorPresentations?.(document, color, range, token);
|
|
19
|
+
}, (data, map) => {
|
|
20
|
+
if (!map) {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
return data
|
|
24
|
+
.map(colorPresentation => {
|
|
25
|
+
if (colorPresentation.textEdit) {
|
|
26
|
+
const range = map.getSourceRange(colorPresentation.textEdit.range);
|
|
27
|
+
if (!range)
|
|
28
|
+
return undefined;
|
|
29
|
+
colorPresentation.textEdit.range = range;
|
|
30
|
+
}
|
|
31
|
+
if (colorPresentation.additionalTextEdits) {
|
|
32
|
+
for (const textEdit of colorPresentation.additionalTextEdits) {
|
|
33
|
+
const range = map.getSourceRange(textEdit.range);
|
|
34
|
+
if (!range)
|
|
35
|
+
return undefined;
|
|
36
|
+
textEdit.range = range;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return colorPresentation;
|
|
40
|
+
})
|
|
41
|
+
.filter(common_1.notEmpty);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.register = register;
|
|
46
|
+
//# sourceMappingURL=provideColorPresentations.js.map
|
|
@@ -3,8 +3,7 @@ import type { ServiceContext } from '../types';
|
|
|
3
3
|
export interface ServiceCompletionData {
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
|
|
6
|
-
|
|
6
|
+
serviceIndex: number;
|
|
7
7
|
virtualDocumentUri: string | undefined;
|
|
8
8
|
}
|
|
9
9
|
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
|
|
10
|
-
//# sourceMappingURL=complete.d.ts.map
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = void 0;
|
|
4
|
-
const
|
|
5
|
-
const definePlugin_1 = require("../utils/definePlugin");
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
6
5
|
const cancellation_1 = require("../utils/cancellation");
|
|
6
|
+
const transform_1 = require("../utils/transform");
|
|
7
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
7
8
|
function register(context) {
|
|
8
9
|
let cache;
|
|
9
10
|
return async (uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
-
|
|
11
|
+
const sourceFile = context.language.files.getSourceFile(uri);
|
|
11
12
|
if (completionContext?.triggerKind === 3
|
|
12
13
|
&& cache?.uri === uri) {
|
|
13
14
|
for (const cacheData of cache.data) {
|
|
14
15
|
if (!cacheData.list.isIncomplete)
|
|
15
16
|
continue;
|
|
16
17
|
if (cacheData.virtualDocumentUri) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const [virtualFile] = context.language.files.getVirtualFile(cacheData.virtualDocumentUri);
|
|
19
|
+
if (!virtualFile)
|
|
20
|
+
continue;
|
|
21
|
+
for (const map of context.documents.getMaps(virtualFile)) {
|
|
22
|
+
for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
|
|
19
23
|
if (!cacheData.service.provideCompletionItems)
|
|
20
24
|
continue;
|
|
21
25
|
const embeddedCompletionList = await cacheData.service.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
|
|
@@ -23,22 +27,23 @@ function register(context) {
|
|
|
23
27
|
cacheData.list.isIncomplete = false;
|
|
24
28
|
continue;
|
|
25
29
|
}
|
|
26
|
-
cacheData.list =
|
|
30
|
+
cacheData.list = (0, transform_1.transformCompletionList)(embeddedCompletionList, range => map.getSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
27
31
|
uri,
|
|
28
32
|
original: {
|
|
29
33
|
additionalTextEdits: oldItem.additionalTextEdits,
|
|
30
34
|
textEdit: oldItem.textEdit,
|
|
31
35
|
data: oldItem.data,
|
|
32
36
|
},
|
|
33
|
-
|
|
37
|
+
serviceIndex: cacheData.serviceIndex,
|
|
34
38
|
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
|
-
else if (
|
|
43
|
+
else if (sourceFile) {
|
|
40
44
|
if (!cacheData.service.provideCompletionItems)
|
|
41
45
|
continue;
|
|
46
|
+
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
42
47
|
const completionList = await cacheData.service.provideCompletionItems(document, position, completionContext, token);
|
|
43
48
|
if (!completionList) {
|
|
44
49
|
cacheData.list.isIncomplete = false;
|
|
@@ -52,7 +57,7 @@ function register(context) {
|
|
|
52
57
|
textEdit: item.textEdit,
|
|
53
58
|
data: item.data,
|
|
54
59
|
},
|
|
55
|
-
|
|
60
|
+
serviceIndex: cacheData.serviceIndex,
|
|
56
61
|
virtualDocumentUri: undefined,
|
|
57
62
|
};
|
|
58
63
|
});
|
|
@@ -60,7 +65,7 @@ function register(context) {
|
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
else {
|
|
63
|
-
const
|
|
68
|
+
const rootVirtualFile = context.language.files.getSourceFile(uri)?.virtualFile?.[0];
|
|
64
69
|
cache = {
|
|
65
70
|
uri,
|
|
66
71
|
data: [],
|
|
@@ -68,51 +73,52 @@ function register(context) {
|
|
|
68
73
|
};
|
|
69
74
|
// monky fix https://github.com/johnsoncodehk/volar/issues/1358
|
|
70
75
|
let isFirstMapping = true;
|
|
71
|
-
if (
|
|
72
|
-
await (0,
|
|
73
|
-
const services =
|
|
76
|
+
if (rootVirtualFile) {
|
|
77
|
+
await (0, featureWorkers_1.visitEmbedded)(context, rootVirtualFile, async (_, map) => {
|
|
78
|
+
const services = [...context.services].sort((a, b) => sortServices(a[1], b[1]));
|
|
74
79
|
let _data;
|
|
75
|
-
for (const mapped of map.
|
|
80
|
+
for (const mapped of map.getGeneratedPositions(position, data => {
|
|
76
81
|
_data = data;
|
|
77
|
-
return
|
|
82
|
+
return (0, language_core_1.isCompletionEnabled)(data);
|
|
78
83
|
})) {
|
|
79
84
|
for (const service of services) {
|
|
80
85
|
if (token.isCancellationRequested)
|
|
81
86
|
break;
|
|
82
|
-
if (!service.provideCompletionItems)
|
|
87
|
+
if (!service[1].provideCompletionItems)
|
|
83
88
|
continue;
|
|
84
|
-
if (service.isAdditionalCompletion && !isFirstMapping)
|
|
89
|
+
if (service[1].isAdditionalCompletion && !isFirstMapping)
|
|
85
90
|
continue;
|
|
86
|
-
if (completionContext?.triggerCharacter && !service.triggerCharacters?.includes(completionContext.triggerCharacter))
|
|
91
|
+
if (completionContext?.triggerCharacter && !service[0].triggerCharacters?.includes(completionContext.triggerCharacter))
|
|
87
92
|
continue;
|
|
88
|
-
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.
|
|
93
|
+
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.isAdditional || service[1].isAdditionalCompletion;
|
|
89
94
|
if (cache.mainCompletion && (!isAdditional || cache?.mainCompletion.documentUri !== map.virtualFileDocument.uri))
|
|
90
95
|
continue;
|
|
91
96
|
// avoid duplicate items with .vue and .vue.html
|
|
92
|
-
if (service.isAdditionalCompletion && cache?.data.some(data => data.service === service))
|
|
97
|
+
if (service[1].isAdditionalCompletion && cache?.data.some(data => data.service === service[1]))
|
|
93
98
|
continue;
|
|
94
|
-
const embeddedCompletionList = await service.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
|
|
99
|
+
const embeddedCompletionList = await service[1].provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token);
|
|
95
100
|
if (!embeddedCompletionList || !embeddedCompletionList.items.length)
|
|
96
101
|
continue;
|
|
97
|
-
if (typeof _data?.completion === 'object' && _data.completion.
|
|
102
|
+
if (typeof _data?.completion === 'object' && _data.completion.onlyImport) {
|
|
98
103
|
embeddedCompletionList.items = embeddedCompletionList.items.filter(item => !!item.labelDetails);
|
|
99
104
|
}
|
|
100
105
|
if (!isAdditional) {
|
|
101
106
|
cache.mainCompletion = { documentUri: map.virtualFileDocument.uri };
|
|
102
107
|
}
|
|
103
|
-
const completionList =
|
|
108
|
+
const completionList = (0, transform_1.transformCompletionList)(embeddedCompletionList, range => map.getSourceRange(range, language_core_1.isCompletionEnabled), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
104
109
|
uri,
|
|
105
110
|
original: {
|
|
106
111
|
additionalTextEdits: oldItem.additionalTextEdits,
|
|
107
112
|
textEdit: oldItem.textEdit,
|
|
108
113
|
data: oldItem.data,
|
|
109
114
|
},
|
|
110
|
-
|
|
115
|
+
serviceIndex: context.services.indexOf(service),
|
|
111
116
|
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
112
117
|
});
|
|
113
118
|
cache.data.push({
|
|
114
119
|
virtualDocumentUri: map.virtualFileDocument.uri,
|
|
115
|
-
service: service,
|
|
120
|
+
service: service[1],
|
|
121
|
+
serviceIndex: context.services.indexOf(service),
|
|
116
122
|
list: completionList,
|
|
117
123
|
});
|
|
118
124
|
}
|
|
@@ -121,26 +127,27 @@ function register(context) {
|
|
|
121
127
|
return true;
|
|
122
128
|
});
|
|
123
129
|
}
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
130
|
+
if (sourceFile) {
|
|
131
|
+
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
132
|
+
const services = [...context.services].sort((a, b) => sortServices(a[1], b[1]));
|
|
126
133
|
for (const service of services) {
|
|
127
134
|
if (token.isCancellationRequested)
|
|
128
135
|
break;
|
|
129
|
-
if (!service.provideCompletionItems)
|
|
136
|
+
if (!service[1].provideCompletionItems)
|
|
130
137
|
continue;
|
|
131
|
-
if (service.isAdditionalCompletion && !isFirstMapping)
|
|
138
|
+
if (service[1].isAdditionalCompletion && !isFirstMapping)
|
|
132
139
|
continue;
|
|
133
|
-
if (completionContext?.triggerCharacter && !service.triggerCharacters?.includes(completionContext.triggerCharacter))
|
|
140
|
+
if (completionContext?.triggerCharacter && !service[0].triggerCharacters?.includes(completionContext.triggerCharacter))
|
|
134
141
|
continue;
|
|
135
|
-
if (cache.mainCompletion && (!service.isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri))
|
|
142
|
+
if (cache.mainCompletion && (!service[1].isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri))
|
|
136
143
|
continue;
|
|
137
144
|
// avoid duplicate items with .vue and .vue.html
|
|
138
|
-
if (service.isAdditionalCompletion && cache?.data.some(data => data.service === service))
|
|
145
|
+
if (service[1].isAdditionalCompletion && cache?.data.some(data => data.service === service[1]))
|
|
139
146
|
continue;
|
|
140
|
-
const completionList = await service.provideCompletionItems(document, position, completionContext, token);
|
|
147
|
+
const completionList = await service[1].provideCompletionItems(document, position, completionContext, token);
|
|
141
148
|
if (!completionList || !completionList.items.length)
|
|
142
149
|
continue;
|
|
143
|
-
if (!service.isAdditionalCompletion) {
|
|
150
|
+
if (!service[1].isAdditionalCompletion) {
|
|
144
151
|
cache.mainCompletion = { documentUri: document.uri };
|
|
145
152
|
}
|
|
146
153
|
completionList.items.forEach(item => {
|
|
@@ -151,13 +158,14 @@ function register(context) {
|
|
|
151
158
|
textEdit: item.textEdit,
|
|
152
159
|
data: item.data,
|
|
153
160
|
},
|
|
154
|
-
|
|
161
|
+
serviceIndex: context.services.indexOf(service),
|
|
155
162
|
virtualDocumentUri: undefined,
|
|
156
163
|
};
|
|
157
164
|
});
|
|
158
165
|
cache.data.push({
|
|
159
166
|
virtualDocumentUri: undefined,
|
|
160
|
-
service: service,
|
|
167
|
+
service: service[1],
|
|
168
|
+
serviceIndex: context.services.indexOf(service),
|
|
161
169
|
list: completionList,
|
|
162
170
|
});
|
|
163
171
|
}
|
|
@@ -177,4 +185,4 @@ function register(context) {
|
|
|
177
185
|
};
|
|
178
186
|
}
|
|
179
187
|
exports.register = register;
|
|
180
|
-
//# sourceMappingURL=
|
|
188
|
+
//# sourceMappingURL=provideCompletionItems.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CodeInformation } from '@volar/language-core';
|
|
2
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
+
import type { ServiceContext } from '../types';
|
|
4
|
+
export declare function register(context: ServiceContext, apiName: 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidPosition: (data: CodeInformation) => boolean): (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = void 0;
|
|
4
|
-
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
5
|
-
const dedupe = require("../utils/dedupe");
|
|
6
|
-
const common_1 = require("../utils/common");
|
|
7
4
|
const cancellation_1 = require("../utils/cancellation");
|
|
8
|
-
|
|
5
|
+
const common_1 = require("../utils/common");
|
|
6
|
+
const dedupe = require("../utils/dedupe");
|
|
7
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
8
|
+
function register(context, apiName, isValidPosition) {
|
|
9
9
|
return (uri, position, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
-
return (0, featureWorkers_1.languageFeatureWorker)(context, uri,
|
|
11
|
-
if (token.isCancellationRequested)
|
|
10
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, map => map.getGeneratedPositions(position, isValidPosition), async (service, document, position) => {
|
|
11
|
+
if (token.isCancellationRequested) {
|
|
12
12
|
return;
|
|
13
|
+
}
|
|
13
14
|
const recursiveChecker = dedupe.createLocationSet();
|
|
14
15
|
const result = [];
|
|
15
16
|
await withMirrors(document, position, undefined);
|
|
16
17
|
return result;
|
|
17
18
|
async function withMirrors(document, position, originDefinition) {
|
|
18
|
-
const api = service[apiName];
|
|
19
|
+
const api = service[1][apiName];
|
|
19
20
|
if (!api)
|
|
20
21
|
return;
|
|
21
22
|
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } }))
|
|
@@ -25,15 +26,14 @@ function register(context, apiName, isValidMapping, isValidMirrorPosition) {
|
|
|
25
26
|
for (const definition of definitions) {
|
|
26
27
|
let foundMirrorPosition = false;
|
|
27
28
|
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
|
|
28
|
-
const
|
|
29
|
+
const [virtualFile] = context.language.files.getVirtualFile(definition.targetUri);
|
|
30
|
+
const mirrorMap = virtualFile ? context.documents.getLinkedCodeMap(virtualFile) : undefined;
|
|
29
31
|
if (mirrorMap) {
|
|
30
|
-
for (const
|
|
31
|
-
if (
|
|
32
|
-
continue;
|
|
33
|
-
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } }))
|
|
32
|
+
for (const linkedPos of mirrorMap.getLinkedCodePositions(definition.targetSelectionRange.start)) {
|
|
33
|
+
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: linkedPos, end: linkedPos } }))
|
|
34
34
|
continue;
|
|
35
35
|
foundMirrorPosition = true;
|
|
36
|
-
await withMirrors(mirrorMap.document,
|
|
36
|
+
await withMirrors(mirrorMap.document, linkedPos, originDefinition ?? definition);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
if (!foundMirrorPosition) {
|
|
@@ -49,43 +49,46 @@ function register(context, apiName, isValidMapping, isValidMirrorPosition) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
}, (data,
|
|
53
|
-
if (link.originSelectionRange &&
|
|
54
|
-
const originSelectionRange = toSourcePositionPreferSurroundedPosition(
|
|
52
|
+
}, (data, map) => data.map(link => {
|
|
53
|
+
if (link.originSelectionRange && map) {
|
|
54
|
+
const originSelectionRange = toSourcePositionPreferSurroundedPosition(map, link.originSelectionRange, position);
|
|
55
55
|
if (!originSelectionRange)
|
|
56
56
|
return;
|
|
57
57
|
link.originSelectionRange = originSelectionRange;
|
|
58
58
|
}
|
|
59
59
|
let foundTargetSelectionRange = false;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
const [targetVirtualFile] = context.language.files.getVirtualFile(link.targetUri);
|
|
61
|
+
if (targetVirtualFile) {
|
|
62
|
+
for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
|
|
63
|
+
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
|
|
64
|
+
if (!targetSelectionRange)
|
|
65
|
+
continue;
|
|
66
|
+
foundTargetSelectionRange = true;
|
|
67
|
+
let targetRange = targetSourceMap.getSourceRange(link.targetRange);
|
|
68
|
+
link.targetUri = targetSourceMap.sourceFileDocument.uri;
|
|
69
|
+
// loose range mapping to for template slots, slot properties
|
|
70
|
+
link.targetRange = targetRange ?? targetSelectionRange;
|
|
71
|
+
link.targetSelectionRange = targetSelectionRange;
|
|
72
|
+
}
|
|
73
|
+
if (apiName === 'provideDefinition' && !foundTargetSelectionRange) {
|
|
74
|
+
for (const targetMap of context.documents.getMaps(targetVirtualFile)) {
|
|
75
|
+
if (targetMap && targetMap.sourceFileDocument.uri !== uri) {
|
|
76
|
+
return {
|
|
77
|
+
...link,
|
|
78
|
+
targetUri: targetMap.sourceFileDocument.uri,
|
|
79
|
+
targetRange: {
|
|
80
|
+
start: { line: 0, character: 0 },
|
|
81
|
+
end: { line: 0, character: 0 },
|
|
82
|
+
},
|
|
83
|
+
targetSelectionRange: {
|
|
84
|
+
start: { line: 0, character: 0 },
|
|
85
|
+
end: { line: 0, character: 0 },
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
86
89
|
}
|
|
90
|
+
return;
|
|
87
91
|
}
|
|
88
|
-
return;
|
|
89
92
|
}
|
|
90
93
|
return link;
|
|
91
94
|
}).filter(common_1.notEmpty), arr => dedupe.withLocationLinks(arr.flat()));
|
|
@@ -94,7 +97,7 @@ function register(context, apiName, isValidMapping, isValidMirrorPosition) {
|
|
|
94
97
|
exports.register = register;
|
|
95
98
|
function toSourcePositionPreferSurroundedPosition(map, mappedRange, position) {
|
|
96
99
|
let result;
|
|
97
|
-
for (const range of map.
|
|
100
|
+
for (const range of map.getSourceRanges(mappedRange)) {
|
|
98
101
|
if (!result) {
|
|
99
102
|
result = range;
|
|
100
103
|
}
|
|
@@ -105,4 +108,4 @@ function toSourcePositionPreferSurroundedPosition(map, mappedRange, position) {
|
|
|
105
108
|
}
|
|
106
109
|
return result;
|
|
107
110
|
}
|
|
108
|
-
//# sourceMappingURL=
|
|
111
|
+
//# sourceMappingURL=provideDefinition.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import { ServiceContext } from '../types';
|
|
2
|
+
import type { ServiceContext } from '../types';
|
|
3
3
|
export declare function updateRange(range: vscode.Range, change: {
|
|
4
4
|
range: vscode.Range;
|
|
5
5
|
newEnd: vscode.Position;
|
|
@@ -8,9 +8,8 @@ export interface ServiceDiagnosticData {
|
|
|
8
8
|
uri: string;
|
|
9
9
|
version: number;
|
|
10
10
|
original: Pick<vscode.Diagnostic, 'data'>;
|
|
11
|
-
type: 'service' | 'rule';
|
|
12
11
|
isFormat: boolean;
|
|
13
|
-
|
|
12
|
+
serviceIndex: number;
|
|
14
13
|
ruleFixIndex: number;
|
|
15
14
|
documentUri: string;
|
|
16
15
|
}
|
|
@@ -19,4 +18,3 @@ export declare const errorMarkups: Record<string, {
|
|
|
19
18
|
markup: vscode.MarkupContent;
|
|
20
19
|
}[]>;
|
|
21
20
|
export declare function register(context: ServiceContext): (uri: string, mode: 'all' | 'semantic' | 'syntactic', token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
22
|
-
//# sourceMappingURL=validation.d.ts.map
|