@volar/language-service 1.4.0-alpha.0 → 1.4.0-alpha.1
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/out/baseLanguageService.d.ts +1 -1
- package/out/baseLanguageService.js +20 -16
- package/out/documentFeatures/colorPresentations.js +1 -2
- package/out/documentFeatures/documentColors.js +1 -2
- package/out/documentFeatures/documentSymbols.js +4 -15
- package/out/documentFeatures/foldingRanges.js +1 -2
- package/out/documentFeatures/format.js +29 -42
- package/out/documentFeatures/linkedEditingRanges.js +1 -2
- package/out/documentFeatures/selectionRanges.js +1 -2
- package/out/documents.js +1 -2
- package/out/languageFeatures/autoInsert.js +7 -6
- package/out/languageFeatures/callHierarchy.js +63 -72
- package/out/languageFeatures/codeActionResolve.js +9 -19
- package/out/languageFeatures/codeActions.js +22 -28
- package/out/languageFeatures/codeLens.js +16 -24
- package/out/languageFeatures/codeLensResolve.js +7 -17
- package/out/languageFeatures/complete.js +20 -32
- package/out/languageFeatures/completeResolve.js +5 -15
- package/out/languageFeatures/definition.js +35 -44
- package/out/languageFeatures/documentHighlights.js +30 -39
- package/out/languageFeatures/documentLinks.js +9 -17
- package/out/languageFeatures/documentSemanticTokens.js +6 -16
- package/out/languageFeatures/fileReferences.js +3 -13
- package/out/languageFeatures/fileRename.js +5 -15
- package/out/languageFeatures/hover.js +5 -9
- package/out/languageFeatures/inlayHints.js +13 -19
- package/out/languageFeatures/references.js +26 -38
- package/out/languageFeatures/rename.js +54 -68
- package/out/languageFeatures/renamePrepare.js +1 -2
- package/out/languageFeatures/signatureHelp.js +6 -7
- package/out/languageFeatures/validation.js +134 -152
- package/out/languageFeatures/workspaceSymbols.js +3 -12
- package/out/transformer/completionItem.js +8 -3
- package/out/transformer/completionList.js +6 -3
- package/out/transformer/documentSymbol.js +8 -3
- package/out/transformer/foldingRanges.js +2 -3
- package/out/transformer/hover.js +5 -2
- package/out/transformer/locationLike.js +4 -1
- package/out/transformer/textEdit.js +20 -5
- package/out/transformer/workspaceSymbol.js +4 -1
- package/out/types.d.ts +3 -3
- package/out/utils/definePlugin.js +11 -23
- package/out/utils/featureWorkers.js +126 -146
- package/package.json +4 -4
|
@@ -17,7 +17,7 @@ export declare function createLanguageService(ctx: LanguageServiceOptions, docum
|
|
|
17
17
|
findDocumentSymbols: (uri: string, token: _.CancellationToken) => Promise<_.DocumentSymbol[] | undefined>;
|
|
18
18
|
findDocumentColors: (uri: string, token: _.CancellationToken) => Promise<_.ColorInformation[] | undefined>;
|
|
19
19
|
getColorPresentations: (uri: string, color: _.Color, range: _.Range, token: _.CancellationToken) => Promise<_.ColorPresentation[] | undefined>;
|
|
20
|
-
doValidation: (uri: string, token: _.CancellationToken, mode: "
|
|
20
|
+
doValidation: (uri: string, token: _.CancellationToken, mode: "semantic" | "all" | "syntactic", response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>;
|
|
21
21
|
findReferences: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.Location[] | undefined>;
|
|
22
22
|
findFileReferences: (uri: string, token: _.CancellationToken) => import("./types").NullableResult<_.Location[]>;
|
|
23
23
|
findDefinition: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.LocationLink[] | undefined>;
|
|
@@ -35,29 +35,34 @@ const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
|
|
|
35
35
|
const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
36
36
|
const common_1 = require("./utils/common");
|
|
37
37
|
function createLanguageService(ctx, documentRegistry) {
|
|
38
|
-
|
|
39
|
-
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(common_1.notEmpty));
|
|
38
|
+
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values(ctx.config.languages ?? {}).filter(common_1.notEmpty));
|
|
40
39
|
const context = createLanguageServiceContext(ctx, languageContext, documentRegistry);
|
|
41
40
|
return createLanguageServiceBase(context);
|
|
42
41
|
}
|
|
43
42
|
exports.createLanguageService = createLanguageService;
|
|
44
43
|
function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
|
|
44
|
+
const ts = ctx.host.getTypeScriptModule?.();
|
|
45
|
+
const tsLs = ts?.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
|
|
48
46
|
if (ts && tsLs) {
|
|
49
47
|
tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs);
|
|
50
48
|
}
|
|
51
49
|
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(ctx, languageContext.virtualFiles);
|
|
52
50
|
const documents = new WeakMap();
|
|
53
51
|
const documentVersions = new Map();
|
|
54
|
-
const context =
|
|
52
|
+
const context = {
|
|
53
|
+
...ctx,
|
|
54
|
+
core: languageContext,
|
|
55
|
+
plugins: {},
|
|
56
|
+
typescript: ts && tsLs ? {
|
|
55
57
|
module: ts,
|
|
56
58
|
languageServiceHost: languageContext.typescript.languageServiceHost,
|
|
57
59
|
languageService: tsLs,
|
|
58
|
-
} : undefined,
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
} : undefined,
|
|
61
|
+
documents: textDocumentMapper,
|
|
62
|
+
getTextDocument,
|
|
63
|
+
};
|
|
64
|
+
for (const pluginId in ctx.config.plugins ?? {}) {
|
|
65
|
+
const plugin = ctx.config.plugins?.[pluginId];
|
|
61
66
|
if (plugin instanceof Function) {
|
|
62
67
|
const _plugin = plugin(context);
|
|
63
68
|
context.plugins[pluginId] = _plugin;
|
|
@@ -68,13 +73,12 @@ function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
|
|
|
68
73
|
}
|
|
69
74
|
return context;
|
|
70
75
|
function getTextDocument(uri) {
|
|
71
|
-
var _a;
|
|
72
76
|
const fileName = ctx.uriToFileName(uri);
|
|
73
77
|
const scriptSnapshot = ctx.host.getScriptSnapshot(fileName);
|
|
74
78
|
if (scriptSnapshot) {
|
|
75
79
|
let document = documents.get(scriptSnapshot);
|
|
76
80
|
if (!document) {
|
|
77
|
-
const newVersion = (
|
|
81
|
+
const newVersion = (documentVersions.get(uri.toLowerCase()) ?? 0) + 1;
|
|
78
82
|
documentVersions.set(uri.toLowerCase(), newVersion);
|
|
79
83
|
document = vscode_languageserver_textdocument_1.TextDocument.create(uri, (0, common_1.syntaxToLanguageId)(uri.substring(uri.lastIndexOf('.') + 1)), newVersion, scriptSnapshot.getText(0, scriptSnapshot.getLength()));
|
|
80
84
|
documents.set(scriptSnapshot, document);
|
|
@@ -85,10 +89,10 @@ function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
|
|
|
85
89
|
}
|
|
86
90
|
function createLanguageServiceBase(context) {
|
|
87
91
|
return {
|
|
88
|
-
triggerCharacters: Object.values(context.plugins).map(plugin =>
|
|
89
|
-
autoFormatTriggerCharacters: Object.values(context.plugins).map(plugin =>
|
|
90
|
-
signatureHelpTriggerCharacters: Object.values(context.plugins).map(plugin =>
|
|
91
|
-
signatureHelpRetriggerCharacters: Object.values(context.plugins).map(plugin =>
|
|
92
|
+
triggerCharacters: Object.values(context.plugins).map(plugin => plugin?.triggerCharacters ?? []).flat(),
|
|
93
|
+
autoFormatTriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.autoFormatTriggerCharacters ?? []).flat(),
|
|
94
|
+
signatureHelpTriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.signatureHelpTriggerCharacters ?? []).flat(),
|
|
95
|
+
signatureHelpRetriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.signatureHelpRetriggerCharacters ?? []).flat(),
|
|
92
96
|
format: format.register(context),
|
|
93
97
|
getFoldingRanges: foldingRanges.register(context),
|
|
94
98
|
getSelectionRanges: selectionRanges.register(context),
|
|
@@ -120,7 +124,7 @@ function createLanguageServiceBase(context) {
|
|
|
120
124
|
doAutoInsert: autoInsert.register(context),
|
|
121
125
|
getInlayHints: inlayHints.register(context),
|
|
122
126
|
callHierarchy: callHierarchy.register(context),
|
|
123
|
-
dispose: () =>
|
|
127
|
+
dispose: () => context.typescript?.languageService.dispose(),
|
|
124
128
|
context,
|
|
125
129
|
};
|
|
126
130
|
}
|
|
@@ -9,10 +9,9 @@ function register(context) {
|
|
|
9
9
|
return map.toGeneratedRanges(range);
|
|
10
10
|
return [];
|
|
11
11
|
}, (plugin, document, range) => {
|
|
12
|
-
var _a;
|
|
13
12
|
if (token.isCancellationRequested)
|
|
14
13
|
return;
|
|
15
|
-
return
|
|
14
|
+
return plugin.provideColorPresentations?.(document, color, range, token);
|
|
16
15
|
}, (data, map) => map ? data.map(cp => {
|
|
17
16
|
if (cp.textEdit) {
|
|
18
17
|
const range = map.toSourceRange(cp.textEdit.range);
|
|
@@ -7,10 +7,9 @@ function register(context) {
|
|
|
7
7
|
return (uri, token) => {
|
|
8
8
|
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, // TODO: add color capability setting
|
|
9
9
|
(plugin, document) => {
|
|
10
|
-
var _a;
|
|
11
10
|
if (token.isCancellationRequested)
|
|
12
11
|
return;
|
|
13
|
-
return
|
|
12
|
+
return plugin.provideDocumentColors?.(document, token);
|
|
14
13
|
}, (data, map) => map ? data.map(color => {
|
|
15
14
|
const range = map.toSourceRange(color.range);
|
|
16
15
|
if (range) {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
@@ -14,12 +5,11 @@ const transformer = require("../transformer");
|
|
|
14
5
|
const common_1 = require("../utils/common");
|
|
15
6
|
function register(context) {
|
|
16
7
|
return (uri, token) => {
|
|
17
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) =>
|
|
18
|
-
var _a;
|
|
8
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, async (plugin, document) => {
|
|
19
9
|
if (token.isCancellationRequested)
|
|
20
10
|
return;
|
|
21
|
-
return
|
|
22
|
-
}
|
|
11
|
+
return plugin.provideDocumentSymbols?.(document, token);
|
|
12
|
+
}, (data, map) => map
|
|
23
13
|
? data
|
|
24
14
|
.map(symbol => transformer.asDocumentSymbol(symbol, range => map.toSourceRange(range)))
|
|
25
15
|
.filter(common_1.notEmpty)
|
|
@@ -29,10 +19,9 @@ function register(context) {
|
|
|
29
19
|
if (i === j)
|
|
30
20
|
continue;
|
|
31
21
|
results[i] = results[i].filter(child => {
|
|
32
|
-
var _a;
|
|
33
22
|
for (const parent of results[j]) {
|
|
34
23
|
if ((0, common_1.isInsideRange)(parent.range, child.range)) {
|
|
35
|
-
|
|
24
|
+
parent.children ??= [];
|
|
36
25
|
parent.children.push(child);
|
|
37
26
|
return false;
|
|
38
27
|
}
|
|
@@ -5,10 +5,9 @@ const transformer = require("../transformer");
|
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (uri, token) => {
|
|
7
7
|
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => {
|
|
8
|
-
var _a;
|
|
9
8
|
if (token.isCancellationRequested)
|
|
10
9
|
return;
|
|
11
|
-
return
|
|
10
|
+
return plugin.provideFoldingRanges?.(document, token);
|
|
12
11
|
}, (data, map) => map ? transformer.asFoldingRanges(data, range => map.toSourceRange(range)) : data, arr => arr.flat());
|
|
13
12
|
};
|
|
14
13
|
}
|
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const vscode = require("vscode-languageserver-protocol");
|
|
13
4
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
14
5
|
const common_1 = require("../utils/common");
|
|
15
6
|
function register(context) {
|
|
16
|
-
return (uri, options, range, onTypeParams, token) =>
|
|
17
|
-
var _a, _b, _c;
|
|
7
|
+
return async (uri, options, range, onTypeParams, token) => {
|
|
18
8
|
let document = context.getTextDocument(uri);
|
|
19
9
|
if (!document)
|
|
20
10
|
return;
|
|
21
|
-
range
|
|
11
|
+
range ??= vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length));
|
|
22
12
|
const source = context.documents.getSourceByUri(document.uri);
|
|
23
13
|
if (!source) {
|
|
24
14
|
return onTypeParams
|
|
25
|
-
?
|
|
26
|
-
:
|
|
15
|
+
? await tryFormat(document, onTypeParams.position, onTypeParams.ch)
|
|
16
|
+
: await tryFormat(document, range, undefined);
|
|
27
17
|
}
|
|
28
|
-
const initialIndentLanguageId =
|
|
18
|
+
const initialIndentLanguageId = await context.configurationHost?.getConfiguration('volar.format.initialIndent') ?? { html: true };
|
|
29
19
|
const originalSnapshot = source.snapshot;
|
|
30
20
|
const rootVirtualFile = source.root;
|
|
31
21
|
const originalDocument = document;
|
|
@@ -44,18 +34,18 @@ function register(context) {
|
|
|
44
34
|
if (onTypeParams && !isCodeBlock)
|
|
45
35
|
continue;
|
|
46
36
|
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
|
|
47
|
-
const map =
|
|
37
|
+
const map = maps.find(map => map[1].sourceFileDocument.uri === document.uri)?.[1];
|
|
48
38
|
if (!map)
|
|
49
39
|
continue;
|
|
50
40
|
let virtualCodeEdits;
|
|
51
41
|
if (onTypeParams) {
|
|
52
42
|
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
53
43
|
if (embeddedPosition) {
|
|
54
|
-
virtualCodeEdits =
|
|
44
|
+
virtualCodeEdits = await tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
55
45
|
}
|
|
56
46
|
}
|
|
57
47
|
else {
|
|
58
|
-
virtualCodeEdits =
|
|
48
|
+
virtualCodeEdits = await tryFormat(map.virtualFileDocument, {
|
|
59
49
|
start: map.virtualFileDocument.positionAt(0),
|
|
60
50
|
end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
|
|
61
51
|
});
|
|
@@ -100,7 +90,7 @@ function register(context) {
|
|
|
100
90
|
if (token.isCancellationRequested)
|
|
101
91
|
break;
|
|
102
92
|
if (plugin.provideFormattingIndentSensitiveLines) {
|
|
103
|
-
const lines =
|
|
93
|
+
const lines = await plugin.provideFormattingIndentSensitiveLines(map.virtualFileDocument, token);
|
|
104
94
|
if (lines) {
|
|
105
95
|
for (const line of lines) {
|
|
106
96
|
indentSensitiveLines.add(line);
|
|
@@ -154,34 +144,31 @@ function register(context) {
|
|
|
154
144
|
embeddedFilesByLevel.push(nextLevel);
|
|
155
145
|
}
|
|
156
146
|
}
|
|
157
|
-
function tryFormat(document, range, ch) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if ((_a = plugin.autoFormatTriggerCharacters) === null || _a === void 0 ? void 0 : _a.includes(ch)) {
|
|
168
|
-
edits = yield ((_b = plugin.provideOnTypeFormattingEdits) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, ch, options, token));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else if (ch === undefined && vscode.Range.is(formatRange)) {
|
|
172
|
-
edits = yield ((_c = plugin.provideDocumentFormattingEdits) === null || _c === void 0 ? void 0 : _c.call(plugin, document, formatRange, options, token));
|
|
147
|
+
async function tryFormat(document, range, ch) {
|
|
148
|
+
let formatRange = range;
|
|
149
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
150
|
+
if (token.isCancellationRequested)
|
|
151
|
+
break;
|
|
152
|
+
let edits;
|
|
153
|
+
try {
|
|
154
|
+
if (ch !== undefined && vscode.Position.is(formatRange)) {
|
|
155
|
+
if (plugin.autoFormatTriggerCharacters?.includes(ch)) {
|
|
156
|
+
edits = await plugin.provideOnTypeFormattingEdits?.(document, formatRange, ch, options, token);
|
|
173
157
|
}
|
|
174
158
|
}
|
|
175
|
-
|
|
176
|
-
|
|
159
|
+
else if (ch === undefined && vscode.Range.is(formatRange)) {
|
|
160
|
+
edits = await plugin.provideDocumentFormattingEdits?.(document, formatRange, options, token);
|
|
177
161
|
}
|
|
178
|
-
if (!edits)
|
|
179
|
-
continue;
|
|
180
|
-
return edits;
|
|
181
162
|
}
|
|
182
|
-
|
|
163
|
+
catch (err) {
|
|
164
|
+
console.warn(err);
|
|
165
|
+
}
|
|
166
|
+
if (!edits)
|
|
167
|
+
continue;
|
|
168
|
+
return edits;
|
|
169
|
+
}
|
|
183
170
|
}
|
|
184
|
-
}
|
|
171
|
+
};
|
|
185
172
|
}
|
|
186
173
|
exports.register = register;
|
|
187
174
|
function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
@@ -5,10 +5,9 @@ const common_1 = require("../utils/common");
|
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (uri, position, token) => {
|
|
7
7
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => {
|
|
8
|
-
var _a;
|
|
9
8
|
if (token.isCancellationRequested)
|
|
10
9
|
return;
|
|
11
|
-
return
|
|
10
|
+
return plugin.provideLinkedEditingRanges?.(document, position, token);
|
|
12
11
|
}, (data, map) => map ? ({
|
|
13
12
|
wordPattern: data.wordPattern,
|
|
14
13
|
ranges: data.ranges.map(range => map.toSourceRange(range)).filter(common_1.notEmpty),
|
|
@@ -16,10 +16,9 @@ function register(context) {
|
|
|
16
16
|
}
|
|
17
17
|
return [];
|
|
18
18
|
}, (plugin, document, positions) => {
|
|
19
|
-
var _a;
|
|
20
19
|
if (token.isCancellationRequested)
|
|
21
20
|
return;
|
|
22
|
-
return
|
|
21
|
+
return plugin.provideSelectionRanges?.(document, positions, token);
|
|
23
22
|
}, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => {
|
|
24
23
|
for (let i = 0; i < results[0].length; i++) {
|
|
25
24
|
const first = results[0][i];
|
package/out/documents.js
CHANGED
|
@@ -176,12 +176,11 @@ function createDocumentsAndSourceMaps(ctx, mapper) {
|
|
|
176
176
|
return this.getMapsByVirtualFileName(ctx.uriToFileName(virtualFileUri));
|
|
177
177
|
},
|
|
178
178
|
*getMapsByVirtualFileName(virtualFileName) {
|
|
179
|
-
var _a;
|
|
180
179
|
const [virtualFile] = mapper.getVirtualFile(virtualFileName);
|
|
181
180
|
if (virtualFile) {
|
|
182
181
|
for (const [sourceFileName, map] of mapper.getMaps(virtualFile)) {
|
|
183
182
|
if (!_maps.has(map)) {
|
|
184
|
-
const sourceSnapshot =
|
|
183
|
+
const sourceSnapshot = mapper.getSource(sourceFileName)?.snapshot;
|
|
185
184
|
if (sourceSnapshot) {
|
|
186
185
|
_maps.set(map, [virtualFile, new SourceMapWithDocuments(getDocumentByFileName(sourceSnapshot, sourceFileName), getDocumentByFileName(virtualFile.snapshot, virtualFileName), map)]);
|
|
187
186
|
}
|
|
@@ -4,26 +4,27 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
4
4
|
function register(context) {
|
|
5
5
|
return (uri, position, autoInsertContext, token) => {
|
|
6
6
|
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, map) {
|
|
7
|
-
var _a;
|
|
8
7
|
for (const position of map.toGeneratedPositions(arg.position, data => !!data.completion)) {
|
|
9
|
-
const rangeOffset =
|
|
8
|
+
const rangeOffset = map.map.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)?.[0];
|
|
10
9
|
const range = map.toGeneratedRange(arg.autoInsertContext.lastChange.range);
|
|
11
10
|
if (rangeOffset !== undefined && range) {
|
|
12
11
|
yield {
|
|
13
12
|
position,
|
|
14
13
|
autoInsertContext: {
|
|
15
|
-
lastChange:
|
|
16
|
-
|
|
14
|
+
lastChange: {
|
|
15
|
+
...arg.autoInsertContext.lastChange,
|
|
16
|
+
rangeOffset,
|
|
17
|
+
range,
|
|
18
|
+
},
|
|
17
19
|
},
|
|
18
20
|
};
|
|
19
21
|
break;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
}, (plugin, document, arg) => {
|
|
23
|
-
var _a;
|
|
24
25
|
if (token.isCancellationRequested)
|
|
25
26
|
return;
|
|
26
|
-
return
|
|
27
|
+
return plugin.provideAutoInsertionEdit?.(document, arg.position, arg.autoInsertContext, token);
|
|
27
28
|
}, (item, map) => {
|
|
28
29
|
if (!map || typeof item === 'string')
|
|
29
30
|
return item;
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const path_1 = require("path");
|
|
@@ -16,12 +7,11 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
16
7
|
function register(context) {
|
|
17
8
|
return {
|
|
18
9
|
doPrepare(uri, position, token) {
|
|
19
|
-
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) =>
|
|
20
|
-
var _a;
|
|
10
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), async (plugin, document, position, map) => {
|
|
21
11
|
if (token.isCancellationRequested)
|
|
22
12
|
return;
|
|
23
|
-
const items =
|
|
24
|
-
items
|
|
13
|
+
const items = await plugin.provideCallHierarchyItems?.(document, position, token);
|
|
14
|
+
items?.forEach(item => {
|
|
25
15
|
item.data = {
|
|
26
16
|
uri,
|
|
27
17
|
original: {
|
|
@@ -34,35 +24,21 @@ function register(context) {
|
|
|
34
24
|
};
|
|
35
25
|
});
|
|
36
26
|
return items;
|
|
37
|
-
}
|
|
38
|
-
.map(item =>
|
|
27
|
+
}, (data, sourceMap) => !sourceMap ? data : data
|
|
28
|
+
.map(item => transformCallHierarchyItem(item, [])?.[0])
|
|
39
29
|
.filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat()));
|
|
40
30
|
},
|
|
41
|
-
getIncomingCalls(item, token) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (data.map) {
|
|
51
|
-
|
|
52
|
-
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
|
|
53
|
-
for (const _call of _calls) {
|
|
54
|
-
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
55
|
-
if (!calls)
|
|
56
|
-
continue;
|
|
57
|
-
incomingItems.push({
|
|
58
|
-
from: calls[0],
|
|
59
|
-
fromRanges: calls[1],
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token);
|
|
31
|
+
async getIncomingCalls(item, token) {
|
|
32
|
+
const data = item.data;
|
|
33
|
+
let incomingItems = [];
|
|
34
|
+
if (data) {
|
|
35
|
+
const plugin = context.plugins[data.pluginId];
|
|
36
|
+
if (!plugin.provideCallHierarchyIncomingCalls)
|
|
37
|
+
return incomingItems;
|
|
38
|
+
Object.assign(item, data.original);
|
|
39
|
+
if (data.map) {
|
|
40
|
+
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
41
|
+
const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token);
|
|
66
42
|
for (const _call of _calls) {
|
|
67
43
|
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
68
44
|
if (!calls)
|
|
@@ -74,34 +50,32 @@ function register(context) {
|
|
|
74
50
|
}
|
|
75
51
|
}
|
|
76
52
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return items;
|
|
88
|
-
Object.assign(item, data.original);
|
|
89
|
-
if (data.map) {
|
|
90
|
-
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
91
|
-
const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token);
|
|
92
|
-
for (const call of _calls) {
|
|
93
|
-
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
94
|
-
if (!calls)
|
|
95
|
-
continue;
|
|
96
|
-
items.push({
|
|
97
|
-
to: calls[0],
|
|
98
|
-
fromRanges: calls[1],
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
53
|
+
else {
|
|
54
|
+
const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token);
|
|
55
|
+
for (const _call of _calls) {
|
|
56
|
+
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
|
|
57
|
+
if (!calls)
|
|
58
|
+
continue;
|
|
59
|
+
incomingItems.push({
|
|
60
|
+
from: calls[0],
|
|
61
|
+
fromRanges: calls[1],
|
|
62
|
+
});
|
|
102
63
|
}
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return dedupe.withCallHierarchyIncomingCalls(incomingItems);
|
|
67
|
+
},
|
|
68
|
+
async getOutgoingCalls(item, token) {
|
|
69
|
+
const data = item.data;
|
|
70
|
+
let items = [];
|
|
71
|
+
if (data) {
|
|
72
|
+
const plugin = context.plugins[data.pluginId];
|
|
73
|
+
if (!plugin.provideCallHierarchyOutgoingCalls)
|
|
74
|
+
return items;
|
|
75
|
+
Object.assign(item, data.original);
|
|
76
|
+
if (data.map) {
|
|
77
|
+
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
78
|
+
const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token);
|
|
105
79
|
for (const call of _calls) {
|
|
106
80
|
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
107
81
|
if (!calls)
|
|
@@ -113,8 +87,20 @@ function register(context) {
|
|
|
113
87
|
}
|
|
114
88
|
}
|
|
115
89
|
}
|
|
116
|
-
|
|
117
|
-
|
|
90
|
+
else {
|
|
91
|
+
const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token);
|
|
92
|
+
for (const call of _calls) {
|
|
93
|
+
const calls = transformCallHierarchyItem(call.to, call.fromRanges);
|
|
94
|
+
if (!calls)
|
|
95
|
+
continue;
|
|
96
|
+
items.push({
|
|
97
|
+
to: calls[0],
|
|
98
|
+
fromRanges: calls[1],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return dedupe.withCallHierarchyOutgoingCalls(items);
|
|
118
104
|
},
|
|
119
105
|
};
|
|
120
106
|
function transformCallHierarchyItem(tsItem, tsRanges) {
|
|
@@ -133,15 +119,20 @@ function register(context) {
|
|
|
133
119
|
if (!selectionRange)
|
|
134
120
|
continue;
|
|
135
121
|
const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(common_1.notEmpty);
|
|
136
|
-
const vueItem =
|
|
122
|
+
const vueItem = {
|
|
123
|
+
...tsItem,
|
|
124
|
+
name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name,
|
|
125
|
+
uri: map.sourceFileDocument.uri,
|
|
137
126
|
// TS Bug: `range: range` not works
|
|
138
127
|
range: {
|
|
139
128
|
start: range.start,
|
|
140
129
|
end: range.end,
|
|
141
|
-
},
|
|
130
|
+
},
|
|
131
|
+
selectionRange: {
|
|
142
132
|
start: selectionRange.start,
|
|
143
133
|
end: selectionRange.end,
|
|
144
|
-
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
145
136
|
selectionRange.end;
|
|
146
137
|
return [vueItem, vueRanges];
|
|
147
138
|
}
|
|
@@ -1,36 +1,26 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const rename_1 = require("./rename");
|
|
13
4
|
function register(context) {
|
|
14
|
-
return (item, token) =>
|
|
15
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5
|
+
return async (item, token) => {
|
|
16
6
|
const data = item.data;
|
|
17
|
-
if (
|
|
7
|
+
if (data?.type === 'plugin') {
|
|
18
8
|
const plugin = context.plugins[data.pluginId];
|
|
19
9
|
if (!plugin.resolveCodeAction)
|
|
20
10
|
return item;
|
|
21
11
|
Object.assign(item, data.original);
|
|
22
|
-
item =
|
|
12
|
+
item = await plugin.resolveCodeAction(item, token);
|
|
23
13
|
if (item.edit) {
|
|
24
14
|
item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version });
|
|
25
15
|
}
|
|
26
16
|
}
|
|
27
|
-
if (
|
|
28
|
-
const fixes =
|
|
29
|
-
const fix = fixes
|
|
17
|
+
if (data?.type === 'rule') {
|
|
18
|
+
const fixes = context.ruleFixes?.[data.documentUri]?.[data.ruleId]?.[data.ruleFixIndex];
|
|
19
|
+
const fix = fixes?.[1][data.index];
|
|
30
20
|
if (fix) {
|
|
31
|
-
let edit =
|
|
21
|
+
let edit = await fix.getWorkspaceEdit?.(fixes[0]) ?? undefined;
|
|
32
22
|
if (!edit) {
|
|
33
|
-
const edits =
|
|
23
|
+
const edits = await fix.getEdits?.(fixes[0]);
|
|
34
24
|
if (edits) {
|
|
35
25
|
edit = {
|
|
36
26
|
documentChanges: [{
|
|
@@ -49,7 +39,7 @@ function register(context) {
|
|
|
49
39
|
}
|
|
50
40
|
}
|
|
51
41
|
return item;
|
|
52
|
-
}
|
|
42
|
+
};
|
|
53
43
|
}
|
|
54
44
|
exports.register = register;
|
|
55
45
|
//# sourceMappingURL=codeActionResolve.js.map
|