@volar/language-service 1.2.0-alpha.1 → 1.2.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/baseLanguageService.d.ts +3 -5
- package/out/baseLanguageService.js +11 -14
- 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 +3 -3
- package/out/languageFeatures/callHierarchy.js +5 -3
- package/out/languageFeatures/codeActionResolve.d.ts +2 -2
- package/out/languageFeatures/codeActionResolve.js +28 -15
- package/out/languageFeatures/codeActions.d.ts +15 -6
- package/out/languageFeatures/codeActions.js +94 -22
- package/out/languageFeatures/codeLens.d.ts +11 -4
- package/out/languageFeatures/codeLens.js +25 -15
- package/out/languageFeatures/codeLensResolve.d.ts +4 -2
- package/out/languageFeatures/codeLensResolve.js +20 -12
- package/out/languageFeatures/complete.d.ts +3 -3
- package/out/languageFeatures/complete.js +20 -4
- package/out/languageFeatures/completeResolve.d.ts +2 -2
- package/out/languageFeatures/completeResolve.js +3 -14
- 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/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 +64 -44
- package/out/languageFeatures/renamePrepare.d.ts +2 -2
- package/out/languageFeatures/signatureHelp.d.ts +2 -2
- package/out/languageFeatures/validation.d.ts +7 -3
- package/out/languageFeatures/validation.js +68 -15
- package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
- package/out/transformer/foldingRanges.js +6 -6
- package/out/types.d.ts +93 -40
- package/out/utils/featureWorkers.d.ts +4 -4
- package/out/utils/featureWorkers.js +44 -11
- package/package.json +9 -9
- package/out/languageFeatures/executeCommand.d.ts +0 -11
- package/out/languageFeatures/executeCommand.js +0 -32
- package/out/languageFeatures/validation copy.d.ts +0 -7
- package/out/languageFeatures/validation copy.js +0 -234
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { LanguageServiceHost } from '@volar/language-core';
|
|
2
|
-
import
|
|
3
|
-
import { LanguageServiceConfig, 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:
|
|
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) {
|
|
@@ -55,29 +53,29 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
|
|
|
55
53
|
const documents = new WeakMap();
|
|
56
54
|
const documentVersions = new Map();
|
|
57
55
|
const context = {
|
|
56
|
+
uriToFileName: shared.uriToFileName,
|
|
57
|
+
fileNameToUri: shared.fileNameToUri,
|
|
58
58
|
host,
|
|
59
59
|
core: languageContext,
|
|
60
60
|
env: env,
|
|
61
61
|
get plugins() {
|
|
62
|
-
var _a, _b
|
|
62
|
+
var _a, _b;
|
|
63
63
|
if (!plugins) {
|
|
64
64
|
plugins = {}; // avoid infinite loop
|
|
65
|
-
for (
|
|
65
|
+
for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
|
|
66
66
|
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
|
|
67
67
|
if (plugin instanceof Function) {
|
|
68
|
-
const _plugin = plugin(this
|
|
69
|
-
(_c = _plugin.setup) === null || _c === void 0 ? void 0 : _c.call(_plugin, this);
|
|
68
|
+
const _plugin = plugin(this);
|
|
70
69
|
plugins[pluginId] = _plugin;
|
|
71
70
|
}
|
|
72
|
-
else {
|
|
73
|
-
(_e = (_d = plugin).setup) === null || _e === void 0 ? void 0 : _e.call(_d, this);
|
|
71
|
+
else if (plugin) {
|
|
74
72
|
plugins[pluginId] = plugin;
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
return plugins;
|
|
79
77
|
},
|
|
80
|
-
|
|
78
|
+
config,
|
|
81
79
|
typescript: ts && tsLs ? {
|
|
82
80
|
module: ts,
|
|
83
81
|
languageServiceHost: languageContext.typescript.languageServiceHost,
|
|
@@ -134,7 +132,6 @@ function createLanguageServiceBase(context) {
|
|
|
134
132
|
findDocumentLinks: documentLink.register(context),
|
|
135
133
|
findWorkspaceSymbols: workspaceSymbol.register(context),
|
|
136
134
|
doAutoInsert: autoInsert.register(context),
|
|
137
|
-
doExecuteCommand: executeCommand.register(context),
|
|
138
135
|
getInlayHints: inlayHints.register(context),
|
|
139
136
|
callHierarchy: callHierarchy.register(context),
|
|
140
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,14 +1,14 @@
|
|
|
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'>;
|
|
6
6
|
pluginId: string;
|
|
7
7
|
map: {
|
|
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[]>;
|
|
@@ -22,7 +22,9 @@ function register(context) {
|
|
|
22
22
|
items === null || items === void 0 ? void 0 : items.forEach(item => {
|
|
23
23
|
item.data = {
|
|
24
24
|
uri,
|
|
25
|
-
|
|
25
|
+
original: {
|
|
26
|
+
data: item.data,
|
|
27
|
+
},
|
|
26
28
|
pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
|
|
27
29
|
map: map ? {
|
|
28
30
|
embeddedDocumentUri: map.virtualFileDocument.uri,
|
|
@@ -42,7 +44,7 @@ function register(context) {
|
|
|
42
44
|
const plugin = context.plugins[data.pluginId];
|
|
43
45
|
if (!plugin.callHierarchy)
|
|
44
46
|
return incomingItems;
|
|
45
|
-
item
|
|
47
|
+
Object.assign(item, data.original);
|
|
46
48
|
if (data.map) {
|
|
47
49
|
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
48
50
|
const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
|
|
@@ -81,7 +83,7 @@ function register(context) {
|
|
|
81
83
|
const plugin = context.plugins[data.pluginId];
|
|
82
84
|
if (!plugin.callHierarchy)
|
|
83
85
|
return items;
|
|
84
|
-
item
|
|
86
|
+
Object.assign(item, data.original);
|
|
85
87
|
if (data.map) {
|
|
86
88
|
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
|
|
87
89
|
const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
|
|
@@ -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>;
|
|
@@ -12,27 +12,40 @@ exports.register = void 0;
|
|
|
12
12
|
const rename_1 = require("./rename");
|
|
13
13
|
function register(context) {
|
|
14
14
|
return (item) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
var _a, _b, _c;
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
16
16
|
const data = item.data;
|
|
17
|
-
if (data) {
|
|
17
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === 'plugin') {
|
|
18
18
|
const plugin = context.plugins[data.pluginId];
|
|
19
19
|
if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
|
|
20
20
|
return item;
|
|
21
|
-
item
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
Object.assign(item, data.original);
|
|
22
|
+
item = yield plugin.codeAction.resolve(item);
|
|
23
|
+
if (item.edit) {
|
|
24
|
+
item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
|
|
28
|
+
const fixes = (_d = (_c = (_b = context.ruleFixes) === null || _b === void 0 ? void 0 : _b[data.documentUri]) === null || _c === void 0 ? void 0 : _c[data.ruleId]) === null || _d === void 0 ? void 0 : _d[data.ruleFixIndex];
|
|
29
|
+
const fix = fixes === null || fixes === void 0 ? void 0 : fixes[1][data.index];
|
|
30
|
+
if (fix) {
|
|
31
|
+
let edit = (_f = yield ((_e = fix.getWorkspaceEdit) === null || _e === void 0 ? void 0 : _e.call(fix, fixes[0]))) !== null && _f !== void 0 ? _f : undefined;
|
|
32
|
+
if (!edit) {
|
|
33
|
+
const edits = yield ((_g = fix.getEdits) === null || _g === void 0 ? void 0 : _g.call(fix, fixes[0]));
|
|
34
|
+
if (edits) {
|
|
35
|
+
edit = {
|
|
36
|
+
documentChanges: [{
|
|
37
|
+
textDocument: {
|
|
38
|
+
uri: data.documentUri,
|
|
39
|
+
version: null
|
|
40
|
+
},
|
|
41
|
+
edits,
|
|
42
|
+
}],
|
|
43
|
+
};
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
if (edit) {
|
|
47
|
+
item.edit = (0, rename_1.embeddedEditToSourceEdit)(edit, context.documents, data.isFormat ? 'format' : 'codeAction', { [data.uri]: data.version });
|
|
48
|
+
}
|
|
36
49
|
}
|
|
37
50
|
}
|
|
38
51
|
return item;
|
|
@@ -1,11 +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
|
-
|
|
5
|
+
version: number;
|
|
6
|
+
type: 'plugin';
|
|
7
|
+
original: Pick<vscode.CodeAction, 'data' | 'edit'>;
|
|
6
8
|
pluginId: string;
|
|
7
|
-
map: {
|
|
8
|
-
embeddedDocumentUri: string;
|
|
9
|
-
} | undefined;
|
|
10
9
|
}
|
|
11
|
-
export
|
|
10
|
+
export interface RuleCodeActionData {
|
|
11
|
+
uri: string;
|
|
12
|
+
version: number;
|
|
13
|
+
documentUri: string;
|
|
14
|
+
type: 'rule';
|
|
15
|
+
isFormat: boolean;
|
|
16
|
+
ruleId: string;
|
|
17
|
+
ruleFixIndex: number;
|
|
18
|
+
index: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|