@volar/language-service 1.2.0-alpha.9 → 1.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/baseLanguageService.d.ts +5 -5
- package/out/baseLanguageService.js +22 -39
- package/out/documentFeatures/documentSymbols.d.ts +1 -1
- package/out/documentFeatures/documentSymbols.js +34 -6
- package/out/documentFeatures/format.js +113 -55
- package/out/documents.d.ts +2 -1
- package/out/documents.js +9 -9
- package/out/languageFeatures/callHierarchy.js +1 -1
- package/out/languageFeatures/codeActions.js +2 -2
- package/out/languageFeatures/codeLens.js +1 -1
- package/out/languageFeatures/documentLinks.js +1 -1
- package/out/languageFeatures/inlayHints.js +2 -3
- package/out/languageFeatures/rename.js +2 -2
- package/out/languageFeatures/renamePrepare.js +9 -13
- package/out/languageFeatures/validation.js +2 -2
- package/out/languageFeatures/workspaceSymbols.d.ts +1 -1
- package/out/languageFeatures/workspaceSymbols.js +3 -2
- package/out/transformer/documentSymbol.d.ts +2 -0
- package/out/transformer/documentSymbol.js +18 -0
- package/out/transformer/index.d.ts +2 -2
- package/out/transformer/index.js +5 -5
- package/out/transformer/workspaceSymbol.d.ts +2 -0
- package/out/transformer/workspaceSymbol.js +15 -0
- package/out/types.d.ts +20 -19
- package/out/utils/dedupe.d.ts +0 -1
- package/out/utils/dedupe.js +1 -13
- package/out/utils/featureWorkers.d.ts +2 -1
- package/out/utils/featureWorkers.js +56 -28
- package/package.json +9 -9
- package/out/languageFeatures/executeCommand.d.ts +0 -10
- package/out/languageFeatures/executeCommand.js +0 -24
- package/out/transformer/symbolInformation.d.ts +0 -2
- package/out/transformer/symbolInformation.js +0 -10
- package/out/transformer/symbolInformations.d.ts +0 -2
- package/out/transformer/symbolInformations.js +0 -11
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Config, LanguageServicePluginContext } from './types';
|
|
1
|
+
import { LanguageServicePluginContext, LanguageServiceOptions } from './types';
|
|
3
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
4
3
|
import type * as _ from 'vscode-languageserver-protocol';
|
|
5
4
|
export type LanguageService = ReturnType<typeof createLanguageService>;
|
|
6
|
-
export declare function createLanguageService(
|
|
5
|
+
export declare function createLanguageService(ctx: LanguageServiceOptions, documentRegistry?: ts.DocumentRegistry): {
|
|
6
|
+
triggerCharacters: string[];
|
|
7
7
|
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
|
|
8
8
|
ch: string;
|
|
9
9
|
position: _.Position;
|
|
@@ -11,7 +11,7 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
|
|
|
11
11
|
getFoldingRanges: (uri: string) => Promise<_.FoldingRange[] | undefined>;
|
|
12
12
|
getSelectionRanges: (uri: string, positions: _.Position[]) => Promise<_.SelectionRange[] | undefined>;
|
|
13
13
|
findLinkedEditingRanges: (uri: string, position: _.Position) => Promise<_.LinkedEditingRanges | undefined>;
|
|
14
|
-
findDocumentSymbols: (uri: string) => Promise<_.
|
|
14
|
+
findDocumentSymbols: (uri: string) => Promise<_.DocumentSymbol[] | undefined>;
|
|
15
15
|
findDocumentColors: (uri: string) => Promise<_.ColorInformation[] | undefined>;
|
|
16
16
|
getColorPresentations: (uri: string, color: _.Color, range: _.Range) => Promise<_.ColorPresentation[] | undefined>;
|
|
17
17
|
doValidation: (uri: string, token?: _.CancellationToken | undefined, response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>;
|
|
@@ -34,7 +34,7 @@ export declare function createLanguageService(host: LanguageServiceHost, config:
|
|
|
34
34
|
doCodeLensResolve: (item: _.CodeLens) => Promise<_.CodeLens>;
|
|
35
35
|
findDocumentHighlights: (uri: string, position: _.Position) => Promise<_.DocumentHighlight[] | undefined>;
|
|
36
36
|
findDocumentLinks: (uri: string) => Promise<_.DocumentLink[]>;
|
|
37
|
-
findWorkspaceSymbols: (query: string) => Promise<_.
|
|
37
|
+
findWorkspaceSymbols: (query: string) => Promise<_.WorkspaceSymbol[]>;
|
|
38
38
|
doAutoInsert: (uri: string, position: _.Position, autoInsertContext: {
|
|
39
39
|
lastChange: {
|
|
40
40
|
range: _.Range;
|
|
@@ -34,61 +34,43 @@ const foldingRanges = require("./documentFeatures/foldingRanges");
|
|
|
34
34
|
const format = require("./documentFeatures/format");
|
|
35
35
|
const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
|
|
36
36
|
const selectionRanges = require("./documentFeatures/selectionRanges");
|
|
37
|
-
function createLanguageService(
|
|
37
|
+
function createLanguageService(ctx, documentRegistry) {
|
|
38
38
|
var _a;
|
|
39
|
-
const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
|
|
40
|
-
const context = createLanguageServiceContext(
|
|
39
|
+
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
|
|
40
|
+
const context = createLanguageServiceContext(ctx, languageContext, documentRegistry);
|
|
41
41
|
return createLanguageServiceBase(context);
|
|
42
42
|
}
|
|
43
43
|
exports.createLanguageService = createLanguageService;
|
|
44
|
-
function createLanguageServiceContext(
|
|
45
|
-
var _a;
|
|
46
|
-
const ts = (_a = host.getTypeScriptModule) === null ||
|
|
44
|
+
function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
const ts = (_b = (_a = ctx.host).getTypeScriptModule) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
47
47
|
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
|
|
48
48
|
if (ts && tsLs) {
|
|
49
49
|
tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(languageContext.virtualFiles);
|
|
51
|
+
const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(ctx, languageContext.virtualFiles);
|
|
53
52
|
const documents = new WeakMap();
|
|
54
53
|
const documentVersions = new Map();
|
|
55
|
-
const context = {
|
|
56
|
-
uriToFileName: shared.uriToFileName,
|
|
57
|
-
fileNameToUri: shared.fileNameToUri,
|
|
58
|
-
host,
|
|
59
|
-
core: languageContext,
|
|
60
|
-
env: env,
|
|
61
|
-
get plugins() {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
if (!plugins) {
|
|
64
|
-
plugins = {}; // avoid infinite loop
|
|
65
|
-
for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
|
|
66
|
-
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
|
|
67
|
-
if (plugin instanceof Function) {
|
|
68
|
-
const _plugin = plugin(this);
|
|
69
|
-
plugins[pluginId] = _plugin;
|
|
70
|
-
}
|
|
71
|
-
else if (plugin) {
|
|
72
|
-
plugins[pluginId] = plugin;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return plugins;
|
|
77
|
-
},
|
|
78
|
-
config,
|
|
79
|
-
typescript: ts && tsLs ? {
|
|
54
|
+
const context = Object.assign(Object.assign({}, ctx), { core: languageContext, plugins: {}, typescript: ts && tsLs ? {
|
|
80
55
|
module: ts,
|
|
81
56
|
languageServiceHost: languageContext.typescript.languageServiceHost,
|
|
82
57
|
languageService: tsLs,
|
|
83
|
-
} : undefined,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
} : undefined, documents: textDocumentMapper, getTextDocument });
|
|
59
|
+
for (const pluginId in (_c = ctx.config.plugins) !== null && _c !== void 0 ? _c : {}) {
|
|
60
|
+
const plugin = (_d = ctx.config.plugins) === null || _d === void 0 ? void 0 : _d[pluginId];
|
|
61
|
+
if (plugin instanceof Function) {
|
|
62
|
+
const _plugin = plugin(context);
|
|
63
|
+
context.plugins[pluginId] = _plugin;
|
|
64
|
+
}
|
|
65
|
+
else if (plugin) {
|
|
66
|
+
context.plugins[pluginId] = plugin;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
87
69
|
return context;
|
|
88
70
|
function getTextDocument(uri) {
|
|
89
71
|
var _a;
|
|
90
|
-
const fileName =
|
|
91
|
-
const scriptSnapshot = host.getScriptSnapshot(fileName);
|
|
72
|
+
const fileName = ctx.uriToFileName(uri);
|
|
73
|
+
const scriptSnapshot = ctx.host.getScriptSnapshot(fileName);
|
|
92
74
|
if (scriptSnapshot) {
|
|
93
75
|
let document = documents.get(scriptSnapshot);
|
|
94
76
|
if (!document) {
|
|
@@ -103,6 +85,7 @@ function createLanguageServiceContext(host, languageContext, config, env, docume
|
|
|
103
85
|
}
|
|
104
86
|
function createLanguageServiceBase(context) {
|
|
105
87
|
return {
|
|
88
|
+
triggerCharacters: Object.values(context.plugins).map(plugin => { var _a, _b; return (_b = (_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.triggerCharacters) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
106
89
|
format: format.register(context),
|
|
107
90
|
getFoldingRanges: foldingRanges.register(context),
|
|
108
91
|
getSelectionRanges: selectionRanges.register(context),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LanguageServicePluginContext } from '../types';
|
|
2
2
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
-
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentSymbol[] | undefined>;
|
|
@@ -1,16 +1,44 @@
|
|
|
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
|
+
};
|
|
1
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
11
|
exports.register = void 0;
|
|
3
12
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
4
13
|
const transformer = require("../transformer");
|
|
5
|
-
const
|
|
14
|
+
const shared = require("@volar/shared");
|
|
15
|
+
const common_1 = require("../utils/common");
|
|
6
16
|
function register(context) {
|
|
7
17
|
return (uri) => {
|
|
8
|
-
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }), (data, map) => map
|
|
19
|
+
? data
|
|
20
|
+
.map(symbol => transformer.asDocumentSymbol(symbol, range => map.toSourceRange(range)))
|
|
21
|
+
.filter(shared.notEmpty)
|
|
22
|
+
: data, results => {
|
|
23
|
+
for (let i = 0; i < results.length; i++) {
|
|
24
|
+
for (let j = 0; j < results.length; j++) {
|
|
25
|
+
if (i === j)
|
|
26
|
+
continue;
|
|
27
|
+
results[i] = results[i].filter(child => {
|
|
28
|
+
var _a;
|
|
29
|
+
for (const parent of results[j]) {
|
|
30
|
+
if ((0, common_1.isInsideRange)(parent.range, child.range)) {
|
|
31
|
+
(_a = parent.children) !== null && _a !== void 0 ? _a : (parent.children = []);
|
|
32
|
+
parent.children.push(child);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
12
39
|
}
|
|
13
|
-
|
|
40
|
+
return results.flat();
|
|
41
|
+
});
|
|
14
42
|
};
|
|
15
43
|
}
|
|
16
44
|
exports.register = register;
|
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.register = void 0;
|
|
12
12
|
const vscode = require("vscode-languageserver-protocol");
|
|
13
13
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
14
|
-
const shared = require("@volar/shared");
|
|
15
14
|
const common_1 = require("../utils/common");
|
|
16
15
|
function register(context) {
|
|
17
16
|
return (uri, options, range, onTypeParams) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -20,13 +19,13 @@ function register(context) {
|
|
|
20
19
|
if (!document)
|
|
21
20
|
return;
|
|
22
21
|
range !== null && range !== void 0 ? range : (range = vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length)));
|
|
23
|
-
const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
|
|
24
22
|
const source = context.documents.getSourceByUri(document.uri);
|
|
25
23
|
if (!source) {
|
|
26
24
|
return onTypeParams
|
|
27
|
-
? yield tryFormat(
|
|
28
|
-
: yield tryFormat(
|
|
25
|
+
? yield tryFormat(document, onTypeParams.position, onTypeParams.ch)
|
|
26
|
+
: yield tryFormat(document, range, undefined);
|
|
29
27
|
}
|
|
28
|
+
const initialIndentLanguageId = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
|
|
30
29
|
const originalSnapshot = source.snapshot;
|
|
31
30
|
const rootVirtualFile = source.root;
|
|
32
31
|
const originalDocument = document;
|
|
@@ -37,42 +36,37 @@ function register(context) {
|
|
|
37
36
|
if (embeddedFiles.length === 0)
|
|
38
37
|
break;
|
|
39
38
|
let edits = [];
|
|
40
|
-
|
|
39
|
+
const toPatchIndentUris = [];
|
|
41
40
|
for (const embedded of embeddedFiles) {
|
|
42
41
|
if (!embedded.capabilities.documentFormatting)
|
|
43
42
|
continue;
|
|
43
|
+
const isCodeBlock = embedded.mappings.length === 1 && embedded.mappings[0].generatedRange[0] === 0 && embedded.mappings[0].generatedRange[1] === embedded.snapshot.getLength();
|
|
44
|
+
if (onTypeParams && !isCodeBlock)
|
|
45
|
+
continue;
|
|
44
46
|
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)];
|
|
45
47
|
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1];
|
|
46
48
|
if (!map)
|
|
47
49
|
continue;
|
|
48
|
-
let
|
|
50
|
+
let virtualCodeEdits;
|
|
49
51
|
if (onTypeParams) {
|
|
50
52
|
const embeddedPosition = map.toGeneratedPosition(onTypeParams.position);
|
|
51
53
|
if (embeddedPosition) {
|
|
52
|
-
|
|
54
|
+
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (firstMapping && document.offsetAt(range.start) < firstMapping.sourceRange[0]
|
|
61
|
-
&& lastMapping && document.offsetAt(range.end) > lastMapping.sourceRange[1]) {
|
|
62
|
-
genRange = {
|
|
63
|
-
start: map.virtualFileDocument.positionAt(firstMapping.generatedRange[0]),
|
|
64
|
-
end: map.virtualFileDocument.positionAt(lastMapping.generatedRange[1]),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (genRange) {
|
|
69
|
-
toPatchIndentUri = map.virtualFileDocument.uri;
|
|
70
|
-
_edits = yield tryFormat(true, map.virtualFileDocument, genRange);
|
|
71
|
-
}
|
|
58
|
+
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, {
|
|
59
|
+
start: map.virtualFileDocument.positionAt(0),
|
|
60
|
+
end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length),
|
|
61
|
+
});
|
|
72
62
|
}
|
|
73
|
-
if (!
|
|
63
|
+
if (!virtualCodeEdits)
|
|
74
64
|
continue;
|
|
75
|
-
|
|
65
|
+
toPatchIndentUris.push({
|
|
66
|
+
uri: map.virtualFileDocument.uri,
|
|
67
|
+
isCodeBlock,
|
|
68
|
+
});
|
|
69
|
+
for (const textEdit of virtualCodeEdits) {
|
|
76
70
|
const range = map.toSourceRange(textEdit.range);
|
|
77
71
|
if (range) {
|
|
78
72
|
edits.push({
|
|
@@ -82,27 +76,64 @@ function register(context) {
|
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
}
|
|
79
|
+
edits = edits.filter(edit => (0, common_1.isInsideRange)(range, edit.range));
|
|
85
80
|
if (edits.length > 0) {
|
|
86
81
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
87
82
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
88
|
-
context.core.virtualFiles.updateSource(
|
|
83
|
+
context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
|
|
89
84
|
edited = true;
|
|
90
85
|
}
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
if (level > 1) {
|
|
87
|
+
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
88
|
+
const editLines = new Set();
|
|
89
|
+
if (onTypeParams) {
|
|
90
|
+
for (const edit of edits) {
|
|
91
|
+
for (let line = edit.range.start.line; line <= edit.range.end.line; line++) {
|
|
92
|
+
editLines.add(line);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const toPatchIndentUri of toPatchIndentUris) {
|
|
97
|
+
for (const [_, map] of context.documents.getMapsByVirtualFileUri(toPatchIndentUri.uri)) {
|
|
98
|
+
const indentSensitiveLines = new Set();
|
|
99
|
+
for (const plugin of Object.values(context.plugins)) {
|
|
100
|
+
if (plugin.getIndentSensitiveLines) {
|
|
101
|
+
const lines = yield plugin.getIndentSensitiveLines(map.virtualFileDocument);
|
|
102
|
+
if (lines) {
|
|
103
|
+
for (const line of lines) {
|
|
104
|
+
indentSensitiveLines.add(line);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
let indentEdits = patchIndents(document, toPatchIndentUri.isCodeBlock, map.map, initialIndentLanguageId[map.virtualFileDocument.languageId] ? baseIndent : '');
|
|
110
|
+
indentEdits = indentEdits.filter(edit => {
|
|
111
|
+
for (let line = edit.range.start.line; line <= edit.range.end.line; line++) {
|
|
112
|
+
if (indentSensitiveLines.has(line) && !edit.newText.includes('\n')) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (onTypeParams && !editLines.has(line)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (!(0, common_1.isInsideRange)(range, edit.range)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
});
|
|
124
|
+
if (indentEdits.length > 0) {
|
|
125
|
+
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
126
|
+
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
127
|
+
context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
|
|
128
|
+
edited = true;
|
|
129
|
+
}
|
|
99
130
|
}
|
|
100
131
|
}
|
|
101
132
|
}
|
|
102
133
|
}
|
|
103
134
|
if (edited) {
|
|
104
135
|
// recover
|
|
105
|
-
context.core.virtualFiles.updateSource(
|
|
136
|
+
context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), originalSnapshot, undefined);
|
|
106
137
|
}
|
|
107
138
|
if (document.getText() === originalDocument.getText())
|
|
108
139
|
return;
|
|
@@ -121,7 +152,7 @@ function register(context) {
|
|
|
121
152
|
embeddedFilesByLevel.push(nextLevel);
|
|
122
153
|
}
|
|
123
154
|
}
|
|
124
|
-
function tryFormat(
|
|
155
|
+
function tryFormat(document, range, ch) {
|
|
125
156
|
var _a, _b;
|
|
126
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
158
|
let formatRange = range;
|
|
@@ -132,11 +163,11 @@ function register(context) {
|
|
|
132
163
|
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, document, formatRange, ch, options));
|
|
133
164
|
}
|
|
134
165
|
else if (ch === undefined && vscode.Range.is(formatRange)) {
|
|
135
|
-
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange,
|
|
166
|
+
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, options));
|
|
136
167
|
}
|
|
137
168
|
}
|
|
138
169
|
catch (err) {
|
|
139
|
-
console.
|
|
170
|
+
console.warn(err);
|
|
140
171
|
}
|
|
141
172
|
if (!edits)
|
|
142
173
|
continue;
|
|
@@ -147,28 +178,55 @@ function register(context) {
|
|
|
147
178
|
});
|
|
148
179
|
}
|
|
149
180
|
exports.register = register;
|
|
150
|
-
function
|
|
181
|
+
function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
151
182
|
const indentTextEdits = [];
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
183
|
+
if (!isCodeBlock) {
|
|
184
|
+
initialIndent = '';
|
|
185
|
+
}
|
|
186
|
+
for (let i = 0; i < map.mappings.length; i++) {
|
|
187
|
+
const mapping = map.mappings[i];
|
|
188
|
+
const firstLineIndent = getBaseIndent(mapping.sourceRange[0]);
|
|
189
|
+
const text = document.getText().substring(mapping.sourceRange[0], mapping.sourceRange[1]);
|
|
190
|
+
const lines = text.split('\n');
|
|
191
|
+
const baseIndent = firstLineIndent + initialIndent;
|
|
192
|
+
let lineOffset = lines[0].length + 1;
|
|
193
|
+
let insertedFinalNewLine = false;
|
|
194
|
+
if (!text.trim())
|
|
155
195
|
continue;
|
|
196
|
+
if (isCodeBlock && text.trimStart().length === text.length) {
|
|
197
|
+
indentTextEdits.push({
|
|
198
|
+
newText: '\n' + baseIndent,
|
|
199
|
+
range: {
|
|
200
|
+
start: document.positionAt(mapping.sourceRange[0]),
|
|
201
|
+
end: document.positionAt(mapping.sourceRange[0]),
|
|
202
|
+
},
|
|
203
|
+
});
|
|
156
204
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
205
|
+
if (isCodeBlock && text.trimEnd().length === text.length) {
|
|
206
|
+
indentTextEdits.push({
|
|
207
|
+
newText: '\n',
|
|
208
|
+
range: {
|
|
209
|
+
start: document.positionAt(mapping.sourceRange[1]),
|
|
210
|
+
end: document.positionAt(mapping.sourceRange[1]),
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
insertedFinalNewLine = true;
|
|
160
214
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
215
|
+
if (baseIndent && lines.length > 1) {
|
|
216
|
+
for (let i = 1; i < lines.length; i++) {
|
|
217
|
+
if (lines[i].trim() || i === lines.length - 1) {
|
|
218
|
+
const isLastLine = i === lines.length - 1 && !insertedFinalNewLine;
|
|
219
|
+
indentTextEdits.push({
|
|
220
|
+
newText: isLastLine ? firstLineIndent : baseIndent,
|
|
221
|
+
range: {
|
|
222
|
+
start: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
223
|
+
end: document.positionAt(mapping.sourceRange[0] + lineOffset),
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
lineOffset += lines[i].length + 1;
|
|
228
|
+
}
|
|
164
229
|
}
|
|
165
|
-
indentTextEdits.push({
|
|
166
|
-
newText: lines.join('\n'),
|
|
167
|
-
range: {
|
|
168
|
-
start: document.positionAt(mapped.sourceRange[0]),
|
|
169
|
-
end: document.positionAt(mapped.sourceRange[1]),
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
230
|
}
|
|
173
231
|
return indentTextEdits;
|
|
174
232
|
function getBaseIndent(pos) {
|
package/out/documents.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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
5
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
6
|
+
import { LanguageServiceOptions } from './types';
|
|
6
7
|
export type DocumentsAndSourceMaps = ReturnType<typeof createDocumentsAndSourceMaps>;
|
|
7
8
|
export declare class SourceMapWithDocuments<Data = any> {
|
|
8
9
|
sourceFileDocument: TextDocument;
|
|
@@ -29,7 +30,7 @@ export declare class MirrorMapWithDocument extends SourceMapWithDocuments<[Mirro
|
|
|
29
30
|
constructor(document: TextDocument, map: MirrorMap);
|
|
30
31
|
findMirrorPositions(start: vscode.Position): Generator<readonly [import("vscode-languageserver-textdocument").Position, MirrorBehaviorCapabilities], void, unknown>;
|
|
31
32
|
}
|
|
32
|
-
export declare function createDocumentsAndSourceMaps(mapper: VirtualFiles): {
|
|
33
|
+
export declare function createDocumentsAndSourceMaps(ctx: LanguageServiceOptions, mapper: VirtualFiles): {
|
|
33
34
|
getSourceByUri(sourceFileUri: string): import("@volar/language-core").Source | undefined;
|
|
34
35
|
hasVirtualFileByUri(virtualFileUri: string): boolean;
|
|
35
36
|
getVirtualFileByUri(virtualFileUri: string): readonly [VirtualFile, import("@volar/language-core").Source] | readonly [undefined, undefined];
|
package/out/documents.js
CHANGED
|
@@ -116,23 +116,23 @@ class MirrorMapWithDocument extends SourceMapWithDocuments {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
exports.MirrorMapWithDocument = MirrorMapWithDocument;
|
|
119
|
-
function createDocumentsAndSourceMaps(mapper) {
|
|
119
|
+
function createDocumentsAndSourceMaps(ctx, mapper) {
|
|
120
120
|
let version = 0;
|
|
121
121
|
const _maps = new WeakMap();
|
|
122
122
|
const _mirrorMaps = new WeakMap();
|
|
123
123
|
const _documents = new WeakMap();
|
|
124
124
|
return {
|
|
125
125
|
getSourceByUri(sourceFileUri) {
|
|
126
|
-
return mapper.getSource(
|
|
126
|
+
return mapper.getSource(ctx.uriToFileName(sourceFileUri));
|
|
127
127
|
},
|
|
128
128
|
hasVirtualFileByUri(virtualFileUri) {
|
|
129
|
-
return mapper.hasVirtualFile(
|
|
129
|
+
return mapper.hasVirtualFile(ctx.uriToFileName(virtualFileUri));
|
|
130
130
|
},
|
|
131
131
|
getVirtualFileByUri(virtualFileUri) {
|
|
132
|
-
return mapper.getVirtualFile(
|
|
132
|
+
return mapper.getVirtualFile(ctx.uriToFileName(virtualFileUri));
|
|
133
133
|
},
|
|
134
134
|
getMirrorMapByUri(virtualFileUri) {
|
|
135
|
-
const fileName =
|
|
135
|
+
const fileName = ctx.uriToFileName(virtualFileUri);
|
|
136
136
|
const [virtualFile] = mapper.getVirtualFile(fileName);
|
|
137
137
|
if (virtualFile) {
|
|
138
138
|
const map = mapper.getMirrorMap(virtualFile);
|
|
@@ -145,7 +145,7 @@ function createDocumentsAndSourceMaps(mapper) {
|
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
147
|
getMapsBySourceFileUri(uri) {
|
|
148
|
-
return this.getMapsBySourceFileName(
|
|
148
|
+
return this.getMapsBySourceFileName(ctx.uriToFileName(uri));
|
|
149
149
|
},
|
|
150
150
|
getMapsBySourceFileName(fileName) {
|
|
151
151
|
const source = mapper.getSource(fileName);
|
|
@@ -173,7 +173,7 @@ function createDocumentsAndSourceMaps(mapper) {
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
getMapsByVirtualFileUri(virtualFileUri) {
|
|
176
|
-
return this.getMapsByVirtualFileName(
|
|
176
|
+
return this.getMapsByVirtualFileName(ctx.uriToFileName(virtualFileUri));
|
|
177
177
|
},
|
|
178
178
|
*getMapsByVirtualFileName(virtualFileName) {
|
|
179
179
|
var _a;
|
|
@@ -193,7 +193,7 @@ function createDocumentsAndSourceMaps(mapper) {
|
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
195
|
getDocumentByUri(snapshot, uri) {
|
|
196
|
-
return this.getDocumentByFileName(snapshot,
|
|
196
|
+
return this.getDocumentByFileName(snapshot, ctx.uriToFileName(uri));
|
|
197
197
|
},
|
|
198
198
|
getDocumentByFileName,
|
|
199
199
|
};
|
|
@@ -203,7 +203,7 @@ function createDocumentsAndSourceMaps(mapper) {
|
|
|
203
203
|
}
|
|
204
204
|
const map = _documents.get(snapshot);
|
|
205
205
|
if (!map.has(fileName)) {
|
|
206
|
-
map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(
|
|
206
|
+
map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(ctx.fileNameToUri(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
|
|
207
207
|
}
|
|
208
208
|
return map.get(fileName);
|
|
209
209
|
}
|
|
@@ -131,7 +131,7 @@ function register(context) {
|
|
|
131
131
|
if (!selectionRange)
|
|
132
132
|
continue;
|
|
133
133
|
const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty);
|
|
134
|
-
const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(
|
|
134
|
+
const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
|
|
135
135
|
// TS Bug: `range: range` not works
|
|
136
136
|
range: {
|
|
137
137
|
start: range.start,
|
|
@@ -60,7 +60,7 @@ function register(context) {
|
|
|
60
60
|
const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
|
|
61
61
|
const data = diagnostic.data;
|
|
62
62
|
if (data && data.version !== sourceDocument.version) {
|
|
63
|
-
console.warn('[volar/plugin-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
63
|
+
// console.warn('[volar/plugin-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId;
|
|
@@ -100,7 +100,7 @@ function register(context) {
|
|
|
100
100
|
for (const diagnostic of codeActionContext.diagnostics) {
|
|
101
101
|
const data = diagnostic.data;
|
|
102
102
|
if (data && data.version !== sourceDocument.version) {
|
|
103
|
-
console.warn('[volar/rules-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
103
|
+
// console.warn('[volar/rules-api] diagnostic version mismatch', data.version, sourceDocument.version);
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
106
|
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') {
|
|
@@ -15,7 +15,7 @@ const vscode = require("vscode-languageserver-protocol");
|
|
|
15
15
|
function register(context) {
|
|
16
16
|
return (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
var _a, _b, _c;
|
|
18
|
-
const referencesCodeLendsEnabled = (_b = yield ((_a = context.
|
|
18
|
+
const referencesCodeLendsEnabled = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true;
|
|
19
19
|
return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
var _d, _e, _f, _g;
|
|
21
21
|
let codeLens = yield ((_e = (_d = plugin.codeLens) === null || _d === void 0 ? void 0 : _d.on) === null || _e === void 0 ? void 0 : _e.call(_d, document));
|
|
@@ -14,7 +14,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
|
|
|
14
14
|
function register(context) {
|
|
15
15
|
return (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
var _a;
|
|
17
|
-
const pluginLinks = (_a = yield (0, featureWorkers_1.
|
|
17
|
+
const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(link => {
|
|
18
18
|
if (!map)
|
|
19
19
|
return link;
|
|
20
20
|
const range = map.toSourceRange(link.range);
|
|
@@ -50,15 +50,14 @@ function register(context) {
|
|
|
50
50
|
}, (plugin, document, arg) => {
|
|
51
51
|
var _a, _b;
|
|
52
52
|
return (_b = (_a = plugin.inlayHints) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg);
|
|
53
|
-
}, (inlayHints, map) => inlayHints.map(_inlayHint => {
|
|
53
|
+
}, (inlayHints, map) => inlayHints.map((_inlayHint) => {
|
|
54
54
|
var _a;
|
|
55
55
|
if (!map)
|
|
56
56
|
return _inlayHint;
|
|
57
57
|
const position = map.toSourcePosition(_inlayHint.position);
|
|
58
58
|
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)).filter(shared.notEmpty);
|
|
59
59
|
if (position) {
|
|
60
|
-
return Object.assign(Object.assign({}, _inlayHint), { position,
|
|
61
|
-
edits });
|
|
60
|
+
return Object.assign(Object.assign({}, _inlayHint), { position, textEdits: edits });
|
|
62
61
|
}
|
|
63
62
|
}).filter(shared.notEmpty), arr => arr.flat());
|
|
64
63
|
});
|
|
@@ -160,7 +160,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
160
160
|
for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
|
|
161
161
|
const tsEdits = tsResult.changes[tsUri];
|
|
162
162
|
for (const tsEdit of tsEdits) {
|
|
163
|
-
if (mode === 'rename') {
|
|
163
|
+
if (mode === 'rename' || mode === 'fileName') {
|
|
164
164
|
let _data;
|
|
165
165
|
const range = map.toSourceRange(tsEdit.range, data => {
|
|
166
166
|
_data = data;
|
|
@@ -199,7 +199,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
199
199
|
version: (_f = versions[map.sourceFileDocument.uri]) !== null && _f !== void 0 ? _f : null,
|
|
200
200
|
}, []);
|
|
201
201
|
for (const tsEdit of tsDocEdit.edits) {
|
|
202
|
-
if (mode === 'rename') {
|
|
202
|
+
if (mode === 'rename' || mode === 'fileName') {
|
|
203
203
|
let _data;
|
|
204
204
|
const range = map.toSourceRange(tsEdit.range, data => {
|
|
205
205
|
_data = data;
|
|
@@ -1,34 +1,30 @@
|
|
|
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
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.register = void 0;
|
|
12
3
|
const vscode = require("vscode-languageserver-protocol");
|
|
13
4
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
14
5
|
function register(context) {
|
|
15
|
-
return (uri, position) =>
|
|
16
|
-
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.
|
|
6
|
+
return (uri, position) => {
|
|
7
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => {
|
|
17
8
|
if (!map) {
|
|
18
9
|
return item;
|
|
19
10
|
}
|
|
20
11
|
if (vscode.Range.is(item)) {
|
|
21
12
|
return map.toSourceRange(item);
|
|
22
13
|
}
|
|
14
|
+
return item;
|
|
23
15
|
}, prepares => {
|
|
24
16
|
for (const prepare of prepares) {
|
|
25
17
|
if (vscode.Range.is(prepare)) {
|
|
26
18
|
return prepare; // if has any valid range, ignore other errors
|
|
27
19
|
}
|
|
28
20
|
}
|
|
29
|
-
|
|
21
|
+
const error = prepares[0];
|
|
22
|
+
const newError = new vscode.ResponseError(error.code, error.message);
|
|
23
|
+
newError.name = error.name;
|
|
24
|
+
newError.stack = error.stack;
|
|
25
|
+
return newError;
|
|
30
26
|
});
|
|
31
|
-
}
|
|
27
|
+
};
|
|
32
28
|
}
|
|
33
29
|
exports.register = register;
|
|
34
30
|
//# sourceMappingURL=renamePrepare.js.map
|
|
@@ -111,7 +111,7 @@ function register(context) {
|
|
|
111
111
|
syntax_rules: { errors: [] },
|
|
112
112
|
format_rules: { errors: [] },
|
|
113
113
|
}).get(uri);
|
|
114
|
-
const newSnapshot = context.host.getScriptSnapshot(
|
|
114
|
+
const newSnapshot = context.host.getScriptSnapshot(context.uriToFileName(uri));
|
|
115
115
|
let updateCacheRangeFailed = false;
|
|
116
116
|
let errorsUpdated = false;
|
|
117
117
|
let lastCheckCancelAt = 0;
|
|
@@ -162,7 +162,7 @@ function register(context) {
|
|
|
162
162
|
}
|
|
163
163
|
function lintWorker(api, cacheMap, cache) {
|
|
164
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const result = yield (0, featureWorkers_1.ruleWorker)(context, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const result = yield (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
|
|
166
166
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
167
167
|
var _h, _j, _k, _l;
|
|
168
168
|
if (token) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
2
|
import type { LanguageServicePluginContext } from '../types';
|
|
3
|
-
export declare function register(context: LanguageServicePluginContext): (query: string) => Promise<vscode.
|
|
3
|
+
export declare function register(context: LanguageServicePluginContext): (query: string) => Promise<vscode.WorkspaceSymbol[]>;
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.register = void 0;
|
|
12
12
|
const transformer = require("../transformer");
|
|
13
13
|
const vscode = require("vscode-languageserver-protocol");
|
|
14
|
+
const shared = require("@volar/shared");
|
|
14
15
|
function register(context) {
|
|
15
16
|
return (query) => __awaiter(this, void 0, void 0, function* () {
|
|
16
17
|
const symbolsList = [];
|
|
@@ -20,7 +21,7 @@ function register(context) {
|
|
|
20
21
|
const embeddedSymbols = yield plugin.findWorkspaceSymbols(query);
|
|
21
22
|
if (!embeddedSymbols)
|
|
22
23
|
continue;
|
|
23
|
-
const symbols = transformer.
|
|
24
|
+
const symbols = embeddedSymbols.map(symbol => transformer.asWorkspaceSymbol(symbol, loc => {
|
|
24
25
|
if (context.documents.hasVirtualFileByUri(loc.uri)) {
|
|
25
26
|
for (const [_, map] of context.documents.getMapsByVirtualFileUri(loc.uri)) {
|
|
26
27
|
const range = map.toSourceRange(loc.range);
|
|
@@ -32,7 +33,7 @@ function register(context) {
|
|
|
32
33
|
else {
|
|
33
34
|
return loc;
|
|
34
35
|
}
|
|
35
|
-
});
|
|
36
|
+
})).filter(shared.notEmpty);
|
|
36
37
|
symbolsList.push(symbols);
|
|
37
38
|
}
|
|
38
39
|
return symbolsList.flat();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.transform = void 0;
|
|
3
|
+
const shared = require("@volar/shared");
|
|
4
|
+
function transform(symbol, getOtherRange) {
|
|
5
|
+
var _a;
|
|
6
|
+
const range = getOtherRange(symbol.range);
|
|
7
|
+
if (!range) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const selectionRange = getOtherRange(symbol.selectionRange);
|
|
11
|
+
if (!selectionRange) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return Object.assign(Object.assign({}, symbol), { range,
|
|
15
|
+
selectionRange, children: (_a = symbol.children) === null || _a === void 0 ? void 0 : _a.map(child => transform(child, getOtherRange)).filter(shared.notEmpty) });
|
|
16
|
+
}
|
|
17
|
+
exports.transform = transform;
|
|
18
|
+
//# sourceMappingURL=documentSymbol.js.map
|
|
@@ -6,6 +6,6 @@ export { transform as asLocation } from './locationLike';
|
|
|
6
6
|
export { transform as asLocations } from './locationsLike';
|
|
7
7
|
export { transform as asSelectionRange } from './selectionRange';
|
|
8
8
|
export { transform as asSelectionRanges } from './selectionRanges';
|
|
9
|
-
export { transform as asSymbolInformation } from './symbolInformation';
|
|
10
|
-
export { transform as asSymbolInformations } from './symbolInformations';
|
|
11
9
|
export { transform as asTextEdit } from './textEdit';
|
|
10
|
+
export { transform as asDocumentSymbol } from './documentSymbol';
|
|
11
|
+
export { transform as asWorkspaceSymbol } from './workspaceSymbol';
|
package/out/transformer/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.
|
|
2
|
+
exports.asWorkspaceSymbol = exports.asDocumentSymbol = exports.asTextEdit = exports.asSelectionRanges = exports.asSelectionRange = exports.asLocations = exports.asLocation = exports.asHover = exports.asFoldingRanges = exports.asCompletionList = exports.asCompletionItem = void 0;
|
|
3
3
|
var completionItem_1 = require("./completionItem");
|
|
4
4
|
Object.defineProperty(exports, "asCompletionItem", { enumerable: true, get: function () { return completionItem_1.transform; } });
|
|
5
5
|
var completionList_1 = require("./completionList");
|
|
@@ -16,10 +16,10 @@ var selectionRange_1 = require("./selectionRange");
|
|
|
16
16
|
Object.defineProperty(exports, "asSelectionRange", { enumerable: true, get: function () { return selectionRange_1.transform; } });
|
|
17
17
|
var selectionRanges_1 = require("./selectionRanges");
|
|
18
18
|
Object.defineProperty(exports, "asSelectionRanges", { enumerable: true, get: function () { return selectionRanges_1.transform; } });
|
|
19
|
-
var symbolInformation_1 = require("./symbolInformation");
|
|
20
|
-
Object.defineProperty(exports, "asSymbolInformation", { enumerable: true, get: function () { return symbolInformation_1.transform; } });
|
|
21
|
-
var symbolInformations_1 = require("./symbolInformations");
|
|
22
|
-
Object.defineProperty(exports, "asSymbolInformations", { enumerable: true, get: function () { return symbolInformations_1.transform; } });
|
|
23
19
|
var textEdit_1 = require("./textEdit");
|
|
24
20
|
Object.defineProperty(exports, "asTextEdit", { enumerable: true, get: function () { return textEdit_1.transform; } });
|
|
21
|
+
var documentSymbol_1 = require("./documentSymbol");
|
|
22
|
+
Object.defineProperty(exports, "asDocumentSymbol", { enumerable: true, get: function () { return documentSymbol_1.transform; } });
|
|
23
|
+
var workspaceSymbol_1 = require("./workspaceSymbol");
|
|
24
|
+
Object.defineProperty(exports, "asWorkspaceSymbol", { enumerable: true, get: function () { return workspaceSymbol_1.transform; } });
|
|
25
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.transform = void 0;
|
|
3
|
+
const vscode = require("vscode-languageserver-protocol");
|
|
4
|
+
function transform(symbol, getOtherLocation) {
|
|
5
|
+
if (!vscode.Location.is(symbol.location)) {
|
|
6
|
+
return symbol;
|
|
7
|
+
}
|
|
8
|
+
const loc = getOtherLocation(symbol.location);
|
|
9
|
+
if (!loc) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return Object.assign(Object.assign({}, symbol), { location: loc });
|
|
13
|
+
}
|
|
14
|
+
exports.transform = transform;
|
|
15
|
+
//# sourceMappingURL=workspaceSymbol.js.map
|
package/out/types.d.ts
CHANGED
|
@@ -7,25 +7,24 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
|
7
7
|
import { URI } from 'vscode-uri';
|
|
8
8
|
import { DocumentsAndSourceMaps } from './documents';
|
|
9
9
|
export * from 'vscode-languageserver-protocol';
|
|
10
|
-
export interface
|
|
10
|
+
export interface LanguageServiceOptions {
|
|
11
|
+
host: LanguageServiceHost;
|
|
11
12
|
config: Config;
|
|
13
|
+
uriToFileName(uri: string): string;
|
|
14
|
+
fileNameToUri(fileName: string): string;
|
|
15
|
+
rootUri: URI;
|
|
16
|
+
locale?: string;
|
|
17
|
+
configurationHost?: ConfigurationHost;
|
|
18
|
+
documentContext?: DocumentContext;
|
|
19
|
+
fileSystemProvider?: FileSystemProvider;
|
|
20
|
+
schemaRequestService?: SchemaRequestService;
|
|
21
|
+
}
|
|
22
|
+
export interface LanguageServicePluginContext extends LanguageServiceOptions {
|
|
12
23
|
typescript: {
|
|
13
24
|
module: typeof import('typescript/lib/tsserverlibrary');
|
|
14
25
|
languageServiceHost: ts.LanguageServiceHost;
|
|
15
26
|
languageService: ts.LanguageService;
|
|
16
27
|
} | undefined;
|
|
17
|
-
env: {
|
|
18
|
-
rootUri: URI;
|
|
19
|
-
locale?: string;
|
|
20
|
-
configurationHost?: ConfigurationHost;
|
|
21
|
-
documentContext: DocumentContext;
|
|
22
|
-
fileSystemProvider?: FileSystemProvider;
|
|
23
|
-
schemaRequestService?: SchemaRequestService;
|
|
24
|
-
};
|
|
25
|
-
uriToFileName(uri: string): string;
|
|
26
|
-
fileNameToUri(fileName: string): string;
|
|
27
|
-
/** @private */
|
|
28
|
-
host: LanguageServiceHost;
|
|
29
28
|
/** @private */
|
|
30
29
|
core: LanguageContext;
|
|
31
30
|
/** @private */
|
|
@@ -60,7 +59,10 @@ export interface LanguageServicePlugin<T = {}> {
|
|
|
60
59
|
}
|
|
61
60
|
export interface LanguageServicePluginInstance {
|
|
62
61
|
rules?: {
|
|
63
|
-
|
|
62
|
+
onAny?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
63
|
+
onFormat?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
64
|
+
onSyntax?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
65
|
+
onSemantic?(context: RuleContext): NotNullableResult<RuleContext>;
|
|
64
66
|
};
|
|
65
67
|
validation?: {
|
|
66
68
|
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
|
|
@@ -74,19 +76,18 @@ export interface LanguageServicePluginInstance {
|
|
|
74
76
|
findFileReferences?(document: TextDocument): NullableResult<vscode.Location[]>;
|
|
75
77
|
findDocumentHighlights?(document: TextDocument, position: vscode.Position): NullableResult<vscode.DocumentHighlight[]>;
|
|
76
78
|
findDocumentLinks?(document: TextDocument): NullableResult<vscode.DocumentLink[]>;
|
|
77
|
-
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.
|
|
79
|
+
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.DocumentSymbol[]>;
|
|
78
80
|
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
|
|
79
|
-
findWorkspaceSymbols?(query: string): NullableResult<vscode.
|
|
81
|
+
findWorkspaceSymbols?(query: string): NullableResult<vscode.WorkspaceSymbol[]>;
|
|
80
82
|
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
|
|
81
83
|
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
|
|
82
84
|
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
|
|
83
85
|
getFoldingRanges?(document: TextDocument): NullableResult<vscode.FoldingRange[]>;
|
|
84
86
|
getSelectionRanges?(document: TextDocument, positions: vscode.Position[]): NullableResult<vscode.SelectionRange[]>;
|
|
85
87
|
getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
|
|
86
|
-
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions
|
|
87
|
-
initialIndent: boolean;
|
|
88
|
-
}): NullableResult<vscode.TextEdit[]>;
|
|
88
|
+
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
|
|
89
89
|
formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
|
|
90
|
+
getIndentSensitiveLines?(document: TextDocument): NullableResult<number[]>;
|
|
90
91
|
definition?: {
|
|
91
92
|
on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
|
|
92
93
|
onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
|
package/out/utils/dedupe.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]):
|
|
|
7
7
|
export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
|
|
8
8
|
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.TextDocumentEdit | vscode.CreateFile | vscode.RenameFile | vscode.DeleteFile)[];
|
|
9
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
10
|
export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
|
|
12
11
|
export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
|
|
13
12
|
export declare function withCallHierarchyIncomingCalls<T extends vscode.CallHierarchyIncomingCall>(items: T[]): T[];
|
package/out/utils/dedupe.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.withRanges = exports.withCallHierarchyOutgoingCalls = exports.withCallHierarchyIncomingCalls = exports.withLocationLinks = exports.withLocations = exports.
|
|
2
|
+
exports.withRanges = exports.withCallHierarchyOutgoingCalls = exports.withCallHierarchyIncomingCalls = exports.withLocationLinks = exports.withLocations = exports.withDiagnostics = exports.withDocumentChanges = exports.withTextEdits = exports.withCodeAction = exports.createLocationSet = void 0;
|
|
3
3
|
function createLocationSet() {
|
|
4
4
|
const set = new Set();
|
|
5
5
|
return {
|
|
@@ -60,18 +60,6 @@ function withDiagnostics(items) {
|
|
|
60
60
|
].join(':'));
|
|
61
61
|
}
|
|
62
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
63
|
function withLocations(items) {
|
|
76
64
|
return dedupe(items, item => [
|
|
77
65
|
item.uri,
|
|
@@ -4,4 +4,5 @@ import { FileRangeCapabilities, VirtualFile } from '@volar/language-service';
|
|
|
4
4
|
import { SourceMapWithDocuments } from '../documents';
|
|
5
5
|
export declare function documentFeatureWorker<T>(context: LanguageServicePluginContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePluginInstance, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
6
6
|
export declare function languageFeatureWorker<T, K>(context: LanguageServicePluginContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePluginInstance, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
-
export declare function ruleWorker<T>(context: LanguageServicePluginContext, uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
7
|
+
export declare function ruleWorker<T>(context: LanguageServicePluginContext, api: 'onSyntax' | 'onSemantic' | 'onFormat', uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
|
|
8
|
+
export declare function safeCall<T>(cb: () => Promise<T> | T, errorMsg?: string): Promise<T | undefined>;
|
|
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
11
|
+
exports.safeCall = exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
|
|
12
12
|
const definePlugin_1 = require("./definePlugin");
|
|
13
|
-
const shared = require("@volar/shared");
|
|
14
13
|
function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) {
|
|
15
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
15
|
return languageFeatureWorker(context, uri, undefined, (_, map, file) => {
|
|
@@ -31,8 +30,8 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
31
30
|
if (virtualFile) {
|
|
32
31
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
33
32
|
for (const mappedArg of transformArg(arg, map, file)) {
|
|
34
|
-
for (const plugin of Object.
|
|
35
|
-
const embeddedResult = yield worker(plugin, map.virtualFileDocument, mappedArg, map, file);
|
|
33
|
+
for (const [pluginId, plugin] of Object.entries(context.plugins)) {
|
|
34
|
+
const embeddedResult = yield safeCall(() => worker(plugin, map.virtualFileDocument, mappedArg, map, file), 'plugin ' + pluginId + ' crashed on ' + map.virtualFileDocument.uri);
|
|
36
35
|
if (!embeddedResult)
|
|
37
36
|
continue;
|
|
38
37
|
const result = transform(embeddedResult, map);
|
|
@@ -51,8 +50,8 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
51
50
|
}));
|
|
52
51
|
}
|
|
53
52
|
else if (document) {
|
|
54
|
-
for (const plugin of Object.
|
|
55
|
-
const embeddedResult = yield worker(plugin, document, arg, undefined, undefined);
|
|
53
|
+
for (const [pluginId, plugin] of Object.entries(context.plugins)) {
|
|
54
|
+
const embeddedResult = yield safeCall(() => worker(plugin, document, arg, undefined, undefined), 'plugin ' + pluginId + ' crashed on ' + uri);
|
|
56
55
|
if (!embeddedResult)
|
|
57
56
|
continue;
|
|
58
57
|
const result = transform(embeddedResult, undefined);
|
|
@@ -76,7 +75,7 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
exports.languageFeatureWorker = languageFeatureWorker;
|
|
79
|
-
function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
78
|
+
function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
80
79
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
81
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
81
|
const document = context.getTextDocument(uri);
|
|
@@ -84,19 +83,19 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
84
83
|
let results = [];
|
|
85
84
|
if (virtualFile) {
|
|
86
85
|
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
var _l, _m, _o, _p, _q, _r, _s, _t;
|
|
86
|
+
var _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
88
87
|
if (!isValidSourceMap(file)) {
|
|
89
88
|
return true;
|
|
90
89
|
}
|
|
91
90
|
let ruleCtx = {
|
|
92
91
|
// project context
|
|
93
92
|
modules: { typescript: (_l = context.typescript) === null || _l === void 0 ? void 0 : _l.module },
|
|
94
|
-
uriToFileName:
|
|
95
|
-
fileNameToUri:
|
|
96
|
-
rootUri: context.
|
|
97
|
-
locale: context.
|
|
98
|
-
getConfiguration: (_m = context.
|
|
99
|
-
onDidChangeConfiguration: (_o = context.
|
|
93
|
+
uriToFileName: context.uriToFileName,
|
|
94
|
+
fileNameToUri: context.fileNameToUri,
|
|
95
|
+
rootUri: context.rootUri,
|
|
96
|
+
locale: context.locale,
|
|
97
|
+
getConfiguration: (_m = context.configurationHost) === null || _m === void 0 ? void 0 : _m.getConfiguration,
|
|
98
|
+
onDidChangeConfiguration: (_o = context.configurationHost) === null || _o === void 0 ? void 0 : _o.onDidChangeConfiguration,
|
|
100
99
|
settings: (_q = (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.settings) !== null && _q !== void 0 ? _q : {},
|
|
101
100
|
// document context
|
|
102
101
|
ruleId: '',
|
|
@@ -104,17 +103,26 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
104
103
|
report: () => { },
|
|
105
104
|
};
|
|
106
105
|
for (const plugin of Object.values(context.plugins)) {
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const fn = (_r = plugin.rules) === null || _r === void 0 ? void 0 : _r[api];
|
|
107
|
+
try {
|
|
108
|
+
if (fn) {
|
|
109
|
+
ruleCtx = yield fn(ruleCtx);
|
|
110
|
+
}
|
|
111
|
+
else if ((_s = plugin.rules) === null || _s === void 0 ? void 0 : _s.onAny) {
|
|
112
|
+
ruleCtx = yield plugin.rules.onAny(ruleCtx);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
console.warn('plugin rule context setup crashed on ' + map.virtualFileDocument.uri + ': ' + err);
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
|
-
for (const ruleName in (
|
|
112
|
-
const rule = (
|
|
119
|
+
for (const ruleName in (_t = context.config.lint) === null || _t === void 0 ? void 0 : _t.rules) {
|
|
120
|
+
const rule = (_u = context.config.lint) === null || _u === void 0 ? void 0 : _u.rules[ruleName];
|
|
113
121
|
if (!rule) {
|
|
114
122
|
continue;
|
|
115
123
|
}
|
|
116
124
|
ruleCtx.ruleId = ruleName;
|
|
117
|
-
const embeddedResult = yield worker(ruleName, rule, ruleCtx);
|
|
125
|
+
const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + map.virtualFileDocument.uri);
|
|
118
126
|
if (!embeddedResult)
|
|
119
127
|
continue;
|
|
120
128
|
const result = transform(embeddedResult, map);
|
|
@@ -135,12 +143,12 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
135
143
|
let ruleCtx = {
|
|
136
144
|
// project context
|
|
137
145
|
modules: { typescript: (_b = context.typescript) === null || _b === void 0 ? void 0 : _b.module },
|
|
138
|
-
uriToFileName:
|
|
139
|
-
fileNameToUri:
|
|
140
|
-
rootUri: context.
|
|
141
|
-
locale: context.
|
|
142
|
-
getConfiguration: (_c = context.
|
|
143
|
-
onDidChangeConfiguration: (_d = context.
|
|
146
|
+
uriToFileName: context.uriToFileName,
|
|
147
|
+
fileNameToUri: context.fileNameToUri,
|
|
148
|
+
rootUri: context.rootUri,
|
|
149
|
+
locale: context.locale,
|
|
150
|
+
getConfiguration: (_c = context.configurationHost) === null || _c === void 0 ? void 0 : _c.getConfiguration,
|
|
151
|
+
onDidChangeConfiguration: (_d = context.configurationHost) === null || _d === void 0 ? void 0 : _d.onDidChangeConfiguration,
|
|
144
152
|
settings: (_f = (_e = context.config.lint) === null || _e === void 0 ? void 0 : _e.settings) !== null && _f !== void 0 ? _f : {},
|
|
145
153
|
// document context
|
|
146
154
|
ruleId: '',
|
|
@@ -148,8 +156,17 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
148
156
|
report: () => { },
|
|
149
157
|
};
|
|
150
158
|
for (const plugin of Object.values(context.plugins)) {
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
const fn = (_g = plugin.rules) === null || _g === void 0 ? void 0 : _g[api];
|
|
160
|
+
try {
|
|
161
|
+
if (fn) {
|
|
162
|
+
ruleCtx = yield fn(ruleCtx);
|
|
163
|
+
}
|
|
164
|
+
else if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.onAny) {
|
|
165
|
+
ruleCtx = yield plugin.rules.onAny(ruleCtx);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
console.warn('plugin rule context setup crashed on ' + document.uri + ': ' + err);
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
172
|
for (const ruleName in (_j = context.config.lint) === null || _j === void 0 ? void 0 : _j.rules) {
|
|
@@ -158,7 +175,7 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
158
175
|
continue;
|
|
159
176
|
}
|
|
160
177
|
ruleCtx.ruleId = ruleName;
|
|
161
|
-
const embeddedResult = yield worker(ruleName, rule, ruleCtx);
|
|
178
|
+
const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + document.uri);
|
|
162
179
|
if (!embeddedResult)
|
|
163
180
|
continue;
|
|
164
181
|
const result = transform(embeddedResult, undefined);
|
|
@@ -182,4 +199,15 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
|
|
|
182
199
|
});
|
|
183
200
|
}
|
|
184
201
|
exports.ruleWorker = ruleWorker;
|
|
202
|
+
function safeCall(cb, errorMsg) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
try {
|
|
205
|
+
return yield cb();
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
console.warn(errorMsg, err);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
exports.safeCall = safeCall;
|
|
185
213
|
//# sourceMappingURL=featureWorkers.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-alpha.1",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.
|
|
17
|
-
"@volar/shared": "1.
|
|
18
|
-
"@volar/source-map": "1.
|
|
19
|
-
"@volar/typescript-faster": "1.
|
|
20
|
-
"vscode-html-languageservice": "^5.0.
|
|
21
|
-
"vscode-json-languageservice": "^5.
|
|
22
|
-
"vscode-languageserver-protocol": "^3.17.
|
|
16
|
+
"@volar/language-core": "1.3.0-alpha.1",
|
|
17
|
+
"@volar/shared": "1.3.0-alpha.1",
|
|
18
|
+
"@volar/source-map": "1.3.0-alpha.1",
|
|
19
|
+
"@volar/typescript-faster": "1.3.0-alpha.1",
|
|
20
|
+
"vscode-html-languageservice": "^5.0.4",
|
|
21
|
+
"vscode-json-languageservice": "^5.2.0",
|
|
22
|
+
"vscode-languageserver-protocol": "^3.17.3",
|
|
23
23
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
24
24
|
"vscode-uri": "^3.0.7"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "2926dc4af31890e01f6218773e88578ddf0de658"
|
|
27
27
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LanguageServiceRuntimeContext } from '../types';
|
|
2
|
-
import { ExecuteCommandContext } from '@volar/language-service';
|
|
3
|
-
import * as vscode from 'vscode-languageserver-protocol';
|
|
4
|
-
export declare const executePluginCommand: string;
|
|
5
|
-
export type ExecutePluginCommandArgs = [
|
|
6
|
-
string,
|
|
7
|
-
string,
|
|
8
|
-
vscode.Command
|
|
9
|
-
];
|
|
10
|
-
export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;
|
|
@@ -1,24 +0,0 @@
|
|
|
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 = exports.executePluginCommand = void 0;
|
|
12
|
-
const randomCommandId = Math.random().toString(36).slice(2); // TODO
|
|
13
|
-
exports.executePluginCommand = `volar.${randomCommandId}.executePluginCommand`;
|
|
14
|
-
function register(context) {
|
|
15
|
-
return (command, args, executeCommandContext) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
var _a, _b;
|
|
17
|
-
if (command === exports.executePluginCommand) {
|
|
18
|
-
const [_uri, pluginId, originalCommand] = args;
|
|
19
|
-
yield ((_b = (_a = context.plugins[pluginId]) === null || _a === void 0 ? void 0 : _a.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(_a, originalCommand.command, originalCommand.arguments, executeCommandContext));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.register = register;
|
|
24
|
-
//# sourceMappingURL=executeCommand.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.transform = void 0;
|
|
3
|
-
function transform(symbol, getOtherLocation) {
|
|
4
|
-
const location = getOtherLocation(symbol.location);
|
|
5
|
-
if (!location)
|
|
6
|
-
return;
|
|
7
|
-
return Object.assign(Object.assign({}, symbol), { location });
|
|
8
|
-
}
|
|
9
|
-
exports.transform = transform;
|
|
10
|
-
//# sourceMappingURL=symbolInformation.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.transform = void 0;
|
|
3
|
-
const shared = require("@volar/shared");
|
|
4
|
-
const symbolInformation_1 = require("./symbolInformation");
|
|
5
|
-
function transform(locations, getOtherLocation) {
|
|
6
|
-
return locations
|
|
7
|
-
.map(location => (0, symbolInformation_1.transform)(location, getOtherLocation))
|
|
8
|
-
.filter(shared.notEmpty);
|
|
9
|
-
}
|
|
10
|
-
exports.transform = transform;
|
|
11
|
-
//# sourceMappingURL=symbolInformations.js.map
|