@volar/language-service 1.2.0-alpha.1 → 1.2.0-alpha.11
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 +84 -151
- 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 +90 -39
- 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");
|
|
@@ -23,13 +23,13 @@ function register(context) {
|
|
|
23
23
|
const source = context.documents.getSourceByUri(document.uri);
|
|
24
24
|
if (!source) {
|
|
25
25
|
return onTypeParams
|
|
26
|
-
? yield tryFormat(document, onTypeParams.position,
|
|
26
|
+
? yield tryFormat(document, onTypeParams.position, onTypeParams.ch)
|
|
27
27
|
: yield tryFormat(document, range, undefined);
|
|
28
28
|
}
|
|
29
|
+
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 };
|
|
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,47 +37,34 @@ function register(context) {
|
|
|
37
37
|
if (embeddedFiles.length === 0)
|
|
38
38
|
break;
|
|
39
39
|
let edits = [];
|
|
40
|
-
|
|
40
|
+
const toPatchIndentUris = [];
|
|
41
41
|
for (const embedded of embeddedFiles) {
|
|
42
42
|
if (!embedded.capabilities.documentFormatting)
|
|
43
43
|
continue;
|
|
44
|
+
const enabledOnType = typeof embedded.capabilities.documentFormatting === 'object' ? !!embedded.capabilities.documentFormatting.onType : true;
|
|
45
|
+
if (onTypeParams && !enabledOnType)
|
|
46
|
+
continue;
|
|
44
47
|
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
|
|
45
48
|
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
|
|
46
49
|
if (!map)
|
|
47
50
|
continue;
|
|
48
|
-
|
|
49
|
-
? embedded.capabilities.documentFormatting.initialIndentBracket
|
|
50
|
-
: undefined;
|
|
51
|
-
let _edits;
|
|
51
|
+
let virtualCodeEdits;
|
|
52
52
|
if (onTypeParams) {
|
|
53
53
|
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
54
54
|
if (embeddedPosition) {
|
|
55
|
-
|
|
55
|
+
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (firstMapping && document.offsetAt(range.start) < firstMapping.sourceRange[0]
|
|
64
|
-
&& lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange[1]) {
|
|
65
|
-
genRange = {
|
|
66
|
-
start: map.virtualFileDocument.positionAt(firstMapping.generatedRange[0]),
|
|
67
|
-
end: map.virtualFileDocument.positionAt(lastMapping.generatedRange[1]),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (genRange) {
|
|
72
|
-
toPatchIndent = {
|
|
73
|
-
sourceMapEmbeddedDocumentUri: map.virtualFileDocument.uri,
|
|
74
|
-
};
|
|
75
|
-
_edits = yield tryFormat(map.virtualFileDocument, genRange, initialIndentBracket);
|
|
76
|
-
}
|
|
59
|
+
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, {
|
|
60
|
+
start: map.virtualFileDocument.positionAt(0),
|
|
61
|
+
end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
|
|
62
|
+
});
|
|
77
63
|
}
|
|
78
|
-
if (!
|
|
64
|
+
if (!virtualCodeEdits)
|
|
79
65
|
continue;
|
|
80
|
-
|
|
66
|
+
toPatchIndentUris.push(map.virtualFileDocument.uri);
|
|
67
|
+
for (const textEdit of virtualCodeEdits) {
|
|
81
68
|
const range = map.toSourceRange(textEdit.range);
|
|
82
69
|
if (range) {
|
|
83
70
|
edits.push({
|
|
@@ -87,20 +74,25 @@ function register(context) {
|
|
|
87
74
|
}
|
|
88
75
|
}
|
|
89
76
|
}
|
|
77
|
+
edits = edits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
|
|
90
78
|
if (edits.length > 0) {
|
|
91
79
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
92
80
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
93
81
|
context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
|
|
94
82
|
edited = true;
|
|
95
83
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
if (level > 1) {
|
|
85
|
+
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
86
|
+
for (const toPatchIndentUri of toPatchIndentUris) {
|
|
87
|
+
for (const [file, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri)) {
|
|
88
|
+
let indentEdits = patchInterpolationIndent(document, map.map, initialIndentLanguageId[map.virtualFileDocument.languageId] ? baseIndent : '', file.capabilities.documentFormatting);
|
|
89
|
+
indentEdits = indentEdits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
|
|
90
|
+
if (indentEdits.length > 0) {
|
|
91
|
+
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
92
|
+
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
93
|
+
context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
|
|
94
|
+
edited = true;
|
|
95
|
+
}
|
|
104
96
|
}
|
|
105
97
|
}
|
|
106
98
|
}
|
|
@@ -126,100 +118,25 @@ function register(context) {
|
|
|
126
118
|
embeddedFilesByLevel.push(nextLevel);
|
|
127
119
|
}
|
|
128
120
|
}
|
|
129
|
-
function tryFormat(document, range,
|
|
121
|
+
function tryFormat(document, range, ch) {
|
|
130
122
|
var _a, _b;
|
|
131
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
let formatDocument = document;
|
|
133
124
|
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
125
|
for (const plugin of Object.values(context.plugins)) {
|
|
159
126
|
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
127
|
try {
|
|
192
128
|
if (ch !== undefined && vscode.Position.is(formatRange)) {
|
|
193
|
-
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin,
|
|
129
|
+
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, document, formatRange, ch, options));
|
|
194
130
|
}
|
|
195
131
|
else if (ch === undefined && vscode.Range.is(formatRange)) {
|
|
196
|
-
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin,
|
|
132
|
+
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, options));
|
|
197
133
|
}
|
|
198
134
|
}
|
|
199
135
|
catch (err) {
|
|
200
|
-
console.
|
|
136
|
+
console.warn(err);
|
|
201
137
|
}
|
|
202
|
-
recover === null || recover === void 0 ? void 0 : recover();
|
|
203
138
|
if (!edits)
|
|
204
139
|
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
140
|
return edits;
|
|
224
141
|
}
|
|
225
142
|
});
|
|
@@ -227,51 +144,67 @@ function register(context) {
|
|
|
227
144
|
});
|
|
228
145
|
}
|
|
229
146
|
exports.register = register;
|
|
230
|
-
function patchInterpolationIndent(document, map) {
|
|
147
|
+
function patchInterpolationIndent(document, map, initialIndent, data) {
|
|
148
|
+
const insertFirstNewline = typeof data === 'object' ? data.insertFirstNewline : false;
|
|
149
|
+
const insertFinalNewline = typeof data === 'object' ? data.insertFinalNewline : false;
|
|
231
150
|
const indentTextEdits = [];
|
|
232
|
-
for (
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const text = document.getText(textRange);
|
|
238
|
-
if (text.indexOf('\n') === -1)
|
|
151
|
+
for (let i = 0; i < map.mappings.length; i++) {
|
|
152
|
+
const mapping = map.mappings[i];
|
|
153
|
+
const firstLineIndent = getBaseIndent(mapping.sourceRange[0]);
|
|
154
|
+
const text = document.getText().substring(mapping.sourceRange[0], mapping.sourceRange[1]);
|
|
155
|
+
if (text.indexOf('\n') === -1) {
|
|
239
156
|
continue;
|
|
157
|
+
}
|
|
240
158
|
const lines = text.split('\n');
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
159
|
+
const baseIndent = firstLineIndent + initialIndent;
|
|
160
|
+
let lineOffset = lines[0].length + 1;
|
|
161
|
+
if (insertFirstNewline && i === 0 && !text.startsWith('\n')) {
|
|
162
|
+
indentTextEdits.push({
|
|
163
|
+
newText: '\n' + baseIndent,
|
|
164
|
+
range: {
|
|
165
|
+
start: document.positionAt(mapping.sourceRange[0]),
|
|
166
|
+
end: document.positionAt(mapping.sourceRange[0]),
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (baseIndent) {
|
|
171
|
+
for (let i = 1; i < lines.length - 1; i++) {
|
|
172
|
+
if (lines[i] !== '') {
|
|
173
|
+
indentTextEdits.push({
|
|
174
|
+
newText: baseIndent,
|
|
175
|
+
range: {
|
|
176
|
+
start: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
177
|
+
end: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
lineOffset += lines[i].length + 1;
|
|
252
182
|
}
|
|
253
183
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
184
|
+
if (firstLineIndent) {
|
|
185
|
+
indentTextEdits.push({
|
|
186
|
+
newText: firstLineIndent,
|
|
187
|
+
range: {
|
|
188
|
+
start: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
189
|
+
end: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (insertFinalNewline && i === map.mappings.length - 1 && !text.endsWith('\n')) {
|
|
194
|
+
indentTextEdits.push({
|
|
195
|
+
newText: '\n',
|
|
196
|
+
range: {
|
|
197
|
+
start: document.positionAt(mapping.sourceRange[1]),
|
|
198
|
+
end: document.positionAt(mapping.sourceRange[1]),
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
}
|
|
258
202
|
}
|
|
259
203
|
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
204
|
function getBaseIndent(pos) {
|
|
265
205
|
const startPos = document.positionAt(pos);
|
|
266
|
-
const startLineText = document.getText({ start:
|
|
206
|
+
const startLineText = document.getText({ start: { line: startPos.line, character: 0 }, end: startPos });
|
|
267
207
|
return startLineText.substring(0, startLineText.length - startLineText.trimStart().length);
|
|
268
208
|
}
|
|
269
209
|
}
|
|
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
210
|
//# 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>;
|