@volar/language-service 1.0.0-alpha.0
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/LICENSE +21 -0
- package/out/baseDocumentService.d.ts +35 -0
- package/out/baseDocumentService.js +100 -0
- package/out/baseLanguageService.d.ts +55 -0
- package/out/baseLanguageService.js +114 -0
- package/out/documentFeatures/autoInsert.d.ts +5 -0
- package/out/documentFeatures/autoInsert.js +25 -0
- package/out/documentFeatures/colorPresentations.d.ts +4 -0
- package/out/documentFeatures/colorPresentations.js +35 -0
- package/out/documentFeatures/documentColors.d.ts +4 -0
- package/out/documentFeatures/documentColors.js +21 -0
- package/out/documentFeatures/documentSymbols.d.ts +4 -0
- package/out/documentFeatures/documentSymbols.js +21 -0
- package/out/documentFeatures/foldingRanges.d.ts +4 -0
- package/out/documentFeatures/foldingRanges.js +16 -0
- package/out/documentFeatures/format.d.ts +7 -0
- package/out/documentFeatures/format.js +242 -0
- package/out/documentFeatures/linkedEditingRanges.d.ts +4 -0
- package/out/documentFeatures/linkedEditingRanges.js +23 -0
- package/out/documentFeatures/selectionRanges.d.ts +4 -0
- package/out/documentFeatures/selectionRanges.js +19 -0
- package/out/documents.d.ts +106 -0
- package/out/documents.js +227 -0
- package/out/index.d.ts +8 -0
- package/out/index.js +27 -0
- package/out/languageFeatures/autoInsert.d.ts +4 -0
- package/out/languageFeatures/autoInsert.js +35 -0
- package/out/languageFeatures/callHierarchy.d.ts +15 -0
- package/out/languageFeatures/callHierarchy.js +148 -0
- package/out/languageFeatures/codeActionResolve.d.ts +3 -0
- package/out/languageFeatures/codeActionResolve.js +45 -0
- package/out/languageFeatures/codeActions.d.ts +11 -0
- package/out/languageFeatures/codeActions.js +89 -0
- package/out/languageFeatures/codeLens.d.ts +8 -0
- package/out/languageFeatures/codeLens.js +45 -0
- package/out/languageFeatures/codeLensResolve.d.ts +3 -0
- package/out/languageFeatures/codeLensResolve.js +30 -0
- package/out/languageFeatures/complete.d.ts +14 -0
- package/out/languageFeatures/complete.js +181 -0
- package/out/languageFeatures/completeResolve.d.ts +3 -0
- package/out/languageFeatures/completeResolve.js +60 -0
- package/out/languageFeatures/definition.d.ts +4 -0
- package/out/languageFeatures/definition.js +85 -0
- package/out/languageFeatures/documentHighlights.d.ts +3 -0
- package/out/languageFeatures/documentHighlights.js +65 -0
- package/out/languageFeatures/documentLinks.d.ts +3 -0
- package/out/languageFeatures/documentLinks.js +53 -0
- package/out/languageFeatures/documentSemanticTokens.d.ts +4 -0
- package/out/languageFeatures/documentSemanticTokens.js +59 -0
- package/out/languageFeatures/executeCommand.d.ts +11 -0
- package/out/languageFeatures/executeCommand.js +31 -0
- package/out/languageFeatures/fileReferences.d.ts +4 -0
- package/out/languageFeatures/fileReferences.js +37 -0
- package/out/languageFeatures/fileRename.d.ts +3 -0
- package/out/languageFeatures/fileRename.js +36 -0
- package/out/languageFeatures/hover.d.ts +3 -0
- package/out/languageFeatures/hover.js +48 -0
- package/out/languageFeatures/inlayHints.d.ts +3 -0
- package/out/languageFeatures/inlayHints.js +65 -0
- package/out/languageFeatures/references.d.ts +3 -0
- package/out/languageFeatures/references.js +68 -0
- package/out/languageFeatures/rename.d.ts +19 -0
- package/out/languageFeatures/rename.js +226 -0
- package/out/languageFeatures/renamePrepare.d.ts +3 -0
- package/out/languageFeatures/renamePrepare.js +41 -0
- package/out/languageFeatures/signatureHelp.d.ts +3 -0
- package/out/languageFeatures/signatureHelp.js +14 -0
- package/out/languageFeatures/validation.d.ts +7 -0
- package/out/languageFeatures/validation.js +237 -0
- package/out/languageFeatures/workspaceSymbols.d.ts +3 -0
- package/out/languageFeatures/workspaceSymbols.js +34 -0
- package/out/plugin.d.ts +93 -0
- package/out/plugin.js +3 -0
- package/out/types.d.ts +43 -0
- package/out/types.js +4 -0
- package/out/utils/dedupe.d.ts +15 -0
- package/out/utils/dedupe.js +132 -0
- package/out/utils/definePlugin.d.ts +2 -0
- package/out/utils/definePlugin.js +27 -0
- package/out/utils/featureWorkers.d.ts +7 -0
- package/out/utils/featureWorkers.js +120 -0
- package/out/utils/singleFileTypeScriptService.d.ts +4 -0
- package/out/utils/singleFileTypeScriptService.js +30 -0
- package/package.json +32 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.register = void 0;
|
|
12
|
+
const transforms_1 = require("@volar/transforms");
|
|
13
|
+
const vscode = require("vscode-languageserver-protocol");
|
|
14
|
+
function register(context) {
|
|
15
|
+
return (query) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const symbolsList = [];
|
|
17
|
+
for (const plugin of context.plugins) {
|
|
18
|
+
if (!plugin.findWorkspaceSymbols)
|
|
19
|
+
continue;
|
|
20
|
+
const embeddedSymbols = yield plugin.findWorkspaceSymbols(query);
|
|
21
|
+
if (!embeddedSymbols)
|
|
22
|
+
continue;
|
|
23
|
+
const symbols = (0, transforms_1.transformSymbolInformations)(embeddedSymbols, loc => {
|
|
24
|
+
for (const vueLoc of context.documents.fromEmbeddedLocation(loc.uri, loc.range.start, loc.range.end)) {
|
|
25
|
+
return vscode.Location.create(vueLoc.uri, vueLoc.range);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
symbolsList.push(symbols);
|
|
29
|
+
}
|
|
30
|
+
return symbolsList.flat();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.register = register;
|
|
34
|
+
//# sourceMappingURL=workspaceSymbols.js.map
|
package/out/plugin.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
import { PluginContext } from './types';
|
|
4
|
+
export declare type NotNullableResult<T> = T | Thenable<T>;
|
|
5
|
+
export declare type NullableResult<T> = NotNullableResult<T | undefined | null>;
|
|
6
|
+
export declare type SemanticToken = [number, number, number, number, number];
|
|
7
|
+
export interface ExecuteCommandContext {
|
|
8
|
+
token: vscode.CancellationToken;
|
|
9
|
+
workDoneProgress: {
|
|
10
|
+
begin(title: string, percentage?: number, message?: string, cancellable?: boolean): void;
|
|
11
|
+
report(percentage: number): void;
|
|
12
|
+
report(message: string): void;
|
|
13
|
+
report(percentage: number, message: string): void;
|
|
14
|
+
done(): void;
|
|
15
|
+
};
|
|
16
|
+
showReferences(params: {
|
|
17
|
+
textDocument: vscode.TextDocumentIdentifier;
|
|
18
|
+
position: vscode.Position;
|
|
19
|
+
references: vscode.Location[];
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
applyEdit(paramOrEdit: vscode.ApplyWorkspaceEditParams | vscode.WorkspaceEdit): Promise<vscode.ApplyWorkspaceEditResult>;
|
|
22
|
+
}
|
|
23
|
+
export interface EmbeddedLanguageServicePlugin {
|
|
24
|
+
setup?(context: PluginContext): void;
|
|
25
|
+
validation?: {
|
|
26
|
+
onFull?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
27
|
+
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
28
|
+
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
29
|
+
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
30
|
+
onDeclaration?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
31
|
+
};
|
|
32
|
+
doHover?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Hover>;
|
|
33
|
+
findImplementations?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
|
|
34
|
+
findReferences?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Location[]>;
|
|
35
|
+
findFileReferences?(document: TextDocument): NullableResult<vscode.Location[]>;
|
|
36
|
+
findDocumentHighlights?(document: TextDocument, position: vscode.Position): NullableResult<vscode.DocumentHighlight[]>;
|
|
37
|
+
findDocumentLinks?(document: TextDocument): NullableResult<vscode.DocumentLink[]>;
|
|
38
|
+
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.SymbolInformation[]>;
|
|
39
|
+
findDocumentSemanticTokens?(document: TextDocument, range?: vscode.Range, cancleToken?: vscode.CancellationToken): NullableResult<SemanticToken[]>;
|
|
40
|
+
findWorkspaceSymbols?(query: string): NullableResult<vscode.SymbolInformation[]>;
|
|
41
|
+
doExecuteCommand?(command: string, args: any[], context: ExecuteCommandContext): NotNullableResult<void>;
|
|
42
|
+
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
|
|
43
|
+
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
|
|
44
|
+
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
|
|
45
|
+
getFoldingRanges?(document: TextDocument): NullableResult<vscode.FoldingRange[]>;
|
|
46
|
+
getSelectionRanges?(document: TextDocument, positions: vscode.Position[]): NullableResult<vscode.SelectionRange[]>;
|
|
47
|
+
getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
|
|
48
|
+
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
|
|
49
|
+
formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
|
|
50
|
+
definition?: {
|
|
51
|
+
on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
|
|
52
|
+
onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
|
|
53
|
+
};
|
|
54
|
+
complete?: {
|
|
55
|
+
triggerCharacters?: string[];
|
|
56
|
+
isAdditional?: boolean;
|
|
57
|
+
on?(document: TextDocument, position: vscode.Position, context?: vscode.CompletionContext): NullableResult<vscode.CompletionList>;
|
|
58
|
+
resolve?(item: vscode.CompletionItem, newPosition?: vscode.Position): NotNullableResult<vscode.CompletionItem>;
|
|
59
|
+
};
|
|
60
|
+
rename?: {
|
|
61
|
+
prepare?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Range | vscode.ResponseError<void>>;
|
|
62
|
+
on?(document: TextDocument, position: vscode.Position, newName: string): NullableResult<vscode.WorkspaceEdit>;
|
|
63
|
+
};
|
|
64
|
+
codeAction?: {
|
|
65
|
+
on?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext): NullableResult<vscode.CodeAction[]>;
|
|
66
|
+
resolve?(codeAction: vscode.CodeAction): NotNullableResult<vscode.CodeAction>;
|
|
67
|
+
};
|
|
68
|
+
codeLens?: {
|
|
69
|
+
on?(document: TextDocument): NullableResult<vscode.CodeLens[]>;
|
|
70
|
+
resolve?(codeLens: vscode.CodeLens): NotNullableResult<vscode.CodeLens>;
|
|
71
|
+
};
|
|
72
|
+
callHierarchy?: {
|
|
73
|
+
prepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>;
|
|
74
|
+
onIncomingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyIncomingCall[]>;
|
|
75
|
+
onOutgoingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyOutgoingCall[]>;
|
|
76
|
+
};
|
|
77
|
+
inlayHints?: {
|
|
78
|
+
on?(document: TextDocument, range: vscode.Range): NullableResult<vscode.InlayHint[]>;
|
|
79
|
+
};
|
|
80
|
+
findLinkedEditingRanges?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LinkedEditingRanges>;
|
|
81
|
+
doAutoInsert?(document: TextDocument, position: vscode.Position, context: {
|
|
82
|
+
lastChange: {
|
|
83
|
+
range: vscode.Range;
|
|
84
|
+
rangeOffset: number;
|
|
85
|
+
rangeLength: number;
|
|
86
|
+
text: string;
|
|
87
|
+
};
|
|
88
|
+
}): NullableResult<string | vscode.TextEdit>;
|
|
89
|
+
/**
|
|
90
|
+
* TODO: only support to doCompleteResolve for now
|
|
91
|
+
*/
|
|
92
|
+
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
93
|
+
}
|
package/out/plugin.js
ADDED
package/out/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EmbeddedLanguageServicePlugin } from '@volar/language-service';
|
|
2
|
+
import { EmbeddedLanguageModule, LanguageServiceHost, EmbeddedLanguageContext, SourceFile } from '@volar/language-core';
|
|
3
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import { SourceFileDocument, SourceFileDocuments } from './documents';
|
|
6
|
+
import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
|
|
7
|
+
import type { SchemaRequestService } from 'vscode-json-languageservice';
|
|
8
|
+
import { URI } from 'vscode-uri';
|
|
9
|
+
export interface DocumentServiceRuntimeContext {
|
|
10
|
+
typescript: typeof import('typescript/lib/tsserverlibrary');
|
|
11
|
+
plugins: EmbeddedLanguageServicePlugin[];
|
|
12
|
+
pluginContext: PluginContext;
|
|
13
|
+
getSourceFileDocument(document: TextDocument): [SourceFileDocument, EmbeddedLanguageModule] | undefined;
|
|
14
|
+
updateSourceFile(sourceFile: SourceFile, snapshot: ts.IScriptSnapshot): void;
|
|
15
|
+
prepareLanguageServices(document: TextDocument): void;
|
|
16
|
+
}
|
|
17
|
+
export interface LanguageServiceRuntimeContext {
|
|
18
|
+
host: LanguageServiceHost;
|
|
19
|
+
core: EmbeddedLanguageContext;
|
|
20
|
+
typescriptLanguageService: ts.LanguageService;
|
|
21
|
+
documents: SourceFileDocuments;
|
|
22
|
+
plugins: EmbeddedLanguageServicePlugin[];
|
|
23
|
+
pluginContext: PluginContext;
|
|
24
|
+
getTextDocument(uri: string): TextDocument | undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface PluginContext {
|
|
27
|
+
typescript: {
|
|
28
|
+
module: typeof import('typescript/lib/tsserverlibrary');
|
|
29
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
30
|
+
languageService: ts.LanguageService;
|
|
31
|
+
};
|
|
32
|
+
env: {
|
|
33
|
+
rootUri: URI;
|
|
34
|
+
configurationHost?: ConfigurationHost;
|
|
35
|
+
documentContext?: DocumentContext;
|
|
36
|
+
fileSystemProvider?: FileSystemProvider;
|
|
37
|
+
schemaRequestService?: SchemaRequestService;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ConfigurationHost {
|
|
41
|
+
getConfiguration: (<T>(section: string, scopeUri?: string) => Promise<T | undefined>);
|
|
42
|
+
onDidChangeConfiguration: (cb: () => void) => void;
|
|
43
|
+
}
|
package/out/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
export declare function createLocationSet(): {
|
|
3
|
+
add: (item: vscode.Location) => boolean;
|
|
4
|
+
has: (item: vscode.Location) => boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]): T[];
|
|
7
|
+
export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
|
|
8
|
+
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.TextDocumentEdit | vscode.CreateFile | vscode.RenameFile | vscode.DeleteFile)[];
|
|
9
|
+
export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];
|
|
10
|
+
export declare function withSymbolInformations<T extends vscode.SymbolInformation>(items: T[]): T[];
|
|
11
|
+
export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
|
|
12
|
+
export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
|
|
13
|
+
export declare function withCallHierarchyIncomingCalls<T extends vscode.CallHierarchyIncomingCall>(items: T[]): T[];
|
|
14
|
+
export declare function withCallHierarchyOutgoingCalls<T extends vscode.CallHierarchyOutgoingCall>(items: T[]): T[];
|
|
15
|
+
export declare function withRanges<T extends vscode.Range>(items: T[]): T[];
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.withRanges = exports.withCallHierarchyOutgoingCalls = exports.withCallHierarchyIncomingCalls = exports.withLocationLinks = exports.withLocations = exports.withSymbolInformations = exports.withDiagnostics = exports.withDocumentChanges = exports.withTextEdits = exports.withCodeAction = exports.createLocationSet = void 0;
|
|
3
|
+
function createLocationSet() {
|
|
4
|
+
const set = new Set();
|
|
5
|
+
return {
|
|
6
|
+
add,
|
|
7
|
+
has,
|
|
8
|
+
};
|
|
9
|
+
function add(item) {
|
|
10
|
+
if (has(item)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
set.add(getKey(item));
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function has(item) {
|
|
17
|
+
return set.has(getKey(item));
|
|
18
|
+
}
|
|
19
|
+
function getKey(item) {
|
|
20
|
+
return [
|
|
21
|
+
item.uri,
|
|
22
|
+
item.range.start.line,
|
|
23
|
+
item.range.start.character,
|
|
24
|
+
item.range.end.line,
|
|
25
|
+
item.range.end.character,
|
|
26
|
+
].join(':');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.createLocationSet = createLocationSet;
|
|
30
|
+
function withCodeAction(items) {
|
|
31
|
+
return dedupe(items, item => [
|
|
32
|
+
item.title
|
|
33
|
+
].join(':'));
|
|
34
|
+
}
|
|
35
|
+
exports.withCodeAction = withCodeAction;
|
|
36
|
+
function withTextEdits(items) {
|
|
37
|
+
return dedupe(items, item => [
|
|
38
|
+
item.range.start.line,
|
|
39
|
+
item.range.start.character,
|
|
40
|
+
item.range.end.line,
|
|
41
|
+
item.range.end.character,
|
|
42
|
+
item.newText,
|
|
43
|
+
].join(':'));
|
|
44
|
+
}
|
|
45
|
+
exports.withTextEdits = withTextEdits;
|
|
46
|
+
function withDocumentChanges(items) {
|
|
47
|
+
return dedupe(items, item => JSON.stringify(item)); // TODO: improve this
|
|
48
|
+
}
|
|
49
|
+
exports.withDocumentChanges = withDocumentChanges;
|
|
50
|
+
function withDiagnostics(items) {
|
|
51
|
+
return dedupe(items, item => [
|
|
52
|
+
item.range.start.line,
|
|
53
|
+
item.range.start.character,
|
|
54
|
+
item.range.end.line,
|
|
55
|
+
item.range.end.character,
|
|
56
|
+
item.source,
|
|
57
|
+
item.code,
|
|
58
|
+
item.severity,
|
|
59
|
+
item.message,
|
|
60
|
+
].join(':'));
|
|
61
|
+
}
|
|
62
|
+
exports.withDiagnostics = withDiagnostics;
|
|
63
|
+
function withSymbolInformations(items) {
|
|
64
|
+
return dedupe(items, item => [
|
|
65
|
+
item.name,
|
|
66
|
+
item.kind,
|
|
67
|
+
item.location.uri,
|
|
68
|
+
item.location.range.start.line,
|
|
69
|
+
item.location.range.start.character,
|
|
70
|
+
item.location.range.end.line,
|
|
71
|
+
item.location.range.end.character,
|
|
72
|
+
].join(':'));
|
|
73
|
+
}
|
|
74
|
+
exports.withSymbolInformations = withSymbolInformations;
|
|
75
|
+
function withLocations(items) {
|
|
76
|
+
return dedupe(items, item => [
|
|
77
|
+
item.uri,
|
|
78
|
+
item.range.start.line,
|
|
79
|
+
item.range.start.character,
|
|
80
|
+
item.range.end.line,
|
|
81
|
+
item.range.end.character,
|
|
82
|
+
].join(':'));
|
|
83
|
+
}
|
|
84
|
+
exports.withLocations = withLocations;
|
|
85
|
+
function withLocationLinks(items) {
|
|
86
|
+
return dedupe(items, item => [
|
|
87
|
+
item.targetUri,
|
|
88
|
+
item.targetSelectionRange.start.line,
|
|
89
|
+
item.targetSelectionRange.start.character,
|
|
90
|
+
item.targetSelectionRange.end.line,
|
|
91
|
+
item.targetSelectionRange.end.character,
|
|
92
|
+
// ignore difference targetRange
|
|
93
|
+
].join(':'));
|
|
94
|
+
}
|
|
95
|
+
exports.withLocationLinks = withLocationLinks;
|
|
96
|
+
function withCallHierarchyIncomingCalls(items) {
|
|
97
|
+
return dedupe(items, item => [
|
|
98
|
+
item.from.uri,
|
|
99
|
+
item.from.range.start.line,
|
|
100
|
+
item.from.range.start.character,
|
|
101
|
+
item.from.range.end.line,
|
|
102
|
+
item.from.range.end.character,
|
|
103
|
+
].join(':'));
|
|
104
|
+
}
|
|
105
|
+
exports.withCallHierarchyIncomingCalls = withCallHierarchyIncomingCalls;
|
|
106
|
+
function withCallHierarchyOutgoingCalls(items) {
|
|
107
|
+
return dedupe(items, item => [
|
|
108
|
+
item.to.uri,
|
|
109
|
+
item.to.range.start.line,
|
|
110
|
+
item.to.range.start.character,
|
|
111
|
+
item.to.range.end.line,
|
|
112
|
+
item.to.range.end.character,
|
|
113
|
+
].join(':'));
|
|
114
|
+
}
|
|
115
|
+
exports.withCallHierarchyOutgoingCalls = withCallHierarchyOutgoingCalls;
|
|
116
|
+
function withRanges(items) {
|
|
117
|
+
return dedupe(items, item => [
|
|
118
|
+
item.start.line,
|
|
119
|
+
item.start.character,
|
|
120
|
+
item.end.line,
|
|
121
|
+
item.end.character,
|
|
122
|
+
].join(':'));
|
|
123
|
+
}
|
|
124
|
+
exports.withRanges = withRanges;
|
|
125
|
+
function dedupe(items, getKey) {
|
|
126
|
+
const map = new Map();
|
|
127
|
+
for (const item of items.reverse()) {
|
|
128
|
+
map.set(getKey(item), item);
|
|
129
|
+
}
|
|
130
|
+
return [...map.values()];
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=dedupe.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { EmbeddedDocumentSourceMap, SourceFileDocument } from '../documents';
|
|
2
|
+
export declare function visitEmbedded(vueDocument: SourceFileDocument, cb: (sourceMap: EmbeddedDocumentSourceMap) => Promise<boolean>, embeddeds?: import("@volar/language-core").EmbeddedFile[]): Promise<boolean>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.visitEmbedded = void 0;
|
|
12
|
+
function visitEmbedded(vueDocument, cb, embeddeds = vueDocument.file.embeddeds) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
for (const embedded of embeddeds) {
|
|
15
|
+
if (!(yield visitEmbedded(vueDocument, cb, embedded.embeddeds))) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const sourceMap = vueDocument.getSourceMap(embedded);
|
|
19
|
+
if (!(yield cb(sourceMap))) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.visitEmbedded = visitEmbedded;
|
|
27
|
+
//# sourceMappingURL=definePlugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import type { DocumentServiceRuntimeContext, LanguageServiceRuntimeContext } from '../types';
|
|
3
|
+
import { EmbeddedLanguageServicePlugin } from '@volar/language-service';
|
|
4
|
+
import { EmbeddedDocumentSourceMap, SourceFileDocument } from '../documents';
|
|
5
|
+
export declare function documentFeatureWorker<T>(context: DocumentServiceRuntimeContext, document: TextDocument, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, worker: (plugin: EmbeddedLanguageServicePlugin, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
6
|
+
export declare function documentArgFeatureWorker<T, K>(context: DocumentServiceRuntimeContext, document: TextDocument, arg: K, isValidSourceMap: (sourceMap: EmbeddedDocumentSourceMap) => boolean, transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | [K], worker: (plugin: EmbeddedLanguageServicePlugin, document: TextDocument, arg: K) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => T | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
+
export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: EmbeddedDocumentSourceMap) => Generator<K> | K[], worker: (plugin: EmbeddedLanguageServicePlugin, document: TextDocument, arg: K, sourceMap: EmbeddedDocumentSourceMap | undefined, vueDocument: SourceFileDocument | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: EmbeddedDocumentSourceMap | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.languageFeatureWorker = exports.documentArgFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
12
|
+
const definePlugin_1 = require("./definePlugin");
|
|
13
|
+
function documentFeatureWorker(context, document, isValidSourceMap, worker, transform, combineResult) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
return documentArgFeatureWorker(context, document, true, isValidSourceMap, () => [true], worker, transform, combineResult);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.documentFeatureWorker = documentFeatureWorker;
|
|
19
|
+
function documentArgFeatureWorker(context, document, arg, isValidSourceMap, transformArg, worker, transform, combineResult) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const vueDocument = context.getSourceFileDocument(document);
|
|
22
|
+
let results = [];
|
|
23
|
+
if (vueDocument) {
|
|
24
|
+
yield (0, definePlugin_1.visitEmbedded)(vueDocument[0], (sourceMap) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (!isValidSourceMap(sourceMap))
|
|
26
|
+
return true;
|
|
27
|
+
context.prepareLanguageServices(sourceMap.mappedDocument);
|
|
28
|
+
for (const mappedArg of transformArg(arg, sourceMap)) {
|
|
29
|
+
for (const plugin of context.plugins) {
|
|
30
|
+
const embeddedResult = yield worker(plugin, sourceMap.mappedDocument, mappedArg);
|
|
31
|
+
if (!embeddedResult)
|
|
32
|
+
continue;
|
|
33
|
+
const result = yield transform(embeddedResult, sourceMap);
|
|
34
|
+
if (!result)
|
|
35
|
+
continue;
|
|
36
|
+
results.push(result);
|
|
37
|
+
if (!combineResult)
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
if (results.length === 0 || !!combineResult) {
|
|
45
|
+
context.prepareLanguageServices(document);
|
|
46
|
+
for (const plugin of context.plugins) {
|
|
47
|
+
const embeddedResult = yield worker(plugin, document, arg);
|
|
48
|
+
if (!embeddedResult)
|
|
49
|
+
continue;
|
|
50
|
+
const result = yield transform(embeddedResult, undefined);
|
|
51
|
+
if (!result)
|
|
52
|
+
continue;
|
|
53
|
+
results.push(result);
|
|
54
|
+
if (!combineResult)
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (combineResult && results.length > 0) {
|
|
59
|
+
return combineResult(results);
|
|
60
|
+
}
|
|
61
|
+
else if (results.length > 0) {
|
|
62
|
+
return results[0];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.documentArgFeatureWorker = documentArgFeatureWorker;
|
|
67
|
+
function languageFeatureWorker(context, uri, arg, transformArg, worker, transform, combineResult, reportProgress) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const document = context.getTextDocument(uri);
|
|
70
|
+
const vueDocument = context.documents.get(uri);
|
|
71
|
+
let results = [];
|
|
72
|
+
if (vueDocument) {
|
|
73
|
+
yield (0, definePlugin_1.visitEmbedded)(vueDocument, (sourceMap) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
for (const mappedArg of transformArg(arg, sourceMap)) {
|
|
75
|
+
for (const plugin of context.plugins) {
|
|
76
|
+
const embeddedResult = yield worker(plugin, sourceMap.mappedDocument, mappedArg, sourceMap, vueDocument);
|
|
77
|
+
if (!embeddedResult)
|
|
78
|
+
continue;
|
|
79
|
+
const result = transform(embeddedResult, sourceMap);
|
|
80
|
+
if (!result)
|
|
81
|
+
continue;
|
|
82
|
+
results.push(result);
|
|
83
|
+
if (!combineResult)
|
|
84
|
+
return false;
|
|
85
|
+
const isEmptyArray = Array.isArray(result) && result.length === 0;
|
|
86
|
+
if (reportProgress && !isEmptyArray) {
|
|
87
|
+
reportProgress(combineResult(results));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
if (document && (results.length === 0 || !!combineResult)) {
|
|
95
|
+
for (const plugin of context.plugins) {
|
|
96
|
+
const embeddedResult = yield worker(plugin, document, arg, undefined, undefined);
|
|
97
|
+
if (!embeddedResult)
|
|
98
|
+
continue;
|
|
99
|
+
const result = transform(embeddedResult, undefined);
|
|
100
|
+
if (!result)
|
|
101
|
+
continue;
|
|
102
|
+
results.push(result);
|
|
103
|
+
if (!combineResult)
|
|
104
|
+
break;
|
|
105
|
+
const isEmptyArray = Array.isArray(result) && result.length === 0;
|
|
106
|
+
if (reportProgress && !isEmptyArray) {
|
|
107
|
+
reportProgress(combineResult(results));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (combineResult && results.length > 0) {
|
|
112
|
+
return combineResult(results);
|
|
113
|
+
}
|
|
114
|
+
else if (results.length > 0) {
|
|
115
|
+
return results[0];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
exports.languageFeatureWorker = languageFeatureWorker;
|
|
120
|
+
//# sourceMappingURL=featureWorkers.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
+
export declare const singleFileTypeScriptServiceHost: ts.LanguageServiceHost;
|
|
4
|
+
export declare function updateSingleFileTypeScriptServiceHost(ts: typeof import('typescript/lib/tsserverlibrary'), _doc: TextDocument): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.updateSingleFileTypeScriptServiceHost = exports.singleFileTypeScriptServiceHost = void 0;
|
|
3
|
+
const shared = require("@volar/shared");
|
|
4
|
+
let projectVersion = 0;
|
|
5
|
+
let doc;
|
|
6
|
+
let scriptFileName;
|
|
7
|
+
let scriptSnapshot;
|
|
8
|
+
exports.singleFileTypeScriptServiceHost = {
|
|
9
|
+
readFile: () => undefined,
|
|
10
|
+
fileExists: fileName => fileName === scriptFileName,
|
|
11
|
+
getProjectVersion: () => projectVersion.toString(),
|
|
12
|
+
getScriptVersion: () => projectVersion.toString(),
|
|
13
|
+
getCompilationSettings: () => ({ allowJs: true, jsx: 1 }),
|
|
14
|
+
getScriptFileNames: () => [scriptFileName],
|
|
15
|
+
getScriptSnapshot: fileName => {
|
|
16
|
+
if (fileName === scriptFileName) {
|
|
17
|
+
return scriptSnapshot;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
getCurrentDirectory: () => '',
|
|
21
|
+
getDefaultLibFileName: () => '',
|
|
22
|
+
};
|
|
23
|
+
function updateSingleFileTypeScriptServiceHost(ts, _doc) {
|
|
24
|
+
projectVersion++;
|
|
25
|
+
doc = _doc;
|
|
26
|
+
scriptFileName = shared.getPathOfUri(_doc.uri);
|
|
27
|
+
scriptSnapshot = ts.ScriptSnapshot.fromString(doc.getText());
|
|
28
|
+
}
|
|
29
|
+
exports.updateSingleFileTypeScriptServiceHost = updateSingleFileTypeScriptServiceHost;
|
|
30
|
+
//# sourceMappingURL=singleFileTypeScriptService.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volar/language-service",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"main": "out/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"out/**/*.js",
|
|
8
|
+
"out/**/*.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/johnsoncodehk/volar.git",
|
|
13
|
+
"directory": "packages/language-service"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "latest"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@volar/language-core": "1.0.0-alpha.0",
|
|
20
|
+
"@volar/shared": "1.0.0-alpha.0",
|
|
21
|
+
"@volar/source-map": "1.0.0-alpha.0",
|
|
22
|
+
"@volar/transforms": "1.0.0-alpha.0",
|
|
23
|
+
"@volar/typescript-faster": "1.0.0-alpha.0",
|
|
24
|
+
"@vue/reactivity": "^3.2.38",
|
|
25
|
+
"upath": "^2.0.1",
|
|
26
|
+
"vscode-html-languageservice": "^5.0.1",
|
|
27
|
+
"vscode-json-languageservice": "^5.1.0",
|
|
28
|
+
"vscode-languageserver-protocol": "^3.17.2",
|
|
29
|
+
"vscode-languageserver-textdocument": "^1.0.7",
|
|
30
|
+
"vscode-uri": "^3.0.3"
|
|
31
|
+
}
|
|
32
|
+
}
|