@volar/language-service 1.0.16 → 1.0.17
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/baseDocumentService.js +13 -28
- package/out/baseLanguageService.d.ts +2 -2
- package/out/baseLanguageService.js +4 -4
- package/out/documentFeatures/autoInsert.js +2 -2
- package/out/documentFeatures/colorPresentations.js +4 -4
- package/out/documentFeatures/documentColors.js +3 -3
- package/out/documentFeatures/documentSymbols.js +4 -4
- package/out/documentFeatures/foldingRanges.js +1 -1
- package/out/documentFeatures/format.js +37 -35
- package/out/documentFeatures/linkedEditingRanges.js +2 -2
- package/out/documentFeatures/selectionRanges.js +3 -3
- package/out/documents.d.ts +26 -56
- package/out/documents.js +102 -144
- package/out/languageFeatures/autoInsert.js +7 -7
- package/out/languageFeatures/callHierarchy.d.ts +1 -1
- package/out/languageFeatures/callHierarchy.js +33 -34
- package/out/languageFeatures/codeActionResolve.js +2 -3
- package/out/languageFeatures/codeActions.d.ts +1 -1
- package/out/languageFeatures/codeActions.js +10 -10
- package/out/languageFeatures/codeLens.js +3 -3
- package/out/languageFeatures/complete.d.ts +1 -1
- package/out/languageFeatures/complete.js +32 -33
- package/out/languageFeatures/completeResolve.js +3 -4
- package/out/languageFeatures/definition.d.ts +2 -2
- package/out/languageFeatures/definition.js +24 -20
- package/out/languageFeatures/documentHighlights.js +15 -15
- package/out/languageFeatures/documentLinks.js +8 -9
- package/out/languageFeatures/documentSemanticTokens.js +5 -5
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +2 -1
- package/out/languageFeatures/fileReferences.js +3 -4
- package/out/languageFeatures/fileRename.js +4 -4
- package/out/languageFeatures/hover.js +3 -3
- package/out/languageFeatures/inlayHints.js +10 -10
- package/out/languageFeatures/references.js +21 -20
- package/out/languageFeatures/rename.d.ts +2 -2
- package/out/languageFeatures/rename.js +99 -80
- package/out/languageFeatures/renamePrepare.js +3 -3
- package/out/languageFeatures/signatureHelp.js +1 -1
- package/out/languageFeatures/validation.js +19 -18
- package/out/languageFeatures/workspaceSymbols.js +6 -5
- package/out/types.d.ts +9 -8
- package/out/utils/definePlugin.d.ts +3 -2
- package/out/utils/definePlugin.js +9 -6
- package/out/utils/featureWorkers.d.ts +5 -5
- package/out/utils/featureWorkers.js +15 -14
- package/package.json +7 -7
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
2
2
|
exports.createDocumentService = exports.isTsDocument = exports.createDocumentServiceContext = void 0;
|
|
3
3
|
const language_core_1 = require("@volar/language-core");
|
|
4
4
|
const shared = require("@volar/shared");
|
|
5
|
-
const reactivity_1 = require("@vue/reactivity");
|
|
6
5
|
const autoInsert = require("./documentFeatures/autoInsert");
|
|
7
6
|
const colorPresentations = require("./documentFeatures/colorPresentations");
|
|
8
7
|
const documentColors = require("./documentFeatures/documentColors");
|
|
@@ -14,8 +13,8 @@ const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
|
14
13
|
const documents_1 = require("./documents");
|
|
15
14
|
const singleFileTypeScriptService_1 = require("./utils/singleFileTypeScriptService");
|
|
16
15
|
function createDocumentServiceContext(options) {
|
|
17
|
-
const ts = options.ts;
|
|
18
16
|
let plugins;
|
|
17
|
+
const ts = options.ts;
|
|
19
18
|
const pluginContext = {
|
|
20
19
|
typescript: {
|
|
21
20
|
module: ts,
|
|
@@ -25,9 +24,9 @@ function createDocumentServiceContext(options) {
|
|
|
25
24
|
env: options.env,
|
|
26
25
|
};
|
|
27
26
|
const languageModules = options.getLanguageModules();
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
27
|
+
const lastUpdateVersions = new Map();
|
|
28
|
+
const virtualFiles = (0, language_core_1.createVirtualFiles)(languageModules);
|
|
29
|
+
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(virtualFiles);
|
|
31
30
|
const context = {
|
|
32
31
|
typescript: ts,
|
|
33
32
|
get plugins() {
|
|
@@ -41,31 +40,17 @@ function createDocumentServiceContext(options) {
|
|
|
41
40
|
return plugins;
|
|
42
41
|
},
|
|
43
42
|
pluginContext,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return cache;
|
|
52
|
-
}
|
|
53
|
-
for (const languageModule of languageModules) {
|
|
54
|
-
let sourceFile = languageModule.createSourceFile('/untitled.' + shared.languageIdToSyntax(document.languageId), ts.ScriptSnapshot.fromString(document.getText()));
|
|
55
|
-
if (sourceFile) {
|
|
56
|
-
sourceFile = (0, reactivity_1.shallowReactive)(sourceFile);
|
|
57
|
-
const sourceFileDoc = (0, documents_1.parseSourceFileDocument)(sourceFile);
|
|
58
|
-
cache = [sourceFileDoc, languageModule];
|
|
59
|
-
vueDocuments.set(document, cache);
|
|
60
|
-
fileMods.set(sourceFile, languageModule);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
43
|
+
documents: textDocumentMapper,
|
|
44
|
+
update(document) {
|
|
45
|
+
let lastVersion = lastUpdateVersions.get(document.uri);
|
|
46
|
+
if (lastVersion === undefined || lastVersion !== document.version) {
|
|
47
|
+
const fileName = shared.getPathOfUri(document.uri);
|
|
48
|
+
virtualFiles.update(fileName, ts.ScriptSnapshot.fromString(document.getText()));
|
|
49
|
+
lastUpdateVersions.set(document.uri, document.version);
|
|
63
50
|
}
|
|
64
|
-
return cache;
|
|
65
51
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
mapper.onSourceFileUpdated(sourceFile);
|
|
52
|
+
updateVirtualFile(fileName, snapshot) {
|
|
53
|
+
virtualFiles.update(fileName, snapshot);
|
|
69
54
|
},
|
|
70
55
|
prepareLanguageServices(document) {
|
|
71
56
|
if (isTsDocument(document)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLanguageContext, LanguageServiceHost } from '@volar/language-core';
|
|
2
2
|
import * as executeCommand from './languageFeatures/executeCommand';
|
|
3
3
|
import { LanguageServicePlugin, LanguageServicePluginContext, LanguageServiceRuntimeContext } from './types';
|
|
4
4
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
@@ -6,7 +6,7 @@ import type * as _ from 'vscode-languageserver-protocol';
|
|
|
6
6
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
7
7
|
export declare function createLanguageServiceContext(options: {
|
|
8
8
|
host: LanguageServiceHost;
|
|
9
|
-
context: ReturnType<typeof
|
|
9
|
+
context: ReturnType<typeof createLanguageContext>;
|
|
10
10
|
getPlugins(): LanguageServicePlugin[];
|
|
11
11
|
env: LanguageServicePluginContext['env'];
|
|
12
12
|
documentRegistry: ts.DocumentRegistry | undefined;
|
|
@@ -29,18 +29,18 @@ const diagnostics = require("./languageFeatures/validation");
|
|
|
29
29
|
const workspaceSymbol = require("./languageFeatures/workspaceSymbols");
|
|
30
30
|
function createLanguageServiceContext(options) {
|
|
31
31
|
const ts = options.host.getTypeScriptModule();
|
|
32
|
-
const tsLs = ts.createLanguageService(options.context.
|
|
33
|
-
tsFaster.decorate(ts, options.context.
|
|
32
|
+
const tsLs = ts.createLanguageService(options.context.typescript.languageServiceHost, options.documentRegistry);
|
|
33
|
+
tsFaster.decorate(ts, options.context.typescript.languageServiceHost, tsLs);
|
|
34
34
|
let plugins;
|
|
35
35
|
const pluginContext = {
|
|
36
36
|
env: options.env,
|
|
37
37
|
typescript: {
|
|
38
38
|
module: options.host.getTypeScriptModule(),
|
|
39
|
-
languageServiceHost: options.context.
|
|
39
|
+
languageServiceHost: options.context.typescript.languageServiceHost,
|
|
40
40
|
languageService: tsLs,
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
const textDocumentMapper = (0, documents_1.
|
|
43
|
+
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(options.context.virtualFiles);
|
|
44
44
|
const documents = new WeakMap();
|
|
45
45
|
const documentVersions = new Map();
|
|
46
46
|
const context = {
|
|
@@ -3,10 +3,10 @@ exports.register = void 0;
|
|
|
3
3
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
4
4
|
function register(context) {
|
|
5
5
|
return (document, position, options) => {
|
|
6
|
-
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, () => true, (position,
|
|
6
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, () => true, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, options); }, (data, map) => {
|
|
7
7
|
if (typeof data === 'string')
|
|
8
8
|
return data;
|
|
9
|
-
const range =
|
|
9
|
+
const range = map.toSourceRange(data.range);
|
|
10
10
|
if (range) {
|
|
11
11
|
data.range = range;
|
|
12
12
|
return data;
|
|
@@ -4,17 +4,17 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
4
4
|
const shared = require("@volar/shared");
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (document, color, range) => {
|
|
7
|
-
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, range,
|
|
8
|
-
(range,
|
|
7
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, range, (file) => !!file.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
8
|
+
(range, map) => map.toGeneratedRanges(range), (plugin, document, range) => { var _a; return (_a = plugin.getColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range); }, (data, map) => data.map(cp => {
|
|
9
9
|
if (cp.textEdit) {
|
|
10
|
-
const range =
|
|
10
|
+
const range = map.toSourceRange(cp.textEdit.range);
|
|
11
11
|
if (!range)
|
|
12
12
|
return undefined;
|
|
13
13
|
cp.textEdit.range = range;
|
|
14
14
|
}
|
|
15
15
|
if (cp.additionalTextEdits) {
|
|
16
16
|
for (const textEdit of cp.additionalTextEdits) {
|
|
17
|
-
const range =
|
|
17
|
+
const range = map.toSourceRange(textEdit.range);
|
|
18
18
|
if (!range)
|
|
19
19
|
return undefined;
|
|
20
20
|
textEdit.range = range;
|
|
@@ -5,9 +5,9 @@ const vscode = require("vscode-languageserver-protocol");
|
|
|
5
5
|
const shared = require("@volar/shared");
|
|
6
6
|
function register(context) {
|
|
7
7
|
return (document) => {
|
|
8
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, document,
|
|
9
|
-
(plugin, document) => { var _a; return (_a = plugin.findDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data,
|
|
10
|
-
const range =
|
|
8
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, document, (file) => !!file.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
9
|
+
(plugin, document) => { var _a; return (_a = plugin.findDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(color => {
|
|
10
|
+
const range = map.toSourceRange(color.range);
|
|
11
11
|
if (range) {
|
|
12
12
|
return vscode.ColorInformation.create(range, color.color);
|
|
13
13
|
}
|
|
@@ -5,11 +5,11 @@ const transforms_1 = require("@volar/transforms");
|
|
|
5
5
|
const vscode = require("vscode-languageserver-protocol");
|
|
6
6
|
function register(context) {
|
|
7
7
|
return (document) => {
|
|
8
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, document,
|
|
9
|
-
(plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data,
|
|
10
|
-
const range =
|
|
8
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, document, file => !!file.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
9
|
+
(plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => (0, transforms_1.transformSymbolInformations)(data, location => {
|
|
10
|
+
const range = map.toSourceRange(location.range);
|
|
11
11
|
if (range) {
|
|
12
|
-
// use document.uri instead of
|
|
12
|
+
// use document.uri instead of map.sourceDocument.uri to fix https://github.com/johnsoncodehk/volar/issues/1925
|
|
13
13
|
return vscode.Location.create(document.uri, range);
|
|
14
14
|
}
|
|
15
15
|
}), arr => arr.flat());
|
|
@@ -4,7 +4,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
4
4
|
const transforms_1 = require("@volar/transforms");
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (document) => {
|
|
7
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, document,
|
|
7
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, document, file => !!file.capabilities.foldingRange, (plugin, document) => { var _a; return (_a = plugin.getFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, sourceMap) => (0, transforms_1.transformFoldingRanges)(data, range => sourceMap === null || sourceMap === void 0 ? void 0 : sourceMap.toSourceRange(range)), arr => arr.flat());
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.register = register;
|
|
@@ -14,16 +14,16 @@ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-text
|
|
|
14
14
|
function register(context) {
|
|
15
15
|
const ts = context.typescript;
|
|
16
16
|
return (document, options, range, onTypeParams) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
var _a, _b;
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
18
|
if (!range) {
|
|
19
19
|
range = vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length));
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const virtualFile = context.documents.getVirtualFileByUri(document.uri);
|
|
22
22
|
const originalDocument = document;
|
|
23
23
|
const rootEdits = onTypeParams
|
|
24
24
|
? yield tryFormat(document, onTypeParams.position, undefined, onTypeParams.ch)
|
|
25
25
|
: yield tryFormat(document, range, undefined);
|
|
26
|
-
if (!
|
|
26
|
+
if (!virtualFile)
|
|
27
27
|
return rootEdits;
|
|
28
28
|
if (rootEdits === null || rootEdits === void 0 ? void 0 : rootEdits.length) {
|
|
29
29
|
applyEdits(rootEdits);
|
|
@@ -32,49 +32,52 @@ function register(context) {
|
|
|
32
32
|
const initialIndentLanguageId = (_b = yield ((_a = context.pluginContext.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
|
|
33
33
|
while (true) {
|
|
34
34
|
tryUpdateVueDocument();
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
35
|
+
const embeddedFiles = getEmbeddedFilesByLevel(virtualFile, level++);
|
|
36
|
+
if (embeddedFiles.length === 0)
|
|
37
37
|
break;
|
|
38
38
|
let edits = [];
|
|
39
39
|
let toPatchIndent;
|
|
40
|
-
for (const embedded of
|
|
40
|
+
for (const embedded of embeddedFiles) {
|
|
41
41
|
if (!embedded.capabilities.documentFormatting)
|
|
42
42
|
continue;
|
|
43
|
-
const
|
|
44
|
-
const
|
|
43
|
+
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
|
|
44
|
+
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
|
|
45
|
+
if (!map)
|
|
46
|
+
continue;
|
|
47
|
+
const initialIndentBracket = typeof embedded.capabilities.documentFormatting === 'object' && initialIndentLanguageId[map.virtualFileDocument.languageId]
|
|
45
48
|
? embedded.capabilities.documentFormatting.initialIndentBracket
|
|
46
49
|
: undefined;
|
|
47
50
|
let _edits;
|
|
48
51
|
if (onTypeParams) {
|
|
49
|
-
const embeddedPosition =
|
|
52
|
+
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
50
53
|
if (embeddedPosition) {
|
|
51
|
-
_edits = yield tryFormat(
|
|
54
|
+
_edits = yield tryFormat(map.virtualFileDocument, embeddedPosition, initialIndentBracket, onTypeParams.ch);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
|
-
let genRange =
|
|
58
|
+
let genRange = map.toGeneratedRange(range);
|
|
56
59
|
if (!genRange) {
|
|
57
|
-
const firstMapping =
|
|
58
|
-
const lastMapping =
|
|
60
|
+
const firstMapping = map.map.mappings.sort((a, b) => a.sourceRange[0] - b.sourceRange[0])[0];
|
|
61
|
+
const lastMapping = map.map.mappings.sort((a, b) => b.sourceRange[0] - a.sourceRange[0])[0];
|
|
59
62
|
if (firstMapping && document.offsetAt(range.start) < firstMapping.sourceRange[0]
|
|
60
63
|
&& lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange[1]) {
|
|
61
64
|
genRange = {
|
|
62
|
-
start:
|
|
63
|
-
end:
|
|
65
|
+
start: map.virtualFileDocument.positionAt(firstMapping.generatedRange[0]),
|
|
66
|
+
end: map.virtualFileDocument.positionAt(lastMapping.generatedRange[1]),
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
if (genRange) {
|
|
68
71
|
toPatchIndent = {
|
|
69
|
-
sourceMapEmbeddedDocumentUri:
|
|
72
|
+
sourceMapEmbeddedDocumentUri: map.virtualFileDocument.uri,
|
|
70
73
|
};
|
|
71
|
-
_edits = yield tryFormat(
|
|
74
|
+
_edits = yield tryFormat(map.virtualFileDocument, genRange, initialIndentBracket);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
if (!_edits)
|
|
75
78
|
continue;
|
|
76
79
|
for (const textEdit of _edits) {
|
|
77
|
-
const range =
|
|
80
|
+
const range = map.toSourceRange(textEdit.range);
|
|
78
81
|
if (range) {
|
|
79
82
|
edits.push({
|
|
80
83
|
newText: textEdit.newText,
|
|
@@ -88,9 +91,10 @@ function register(context) {
|
|
|
88
91
|
}
|
|
89
92
|
if (toPatchIndent) {
|
|
90
93
|
tryUpdateVueDocument();
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
const maps = [...context.documents.getMapsByVirtualFileName(virtualFile.fileName)];
|
|
95
|
+
const map = (_d = maps.find(map => map[1].sourceFileDocument.uri === (toPatchIndent === null || toPatchIndent === void 0 ? void 0 : toPatchIndent.sourceMapEmbeddedDocumentUri))) === null || _d === void 0 ? void 0 : _d[1];
|
|
96
|
+
if (map) {
|
|
97
|
+
const indentEdits = patchInterpolationIndent(context.documents.getDocumentByFileName(virtualFile.snapshot, virtualFile.fileName), map);
|
|
94
98
|
if (indentEdits.length > 0) {
|
|
95
99
|
applyEdits(indentEdits);
|
|
96
100
|
}
|
|
@@ -103,21 +107,20 @@ function register(context) {
|
|
|
103
107
|
const textEdit = vscode.TextEdit.replace(editRange, document.getText());
|
|
104
108
|
return [textEdit];
|
|
105
109
|
function tryUpdateVueDocument() {
|
|
106
|
-
if (
|
|
107
|
-
context.
|
|
110
|
+
if (virtualFile && virtualFile.snapshot.getText(0, virtualFile.snapshot.getLength()) !== document.getText()) {
|
|
111
|
+
context.updateVirtualFile(virtualFile.fileName, ts.ScriptSnapshot.fromString(document.getText()));
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
const embeddedsLevels = [embeddeds];
|
|
114
|
+
function getEmbeddedFilesByLevel(rootFile, level) {
|
|
115
|
+
const embeddedFilesByLevel = [rootFile.embeddedFiles];
|
|
113
116
|
while (true) {
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
116
|
-
let
|
|
117
|
-
for (const
|
|
118
|
-
|
|
117
|
+
if (embeddedFilesByLevel.length > level)
|
|
118
|
+
return embeddedFilesByLevel[level];
|
|
119
|
+
let nextLevel = [];
|
|
120
|
+
for (const file of embeddedFilesByLevel[embeddedFilesByLevel.length - 1]) {
|
|
121
|
+
nextLevel = nextLevel.concat(file.embeddedFiles);
|
|
119
122
|
}
|
|
120
|
-
|
|
123
|
+
embeddedFilesByLevel.push(nextLevel);
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
function tryFormat(document, range, initialIndentBracket, ch) {
|
|
@@ -196,10 +199,9 @@ function register(context) {
|
|
|
196
199
|
});
|
|
197
200
|
}
|
|
198
201
|
exports.register = register;
|
|
199
|
-
function patchInterpolationIndent(
|
|
202
|
+
function patchInterpolationIndent(document, map) {
|
|
200
203
|
const indentTextEdits = [];
|
|
201
|
-
const
|
|
202
|
-
for (const mapped of sourceMap.mappings) {
|
|
204
|
+
for (const mapped of map.map.mappings) {
|
|
203
205
|
const textRange = {
|
|
204
206
|
start: document.positionAt(mapped.sourceRange[0]),
|
|
205
207
|
end: document.positionAt(mapped.sourceRange[1]),
|
|
@@ -4,9 +4,9 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
4
4
|
const shared = require("@volar/shared");
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (document, position) => {
|
|
7
|
-
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, () => true, (position,
|
|
7
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, () => true, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.findLinkedEditingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (data, map) => ({
|
|
8
8
|
wordPattern: data.wordPattern,
|
|
9
|
-
ranges: data.ranges.map(range =>
|
|
9
|
+
ranges: data.ranges.map(range => map.toSourceRange(range)).filter(shared.notEmpty),
|
|
10
10
|
}));
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -5,15 +5,15 @@ const transforms_1 = require("@volar/transforms");
|
|
|
5
5
|
const shared = require("@volar/shared");
|
|
6
6
|
function register(context) {
|
|
7
7
|
return (document, positions) => {
|
|
8
|
-
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, positions,
|
|
8
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, positions, file => !!file.capabilities.documentFormatting, (positions, map) => {
|
|
9
9
|
const result = positions
|
|
10
|
-
.map(position =>
|
|
10
|
+
.map(position => map.toGeneratedPosition(position))
|
|
11
11
|
.filter(shared.notEmpty);
|
|
12
12
|
if (result.length) {
|
|
13
13
|
return [result];
|
|
14
14
|
}
|
|
15
15
|
return [];
|
|
16
|
-
}, (plugin, document, positions) => { var _a; return (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions); }, (item,
|
|
16
|
+
}, (plugin, document, positions) => { var _a; return (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions); }, (item, map) => (0, transforms_1.transformSelectionRanges)(item, range => map.toSourceRange(range)), results => {
|
|
17
17
|
for (let i = 0; i < results[0].length; i++) {
|
|
18
18
|
const first = results[0][i];
|
|
19
19
|
let lastParent = first;
|
package/out/documents.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Mapping,
|
|
1
|
+
import { VirtualFiles, VirtualFile, FileRangeCapabilities, MirrorBehaviorCapabilities, MirrorMap } from '@volar/language-core';
|
|
2
|
+
import { Mapping, SourceMap } from '@volar/source-map';
|
|
3
3
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
4
4
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
|
|
6
|
-
export type
|
|
7
|
-
export declare class
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
5
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
6
|
+
export type DocumentsAndSourceMaps = ReturnType<typeof createDocumentsAndSourceMaps>;
|
|
7
|
+
export declare class SourceMapWithDocuments<Data = any> {
|
|
8
|
+
sourceFileDocument: TextDocument;
|
|
9
|
+
virtualFileDocument: TextDocument;
|
|
10
|
+
map: SourceMap<Data>;
|
|
11
|
+
constructor(sourceFileDocument: TextDocument, virtualFileDocument: TextDocument, map: SourceMap<Data>);
|
|
12
12
|
toSourceRange(range: vscode.Range, filter?: (data: Data) => boolean): vscode.Range | undefined;
|
|
13
13
|
toGeneratedRange(range: vscode.Range, filter?: (data: Data) => boolean): vscode.Range | undefined;
|
|
14
14
|
toSourceRanges(range: vscode.Range, filter?: (data: Data) => boolean): Generator<vscode.Range, void, unknown>;
|
|
@@ -24,55 +24,25 @@ export declare class SourceMap<Data = undefined> extends SourceMapBase<Data> {
|
|
|
24
24
|
protected matchSourcePosition(position: vscode.Position, mapping: Mapping, baseOffset: 'left' | 'right'): import("vscode-languageserver-textdocument").Position | undefined;
|
|
25
25
|
protected matchGeneratedPosition(position: vscode.Position, mapping: Mapping, baseOffset: 'left' | 'right'): import("vscode-languageserver-textdocument").Position | undefined;
|
|
26
26
|
}
|
|
27
|
-
export declare class
|
|
28
|
-
embeddedFile: EmbeddedFile;
|
|
29
|
-
sourceDocument: TextDocument;
|
|
30
|
-
mappedDocument: TextDocument;
|
|
31
|
-
constructor(embeddedFile: EmbeddedFile, sourceDocument: TextDocument, mappedDocument: TextDocument, mappings: Mapping<PositionCapabilities>[]);
|
|
32
|
-
}
|
|
33
|
-
export declare class TeleportSourceMap extends SourceMap<TeleportMappingData> {
|
|
34
|
-
embeddedFile: EmbeddedFile;
|
|
27
|
+
export declare class MirrorMapWithDocument extends SourceMapWithDocuments<[MirrorBehaviorCapabilities, MirrorBehaviorCapabilities]> {
|
|
35
28
|
document: TextDocument;
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
29
|
+
constructor(document: TextDocument, map: MirrorMap);
|
|
30
|
+
findMirrorPositions(start: vscode.Position): Generator<readonly [import("vscode-languageserver-textdocument").Position, MirrorBehaviorCapabilities], void, unknown>;
|
|
38
31
|
}
|
|
39
|
-
export declare function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getTeleports: () => TeleportSourceMap[];
|
|
47
|
-
getDocument: () => TextDocument;
|
|
48
|
-
}[];
|
|
49
|
-
get: (uri: string) => {
|
|
50
|
-
uri: string;
|
|
51
|
-
file: SourceFile;
|
|
52
|
-
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
53
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => TextDocument;
|
|
54
|
-
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
55
|
-
getTeleports: () => TeleportSourceMap[];
|
|
56
|
-
getDocument: () => TextDocument;
|
|
32
|
+
export declare function createDocumentsAndSourceMaps(mapper: VirtualFiles): {
|
|
33
|
+
getRootFileBySourceFileUri(sourceFileUri: string): VirtualFile | undefined;
|
|
34
|
+
getVirtualFileByUri(virtualFileUri: string): VirtualFile | undefined;
|
|
35
|
+
getMirrorMapByUri(virtualFileUri: string): [VirtualFile, MirrorMapWithDocument] | undefined;
|
|
36
|
+
getMapsBySourceFileUri(uri: string): {
|
|
37
|
+
snapshot: ts.IScriptSnapshot;
|
|
38
|
+
maps: [VirtualFile, SourceMapWithDocuments<FileRangeCapabilities>][];
|
|
57
39
|
} | undefined;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
62
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => TextDocument;
|
|
63
|
-
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
64
|
-
getTeleports: () => TeleportSourceMap[];
|
|
65
|
-
getDocument: () => TextDocument;
|
|
40
|
+
getMapsBySourceFileName(fileName: string): {
|
|
41
|
+
snapshot: ts.IScriptSnapshot;
|
|
42
|
+
maps: [VirtualFile, SourceMapWithDocuments<FileRangeCapabilities>][];
|
|
66
43
|
} | undefined;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
uri: string;
|
|
72
|
-
file: SourceFile;
|
|
73
|
-
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
74
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => TextDocument;
|
|
75
|
-
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
76
|
-
getTeleports: () => TeleportSourceMap[];
|
|
77
|
-
getDocument: () => TextDocument;
|
|
44
|
+
getMapsByVirtualFileUri(virtualFileUri: string): IterableIterator<[VirtualFile, SourceMapWithDocuments<FileRangeCapabilities>]>;
|
|
45
|
+
getMapsByVirtualFileName(virtualFileName: string): IterableIterator<[VirtualFile, SourceMapWithDocuments<FileRangeCapabilities>]>;
|
|
46
|
+
getDocumentByUri(snapshot: ts.IScriptSnapshot, uri: string): TextDocument;
|
|
47
|
+
getDocumentByFileName: (snapshot: ts.IScriptSnapshot, fileName: string) => TextDocument;
|
|
78
48
|
};
|