@volar/language-service 1.0.0-beta.1 → 1.0.0-beta.3
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.d.ts +15 -16
- package/out/baseDocumentService.js +5 -5
- package/out/baseLanguageService.d.ts +35 -36
- package/out/baseLanguageService.js +6 -6
- package/out/documentFeatures/autoInsert.js +2 -9
- package/out/documentFeatures/colorPresentations.js +7 -14
- package/out/documentFeatures/documentColors.js +1 -4
- package/out/documentFeatures/documentSymbols.js +3 -6
- package/out/documentFeatures/foldingRanges.js +1 -6
- package/out/documentFeatures/format.js +23 -30
- package/out/documentFeatures/linkedEditingRanges.js +2 -11
- package/out/documentFeatures/selectionRanges.js +3 -8
- package/out/documents.d.ts +31 -57
- package/out/documents.js +105 -73
- package/out/index.d.ts +0 -1
- package/out/index.js +0 -1
- package/out/languageFeatures/autoInsert.js +20 -21
- package/out/languageFeatures/callHierarchy.js +18 -14
- package/out/languageFeatures/codeActions.js +10 -9
- package/out/languageFeatures/codeLens.js +1 -2
- package/out/languageFeatures/complete.js +11 -7
- package/out/languageFeatures/completeResolve.d.ts +1 -1
- package/out/languageFeatures/completeResolve.js +8 -8
- package/out/languageFeatures/definition.js +17 -20
- package/out/languageFeatures/documentHighlights.js +7 -10
- package/out/languageFeatures/documentLinks.js +4 -5
- package/out/languageFeatures/documentSemanticTokens.d.ts +1 -1
- package/out/languageFeatures/documentSemanticTokens.js +21 -25
- package/out/languageFeatures/executeCommand.d.ts +1 -1
- package/out/languageFeatures/executeCommand.js +1 -1
- package/out/languageFeatures/fileReferences.js +13 -11
- package/out/languageFeatures/fileRename.js +1 -1
- package/out/languageFeatures/hover.js +6 -13
- package/out/languageFeatures/inlayHints.js +12 -11
- package/out/languageFeatures/references.js +14 -13
- package/out/languageFeatures/rename.d.ts +0 -13
- package/out/languageFeatures/rename.js +49 -37
- package/out/languageFeatures/renamePrepare.js +6 -8
- package/out/languageFeatures/signatureHelp.js +1 -5
- package/out/languageFeatures/validation.d.ts +1 -1
- package/out/languageFeatures/validation.js +35 -55
- package/out/languageFeatures/workspaceSymbols.js +9 -2
- package/out/types.d.ts +93 -1
- package/out/types.js +1 -0
- package/out/utils/featureWorkers.d.ts +2 -2
- package/out/utils/featureWorkers.js +1 -4
- package/package.json +7 -8
- package/out/plugin.d.ts +0 -93
- package/out/plugin.js +0 -3
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmbeddedLanguageModule } from '@volar/language-core';
|
|
2
2
|
import * as shared from '@volar/shared';
|
|
3
3
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
import { LanguageServicePlugin } from './
|
|
5
|
-
import
|
|
6
|
-
import type * as _0 from 'vscode-languageserver-protocol';
|
|
4
|
+
import { DocumentServiceRuntimeContext, LanguageServicePlugin, LanguageServicePluginContext } from './types';
|
|
5
|
+
import type * as _ from 'vscode-languageserver-protocol';
|
|
7
6
|
export type DocumentService = ReturnType<typeof createDocumentService>;
|
|
8
7
|
export declare function createDocumentServiceContext(options: {
|
|
9
8
|
ts: typeof import('typescript/lib/tsserverlibrary');
|
|
@@ -13,23 +12,23 @@ export declare function createDocumentServiceContext(options: {
|
|
|
13
12
|
}): DocumentServiceRuntimeContext;
|
|
14
13
|
export declare function isTsDocument(document: TextDocument): boolean;
|
|
15
14
|
export declare function createDocumentService(context: DocumentServiceRuntimeContext): {
|
|
16
|
-
format: (document: shared.
|
|
15
|
+
format: (document: shared._1.TextDocument, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
|
|
17
16
|
ch: string;
|
|
18
|
-
position:
|
|
19
|
-
} | undefined) => Promise<
|
|
20
|
-
getFoldingRanges: (document: shared.
|
|
21
|
-
getSelectionRanges: (document: shared.
|
|
22
|
-
findLinkedEditingRanges: (document: shared.
|
|
23
|
-
findDocumentSymbols: (document: shared.
|
|
24
|
-
findDocumentColors: (document: shared.
|
|
25
|
-
getColorPresentations: (document: shared.
|
|
26
|
-
doAutoInsert: (document: shared.
|
|
17
|
+
position: _.Position;
|
|
18
|
+
} | undefined) => Promise<_.TextEdit[] | undefined>;
|
|
19
|
+
getFoldingRanges: (document: shared._1.TextDocument) => Promise<_.FoldingRange[] | undefined>;
|
|
20
|
+
getSelectionRanges: (document: shared._1.TextDocument, positions: _.Position[]) => Promise<_.SelectionRange[] | undefined>;
|
|
21
|
+
findLinkedEditingRanges: (document: shared._1.TextDocument, position: _.Position) => Promise<_.LinkedEditingRanges | undefined>;
|
|
22
|
+
findDocumentSymbols: (document: shared._1.TextDocument) => Promise<_.SymbolInformation[] | undefined>;
|
|
23
|
+
findDocumentColors: (document: shared._1.TextDocument) => Promise<_.ColorInformation[] | undefined>;
|
|
24
|
+
getColorPresentations: (document: shared._1.TextDocument, color: _.Color, range: _.Range) => Promise<_.ColorPresentation[] | undefined>;
|
|
25
|
+
doAutoInsert: (document: shared._1.TextDocument, position: _.Position, options: {
|
|
27
26
|
lastChange: {
|
|
28
|
-
range:
|
|
27
|
+
range: _.Range;
|
|
29
28
|
rangeOffset: number;
|
|
30
29
|
rangeLength: number;
|
|
31
30
|
text: string;
|
|
32
31
|
};
|
|
33
|
-
}) => Promise<NonNullable<string |
|
|
32
|
+
}) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>;
|
|
34
33
|
context: DocumentServiceRuntimeContext;
|
|
35
34
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
2
|
exports.createDocumentService = exports.isTsDocument = exports.createDocumentServiceContext = void 0;
|
|
3
|
+
const language_core_1 = require("@volar/language-core");
|
|
4
|
+
const shared = require("@volar/shared");
|
|
5
|
+
const reactivity_1 = require("@vue/reactivity");
|
|
3
6
|
const autoInsert = require("./documentFeatures/autoInsert");
|
|
4
7
|
const colorPresentations = require("./documentFeatures/colorPresentations");
|
|
5
8
|
const documentColors = require("./documentFeatures/documentColors");
|
|
@@ -8,11 +11,8 @@ const foldingRanges = require("./documentFeatures/foldingRanges");
|
|
|
8
11
|
const format = require("./documentFeatures/format");
|
|
9
12
|
const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
|
|
10
13
|
const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
11
|
-
const shared = require("@volar/shared");
|
|
12
|
-
const singleFileTypeScriptService_1 = require("./utils/singleFileTypeScriptService");
|
|
13
|
-
const language_core_1 = require("@volar/language-core");
|
|
14
14
|
const documents_1 = require("./documents");
|
|
15
|
-
const
|
|
15
|
+
const singleFileTypeScriptService_1 = require("./utils/singleFileTypeScriptService");
|
|
16
16
|
function createDocumentServiceContext(options) {
|
|
17
17
|
const ts = options.ts;
|
|
18
18
|
let plugins;
|
|
@@ -54,7 +54,7 @@ function createDocumentServiceContext(options) {
|
|
|
54
54
|
let sourceFile = languageModule.createSourceFile('/untitled.' + shared.languageIdToSyntax(document.languageId), ts.ScriptSnapshot.fromString(document.getText()));
|
|
55
55
|
if (sourceFile) {
|
|
56
56
|
sourceFile = (0, reactivity_1.shallowReactive)(sourceFile);
|
|
57
|
-
const sourceFileDoc = (0, documents_1.parseSourceFileDocument)(options.env.rootUri, sourceFile
|
|
57
|
+
const sourceFileDoc = (0, documents_1.parseSourceFileDocument)(options.env.rootUri, sourceFile);
|
|
58
58
|
cache = [sourceFileDoc, languageModule];
|
|
59
59
|
vueDocuments.set(document, cache);
|
|
60
60
|
fileMods.set(sourceFile, languageModule);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createEmbeddedLanguageServiceHost, LanguageServiceHost } from '@volar/language-core';
|
|
2
2
|
import * as executeCommand from './languageFeatures/executeCommand';
|
|
3
|
-
import { LanguageServicePlugin } from './
|
|
4
|
-
import
|
|
5
|
-
import type * as _0 from 'vscode-languageserver-protocol';
|
|
3
|
+
import { LanguageServicePlugin, LanguageServicePluginContext, LanguageServiceRuntimeContext } from './types';
|
|
4
|
+
import type * as _ from 'vscode-languageserver-protocol';
|
|
6
5
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
7
6
|
export declare function createLanguageServiceContext(options: {
|
|
8
7
|
host: LanguageServiceHost;
|
|
@@ -10,47 +9,47 @@ export declare function createLanguageServiceContext(options: {
|
|
|
10
9
|
getPlugins(): LanguageServicePlugin[];
|
|
11
10
|
env: LanguageServicePluginContext['env'];
|
|
12
11
|
documentRegistry: ts.DocumentRegistry | undefined;
|
|
13
|
-
}):
|
|
14
|
-
export declare function createLanguageService(context:
|
|
15
|
-
doValidation: (uri: string, response?: ((result:
|
|
16
|
-
findReferences: (uri: string, position:
|
|
17
|
-
findFileReferences: (uri: string) => import("./
|
|
18
|
-
findDefinition: (uri: string, position:
|
|
19
|
-
findTypeDefinition: (uri: string, position:
|
|
20
|
-
findImplementations: (uri: string, position:
|
|
21
|
-
prepareRename: (uri: string, position:
|
|
22
|
-
doRename: (uri: string, position:
|
|
23
|
-
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<
|
|
24
|
-
getSemanticTokens: (uri: string, range
|
|
25
|
-
doHover: (uri: string, position:
|
|
26
|
-
doComplete: (uri: string, position:
|
|
12
|
+
}): LanguageServiceRuntimeContext;
|
|
13
|
+
export declare function createLanguageService(context: LanguageServiceRuntimeContext): {
|
|
14
|
+
doValidation: (uri: string, token?: _.CancellationToken | undefined, response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>;
|
|
15
|
+
findReferences: (uri: string, position: _.Position) => Promise<_.Location[] | undefined>;
|
|
16
|
+
findFileReferences: (uri: string) => import("./types").NullableResult<_.Location[]>;
|
|
17
|
+
findDefinition: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>;
|
|
18
|
+
findTypeDefinition: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>;
|
|
19
|
+
findImplementations: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>;
|
|
20
|
+
prepareRename: (uri: string, position: _.Position) => Promise<NonNullable<_.Range | _.ResponseError<void> | null | undefined> | undefined>;
|
|
21
|
+
doRename: (uri: string, position: _.Position, newName: string) => Promise<_.WorkspaceEdit | undefined>;
|
|
22
|
+
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<_.WorkspaceEdit | undefined>;
|
|
23
|
+
getSemanticTokens: (uri: string, range: _.Range | undefined, cancleToken: _.CancellationToken, reportProgress?: ((tokens: import("./types").SemanticToken[]) => void) | undefined) => Promise<import("./types").SemanticToken[] | undefined> | undefined;
|
|
24
|
+
doHover: (uri: string, position: _.Position) => Promise<_.Hover | undefined>;
|
|
25
|
+
doComplete: (uri: string, position: _.Position, completionContext?: _.CompletionContext | undefined) => Promise<{
|
|
27
26
|
isIncomplete: boolean;
|
|
28
|
-
items:
|
|
27
|
+
items: _.CompletionItem[];
|
|
29
28
|
}>;
|
|
30
|
-
doCodeActions: (uri: string, range:
|
|
31
|
-
doCodeActionResolve: (item:
|
|
32
|
-
doCompletionResolve: (item:
|
|
33
|
-
getSignatureHelp: (uri: string, position:
|
|
34
|
-
doCodeLens: (uri: string) => Promise<
|
|
35
|
-
doCodeLensResolve: (item:
|
|
36
|
-
findDocumentHighlights: (uri: string, position:
|
|
37
|
-
findDocumentLinks: (uri: string) => Promise<
|
|
38
|
-
findWorkspaceSymbols: (query: string) => Promise<
|
|
39
|
-
doAutoInsert: (uri: string, position:
|
|
29
|
+
doCodeActions: (uri: string, range: _.Range, codeActionContext: _.CodeActionContext) => Promise<_.CodeAction[] | undefined>;
|
|
30
|
+
doCodeActionResolve: (item: _.CodeAction) => Promise<_.CodeAction>;
|
|
31
|
+
doCompletionResolve: (item: _.CompletionItem) => Promise<_.CompletionItem>;
|
|
32
|
+
getSignatureHelp: (uri: string, position: _.Position, signatureHelpContext?: _.SignatureHelpContext | undefined) => Promise<_.SignatureHelp | undefined>;
|
|
33
|
+
doCodeLens: (uri: string) => Promise<_.CodeLens[]>;
|
|
34
|
+
doCodeLensResolve: (item: _.CodeLens) => Promise<_.CodeLens>;
|
|
35
|
+
findDocumentHighlights: (uri: string, position: _.Position) => Promise<_.DocumentHighlight[] | undefined>;
|
|
36
|
+
findDocumentLinks: (uri: string) => Promise<_.DocumentLink[]>;
|
|
37
|
+
findWorkspaceSymbols: (query: string) => Promise<_.SymbolInformation[]>;
|
|
38
|
+
doAutoInsert: (uri: string, position: _.Position, autoInsertContext: {
|
|
40
39
|
lastChange: {
|
|
41
|
-
range:
|
|
40
|
+
range: _.Range;
|
|
42
41
|
rangeOffset: number;
|
|
43
42
|
rangeLength: number;
|
|
44
43
|
text: string;
|
|
45
44
|
};
|
|
46
|
-
}) => Promise<NonNullable<string |
|
|
47
|
-
doExecuteCommand: (command: string, args: executeCommand.ExecutePluginCommandArgs, executeCommandContext: import("./
|
|
48
|
-
getInlayHints: (uri: string, range:
|
|
45
|
+
}) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>;
|
|
46
|
+
doExecuteCommand: (command: string, args: executeCommand.ExecutePluginCommandArgs, executeCommandContext: import("./types").ExecuteCommandContext) => Promise<void>;
|
|
47
|
+
getInlayHints: (uri: string, range: _.Range) => Promise<_.InlayHint[] | undefined>;
|
|
49
48
|
callHierarchy: {
|
|
50
|
-
doPrepare(uri: string, position:
|
|
51
|
-
getIncomingCalls(item:
|
|
52
|
-
getOutgoingCalls(item:
|
|
49
|
+
doPrepare(uri: string, position: _.Position): Promise<_.CallHierarchyItem[] | undefined>;
|
|
50
|
+
getIncomingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyIncomingCall[]>;
|
|
51
|
+
getOutgoingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyOutgoingCall[]>;
|
|
53
52
|
};
|
|
54
53
|
dispose: () => void;
|
|
55
|
-
context:
|
|
54
|
+
context: LanguageServiceRuntimeContext;
|
|
56
55
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
2
|
exports.createLanguageService = exports.createLanguageServiceContext = void 0;
|
|
3
|
+
const shared = require("@volar/shared");
|
|
4
|
+
const tsFaster = require("@volar/typescript-faster");
|
|
5
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
+
const documents_1 = require("./documents");
|
|
3
7
|
const autoInsert = require("./languageFeatures/autoInsert");
|
|
4
8
|
const callHierarchy = require("./languageFeatures/callHierarchy");
|
|
5
9
|
const codeActionResolve = require("./languageFeatures/codeActionResolve");
|
|
@@ -23,10 +27,6 @@ const renamePrepare = require("./languageFeatures/renamePrepare");
|
|
|
23
27
|
const signatureHelp = require("./languageFeatures/signatureHelp");
|
|
24
28
|
const diagnostics = require("./languageFeatures/validation");
|
|
25
29
|
const workspaceSymbol = require("./languageFeatures/workspaceSymbols");
|
|
26
|
-
const tsFaster = require("@volar/typescript-faster");
|
|
27
|
-
const shared = require("@volar/shared");
|
|
28
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
29
|
-
const documents_1 = require("./documents");
|
|
30
30
|
function createLanguageServiceContext(options) {
|
|
31
31
|
const ts = options.host.getTypeScriptModule();
|
|
32
32
|
const tsLs = ts.createLanguageService(options.context.typescriptLanguageServiceHost, options.documentRegistry);
|
|
@@ -84,8 +84,8 @@ function createLanguageService(context) {
|
|
|
84
84
|
doValidation: diagnostics.register(context),
|
|
85
85
|
findReferences: references.register(context),
|
|
86
86
|
findFileReferences: fileReferences.register(context),
|
|
87
|
-
findDefinition: definition.register(context, 'findDefinition', data => !!data.
|
|
88
|
-
findTypeDefinition: definition.register(context, 'findTypeDefinition', data => !!data.
|
|
87
|
+
findDefinition: definition.register(context, 'findDefinition', data => !!data.definition, data => !!data.definition),
|
|
88
|
+
findTypeDefinition: definition.register(context, 'findTypeDefinition', data => !!data.definition, data => !!data.definition),
|
|
89
89
|
findImplementations: definition.register(context, 'findImplementations', data => !!data.references, data => false),
|
|
90
90
|
prepareRename: renamePrepare.register(context),
|
|
91
91
|
doRename: rename.register(context),
|
|
@@ -3,17 +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, sourceMap => true,
|
|
7
|
-
for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
|
|
8
|
-
yield mappedRange.start;
|
|
9
|
-
}
|
|
10
|
-
}, (plugin, document, position) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, options); }, (data, sourceMap) => {
|
|
11
|
-
var _a;
|
|
12
|
-
if (!sourceMap)
|
|
13
|
-
return data;
|
|
6
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, sourceMap => true, (position, sourceMap) => sourceMap.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, sourceMap) => {
|
|
14
7
|
if (typeof data === 'string')
|
|
15
8
|
return data;
|
|
16
|
-
const range =
|
|
9
|
+
const range = sourceMap.toSourceRange(data.range);
|
|
17
10
|
if (range) {
|
|
18
11
|
data.range = range;
|
|
19
12
|
return data;
|
|
@@ -5,26 +5,19 @@ const shared = require("@volar/shared");
|
|
|
5
5
|
function register(context) {
|
|
6
6
|
return (document, color, range) => {
|
|
7
7
|
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, range, sourceMap => !!sourceMap.embeddedFile.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
8
|
-
|
|
9
|
-
for (const [mappedRange] of sourceMap.getMappedRanges(range.start, range.end)) {
|
|
10
|
-
yield mappedRange;
|
|
11
|
-
}
|
|
12
|
-
}, (plugin, document, range) => { var _a; return (_a = plugin.getColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range); }, (data, sourceMap) => data.map(cp => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
if (!sourceMap)
|
|
15
|
-
return cp;
|
|
8
|
+
(range, sourceMap) => sourceMap.toGeneratedRanges(range), (plugin, document, range) => { var _a; return (_a = plugin.getColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range); }, (data, sourceMap) => data.map(cp => {
|
|
16
9
|
if (cp.textEdit) {
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
10
|
+
const range = sourceMap.toSourceRange(cp.textEdit.range);
|
|
11
|
+
if (!range)
|
|
19
12
|
return undefined;
|
|
20
|
-
cp.textEdit.range =
|
|
13
|
+
cp.textEdit.range = range;
|
|
21
14
|
}
|
|
22
15
|
if (cp.additionalTextEdits) {
|
|
23
16
|
for (const textEdit of cp.additionalTextEdits) {
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
17
|
+
const range = sourceMap.toSourceRange(textEdit.range);
|
|
18
|
+
if (!range)
|
|
26
19
|
return undefined;
|
|
27
|
-
textEdit.range =
|
|
20
|
+
textEdit.range = range;
|
|
28
21
|
}
|
|
29
22
|
}
|
|
30
23
|
return cp;
|
|
@@ -7,10 +7,7 @@ function register(context) {
|
|
|
7
7
|
return (document) => {
|
|
8
8
|
return (0, featureWorkers_1.documentFeatureWorker)(context, document, sourceMap => !!sourceMap.embeddedFile.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
9
9
|
(plugin, document) => { var _a; return (_a = plugin.findDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, sourceMap) => data.map(color => {
|
|
10
|
-
|
|
11
|
-
if (!sourceMap)
|
|
12
|
-
return color;
|
|
13
|
-
const range = (_a = sourceMap.getSourceRange(color.range.start, color.range.end)) === null || _a === void 0 ? void 0 : _a[0];
|
|
10
|
+
const range = sourceMap.toSourceRange(color.range);
|
|
14
11
|
if (range) {
|
|
15
12
|
return vscode.ColorInformation.create(range, color.color);
|
|
16
13
|
}
|
|
@@ -7,12 +7,9 @@ function register(context) {
|
|
|
7
7
|
return (document) => {
|
|
8
8
|
return (0, featureWorkers_1.documentFeatureWorker)(context, document, sourceMap => !!sourceMap.embeddedFile.capabilities.documentSymbol, // TODO: add color capabilitie setting
|
|
9
9
|
(plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, sourceMap) => (0, transforms_1.transformSymbolInformations)(data, location => {
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
-
const sourceRange = (_a = sourceMap.getSourceRange(location.range.start, location.range.end)) === null || _a === void 0 ? void 0 : _a[0];
|
|
14
|
-
if (sourceRange) {
|
|
15
|
-
return vscode.Location.create(sourceMap.sourceDocument.uri, sourceRange);
|
|
10
|
+
const range = sourceMap.toSourceRange(location.range);
|
|
11
|
+
if (range) {
|
|
12
|
+
return vscode.Location.create(sourceMap.sourceDocument.uri, range);
|
|
16
13
|
}
|
|
17
14
|
}), arr => arr.flat());
|
|
18
15
|
};
|
|
@@ -4,12 +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, sourceMap => !!sourceMap.embeddedFile.capabilities.
|
|
8
|
-
var _a;
|
|
9
|
-
if (!sourceMap)
|
|
10
|
-
return range;
|
|
11
|
-
return (_a = sourceMap.getSourceRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0];
|
|
12
|
-
}), arr => arr.flat());
|
|
7
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, document, sourceMap => !!sourceMap.embeddedFile.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());
|
|
13
8
|
};
|
|
14
9
|
}
|
|
15
10
|
exports.register = register;
|
|
@@ -14,7 +14,7 @@ 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;
|
|
18
18
|
if (!range) {
|
|
19
19
|
range = vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length));
|
|
20
20
|
}
|
|
@@ -38,51 +38,44 @@ function register(context) {
|
|
|
38
38
|
let edits = [];
|
|
39
39
|
let toPatchIndent;
|
|
40
40
|
for (const embedded of embeddeds) {
|
|
41
|
-
if (!embedded.capabilities.
|
|
41
|
+
if (!embedded.capabilities.documentFormatting)
|
|
42
42
|
continue;
|
|
43
43
|
const sourceMap = vueDocument[0].getSourceMap(embedded);
|
|
44
|
-
const initialIndentBracket = typeof embedded.capabilities.
|
|
45
|
-
? embedded.capabilities.
|
|
44
|
+
const initialIndentBracket = typeof embedded.capabilities.documentFormatting === 'object' && initialIndentLanguageId[sourceMap.mappedDocument.languageId]
|
|
45
|
+
? embedded.capabilities.documentFormatting.initialIndentBracket
|
|
46
46
|
: undefined;
|
|
47
47
|
let _edits;
|
|
48
48
|
if (onTypeParams) {
|
|
49
|
-
const embeddedPosition =
|
|
49
|
+
const embeddedPosition = sourceMap.toGeneratedPosition(onTypeParams.position);
|
|
50
50
|
if (embeddedPosition) {
|
|
51
51
|
_edits = yield tryFormat(sourceMap.mappedDocument, embeddedPosition, initialIndentBracket, onTypeParams.ch);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
let
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
start
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!end) {
|
|
66
|
-
const lastMapping = sourceMap.base.mappings.sort((a, b) => b.sourceRange.start - a.sourceRange.start)[0];
|
|
67
|
-
if (lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange.end) {
|
|
68
|
-
end = sourceMap.mappedDocument.positionAt(lastMapping.mappedRange.end);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (start && end) {
|
|
72
|
-
embeddedRange = { start, end };
|
|
55
|
+
let genRange = sourceMap.toGeneratedRange(range);
|
|
56
|
+
if (!genRange) {
|
|
57
|
+
const firstMapping = sourceMap.mappings.sort((a, b) => a.sourceRange[0] - b.sourceRange[0])[0];
|
|
58
|
+
const lastMapping = sourceMap.mappings.sort((a, b) => b.sourceRange[0] - a.sourceRange[0])[0];
|
|
59
|
+
if (firstMapping && document.offsetAt(range.start) < firstMapping.sourceRange[0]
|
|
60
|
+
&& lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange[1]) {
|
|
61
|
+
genRange = {
|
|
62
|
+
start: sourceMap.mappedDocument.positionAt(firstMapping.generatedRange[0]),
|
|
63
|
+
end: sourceMap.mappedDocument.positionAt(lastMapping.generatedRange[1]),
|
|
64
|
+
};
|
|
73
65
|
}
|
|
74
66
|
}
|
|
75
|
-
if (
|
|
67
|
+
if (genRange) {
|
|
76
68
|
toPatchIndent = {
|
|
77
69
|
sourceMapEmbeddedDocumentUri: sourceMap.mappedDocument.uri,
|
|
78
70
|
};
|
|
79
|
-
_edits = yield tryFormat(sourceMap.mappedDocument,
|
|
71
|
+
_edits = yield tryFormat(sourceMap.mappedDocument, genRange, initialIndentBracket);
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
74
|
if (!_edits)
|
|
83
75
|
continue;
|
|
84
76
|
for (const textEdit of _edits) {
|
|
85
|
-
|
|
77
|
+
const range = sourceMap.toSourceRange(textEdit.range);
|
|
78
|
+
if (range) {
|
|
86
79
|
edits.push({
|
|
87
80
|
newText: textEdit.newText,
|
|
88
81
|
range,
|
|
@@ -203,17 +196,17 @@ exports.register = register;
|
|
|
203
196
|
function patchInterpolationIndent(vueDocument, sourceMap) {
|
|
204
197
|
const indentTextEdits = [];
|
|
205
198
|
const document = vueDocument.getDocument();
|
|
206
|
-
for (const mapped of sourceMap.
|
|
199
|
+
for (const mapped of sourceMap.mappings) {
|
|
207
200
|
const textRange = {
|
|
208
|
-
start: document.positionAt(mapped.sourceRange
|
|
209
|
-
end: document.positionAt(mapped.sourceRange
|
|
201
|
+
start: document.positionAt(mapped.sourceRange[0]),
|
|
202
|
+
end: document.positionAt(mapped.sourceRange[1]),
|
|
210
203
|
};
|
|
211
204
|
const text = document.getText(textRange);
|
|
212
205
|
if (text.indexOf('\n') === -1)
|
|
213
206
|
continue;
|
|
214
207
|
const lines = text.split('\n');
|
|
215
208
|
const removeIndent = getRemoveIndent(lines);
|
|
216
|
-
const baseIndent = getBaseIndent(mapped.sourceRange
|
|
209
|
+
const baseIndent = getBaseIndent(mapped.sourceRange[0]);
|
|
217
210
|
for (let i = 1; i < lines.length; i++) {
|
|
218
211
|
const line = lines[i];
|
|
219
212
|
if (line.startsWith(removeIndent)) {
|
|
@@ -4,18 +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, sourceMap => true,
|
|
8
|
-
for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
|
|
9
|
-
yield mappedRange.start;
|
|
10
|
-
}
|
|
11
|
-
}, (plugin, document, position) => { var _a; return (_a = plugin.findLinkedEditingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (data, sourceMap) => ({
|
|
7
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, position, sourceMap => true, (position, sourceMap) => sourceMap.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, sourceMap) => ({
|
|
12
8
|
wordPattern: data.wordPattern,
|
|
13
|
-
ranges: data.ranges.map(range =>
|
|
14
|
-
var _a;
|
|
15
|
-
if (!sourceMap)
|
|
16
|
-
return range;
|
|
17
|
-
return (_a = sourceMap.getSourceRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0];
|
|
18
|
-
}).filter(shared.notEmpty),
|
|
9
|
+
ranges: data.ranges.map(range => sourceMap.toSourceRange(range)).filter(shared.notEmpty),
|
|
19
10
|
}));
|
|
20
11
|
};
|
|
21
12
|
}
|
|
@@ -5,14 +5,9 @@ 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, sourceMap => !!sourceMap.embeddedFile.capabilities.
|
|
9
|
-
.map(position =>
|
|
10
|
-
.filter(shared.notEmpty)], (plugin, document, positions) => { var _a; return positions.length ? (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions) : undefined; }, (
|
|
11
|
-
var _a;
|
|
12
|
-
if (!sourceMap)
|
|
13
|
-
return range;
|
|
14
|
-
return (_a = sourceMap.getSourceRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0];
|
|
15
|
-
}));
|
|
8
|
+
return (0, featureWorkers_1.documentArgFeatureWorker)(context, document, positions, sourceMap => !!sourceMap.embeddedFile.capabilities.foldingRange, (positions, sourceMap) => [positions
|
|
9
|
+
.map(position => sourceMap.toGeneratedPosition(position))
|
|
10
|
+
.filter(shared.notEmpty)], (plugin, document, positions) => { var _a; return positions.length ? (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions) : undefined; }, (item, sourceMap) => (0, transforms_1.transformSelectionRanges)(item, range => sourceMap.toSourceRange(range)));
|
|
16
11
|
};
|
|
17
12
|
}
|
|
18
13
|
exports.register = register;
|
package/out/documents.d.ts
CHANGED
|
@@ -1,106 +1,80 @@
|
|
|
1
|
-
import { DocumentRegistry,
|
|
1
|
+
import { DocumentRegistry, EmbeddedFile, PositionCapabilities, SourceFile, TeleportMappingData } from '@volar/language-core';
|
|
2
2
|
import * as shared from '@volar/shared';
|
|
3
|
-
import { SourceMapBase } from '@volar/source-map';
|
|
3
|
+
import { Mapping, SourceMapBase } from '@volar/source-map';
|
|
4
4
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
5
5
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
6
6
|
import { URI } from 'vscode-uri';
|
|
7
7
|
export type SourceFileDocuments = ReturnType<typeof parseSourceFileDocuments>;
|
|
8
8
|
export type SourceFileDocument = ReturnType<typeof parseSourceFileDocument>;
|
|
9
|
-
export declare class SourceMap<Data = undefined> {
|
|
9
|
+
export declare class SourceMap<Data = undefined> extends SourceMapBase<Data> {
|
|
10
10
|
sourceDocument: TextDocument;
|
|
11
11
|
mappedDocument: TextDocument;
|
|
12
|
-
|
|
13
|
-
constructor(sourceDocument: TextDocument, mappedDocument: TextDocument,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end: T;
|
|
29
|
-
}, Data], void, unknown>;
|
|
30
|
-
protected getRanges<T extends number | vscode.Position>(start: T, end: T, sourceToTarget: boolean, filter?: (data: Data) => boolean): Generator<[{
|
|
31
|
-
start: T;
|
|
32
|
-
end: T;
|
|
33
|
-
}, Data], void, unknown>;
|
|
12
|
+
mappings: Mapping<Data>[];
|
|
13
|
+
constructor(sourceDocument: TextDocument, mappedDocument: TextDocument, mappings: Mapping<Data>[]);
|
|
14
|
+
toSourceRange(range: vscode.Range, filter?: (data: Data) => boolean): vscode.Range | undefined;
|
|
15
|
+
toGeneratedRange(range: vscode.Range, filter?: (data: Data) => boolean): vscode.Range | undefined;
|
|
16
|
+
toSourceRanges(range: vscode.Range, filter?: (data: Data) => boolean): Generator<vscode.Range, void, unknown>;
|
|
17
|
+
toGeneratedRanges(range: vscode.Range, filter?: (data: Data) => boolean): Generator<vscode.Range, void, unknown>;
|
|
18
|
+
protected toRanges(range: vscode.Range, filter: (data: Data) => boolean, api: 'toSourcePositionsBase' | 'toGeneratedPositionsBase', api2: 'matchSourcePosition' | 'matchGeneratedPosition'): Generator<vscode.Range, void, unknown>;
|
|
19
|
+
toSourcePosition(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): shared._1.Position | undefined;
|
|
20
|
+
toGeneratedPosition(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): shared._1.Position | undefined;
|
|
21
|
+
toSourcePositions(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): Generator<shared._1.Position, void, unknown>;
|
|
22
|
+
toGeneratedPositions(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): Generator<shared._1.Position, void, unknown>;
|
|
23
|
+
toSourcePositionsBase(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): Generator<readonly [shared._1.Position, Mapping<Data>], void, unknown>;
|
|
24
|
+
toGeneratedPositionsBase(position: vscode.Position, filter?: (data: Data) => boolean, baseOffset?: 'left' | 'right'): Generator<readonly [shared._1.Position, Mapping<Data>], void, unknown>;
|
|
25
|
+
protected toPositions(position: vscode.Position, filter: (data: Data) => boolean, fromDoc: TextDocument, toDoc: TextDocument, from: 'sourceRange' | 'generatedRange', to: 'sourceRange' | 'generatedRange', baseOffset: 'left' | 'right'): Generator<readonly [shared._1.Position, Mapping<Data>], void, unknown>;
|
|
26
|
+
protected matchSourcePosition(position: vscode.Position, mapping: Mapping, baseOffset: 'left' | 'right'): shared._1.Position | undefined;
|
|
27
|
+
protected matchGeneratedPosition(position: vscode.Position, mapping: Mapping, baseOffset: 'left' | 'right'): shared._1.Position | undefined;
|
|
34
28
|
}
|
|
35
29
|
export declare class EmbeddedDocumentSourceMap extends SourceMap<PositionCapabilities> {
|
|
36
30
|
embeddedFile: EmbeddedFile;
|
|
37
31
|
sourceDocument: TextDocument;
|
|
38
32
|
mappedDocument: TextDocument;
|
|
39
|
-
constructor(embeddedFile: EmbeddedFile, sourceDocument: TextDocument, mappedDocument: TextDocument,
|
|
33
|
+
constructor(embeddedFile: EmbeddedFile, sourceDocument: TextDocument, mappedDocument: TextDocument, mappings: Mapping<PositionCapabilities>[]);
|
|
40
34
|
}
|
|
41
35
|
export declare class TeleportSourceMap extends SourceMap<TeleportMappingData> {
|
|
42
36
|
embeddedFile: EmbeddedFile;
|
|
43
37
|
document: TextDocument;
|
|
44
|
-
constructor(embeddedFile: EmbeddedFile, document: TextDocument,
|
|
45
|
-
findTeleports(start: vscode.Position
|
|
46
|
-
start: vscode.Position;
|
|
47
|
-
end: vscode.Position;
|
|
48
|
-
}, TeleportCapabilities], void, unknown>;
|
|
38
|
+
constructor(embeddedFile: EmbeddedFile, document: TextDocument, mappings: Mapping<TeleportMappingData>[]);
|
|
39
|
+
findTeleports(start: vscode.Position): Generator<readonly [shared._1.Position, import("@volar/language-core").TeleportCapabilities], void, unknown>;
|
|
49
40
|
}
|
|
50
41
|
export declare function parseSourceFileDocuments(rootUri: URI, mapper: DocumentRegistry): {
|
|
51
42
|
getAll: () => {
|
|
52
43
|
uri: string;
|
|
53
44
|
file: SourceFile;
|
|
54
45
|
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
55
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => shared.
|
|
46
|
+
getEmbeddedDocument: (embeddedFile: SourceFile) => shared._1.TextDocument;
|
|
56
47
|
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
57
48
|
getTeleports: () => TeleportSourceMap[];
|
|
58
|
-
getDocument: () => shared.
|
|
49
|
+
getDocument: () => shared._1.TextDocument;
|
|
59
50
|
}[];
|
|
60
51
|
get: (uri: string) => {
|
|
61
52
|
uri: string;
|
|
62
53
|
file: SourceFile;
|
|
63
54
|
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
64
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => shared.
|
|
55
|
+
getEmbeddedDocument: (embeddedFile: SourceFile) => shared._1.TextDocument;
|
|
65
56
|
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
66
57
|
getTeleports: () => TeleportSourceMap[];
|
|
67
|
-
getDocument: () => shared.
|
|
58
|
+
getDocument: () => shared._1.TextDocument;
|
|
68
59
|
} | undefined;
|
|
69
60
|
fromEmbeddedDocument: (document: TextDocument) => {
|
|
70
61
|
uri: string;
|
|
71
62
|
file: SourceFile;
|
|
72
63
|
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
73
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => shared.
|
|
64
|
+
getEmbeddedDocument: (embeddedFile: SourceFile) => shared._1.TextDocument;
|
|
74
65
|
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
75
66
|
getTeleports: () => TeleportSourceMap[];
|
|
76
|
-
getDocument: () => shared.
|
|
67
|
+
getDocument: () => shared._1.TextDocument;
|
|
77
68
|
} | undefined;
|
|
78
69
|
sourceMapFromEmbeddedDocumentUri: (uri: string) => EmbeddedDocumentSourceMap | undefined;
|
|
79
70
|
teleportfromEmbeddedDocumentUri: (uri: string) => TeleportSourceMap | undefined;
|
|
80
|
-
fromEmbeddedLocation: (uri: string, start: vscode.Position, end?: vscode.Position, filter?: ((data: PositionCapabilities) => boolean) | undefined, sourceMapFilter?: ((sourceMap: EmbeddedFileSourceMap) => boolean) | undefined) => Generator<{
|
|
81
|
-
uri: string;
|
|
82
|
-
range: {
|
|
83
|
-
start: vscode.Position;
|
|
84
|
-
end: vscode.Position;
|
|
85
|
-
};
|
|
86
|
-
sourceMap: EmbeddedDocumentSourceMap;
|
|
87
|
-
data: PositionCapabilities;
|
|
88
|
-
} | {
|
|
89
|
-
uri: string;
|
|
90
|
-
range: {
|
|
91
|
-
start: vscode.Position;
|
|
92
|
-
end: vscode.Position;
|
|
93
|
-
};
|
|
94
|
-
sourceMap?: undefined;
|
|
95
|
-
data?: undefined;
|
|
96
|
-
}, void, unknown>;
|
|
97
71
|
};
|
|
98
|
-
export declare function parseSourceFileDocument(rootUri: URI, sourceFile: SourceFile
|
|
72
|
+
export declare function parseSourceFileDocument(rootUri: URI, sourceFile: SourceFile): {
|
|
99
73
|
uri: string;
|
|
100
74
|
file: SourceFile;
|
|
101
75
|
getSourceMap: (embedded: EmbeddedFile) => EmbeddedDocumentSourceMap;
|
|
102
|
-
getEmbeddedDocument: (embeddedFile: SourceFile) => shared.
|
|
76
|
+
getEmbeddedDocument: (embeddedFile: SourceFile) => shared._1.TextDocument;
|
|
103
77
|
getSourceMaps: () => EmbeddedDocumentSourceMap[];
|
|
104
78
|
getTeleports: () => TeleportSourceMap[];
|
|
105
|
-
getDocument: () => shared.
|
|
79
|
+
getDocument: () => shared._1.TextDocument;
|
|
106
80
|
};
|