@volar/language-service 1.0.22 → 1.1.0-1.2.0-alpha.1.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/out/baseLanguageService.d.ts +3 -11
- package/out/baseLanguageService.js +34 -24
- package/out/documentFeatures/documentSymbols.js +3 -5
- package/out/documentFeatures/foldingRanges.js +2 -2
- package/out/documentFeatures/format.js +7 -7
- package/out/documentFeatures/selectionRanges.js +2 -2
- package/out/documents.d.ts +3 -3
- package/out/documents.js +17 -24
- package/out/index.d.ts +1 -0
- package/out/index.js +2 -1
- package/out/languageFeatures/callHierarchy.d.ts +2 -2
- package/out/languageFeatures/callHierarchy.js +18 -21
- package/out/languageFeatures/codeActionResolve.js +4 -6
- package/out/languageFeatures/codeActions.d.ts +2 -2
- package/out/languageFeatures/codeActions.js +14 -7
- package/out/languageFeatures/codeLens.d.ts +4 -4
- package/out/languageFeatures/codeLens.js +16 -10
- package/out/languageFeatures/codeLensResolve.js +10 -4
- package/out/languageFeatures/complete.d.ts +2 -2
- package/out/languageFeatures/complete.js +34 -35
- package/out/languageFeatures/completeResolve.js +5 -7
- package/out/languageFeatures/definition.js +1 -1
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +1 -1
- package/out/languageFeatures/fileReferences.js +1 -1
- package/out/languageFeatures/fileRename.js +4 -3
- package/out/languageFeatures/inlayHints.js +2 -2
- package/out/languageFeatures/references.js +1 -1
- package/out/languageFeatures/rename.js +5 -5
- package/out/languageFeatures/renamePrepare.js +1 -6
- package/out/languageFeatures/validation copy.d.ts +7 -0
- package/out/languageFeatures/validation copy.js +234 -0
- package/out/languageFeatures/validation.d.ts +6 -0
- package/out/languageFeatures/validation.js +118 -41
- package/out/languageFeatures/workspaceSymbols.js +4 -4
- package/out/transformer/completionItem.d.ts +2 -0
- package/out/transformer/completionItem.js +12 -0
- package/out/transformer/completionList.d.ts +2 -0
- package/out/transformer/completionList.js +23 -0
- package/out/transformer/foldingRanges.d.ts +2 -0
- package/out/transformer/foldingRanges.js +24 -0
- package/out/transformer/hover.d.ts +2 -0
- package/out/transformer/hover.js +13 -0
- package/out/transformer/index.d.ts +11 -0
- package/out/transformer/index.js +25 -0
- package/out/transformer/locationLike.d.ts +4 -0
- package/out/transformer/locationLike.js +10 -0
- package/out/transformer/locationsLike.d.ts +4 -0
- package/out/transformer/locationsLike.js +11 -0
- package/out/transformer/selectionRange.d.ts +2 -0
- package/out/transformer/selectionRange.js +14 -0
- package/out/transformer/selectionRanges.d.ts +2 -0
- package/out/transformer/selectionRanges.js +11 -0
- package/out/transformer/symbolInformation.d.ts +2 -0
- package/out/transformer/symbolInformation.js +10 -0
- package/out/transformer/symbolInformations.d.ts +2 -0
- package/out/transformer/symbolInformations.js +11 -0
- package/out/transformer/textEdit.d.ts +2 -0
- package/out/transformer/textEdit.js +57 -0
- package/out/types.d.ts +45 -9
- package/out/types.js +0 -1
- package/out/utils/common.d.ts +0 -2
- package/out/utils/common.js +1 -28
- package/out/utils/definePlugin.js +2 -1
- package/out/utils/featureWorkers.d.ts +2 -1
- package/out/utils/featureWorkers.js +89 -6
- package/package.json +7 -8
|
@@ -2,8 +2,8 @@ import * as vscode from 'vscode-languageserver-protocol';
|
|
|
2
2
|
import type { LanguageServiceRuntimeContext } from '../types';
|
|
3
3
|
export interface PluginCompletionData {
|
|
4
4
|
uri: string;
|
|
5
|
-
|
|
6
|
-
pluginId:
|
|
5
|
+
originalData: any;
|
|
6
|
+
pluginId: string;
|
|
7
7
|
map: {
|
|
8
8
|
embeddedDocumentUri: string;
|
|
9
9
|
} | undefined;
|
|
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = void 0;
|
|
12
|
-
const
|
|
12
|
+
const transformer = require("../transformer");
|
|
13
13
|
const vscode = require("vscode-languageserver-protocol");
|
|
14
14
|
const definePlugin_1 = require("../utils/definePlugin");
|
|
15
15
|
function register(context) {
|
|
16
16
|
let cache;
|
|
17
17
|
return (uri, position, completionContext) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
var _a, _b, _c, _d;
|
|
18
|
+
var _a, _b, _c, _d, _e;
|
|
19
19
|
let document;
|
|
20
20
|
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerKind) === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions
|
|
21
21
|
&& (cache === null || cache === void 0 ? void 0 : cache.uri) === uri) {
|
|
@@ -32,10 +32,10 @@ function register(context) {
|
|
|
32
32
|
cacheData.list.isIncomplete = false;
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
cacheData.list =
|
|
35
|
+
cacheData.list = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
36
36
|
uri,
|
|
37
|
-
|
|
38
|
-
pluginId: context.plugins.
|
|
37
|
+
originalData: oldItem.data,
|
|
38
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
39
39
|
map: {
|
|
40
40
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
41
41
|
},
|
|
@@ -51,17 +51,19 @@ function register(context) {
|
|
|
51
51
|
cacheData.list.isIncomplete = false;
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
completionList.items.forEach(item => {
|
|
55
|
+
item.data = {
|
|
56
|
+
uri,
|
|
57
|
+
originalData: item.data,
|
|
58
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
|
|
59
|
+
map: undefined,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
|
-
const rootFile = context.documents.
|
|
66
|
+
const rootFile = (_c = context.documents.getSourceByUri(uri)) === null || _c === void 0 ? void 0 : _c.root;
|
|
65
67
|
cache = {
|
|
66
68
|
uri,
|
|
67
69
|
data: [],
|
|
@@ -71,19 +73,19 @@ function register(context) {
|
|
|
71
73
|
let isFirstMapping = true;
|
|
72
74
|
if (rootFile) {
|
|
73
75
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
var
|
|
75
|
-
const plugins = context.plugins.sort(sortPlugins);
|
|
76
|
+
var _f, _g;
|
|
77
|
+
const plugins = Object.values(context.plugins).sort(sortPlugins);
|
|
76
78
|
let _data;
|
|
77
79
|
for (const mapped of map.toGeneratedPositions(position, data => {
|
|
78
80
|
_data = data;
|
|
79
81
|
return !!data.completion;
|
|
80
82
|
})) {
|
|
81
83
|
for (const plugin of plugins) {
|
|
82
|
-
if (!((
|
|
84
|
+
if (!((_f = plugin.complete) === null || _f === void 0 ? void 0 : _f.on))
|
|
83
85
|
continue;
|
|
84
86
|
if (plugin.complete.isAdditional && !isFirstMapping)
|
|
85
87
|
continue;
|
|
86
|
-
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((
|
|
88
|
+
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_g = plugin.complete.triggerCharacters) === null || _g === void 0 ? void 0 : _g.includes(completionContext.triggerCharacter)))
|
|
87
89
|
continue;
|
|
88
90
|
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.complete.isAdditional;
|
|
89
91
|
if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== map.virtualFileDocument.uri))
|
|
@@ -100,10 +102,10 @@ function register(context) {
|
|
|
100
102
|
if (!isAdditional) {
|
|
101
103
|
cache.mainCompletion = { documentUri: map.virtualFileDocument.uri };
|
|
102
104
|
}
|
|
103
|
-
const completionList =
|
|
105
|
+
const completionList = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
|
|
104
106
|
uri,
|
|
105
|
-
|
|
106
|
-
pluginId: context.plugins.
|
|
107
|
+
originalData: oldItem.data,
|
|
108
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
107
109
|
map: {
|
|
108
110
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
109
111
|
}
|
|
@@ -122,13 +124,13 @@ function register(context) {
|
|
|
122
124
|
}));
|
|
123
125
|
}
|
|
124
126
|
if (document = context.getTextDocument(uri)) {
|
|
125
|
-
const plugins = context.plugins.sort(sortPlugins);
|
|
127
|
+
const plugins = Object.values(context.plugins).sort(sortPlugins);
|
|
126
128
|
for (const plugin of plugins) {
|
|
127
|
-
if (!((
|
|
129
|
+
if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on))
|
|
128
130
|
continue;
|
|
129
131
|
if (plugin.complete.isAdditional && !isFirstMapping)
|
|
130
132
|
continue;
|
|
131
|
-
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((
|
|
133
|
+
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_e = plugin.complete.triggerCharacters) === null || _e === void 0 ? void 0 : _e.includes(completionContext.triggerCharacter)))
|
|
132
134
|
continue;
|
|
133
135
|
if (cache.mainCompletion && (!plugin.complete.isAdditional || cache.mainCompletion.documentUri !== document.uri))
|
|
134
136
|
continue;
|
|
@@ -141,17 +143,18 @@ function register(context) {
|
|
|
141
143
|
if (!plugin.complete.isAdditional) {
|
|
142
144
|
cache.mainCompletion = { documentUri: document.uri };
|
|
143
145
|
}
|
|
146
|
+
completionList.items.forEach(item => {
|
|
147
|
+
item.data = {
|
|
148
|
+
uri,
|
|
149
|
+
originalData: item.data,
|
|
150
|
+
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
151
|
+
map: undefined,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
144
154
|
cache.data.push({
|
|
145
155
|
map: undefined,
|
|
146
156
|
plugin,
|
|
147
|
-
list:
|
|
148
|
-
return Object.assign(Object.assign({}, item), { data: {
|
|
149
|
-
uri,
|
|
150
|
-
originalItem: item,
|
|
151
|
-
pluginId: context.plugins.indexOf(plugin),
|
|
152
|
-
sourceMap: undefined,
|
|
153
|
-
} });
|
|
154
|
-
}) }),
|
|
157
|
+
list: completionList,
|
|
155
158
|
});
|
|
156
159
|
}
|
|
157
160
|
}
|
|
@@ -166,11 +169,7 @@ function register(context) {
|
|
|
166
169
|
return {
|
|
167
170
|
isIncomplete: lists.some(list => list.isIncomplete),
|
|
168
171
|
itemDefaults: (_a = lists.find(list => list.itemDefaults)) === null || _a === void 0 ? void 0 : _a.itemDefaults,
|
|
169
|
-
items: lists.map(list => list.items).flat()
|
|
170
|
-
var _a;
|
|
171
|
-
return result.label.indexOf('__VLS_') === -1
|
|
172
|
-
&& (!((_a = result.labelDetails) === null || _a === void 0 ? void 0 : _a.description) || result.labelDetails.description.indexOf('__VLS_') === -1);
|
|
173
|
-
}),
|
|
172
|
+
items: lists.map(list => list.items).flat(),
|
|
174
173
|
};
|
|
175
174
|
}
|
|
176
175
|
});
|
|
@@ -9,21 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = void 0;
|
|
12
|
-
const
|
|
12
|
+
const transformer = require("../transformer");
|
|
13
13
|
function register(context) {
|
|
14
14
|
return (item) => __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
var _a;
|
|
16
16
|
const data = item.data;
|
|
17
17
|
if (data) {
|
|
18
18
|
const plugin = context.plugins[data.pluginId];
|
|
19
|
-
if (!plugin)
|
|
20
|
-
return item;
|
|
21
19
|
if (!((_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.resolve))
|
|
22
20
|
return item;
|
|
23
|
-
|
|
21
|
+
item.data = data.originalData;
|
|
24
22
|
if (data.map) {
|
|
25
23
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) {
|
|
26
|
-
const resolvedItem = yield plugin.complete.resolve(
|
|
24
|
+
const resolvedItem = yield plugin.complete.resolve(item);
|
|
27
25
|
// fix https://github.com/johnsoncodehk/volar/issues/916
|
|
28
26
|
if (resolvedItem.additionalTextEdits) {
|
|
29
27
|
for (const edit of resolvedItem.additionalTextEdits) {
|
|
@@ -35,7 +33,7 @@ function register(context) {
|
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
item =
|
|
36
|
+
item = transformer.asCompletionItem(resolvedItem, embeddedRange => {
|
|
39
37
|
var _a;
|
|
40
38
|
let range = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange);
|
|
41
39
|
if (range)
|
|
@@ -45,7 +43,7 @@ function register(context) {
|
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
else {
|
|
48
|
-
item = yield plugin.complete.resolve(
|
|
46
|
+
item = yield plugin.complete.resolve(item);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
// TODO: monkey fix import ts file icon
|
|
@@ -76,7 +76,7 @@ function register(context, api, isValidMapping, isValidMirrorPosition) {
|
|
|
76
76
|
link.targetRange = targetRange !== null && targetRange !== void 0 ? targetRange : targetSelectionRange;
|
|
77
77
|
link.targetSelectionRange = targetSelectionRange;
|
|
78
78
|
}
|
|
79
|
-
if (context.documents.
|
|
79
|
+
if (context.documents.hasVirtualFileByUri(link.targetUri) && !foundTargetSelectionRange) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
return link;
|
|
@@ -5,7 +5,7 @@ export declare const executePluginCommand: string;
|
|
|
5
5
|
export type ExecutePluginCommandArgs = [
|
|
6
6
|
string,
|
|
7
7
|
// uri
|
|
8
|
-
|
|
8
|
+
string | undefined,
|
|
9
9
|
vscode.Command
|
|
10
10
|
];
|
|
11
11
|
export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;
|
|
@@ -21,7 +21,7 @@ function register(context) {
|
|
|
21
21
|
yield ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.doExecuteCommand) === null || _a === void 0 ? void 0 : _a.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
for (const plugin of context.plugins) {
|
|
24
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
25
25
|
yield ((_b = plugin.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -20,7 +20,7 @@ function register(context) {
|
|
|
20
20
|
var _a, _b;
|
|
21
21
|
return (_b = yield ((_a = plugin.findFileReferences) === null || _a === void 0 ? void 0 : _a.call(plugin, document))) !== null && _b !== void 0 ? _b : [];
|
|
22
22
|
}), (data) => data.map(reference => {
|
|
23
|
-
if (!context.documents.
|
|
23
|
+
if (!context.documents.hasVirtualFileByUri(reference.uri)) {
|
|
24
24
|
return reference;
|
|
25
25
|
}
|
|
26
26
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(reference.uri)) {
|
|
@@ -14,11 +14,12 @@ const dedupe = require("../utils/dedupe");
|
|
|
14
14
|
const language_core_1 = require("@volar/language-core");
|
|
15
15
|
function register(context) {
|
|
16
16
|
return (oldUri, newUri) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
const rootFile = (_a = context.documents.getSourceByUri(oldUri)) === null || _a === void 0 ? void 0 : _a.root;
|
|
18
19
|
if (rootFile) {
|
|
19
20
|
let tsExt;
|
|
20
21
|
(0, language_core_1.forEachEmbeddedFile)(rootFile, embedded => {
|
|
21
|
-
if (embedded.kind && embedded.fileName.replace(rootFile.fileName, '').match(/^\.(js|ts)x?$/)) {
|
|
22
|
+
if (embedded.kind === language_core_1.FileKind.TypeScriptHostFile && embedded.fileName.replace(rootFile.fileName, '').match(/^\.(js|ts)x?$/)) {
|
|
22
23
|
tsExt = embedded.fileName.substring(embedded.fileName.lastIndexOf('.'));
|
|
23
24
|
}
|
|
24
25
|
});
|
|
@@ -28,7 +29,7 @@ function register(context) {
|
|
|
28
29
|
oldUri += tsExt;
|
|
29
30
|
newUri += tsExt;
|
|
30
31
|
}
|
|
31
|
-
for (const plugin of context.plugins) {
|
|
32
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
32
33
|
if (!plugin.doFileRename)
|
|
33
34
|
continue;
|
|
34
35
|
const workspaceEdit = yield plugin.doFileRename(oldUri, newUri);
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = void 0;
|
|
12
12
|
const shared = require("@volar/shared");
|
|
13
|
-
const
|
|
13
|
+
const transformer = require("../transformer");
|
|
14
14
|
const vscode = require("vscode-languageserver-protocol");
|
|
15
15
|
const common_1 = require("../utils/common");
|
|
16
16
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
@@ -55,7 +55,7 @@ function register(context) {
|
|
|
55
55
|
if (!map)
|
|
56
56
|
return _inlayHint;
|
|
57
57
|
const position = map.toSourcePosition(_inlayHint.position);
|
|
58
|
-
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit =>
|
|
58
|
+
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)).filter(shared.notEmpty);
|
|
59
59
|
if (position) {
|
|
60
60
|
return Object.assign(Object.assign({}, _inlayHint), { position,
|
|
61
61
|
edits });
|
|
@@ -50,7 +50,7 @@ function register(context) {
|
|
|
50
50
|
}), (data) => {
|
|
51
51
|
const results = [];
|
|
52
52
|
for (const reference of data) {
|
|
53
|
-
if (context.documents.
|
|
53
|
+
if (context.documents.hasVirtualFileByUri(reference.uri)) {
|
|
54
54
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(reference.uri)) {
|
|
55
55
|
const range = map.toSourceRange(reference.range, data => !!data.references);
|
|
56
56
|
if (range) {
|
|
@@ -138,7 +138,7 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
138
138
|
for (const tsUri in tsResult.changeAnnotations) {
|
|
139
139
|
(_a = sourceResult.changeAnnotations) !== null && _a !== void 0 ? _a : (sourceResult.changeAnnotations = {});
|
|
140
140
|
const tsAnno = tsResult.changeAnnotations[tsUri];
|
|
141
|
-
if (!vueDocuments.
|
|
141
|
+
if (!vueDocuments.hasVirtualFileByUri(tsUri)) {
|
|
142
142
|
sourceResult.changeAnnotations[tsUri] = tsAnno;
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
@@ -151,7 +151,7 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
151
151
|
}
|
|
152
152
|
for (const tsUri in tsResult.changes) {
|
|
153
153
|
(_b = sourceResult.changes) !== null && _b !== void 0 ? _b : (sourceResult.changes = {});
|
|
154
|
-
if (!vueDocuments.
|
|
154
|
+
if (!vueDocuments.hasVirtualFileByUri(tsUri)) {
|
|
155
155
|
sourceResult.changes[tsUri] = tsResult.changes[tsUri];
|
|
156
156
|
hasResult = true;
|
|
157
157
|
continue;
|
|
@@ -183,7 +183,7 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
183
183
|
(_c = sourceResult.documentChanges) !== null && _c !== void 0 ? _c : (sourceResult.documentChanges = []);
|
|
184
184
|
let sourceEdit;
|
|
185
185
|
if (vscode.TextDocumentEdit.is(tsDocEdit)) {
|
|
186
|
-
if (vueDocuments.
|
|
186
|
+
if (vueDocuments.hasVirtualFileByUri(tsDocEdit.textDocument.uri)) {
|
|
187
187
|
for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
|
|
188
188
|
sourceEdit = vscode.TextDocumentEdit.create({
|
|
189
189
|
uri: map.sourceFileDocument.uri,
|
|
@@ -222,7 +222,7 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
222
222
|
sourceEdit = tsDocEdit; // TODO: remove .ts?
|
|
223
223
|
}
|
|
224
224
|
else if (vscode.RenameFile.is(tsDocEdit)) {
|
|
225
|
-
if (!vueDocuments.
|
|
225
|
+
if (!vueDocuments.hasVirtualFileByUri(tsDocEdit.oldUri)) {
|
|
226
226
|
sourceEdit = tsDocEdit;
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
@@ -233,7 +233,7 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
|
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
else if (vscode.DeleteFile.is(tsDocEdit)) {
|
|
236
|
-
if (!vueDocuments.
|
|
236
|
+
if (!vueDocuments.hasVirtualFileByUri(tsDocEdit.uri)) {
|
|
237
237
|
sourceEdit = tsDocEdit;
|
|
238
238
|
}
|
|
239
239
|
else {
|
|
@@ -10,14 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = void 0;
|
|
12
12
|
const vscode = require("vscode-languageserver-protocol");
|
|
13
|
-
const common_1 = require("../utils/common");
|
|
14
13
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
15
|
-
// https://github.com/microsoft/vscode/blob/dcf27391b7dd7c1cece483806af75b4f87188e70/extensions/html/language-configuration.json#L35
|
|
16
|
-
const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\\"\,\.\<\>\/\s]+)/g;
|
|
17
14
|
function register(context) {
|
|
18
15
|
return (uri, position) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
|
|
16
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
|
|
21
17
|
if (!map) {
|
|
22
18
|
return item;
|
|
23
19
|
}
|
|
@@ -32,7 +28,6 @@ function register(context) {
|
|
|
32
28
|
}
|
|
33
29
|
return prepares[0];
|
|
34
30
|
});
|
|
35
|
-
return result !== null && result !== void 0 ? result : (document ? (0, common_1.getWordRange)(htmlWordPatterns, position, document) : undefined);
|
|
36
31
|
});
|
|
37
32
|
}
|
|
38
33
|
exports.register = register;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { LanguageServiceRuntimeContext } from '../types';
|
|
3
|
+
export declare function updateRange(range: vscode.Range, change: {
|
|
4
|
+
range: vscode.Range;
|
|
5
|
+
newEnd: vscode.Position;
|
|
6
|
+
}): vscode.Range | undefined;
|
|
7
|
+
export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.register = exports.updateRange = void 0;
|
|
12
|
+
const shared = require("@volar/shared");
|
|
13
|
+
const dedupe = require("../utils/dedupe");
|
|
14
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
15
|
+
function updateRange(range, change) {
|
|
16
|
+
if (!updatePosition(range.start, change, false)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!updatePosition(range.end, change, true)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (range.end.line === range.start.line && range.end.character <= range.start.character) {
|
|
23
|
+
range.end.character++;
|
|
24
|
+
}
|
|
25
|
+
return range;
|
|
26
|
+
}
|
|
27
|
+
exports.updateRange = updateRange;
|
|
28
|
+
function updatePosition(position, change, isEnd) {
|
|
29
|
+
if (change.range.end.line > position.line) {
|
|
30
|
+
if (change.newEnd.line > position.line) {
|
|
31
|
+
// No change
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
else if (change.newEnd.line === position.line) {
|
|
35
|
+
position.character = Math.min(position.character, change.newEnd.character);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
else if (change.newEnd.line < position.line) {
|
|
39
|
+
position.line = change.newEnd.line;
|
|
40
|
+
position.character = change.newEnd.character;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (change.range.end.line === position.line) {
|
|
45
|
+
const characterDiff = change.newEnd.character - change.range.end.character;
|
|
46
|
+
if (position.character >= change.range.end.character) {
|
|
47
|
+
if (change.newEnd.line !== change.range.end.line) {
|
|
48
|
+
position.line = change.newEnd.line;
|
|
49
|
+
position.character = change.newEnd.character + position.character - change.range.end.character;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
|
|
53
|
+
position.character += characterDiff;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const offset = change.range.end.character - position.character;
|
|
57
|
+
if (-characterDiff > offset) {
|
|
58
|
+
position.character += characterDiff + offset;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (change.newEnd.line === change.range.end.line) {
|
|
66
|
+
const offset = change.range.end.character - position.character;
|
|
67
|
+
if (-characterDiff > offset) {
|
|
68
|
+
position.character += characterDiff + offset;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (change.newEnd.line < change.range.end.line) {
|
|
72
|
+
position.line = change.newEnd.line;
|
|
73
|
+
position.character = change.newEnd.character;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// No change
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (change.range.end.line < position.line) {
|
|
82
|
+
position.line += change.newEnd.line - change.range.end.line;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
function register(context) {
|
|
88
|
+
const responseCache = new Map();
|
|
89
|
+
const cacheMaps = {
|
|
90
|
+
semantic: new Map(),
|
|
91
|
+
declaration: new Map(),
|
|
92
|
+
syntactic: new Map(),
|
|
93
|
+
suggestion: new Map(),
|
|
94
|
+
};
|
|
95
|
+
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
var _a;
|
|
97
|
+
const lastResponse = (_a = responseCache.get(uri)) !== null && _a !== void 0 ? _a : responseCache.set(uri, {
|
|
98
|
+
semantic: { errors: [] },
|
|
99
|
+
declaration: { errors: [] },
|
|
100
|
+
suggestion: { errors: [] },
|
|
101
|
+
syntactic: { errors: [] },
|
|
102
|
+
}).get(uri);
|
|
103
|
+
const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
|
|
104
|
+
const newDocument = context.getTextDocument(uri);
|
|
105
|
+
let updateCacheRangeFailed = false;
|
|
106
|
+
let errorsUpdated = false;
|
|
107
|
+
let lastCheckCancelAt = 0;
|
|
108
|
+
for (const cache of Object.values(lastResponse)) {
|
|
109
|
+
const oldSnapshot = cache.snapshot;
|
|
110
|
+
const oldDocument = cache.document;
|
|
111
|
+
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
|
|
112
|
+
cache.snapshot = newSnapshot;
|
|
113
|
+
cache.document = newDocument;
|
|
114
|
+
if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
|
|
115
|
+
const changeRange = {
|
|
116
|
+
range: {
|
|
117
|
+
start: oldDocument.positionAt(change.span.start),
|
|
118
|
+
end: oldDocument.positionAt(change.span.start + change.span.length),
|
|
119
|
+
},
|
|
120
|
+
newEnd: newDocument.positionAt(change.span.start + change.newLength),
|
|
121
|
+
};
|
|
122
|
+
for (const error of cache.errors) {
|
|
123
|
+
if (!updateRange(error.range, changeRange)) {
|
|
124
|
+
updateCacheRangeFailed = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
|
131
|
+
doResponse();
|
|
132
|
+
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
|
|
133
|
+
doResponse();
|
|
134
|
+
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
|
|
135
|
+
doResponse();
|
|
136
|
+
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
|
|
137
|
+
return collectErrors();
|
|
138
|
+
function doResponse() {
|
|
139
|
+
if (errorsUpdated && !updateCacheRangeFailed) {
|
|
140
|
+
response === null || response === void 0 ? void 0 : response(collectErrors());
|
|
141
|
+
errorsUpdated = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function collectErrors() {
|
|
145
|
+
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
146
|
+
}
|
|
147
|
+
function worker(api, cacheMap, cache) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
|
|
150
|
+
if (file.capabilities.diagnostic) {
|
|
151
|
+
yield arg;
|
|
152
|
+
}
|
|
153
|
+
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
var _a, _b, _c, _d, _e;
|
|
155
|
+
if (token) {
|
|
156
|
+
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
157
|
+
yield shared.sleep(5); // wait for LSP event polling
|
|
158
|
+
lastCheckCancelAt = Date.now();
|
|
159
|
+
}
|
|
160
|
+
if (token.isCancellationRequested)
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const pluginId = context.plugins.indexOf(plugin);
|
|
164
|
+
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
|
|
165
|
+
const cache = pluginCache.get(document.uri);
|
|
166
|
+
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
|
|
167
|
+
if (api === 'onDeclaration' || api === 'onSemantic') {
|
|
168
|
+
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
|
|
169
|
+
return cache.errors;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (cache && cache.documentVersion === document.version) {
|
|
174
|
+
return cache.errors;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[api]) === null || _e === void 0 ? void 0 : _e.call(_d, document));
|
|
178
|
+
errorsUpdated = true;
|
|
179
|
+
pluginCache.set(document.uri, {
|
|
180
|
+
documentVersion: document.version,
|
|
181
|
+
errors,
|
|
182
|
+
tsProjectVersion,
|
|
183
|
+
});
|
|
184
|
+
return errors;
|
|
185
|
+
}), (errors, map) => transformErrorRange(map, errors), arr => dedupe.withDiagnostics(arr.flat()));
|
|
186
|
+
if (result) {
|
|
187
|
+
cache.errors = result;
|
|
188
|
+
cache.snapshot = newSnapshot;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
function transformErrorRange(map, errors) {
|
|
194
|
+
const result = [];
|
|
195
|
+
for (const error of errors) {
|
|
196
|
+
// clone it to avoid modify cache
|
|
197
|
+
let _error = Object.assign({}, error);
|
|
198
|
+
if (map) {
|
|
199
|
+
const range = map.toSourceRange(error.range, data => !!data.diagnostic);
|
|
200
|
+
if (!range) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
_error.range = range;
|
|
204
|
+
}
|
|
205
|
+
if (_error.relatedInformation) {
|
|
206
|
+
const relatedInfos = [];
|
|
207
|
+
for (const info of _error.relatedInformation) {
|
|
208
|
+
if (context.documents.hasVirtualFileByUri(info.location.uri)) {
|
|
209
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(info.location.uri)) {
|
|
210
|
+
const range = map.toSourceRange(info.location.range, data => !!data.diagnostic);
|
|
211
|
+
if (range) {
|
|
212
|
+
relatedInfos.push({
|
|
213
|
+
location: {
|
|
214
|
+
uri: map.sourceFileDocument.uri,
|
|
215
|
+
range,
|
|
216
|
+
},
|
|
217
|
+
message: info.message,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
relatedInfos.push(info);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
_error.relatedInformation = relatedInfos;
|
|
227
|
+
}
|
|
228
|
+
result.push(_error);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.register = register;
|
|
234
|
+
//# sourceMappingURL=validation%20copy.js.map
|
|
@@ -4,4 +4,10 @@ export declare function updateRange(range: vscode.Range, change: {
|
|
|
4
4
|
range: vscode.Range;
|
|
5
5
|
newEnd: vscode.Position;
|
|
6
6
|
}): vscode.Range | undefined;
|
|
7
|
+
export interface PluginDiagnosticData {
|
|
8
|
+
uri: string;
|
|
9
|
+
originalData: any;
|
|
10
|
+
type: 'plugin' | 'rule';
|
|
11
|
+
pluginOrRuleId: string;
|
|
12
|
+
}
|
|
7
13
|
export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|