@volar/language-service 1.2.0-alpha.8 → 1.2.0-alpha.9
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 -5
- package/out/baseLanguageService.js +6 -10
- package/out/documentFeatures/colorPresentations.d.ts +2 -2
- package/out/documentFeatures/documentColors.d.ts +2 -2
- package/out/documentFeatures/documentSymbols.d.ts +2 -2
- package/out/documentFeatures/foldingRanges.d.ts +2 -2
- package/out/documentFeatures/format.d.ts +2 -4
- package/out/documentFeatures/format.js +26 -123
- package/out/documentFeatures/linkedEditingRanges.d.ts +2 -2
- package/out/documentFeatures/selectionRanges.d.ts +2 -2
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -3
- package/out/languageFeatures/autoInsert.d.ts +2 -2
- package/out/languageFeatures/callHierarchy.d.ts +2 -2
- package/out/languageFeatures/codeActionResolve.d.ts +2 -2
- package/out/languageFeatures/codeActionResolve.js +9 -3
- package/out/languageFeatures/codeActions.d.ts +5 -2
- package/out/languageFeatures/codeActions.js +17 -6
- package/out/languageFeatures/codeLens.d.ts +11 -4
- package/out/languageFeatures/codeLens.js +22 -14
- package/out/languageFeatures/codeLensResolve.d.ts +4 -2
- package/out/languageFeatures/codeLensResolve.js +19 -11
- package/out/languageFeatures/complete.d.ts +2 -2
- package/out/languageFeatures/completeResolve.d.ts +2 -2
- package/out/languageFeatures/definition.d.ts +2 -2
- package/out/languageFeatures/documentHighlights.d.ts +2 -2
- package/out/languageFeatures/documentLinks.d.ts +2 -2
- package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
- package/out/languageFeatures/executeCommand.d.ts +1 -2
- package/out/languageFeatures/executeCommand.js +1 -9
- package/out/languageFeatures/fileReferences.d.ts +2 -2
- package/out/languageFeatures/fileRename.d.ts +2 -2
- package/out/languageFeatures/fileRename.js +1 -1
- package/out/languageFeatures/hover.d.ts +2 -2
- package/out/languageFeatures/inlayHints.d.ts +2 -2
- package/out/languageFeatures/references.d.ts +2 -2
- package/out/languageFeatures/rename.d.ts +3 -3
- package/out/languageFeatures/rename.js +54 -34
- package/out/languageFeatures/renamePrepare.d.ts +2 -2
- package/out/languageFeatures/signatureHelp.d.ts +2 -2
- package/out/languageFeatures/validation.d.ts +4 -2
- package/out/languageFeatures/validation.js +41 -8
- package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
- package/out/types.d.ts +60 -40
- package/out/utils/featureWorkers.d.ts +4 -4
- package/out/utils/featureWorkers.js +17 -15
- package/package.json +6 -6
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { LanguageServiceHost } from '@volar/language-core';
|
|
2
|
-
import
|
|
3
|
-
import { Config, LanguageServiceRuntimeContext } from './types';
|
|
2
|
+
import { Config, LanguageServicePluginContext } from './types';
|
|
4
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
4
|
import type * as _ from 'vscode-languageserver-protocol';
|
|
6
5
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
7
|
-
export declare function createLanguageService(host: LanguageServiceHost, config: Config, env:
|
|
6
|
+
export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServicePluginContext['env'], documentRegistry?: ts.DocumentRegistry): {
|
|
8
7
|
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
|
|
9
8
|
ch: string;
|
|
10
9
|
position: _.Position;
|
|
@@ -44,7 +43,6 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
|
|
|
44
43
|
text: string;
|
|
45
44
|
};
|
|
46
45
|
}) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>;
|
|
47
|
-
doExecuteCommand: (command: string, args: executeCommand.ExecutePluginCommandArgs, executeCommandContext: import("./types").ExecuteCommandContext) => Promise<void>;
|
|
48
46
|
getInlayHints: (uri: string, range: _.Range) => Promise<_.InlayHint[] | undefined>;
|
|
49
47
|
callHierarchy: {
|
|
50
48
|
doPrepare(uri: string, position: _.Position): Promise<_.CallHierarchyItem[] | undefined>;
|
|
@@ -52,5 +50,5 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
|
|
|
52
50
|
getOutgoingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyOutgoingCall[]>;
|
|
53
51
|
};
|
|
54
52
|
dispose: () => void | undefined;
|
|
55
|
-
context:
|
|
53
|
+
context: LanguageServicePluginContext;
|
|
56
54
|
};
|
|
@@ -17,7 +17,6 @@ const definition = require("./languageFeatures/definition");
|
|
|
17
17
|
const documentHighlight = require("./languageFeatures/documentHighlights");
|
|
18
18
|
const documentLink = require("./languageFeatures/documentLinks");
|
|
19
19
|
const semanticTokens = require("./languageFeatures/documentSemanticTokens");
|
|
20
|
-
const executeCommand = require("./languageFeatures/executeCommand");
|
|
21
20
|
const fileReferences = require("./languageFeatures/fileReferences");
|
|
22
21
|
const fileRename = require("./languageFeatures/fileRename");
|
|
23
22
|
const hover = require("./languageFeatures/hover");
|
|
@@ -38,13 +37,12 @@ const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
|
38
37
|
function createLanguageService(host, config, env, documentRegistry) {
|
|
39
38
|
var _a;
|
|
40
39
|
const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
|
|
41
|
-
const context = createLanguageServiceContext(host, languageContext, config, env,
|
|
42
|
-
|
|
43
|
-
return languageService;
|
|
40
|
+
const context = createLanguageServiceContext(host, languageContext, config, env, documentRegistry);
|
|
41
|
+
return createLanguageServiceBase(context);
|
|
44
42
|
}
|
|
45
43
|
exports.createLanguageService = createLanguageService;
|
|
46
|
-
function createLanguageServiceContext(host, languageContext, config, env,
|
|
47
|
-
var _a
|
|
44
|
+
function createLanguageServiceContext(host, languageContext, config, env, documentRegistry) {
|
|
45
|
+
var _a;
|
|
48
46
|
const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
49
47
|
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
|
|
50
48
|
if (ts && tsLs) {
|
|
@@ -67,7 +65,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
|
|
|
67
65
|
for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
|
|
68
66
|
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
|
|
69
67
|
if (plugin instanceof Function) {
|
|
70
|
-
const _plugin = plugin(this
|
|
68
|
+
const _plugin = plugin(this);
|
|
71
69
|
plugins[pluginId] = _plugin;
|
|
72
70
|
}
|
|
73
71
|
else if (plugin) {
|
|
@@ -77,8 +75,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
|
|
|
77
75
|
}
|
|
78
76
|
return plugins;
|
|
79
77
|
},
|
|
80
|
-
|
|
81
|
-
rulesSettings: (_c = config.rulesSettings) !== null && _c !== void 0 ? _c : {},
|
|
78
|
+
config,
|
|
82
79
|
typescript: ts && tsLs ? {
|
|
83
80
|
module: ts,
|
|
84
81
|
languageServiceHost: languageContext.typescript.languageServiceHost,
|
|
@@ -135,7 +132,6 @@ function createLanguageServiceBase(context) {
|
|
|
135
132
|
findDocumentLinks: documentLink.register(context),
|
|
136
133
|
findWorkspaceSymbols: workspaceSymbol.register(context),
|
|
137
134
|
doAutoInsert: autoInsert.register(context),
|
|
138
|
-
doExecuteCommand: executeCommand.register(context),
|
|
139
135
|
getInlayHints: inlayHints.register(context),
|
|
140
136
|
callHierarchy: callHierarchy.register(context),
|
|
141
137
|
dispose: () => { var _a; return (_a = context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.dispose(); },
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, color: vscode.Color, range: vscode.Range) => Promise<vscode.ColorPresentation[] | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.ColorInformation[] | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.SymbolInformation[] | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import type * as _ from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<_.FoldingRange[] | undefined>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function register(context: LanguageServiceRuntimeContext): (uri: string, options: vscode.FormattingOptions, range?: vscode.Range, onTypeParams?: {
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, options: vscode.FormattingOptions, range?: vscode.Range, onTypeParams?: {
|
|
5
4
|
ch: string;
|
|
6
5
|
position: vscode.Position;
|
|
7
6
|
}) => Promise<vscode.TextEdit[] | undefined>;
|
|
8
|
-
export declare function isTsDocument(document: TextDocument): boolean;
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.register = void 0;
|
|
12
12
|
const vscode = require("vscode-languageserver-protocol");
|
|
13
13
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
14
14
|
const shared = require("@volar/shared");
|
|
@@ -20,16 +20,16 @@ function register(context) {
|
|
|
20
20
|
if (!document)
|
|
21
21
|
return;
|
|
22
22
|
range !== null && range !== void 0 ? range : (range = vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length)));
|
|
23
|
+
const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
|
|
23
24
|
const source = context.documents.getSourceByUri(document.uri);
|
|
24
25
|
if (!source) {
|
|
25
26
|
return onTypeParams
|
|
26
|
-
? yield tryFormat(document, onTypeParams.position,
|
|
27
|
-
: yield tryFormat(document, range, undefined);
|
|
27
|
+
? yield tryFormat(false, document, onTypeParams.position, onTypeParams.ch)
|
|
28
|
+
: yield tryFormat(false, document, range, undefined);
|
|
28
29
|
}
|
|
29
30
|
const originalSnapshot = source.snapshot;
|
|
30
31
|
const rootVirtualFile = source.root;
|
|
31
32
|
const originalDocument = document;
|
|
32
|
-
const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
|
|
33
33
|
let level = 0;
|
|
34
34
|
let edited = false;
|
|
35
35
|
while (true) {
|
|
@@ -37,7 +37,7 @@ function register(context) {
|
|
|
37
37
|
if (embeddedFiles.length === 0)
|
|
38
38
|
break;
|
|
39
39
|
let edits = [];
|
|
40
|
-
let
|
|
40
|
+
let toPatchIndentUri;
|
|
41
41
|
for (const embedded of embeddedFiles) {
|
|
42
42
|
if (!embedded.capabilities.documentFormatting)
|
|
43
43
|
continue;
|
|
@@ -45,14 +45,11 @@ function register(context) {
|
|
|
45
45
|
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
|
|
46
46
|
if (!map)
|
|
47
47
|
continue;
|
|
48
|
-
const initialIndentBracket = typeof embedded.capabilities.documentFormatting === 'object' && initialIndentLanguageId[map.virtualFileDocument.languageId]
|
|
49
|
-
? embedded.capabilities.documentFormatting.initialIndentBracket
|
|
50
|
-
: undefined;
|
|
51
48
|
let _edits;
|
|
52
49
|
if (onTypeParams) {
|
|
53
50
|
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
54
51
|
if (embeddedPosition) {
|
|
55
|
-
_edits = yield tryFormat(map.virtualFileDocument, embeddedPosition,
|
|
52
|
+
_edits = yield tryFormat(true, map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
else {
|
|
@@ -69,10 +66,8 @@ function register(context) {
|
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
if (genRange) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
_edits = yield tryFormat(map.virtualFileDocument, genRange, initialIndentBracket);
|
|
69
|
+
toPatchIndentUri = map.virtualFileDocument.uri;
|
|
70
|
+
_edits = yield tryFormat(true, map.virtualFileDocument, genRange);
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
if (!_edits)
|
|
@@ -93,8 +88,8 @@ function register(context) {
|
|
|
93
88
|
context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
|
|
94
89
|
edited = true;
|
|
95
90
|
}
|
|
96
|
-
if (
|
|
97
|
-
for (const [_, map] of context.documents.getMapsByVirtualFileUri(
|
|
91
|
+
if (toPatchIndentUri) {
|
|
92
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri)) {
|
|
98
93
|
const indentEdits = patchInterpolationIndent(document, map.map);
|
|
99
94
|
if (indentEdits.length > 0) {
|
|
100
95
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
@@ -126,100 +121,25 @@ function register(context) {
|
|
|
126
121
|
embeddedFilesByLevel.push(nextLevel);
|
|
127
122
|
}
|
|
128
123
|
}
|
|
129
|
-
function tryFormat(document, range,
|
|
124
|
+
function tryFormat(isEmbedded, document, range, ch) {
|
|
130
125
|
var _a, _b;
|
|
131
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
let formatDocument = document;
|
|
133
127
|
let formatRange = range;
|
|
134
|
-
if (initialIndentBracket) {
|
|
135
|
-
formatDocument = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version, initialIndentBracket[0] + document.getText() + initialIndentBracket[1]);
|
|
136
|
-
if (vscode.Position.is(range)) {
|
|
137
|
-
formatRange = formatDocument.positionAt(document.offsetAt(range) + initialIndentBracket[0].length);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
const startOffset = document.offsetAt(range.start);
|
|
141
|
-
const endOffset = document.offsetAt(range.end);
|
|
142
|
-
if (startOffset === 0 && endOffset === document.getText().length) {
|
|
143
|
-
// full format
|
|
144
|
-
formatRange = {
|
|
145
|
-
start: formatDocument.positionAt(0),
|
|
146
|
-
end: formatDocument.positionAt(formatDocument.getText().length),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
// range format
|
|
151
|
-
formatRange = {
|
|
152
|
-
start: formatDocument.positionAt(startOffset + initialIndentBracket[0].length),
|
|
153
|
-
end: formatDocument.positionAt(endOffset + initialIndentBracket[0].length),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
128
|
for (const plugin of Object.values(context.plugins)) {
|
|
159
129
|
let edits;
|
|
160
|
-
let recover;
|
|
161
|
-
if (formatDocument !== document && isTsDocument(formatDocument) && context.typescript) {
|
|
162
|
-
const formatFileName = shared.uriToFileName(formatDocument.uri);
|
|
163
|
-
const formatSnapshot = (0, common_1.stringToSnapshot)(formatDocument.getText());
|
|
164
|
-
const host = context.typescript.languageServiceHost;
|
|
165
|
-
const original = {
|
|
166
|
-
getProjectVersion: host.getProjectVersion,
|
|
167
|
-
getScriptVersion: host.getScriptVersion,
|
|
168
|
-
getScriptSnapshot: host.getScriptSnapshot,
|
|
169
|
-
};
|
|
170
|
-
host.getProjectVersion = () => { var _a; return ((_a = original.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(original)) + '-' + formatDocument.version; };
|
|
171
|
-
host.getScriptVersion = (fileName) => {
|
|
172
|
-
var _a, _b;
|
|
173
|
-
if (fileName === formatFileName) {
|
|
174
|
-
return ((_a = original.getScriptVersion) === null || _a === void 0 ? void 0 : _a.call(original, fileName)) + '-' + formatDocument.version.toString();
|
|
175
|
-
}
|
|
176
|
-
return (_b = original.getScriptVersion) === null || _b === void 0 ? void 0 : _b.call(original, fileName);
|
|
177
|
-
};
|
|
178
|
-
host.getScriptSnapshot = (fileName) => {
|
|
179
|
-
var _a;
|
|
180
|
-
if (fileName === formatFileName) {
|
|
181
|
-
return formatSnapshot;
|
|
182
|
-
}
|
|
183
|
-
return (_a = original.getScriptSnapshot) === null || _a === void 0 ? void 0 : _a.call(original, fileName);
|
|
184
|
-
};
|
|
185
|
-
recover = () => {
|
|
186
|
-
host.getProjectVersion = original.getProjectVersion;
|
|
187
|
-
host.getScriptVersion = original.getScriptVersion;
|
|
188
|
-
host.getScriptSnapshot = original.getScriptSnapshot;
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
130
|
try {
|
|
192
131
|
if (ch !== undefined && vscode.Position.is(formatRange)) {
|
|
193
|
-
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin,
|
|
132
|
+
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, document, formatRange, ch, options));
|
|
194
133
|
}
|
|
195
134
|
else if (ch === undefined && vscode.Range.is(formatRange)) {
|
|
196
|
-
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin,
|
|
135
|
+
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, Object.assign(Object.assign({}, options), { initialIndent: isEmbedded ? !!initialIndentLanguageId[document.languageId] : false })));
|
|
197
136
|
}
|
|
198
137
|
}
|
|
199
138
|
catch (err) {
|
|
200
139
|
console.error(err);
|
|
201
140
|
}
|
|
202
|
-
recover === null || recover === void 0 ? void 0 : recover();
|
|
203
141
|
if (!edits)
|
|
204
142
|
continue;
|
|
205
|
-
if (!edits.length)
|
|
206
|
-
return edits;
|
|
207
|
-
if (initialIndentBracket) {
|
|
208
|
-
let newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(formatDocument, edits);
|
|
209
|
-
newText = newText.substring(newText.indexOf(initialIndentBracket[0]) + initialIndentBracket[0].length, newText.lastIndexOf(initialIndentBracket[1]));
|
|
210
|
-
if (newText === document.getText()) {
|
|
211
|
-
edits = [];
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
edits = [{
|
|
215
|
-
newText,
|
|
216
|
-
range: {
|
|
217
|
-
start: document.positionAt(0),
|
|
218
|
-
end: document.positionAt(document.getText().length),
|
|
219
|
-
},
|
|
220
|
-
}];
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
143
|
return edits;
|
|
224
144
|
}
|
|
225
145
|
});
|
|
@@ -230,48 +150,31 @@ exports.register = register;
|
|
|
230
150
|
function patchInterpolationIndent(document, map) {
|
|
231
151
|
const indentTextEdits = [];
|
|
232
152
|
for (const mapped of map.mappings) {
|
|
233
|
-
const textRange = {
|
|
234
|
-
start: document.positionAt(mapped.sourceRange[0]),
|
|
235
|
-
end: document.positionAt(mapped.sourceRange[1]),
|
|
236
|
-
};
|
|
237
|
-
const text = document.getText(textRange);
|
|
238
|
-
if (text.indexOf('\n') === -1)
|
|
239
|
-
continue;
|
|
240
|
-
const lines = text.split('\n');
|
|
241
|
-
const removeIndent = getRemoveIndent(lines);
|
|
242
153
|
const baseIndent = getBaseIndent(mapped.sourceRange[0]);
|
|
243
|
-
if (
|
|
154
|
+
if (baseIndent === '') {
|
|
244
155
|
continue;
|
|
156
|
+
}
|
|
157
|
+
const text = document.getText().substring(mapped.sourceRange[0], mapped.sourceRange[1]);
|
|
158
|
+
if (text.indexOf('\n') === -1) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const lines = text.split('\n');
|
|
245
162
|
for (let i = 1; i < lines.length; i++) {
|
|
246
|
-
|
|
247
|
-
if (line.startsWith(removeIndent)) {
|
|
248
|
-
lines[i] = line.replace(removeIndent, baseIndent);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
lines[i] = baseIndent.replace(removeIndent, '') + line;
|
|
252
|
-
}
|
|
163
|
+
lines[i] = baseIndent + lines[i];
|
|
253
164
|
}
|
|
254
165
|
indentTextEdits.push({
|
|
255
166
|
newText: lines.join('\n'),
|
|
256
|
-
range:
|
|
167
|
+
range: {
|
|
168
|
+
start: document.positionAt(mapped.sourceRange[0]),
|
|
169
|
+
end: document.positionAt(mapped.sourceRange[1]),
|
|
170
|
+
},
|
|
257
171
|
});
|
|
258
172
|
}
|
|
259
173
|
return indentTextEdits;
|
|
260
|
-
function getRemoveIndent(lines) {
|
|
261
|
-
const lastLine = lines[lines.length - 1];
|
|
262
|
-
return lastLine.substring(0, lastLine.length - lastLine.trimStart().length);
|
|
263
|
-
}
|
|
264
174
|
function getBaseIndent(pos) {
|
|
265
175
|
const startPos = document.positionAt(pos);
|
|
266
|
-
const startLineText = document.getText({ start:
|
|
176
|
+
const startLineText = document.getText({ start: { line: startPos.line, character: 0 }, end: startPos });
|
|
267
177
|
return startLineText.substring(0, startLineText.length - startLineText.trimStart().length);
|
|
268
178
|
}
|
|
269
179
|
}
|
|
270
|
-
function isTsDocument(document) {
|
|
271
|
-
return document.languageId === 'javascript' ||
|
|
272
|
-
document.languageId === 'typescript' ||
|
|
273
|
-
document.languageId === 'javascriptreact' ||
|
|
274
|
-
document.languageId === 'typescriptreact';
|
|
275
|
-
}
|
|
276
|
-
exports.isTsDocument = isTsDocument;
|
|
277
180
|
//# sourceMappingURL=format.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.LinkedEditingRanges | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context:
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, positions: vscode.Position[]) => Promise<vscode.SelectionRange[] | undefined>;
|
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from '@volar/language-core';
|
|
2
2
|
export * from './baseLanguageService';
|
|
3
3
|
export * from './documents';
|
|
4
|
-
export { executePluginCommand, ExecutePluginCommandArgs } from './languageFeatures/executeCommand';
|
|
5
4
|
export { mergeWorkspaceEdits } from './languageFeatures/rename';
|
|
6
5
|
export * from './types';
|
|
7
6
|
export * as transformer from './transformer';
|
|
7
|
+
export { showReferencesCommand, ShowReferencesCommandData } from './languageFeatures/codeLensResolve';
|
package/out/index.js
CHANGED
|
@@ -13,14 +13,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
13
13
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.showReferencesCommand = exports.transformer = exports.mergeWorkspaceEdits = void 0;
|
|
17
17
|
__exportStar(require("@volar/language-core"), exports);
|
|
18
18
|
__exportStar(require("./baseLanguageService"), exports);
|
|
19
19
|
__exportStar(require("./documents"), exports);
|
|
20
|
-
var executeCommand_1 = require("./languageFeatures/executeCommand");
|
|
21
|
-
Object.defineProperty(exports, "executePluginCommand", { enumerable: true, get: function () { return executeCommand_1.executePluginCommand; } });
|
|
22
20
|
var rename_1 = require("./languageFeatures/rename");
|
|
23
21
|
Object.defineProperty(exports, "mergeWorkspaceEdits", { enumerable: true, get: function () { return rename_1.mergeWorkspaceEdits; } });
|
|
24
22
|
__exportStar(require("./types"), exports);
|
|
25
23
|
exports.transformer = require("./transformer");
|
|
24
|
+
var codeLensResolve_1 = require("./languageFeatures/codeLensResolve");
|
|
25
|
+
Object.defineProperty(exports, "showReferencesCommand", { enumerable: true, get: function () { return codeLensResolve_1.showReferencesCommand; } });
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type { LanguageServicePluginInstance,
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginInstance, LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, autoInsertContext: Parameters<NonNullable<LanguageServicePluginInstance['doAutoInsert']>>[2]) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
3
|
export interface PluginCallHierarchyData {
|
|
4
4
|
uri: string;
|
|
5
5
|
original: Pick<vscode.CallHierarchyItem, 'data'>;
|
|
@@ -8,7 +8,7 @@ export interface PluginCallHierarchyData {
|
|
|
8
8
|
embeddedDocumentUri: string;
|
|
9
9
|
} | undefined;
|
|
10
10
|
}
|
|
11
|
-
export declare function register(context:
|
|
11
|
+
export declare function register(context: LanguageServicePluginContext): {
|
|
12
12
|
doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>;
|
|
13
13
|
getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>;
|
|
14
14
|
getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { CodeAction } from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function register(context:
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (item: CodeAction) => Promise<CodeAction>;
|
|
@@ -21,7 +21,7 @@ function register(context) {
|
|
|
21
21
|
Object.assign(item, data.original);
|
|
22
22
|
item = yield plugin.codeAction.resolve(item);
|
|
23
23
|
if (item.edit) {
|
|
24
|
-
item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents);
|
|
24
|
+
item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version });
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
|
|
@@ -33,12 +33,18 @@ function register(context) {
|
|
|
33
33
|
const edits = yield ((_g = fix.getEdits) === null || _g === void 0 ? void 0 : _g.call(fix, fixes[0]));
|
|
34
34
|
if (edits) {
|
|
35
35
|
edit = {
|
|
36
|
-
|
|
36
|
+
documentChanges: [{
|
|
37
|
+
textDocument: {
|
|
38
|
+
uri: data.documentUri,
|
|
39
|
+
version: null
|
|
40
|
+
},
|
|
41
|
+
edits,
|
|
42
|
+
}],
|
|
37
43
|
};
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
if (edit) {
|
|
41
|
-
item.edit = (0, rename_1.embeddedEditToSourceEdit)(edit, context.documents);
|
|
47
|
+
item.edit = (0, rename_1.embeddedEditToSourceEdit)(edit, context.documents, data.isFormat ? 'format' : 'codeAction', { [data.uri]: data.version });
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
3
3
|
export interface PluginCodeActionData {
|
|
4
4
|
uri: string;
|
|
5
|
+
version: number;
|
|
5
6
|
type: 'plugin';
|
|
6
7
|
original: Pick<vscode.CodeAction, 'data' | 'edit'>;
|
|
7
8
|
pluginId: string;
|
|
8
9
|
}
|
|
9
10
|
export interface RuleCodeActionData {
|
|
10
11
|
uri: string;
|
|
12
|
+
version: number;
|
|
11
13
|
documentUri: string;
|
|
12
14
|
type: 'rule';
|
|
15
|
+
isFormat: boolean;
|
|
13
16
|
ruleId: string;
|
|
14
17
|
ruleFixIndex: number;
|
|
15
18
|
index: number;
|
|
16
19
|
}
|
|
17
|
-
export declare function register(context:
|
|
20
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
@@ -19,12 +19,12 @@ const rename_1 = require("./rename");
|
|
|
19
19
|
function register(context) {
|
|
20
20
|
return (uri, range, codeActionContext) => __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
var _a, _b, _c, _d, _e;
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
22
|
+
const sourceDocument = context.getTextDocument(uri);
|
|
23
|
+
if (!sourceDocument)
|
|
24
24
|
return;
|
|
25
25
|
const offsetRange = {
|
|
26
|
-
start:
|
|
27
|
-
end:
|
|
26
|
+
start: sourceDocument.offsetAt(range.start),
|
|
27
|
+
end: sourceDocument.offsetAt(range.end),
|
|
28
28
|
};
|
|
29
29
|
const pluginActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => {
|
|
30
30
|
var _a, _b;
|
|
@@ -59,6 +59,10 @@ function register(context) {
|
|
|
59
59
|
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
|
|
60
60
|
const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
|
|
61
61
|
const data = diagnostic.data;
|
|
62
|
+
if (data && data.version !== sourceDocument.version) {
|
|
63
|
+
console.warn('[volar/plugin-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
62
66
|
return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId;
|
|
63
67
|
}).map(diagnostic => {
|
|
64
68
|
const data = diagnostic.data;
|
|
@@ -68,6 +72,7 @@ function register(context) {
|
|
|
68
72
|
codeActions === null || codeActions === void 0 ? void 0 : codeActions.forEach(codeAction => {
|
|
69
73
|
codeAction.data = {
|
|
70
74
|
uri,
|
|
75
|
+
version: document.version,
|
|
71
76
|
type: 'plugin',
|
|
72
77
|
original: {
|
|
73
78
|
data: codeAction.data,
|
|
@@ -81,7 +86,7 @@ function register(context) {
|
|
|
81
86
|
if (!sourceMap)
|
|
82
87
|
return _codeAction;
|
|
83
88
|
if (_codeAction.edit) {
|
|
84
|
-
const edit = (0, rename_1.embeddedEditToSourceEdit)(_codeAction.edit, context.documents);
|
|
89
|
+
const edit = (0, rename_1.embeddedEditToSourceEdit)(_codeAction.edit, context.documents, 'codeAction');
|
|
85
90
|
if (edit) {
|
|
86
91
|
_codeAction.edit = edit;
|
|
87
92
|
return _codeAction;
|
|
@@ -94,6 +99,10 @@ function register(context) {
|
|
|
94
99
|
const ruleActions = [];
|
|
95
100
|
for (const diagnostic of codeActionContext.diagnostics) {
|
|
96
101
|
const data = diagnostic.data;
|
|
102
|
+
if (data && data.version !== sourceDocument.version) {
|
|
103
|
+
console.warn('[volar/rules-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
97
106
|
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
|
|
98
107
|
const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.pluginOrRuleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex];
|
|
99
108
|
if (fixes) {
|
|
@@ -104,7 +113,7 @@ function register(context) {
|
|
|
104
113
|
matchKinds.push(undefined);
|
|
105
114
|
}
|
|
106
115
|
else {
|
|
107
|
-
for (const kind of (_d = fix.kinds) !== null && _d !== void 0 ? _d : ['quickfix'
|
|
116
|
+
for (const kind of (_d = fix.kinds) !== null && _d !== void 0 ? _d : ['quickfix']) {
|
|
108
117
|
const matchOnly = matchOnlyKind(codeActionContext.only, kind);
|
|
109
118
|
if (matchOnly) {
|
|
110
119
|
matchKinds.push(matchOnly);
|
|
@@ -119,6 +128,8 @@ function register(context) {
|
|
|
119
128
|
data: {
|
|
120
129
|
uri,
|
|
121
130
|
type: 'rule',
|
|
131
|
+
version: data.version,
|
|
132
|
+
isFormat: data.isFormat,
|
|
122
133
|
ruleId: data.pluginOrRuleId,
|
|
123
134
|
documentUri: data.documentUri,
|
|
124
135
|
ruleFixIndex: data.ruleFixIndex,
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { LanguageServicePluginContext } from '../types';
|
|
2
|
+
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
3
|
export interface PluginCodeLensData {
|
|
4
|
+
kind: 'normal';
|
|
4
5
|
uri: string;
|
|
5
|
-
original: Pick<
|
|
6
|
+
original: Pick<vscode.CodeLens, 'data'>;
|
|
6
7
|
pluginId: string;
|
|
7
8
|
}
|
|
8
|
-
export
|
|
9
|
+
export interface PluginReferencesCodeLensData {
|
|
10
|
+
kind: 'references';
|
|
11
|
+
uri: string;
|
|
12
|
+
location: vscode.Location;
|
|
13
|
+
pluginId: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.CodeLens[]>;
|