@volar/language-server 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/browser/fileSystems.d.ts +2 -2
- package/out/browser/fileSystems.js +151 -161
- package/out/browser/index.js +64 -32
- package/out/common/documents.d.ts +2 -1
- package/out/common/documents.js +8 -2
- package/out/common/features/customFeatures.d.ts +2 -1
- package/out/common/features/customFeatures.js +12 -12
- package/out/common/features/languageFeatures.d.ts +3 -2
- package/out/common/features/languageFeatures.js +56 -32
- package/out/common/project.d.ts +7 -5
- package/out/common/project.js +26 -17
- package/out/common/schemaRequestHandlers/http.d.ts +1 -1
- package/out/common/schemaRequestHandlers/http.js +3 -0
- package/out/common/server.d.ts +2 -2
- package/out/common/server.js +18 -15
- package/out/common/utils/uriMap.d.ts +1 -1
- package/out/common/utils/uriMap.js +2 -3
- package/out/common/workspace.d.ts +63 -45
- package/out/common/workspace.js +16 -15
- package/out/common/workspaces.d.ts +78 -56
- package/out/common/workspaces.js +4 -3
- package/out/node/fileSystem.d.ts +2 -2
- package/out/node/fileSystem.js +3 -4
- package/out/node/index.js +72 -66
- package/out/protocol.d.ts +6 -7
- package/out/protocol.js +1 -5
- package/out/types.d.ts +41 -15
- package/package.json +10 -10
|
@@ -9,10 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.register = void 0;
|
|
12
|
-
const shared = require("@volar/shared");
|
|
13
12
|
const protocol_1 = require("../../protocol");
|
|
14
13
|
const language_core_1 = require("@volar/language-core");
|
|
15
|
-
function register(connection, projects) {
|
|
14
|
+
function register(connection, projects, env) {
|
|
16
15
|
connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
|
|
17
16
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
18
17
|
for (const [rootUri, _workspace] of projects.workspaces) {
|
|
@@ -67,18 +66,19 @@ function register(connection, projects) {
|
|
|
67
66
|
connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
|
|
68
67
|
const project = (yield projects.getProject(params.uri));
|
|
69
68
|
if (project === null || project === void 0 ? void 0 : project.tsconfig) {
|
|
70
|
-
return { uri:
|
|
69
|
+
return { uri: env.fileNameToUri(project.tsconfig) };
|
|
71
70
|
}
|
|
72
71
|
}));
|
|
73
72
|
connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
var _p, _q;
|
|
73
|
+
var _p, _q, _r;
|
|
75
74
|
const project = yield projects.getProject(document.uri);
|
|
76
75
|
const fileNames = [];
|
|
77
76
|
if (project) {
|
|
78
|
-
const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(
|
|
77
|
+
const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(env.uriToFileName(document.uri))) === null || _q === void 0 ? void 0 : _q.root;
|
|
79
78
|
if (rootVirtualFile) {
|
|
79
|
+
const kinds = (_r = document.fileKinds) !== null && _r !== void 0 ? _r : [language_core_1.FileKind.TypeScriptHostFile];
|
|
80
80
|
(0, language_core_1.forEachEmbeddedFile)(rootVirtualFile, e => {
|
|
81
|
-
if (e.snapshot.getLength() && e.kind
|
|
81
|
+
if (e.snapshot.getLength() && kinds.includes(e.kind)) {
|
|
82
82
|
fileNames.push(e.fileName);
|
|
83
83
|
}
|
|
84
84
|
});
|
|
@@ -87,15 +87,15 @@ function register(connection, projects) {
|
|
|
87
87
|
return fileNames;
|
|
88
88
|
}));
|
|
89
89
|
connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
var
|
|
90
|
+
var _s, _t, _u, _v;
|
|
91
91
|
const project = yield projects.getProject(params.sourceFileUri);
|
|
92
92
|
if (project) {
|
|
93
|
-
const [virtualFile, source] = (
|
|
93
|
+
const [virtualFile, source] = (_t = (_s = project.project) === null || _s === void 0 ? void 0 : _s.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName)) !== null && _t !== void 0 ? _t : [];
|
|
94
94
|
if (virtualFile && source) {
|
|
95
95
|
const mappings = {};
|
|
96
96
|
for (const mapping of virtualFile.mappings) {
|
|
97
|
-
const sourceUri =
|
|
98
|
-
(
|
|
97
|
+
const sourceUri = env.fileNameToUri((_u = mapping.source) !== null && _u !== void 0 ? _u : source.fileName);
|
|
98
|
+
(_v = mappings[sourceUri]) !== null && _v !== void 0 ? _v : (mappings[sourceUri] = []);
|
|
99
99
|
mappings[sourceUri].push(mapping);
|
|
100
100
|
}
|
|
101
101
|
return {
|
|
@@ -109,11 +109,11 @@ function register(connection, projects) {
|
|
|
109
109
|
projects.reloadProject();
|
|
110
110
|
});
|
|
111
111
|
connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
var
|
|
112
|
+
var _w;
|
|
113
113
|
const fs = yield Promise.resolve().then(() => require('fs'));
|
|
114
114
|
const project = yield projects.getProject(params.uri);
|
|
115
115
|
if (project) {
|
|
116
|
-
const ls = (
|
|
116
|
+
const ls = (_w = (yield project.project)) === null || _w === void 0 ? void 0 : _w.getLanguageServiceDontCreate();
|
|
117
117
|
if (ls) {
|
|
118
118
|
const sourceFiles = new Set(ls.context.host.getScriptFileNames());
|
|
119
119
|
for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver';
|
|
2
2
|
import { CancellationTokenHost } from '../cancellationPipe';
|
|
3
3
|
import type { Workspaces } from '../workspaces';
|
|
4
|
-
import { RuntimeEnvironment } from '../../types';
|
|
5
|
-
|
|
4
|
+
import { RuntimeEnvironment, LanguageServerInitializationOptions } from '../../types';
|
|
5
|
+
import { createDocuments } from '../documents';
|
|
6
|
+
export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, initOptions: LanguageServerInitializationOptions, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment, documents: ReturnType<typeof createDocuments>): void;
|
|
@@ -13,7 +13,7 @@ const embedded = require("@volar/language-service");
|
|
|
13
13
|
const vscode = require("vscode-languageserver");
|
|
14
14
|
const protocol_1 = require("../../protocol");
|
|
15
15
|
const shared = require("@volar/shared");
|
|
16
|
-
function register(connection, projects, initParams, cancelHost, semanticTokensLegend, runtime) {
|
|
16
|
+
function register(connection, projects, initParams, initOptions, cancelHost, semanticTokensLegend, runtime, documents) {
|
|
17
17
|
let lastCompleteUri;
|
|
18
18
|
let lastCompleteLs;
|
|
19
19
|
let lastCodeLensLs;
|
|
@@ -66,13 +66,37 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
66
66
|
}));
|
|
67
67
|
connection.onCompletion((params, token) => __awaiter(this, void 0, void 0, function* () {
|
|
68
68
|
return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
var _a;
|
|
69
70
|
lastCompleteUri = params.textDocument.uri;
|
|
70
71
|
lastCompleteLs = service;
|
|
72
|
+
const document = (_a = documents.data.uriGet(params.textDocument.uri)) === null || _a === void 0 ? void 0 : _a.getDocument();
|
|
71
73
|
const list = yield service.doComplete(params.textDocument.uri, params.position, params.context);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
for (const item of list.items) {
|
|
75
|
+
fixTextEdit(item);
|
|
76
|
+
}
|
|
77
|
+
if (!initOptions.fullCompletionList && document) {
|
|
78
|
+
list.items = list.items.filter(item => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const range = item.textEdit ? (vscode.InsertReplaceEdit.is(item.textEdit)
|
|
81
|
+
? item.textEdit.replace
|
|
82
|
+
: item.textEdit.range) : ((_a = list.itemDefaults) === null || _a === void 0 ? void 0 : _a.editRange) ? (vscode.Range.is(list.itemDefaults.editRange)
|
|
83
|
+
? list.itemDefaults.editRange
|
|
84
|
+
: list.itemDefaults.editRange.replace) : undefined;
|
|
85
|
+
if (range) {
|
|
86
|
+
const sourceText = document.getText(range).toLowerCase();
|
|
87
|
+
if (sourceText.trim()) {
|
|
88
|
+
let filterText = ((_b = item.filterText) !== null && _b !== void 0 ? _b : item.label).toLowerCase();
|
|
89
|
+
for (const char of sourceText) {
|
|
90
|
+
const index = filterText.indexOf(char);
|
|
91
|
+
if (index === -1) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
filterText = filterText.slice(index + 1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
76
100
|
}
|
|
77
101
|
return list;
|
|
78
102
|
}));
|
|
@@ -111,8 +135,8 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
111
135
|
}));
|
|
112
136
|
}));
|
|
113
137
|
connection.onCodeLensResolve((codeLens) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
var
|
|
115
|
-
return (
|
|
138
|
+
var _b;
|
|
139
|
+
return (_b = yield (lastCodeLensLs === null || lastCodeLensLs === void 0 ? void 0 : lastCodeLensLs.doCodeLensResolve(codeLens))) !== null && _b !== void 0 ? _b : codeLens;
|
|
116
140
|
}));
|
|
117
141
|
connection.onExecuteCommand((params) => __awaiter(this, void 0, void 0, function* () {
|
|
118
142
|
if (params.command === embedded.showReferencesCommand
|
|
@@ -129,9 +153,9 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
129
153
|
}));
|
|
130
154
|
connection.onCodeAction((params, token) => __awaiter(this, void 0, void 0, function* () {
|
|
131
155
|
return worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
var
|
|
156
|
+
var _c, _d, _e;
|
|
133
157
|
lastCodeActionLs = service;
|
|
134
|
-
let codeActions = (
|
|
158
|
+
let codeActions = (_c = yield service.doCodeActions(params.textDocument.uri, params.range, params.context)) !== null && _c !== void 0 ? _c : [];
|
|
135
159
|
for (const codeAction of codeActions) {
|
|
136
160
|
if (codeAction.data && typeof codeAction.data === 'object') {
|
|
137
161
|
codeAction.data.uri = params.textDocument.uri;
|
|
@@ -140,15 +164,15 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
140
164
|
codeAction.data = { uri: params.textDocument.uri };
|
|
141
165
|
}
|
|
142
166
|
}
|
|
143
|
-
if (!((
|
|
167
|
+
if (!((_e = (_d = initParams.capabilities.textDocument) === null || _d === void 0 ? void 0 : _d.codeAction) === null || _e === void 0 ? void 0 : _e.disabledSupport)) {
|
|
144
168
|
codeActions = codeActions.filter(codeAction => !codeAction.disabled);
|
|
145
169
|
}
|
|
146
170
|
return codeActions;
|
|
147
171
|
}));
|
|
148
172
|
}));
|
|
149
173
|
connection.onCodeActionResolve((codeAction) => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
var
|
|
151
|
-
return (
|
|
174
|
+
var _f;
|
|
175
|
+
return (_f = yield lastCodeActionLs.doCodeActionResolve(codeAction)) !== null && _f !== void 0 ? _f : codeAction;
|
|
152
176
|
}));
|
|
153
177
|
connection.onReferences((params, token) => __awaiter(this, void 0, void 0, function* () {
|
|
154
178
|
return worker(params.textDocument.uri, token, service => {
|
|
@@ -201,37 +225,37 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
201
225
|
return results;
|
|
202
226
|
}));
|
|
203
227
|
connection.languages.callHierarchy.onPrepare((params, token) => __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
var
|
|
205
|
-
return (
|
|
228
|
+
var _g;
|
|
229
|
+
return (_g = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
206
230
|
lastCallHierarchyLs = service;
|
|
207
231
|
return service.callHierarchy.doPrepare(params.textDocument.uri, params.position);
|
|
208
|
-
}))) !== null &&
|
|
232
|
+
}))) !== null && _g !== void 0 ? _g : [];
|
|
209
233
|
}));
|
|
210
234
|
connection.languages.callHierarchy.onIncomingCalls((params) => __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
var
|
|
212
|
-
return (
|
|
235
|
+
var _h;
|
|
236
|
+
return (_h = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getIncomingCalls(params.item))) !== null && _h !== void 0 ? _h : [];
|
|
213
237
|
}));
|
|
214
238
|
connection.languages.callHierarchy.onOutgoingCalls((params) => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
var
|
|
216
|
-
return (
|
|
239
|
+
var _j;
|
|
240
|
+
return (_j = yield (lastCallHierarchyLs === null || lastCallHierarchyLs === void 0 ? void 0 : lastCallHierarchyLs.callHierarchy.getOutgoingCalls(params.item))) !== null && _j !== void 0 ? _j : [];
|
|
217
241
|
}));
|
|
218
242
|
connection.languages.semanticTokens.on((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
var
|
|
243
|
+
var _k;
|
|
220
244
|
yield shared.sleep(200);
|
|
221
|
-
return (
|
|
222
|
-
var
|
|
223
|
-
const result = (
|
|
245
|
+
return (_k = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
var _l;
|
|
247
|
+
const result = (_l = yield (service === null || service === void 0 ? void 0 : service.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _l !== void 0 ? _l : [];
|
|
224
248
|
return buildTokens(result);
|
|
225
|
-
}))) !== null &&
|
|
249
|
+
}))) !== null && _k !== void 0 ? _k : buildTokens([]);
|
|
226
250
|
}));
|
|
227
251
|
connection.languages.semanticTokens.onRange((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
var
|
|
252
|
+
var _m;
|
|
229
253
|
yield shared.sleep(200);
|
|
230
|
-
return (
|
|
231
|
-
var
|
|
232
|
-
const result = (
|
|
254
|
+
return (_m = yield worker(params.textDocument.uri, token, (service) => __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
var _o;
|
|
256
|
+
const result = (_o = yield (service === null || service === void 0 ? void 0 : service.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _o !== void 0 ? _o : [];
|
|
233
257
|
return buildTokens(result);
|
|
234
|
-
}))) !== null &&
|
|
258
|
+
}))) !== null && _m !== void 0 ? _m : buildTokens([]);
|
|
235
259
|
}));
|
|
236
260
|
connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
|
|
237
261
|
const result = yield worker(params.textDocument.uri, token, service => {
|
|
@@ -265,11 +289,11 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
265
289
|
return null;
|
|
266
290
|
}
|
|
267
291
|
const _edits = yield Promise.all(params.files.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
var
|
|
269
|
-
return (
|
|
292
|
+
var _p;
|
|
293
|
+
return (_p = yield worker(file.oldUri, token, service => {
|
|
270
294
|
var _a;
|
|
271
295
|
return (_a = service.getEditsForFileRename(file.oldUri, file.newUri)) !== null && _a !== void 0 ? _a : null;
|
|
272
|
-
})) !== null &&
|
|
296
|
+
})) !== null && _p !== void 0 ? _p : null;
|
|
273
297
|
})));
|
|
274
298
|
const edits = _edits.filter(shared.notEmpty);
|
|
275
299
|
if (edits.length) {
|
package/out/common/project.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface ProjectContext {
|
|
|
14
14
|
}
|
|
15
15
|
export type Project = ReturnType<typeof createProject>;
|
|
16
16
|
export declare function createProject(context: ProjectContext): Promise<{
|
|
17
|
-
tsConfig:
|
|
17
|
+
tsConfig: path.PosixPath | ts.CompilerOptions;
|
|
18
18
|
scripts: {
|
|
19
19
|
clear: () => void;
|
|
20
20
|
values: () => IterableIterator<{
|
|
@@ -59,6 +59,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
59
59
|
};
|
|
60
60
|
languageServiceHost: embedded.LanguageServiceHost;
|
|
61
61
|
getLanguageService: () => {
|
|
62
|
+
triggerCharacters: string[];
|
|
62
63
|
format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
|
|
63
64
|
ch: string;
|
|
64
65
|
position: embeddedLS.Position;
|
|
@@ -66,7 +67,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
66
67
|
getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
|
|
67
68
|
getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
|
|
68
69
|
findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
|
|
69
|
-
findDocumentSymbols: (uri: string) => Promise<embeddedLS.
|
|
70
|
+
findDocumentSymbols: (uri: string) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
|
|
70
71
|
findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
|
|
71
72
|
getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
|
|
72
73
|
doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
|
|
@@ -89,7 +90,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
89
90
|
doCodeLensResolve: (item: embeddedLS.CodeLens) => Promise<embeddedLS.CodeLens>;
|
|
90
91
|
findDocumentHighlights: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
|
|
91
92
|
findDocumentLinks: (uri: string) => Promise<embeddedLS.DocumentLink[]>;
|
|
92
|
-
findWorkspaceSymbols: (query: string) => Promise<embeddedLS.
|
|
93
|
+
findWorkspaceSymbols: (query: string) => Promise<embeddedLS.WorkspaceSymbol[]>;
|
|
93
94
|
doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: {
|
|
94
95
|
lastChange: {
|
|
95
96
|
range: embeddedLS.Range;
|
|
@@ -108,6 +109,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
108
109
|
context: embeddedLS.LanguageServicePluginContext;
|
|
109
110
|
};
|
|
110
111
|
getLanguageServiceDontCreate: () => {
|
|
112
|
+
triggerCharacters: string[];
|
|
111
113
|
format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
|
|
112
114
|
ch: string;
|
|
113
115
|
position: embeddedLS.Position;
|
|
@@ -115,7 +117,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
115
117
|
getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
|
|
116
118
|
getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
|
|
117
119
|
findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
|
|
118
|
-
findDocumentSymbols: (uri: string) => Promise<embeddedLS.
|
|
120
|
+
findDocumentSymbols: (uri: string) => Promise<embeddedLS.DocumentSymbol[] | undefined>;
|
|
119
121
|
findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
|
|
120
122
|
getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
|
|
121
123
|
doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
|
|
@@ -138,7 +140,7 @@ export declare function createProject(context: ProjectContext): Promise<{
|
|
|
138
140
|
doCodeLensResolve: (item: embeddedLS.CodeLens) => Promise<embeddedLS.CodeLens>;
|
|
139
141
|
findDocumentHighlights: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.DocumentHighlight[] | undefined>;
|
|
140
142
|
findDocumentLinks: (uri: string) => Promise<embeddedLS.DocumentLink[]>;
|
|
141
|
-
findWorkspaceSymbols: (query: string) => Promise<embeddedLS.
|
|
143
|
+
findWorkspaceSymbols: (query: string) => Promise<embeddedLS.WorkspaceSymbol[]>;
|
|
142
144
|
doAutoInsert: (uri: string, position: embeddedLS.Position, autoInsertContext: {
|
|
143
145
|
lastChange: {
|
|
144
146
|
range: embeddedLS.Range;
|
package/out/common/project.js
CHANGED
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createProject = void 0;
|
|
12
12
|
const embeddedLS = require("@volar/language-service");
|
|
13
|
-
const shared = require("@volar/shared");
|
|
14
13
|
const path = require("typesafe-path");
|
|
15
14
|
const vscode = require("vscode-languageserver");
|
|
16
15
|
const vscode_uri_1 = require("vscode-uri");
|
|
@@ -19,6 +18,8 @@ const uriMap_1 = require("./utils/uriMap");
|
|
|
19
18
|
function createProject(context) {
|
|
20
19
|
var _a;
|
|
21
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
|
|
22
|
+
const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
|
|
22
23
|
const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
|
|
23
24
|
? {
|
|
24
25
|
newLine: '\n',
|
|
@@ -35,8 +36,8 @@ function createProject(context) {
|
|
|
35
36
|
let projectVersion = 0;
|
|
36
37
|
let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
37
38
|
let languageService;
|
|
38
|
-
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys,
|
|
39
|
-
const scripts = (0, uriMap_1.createUriMap)();
|
|
39
|
+
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
40
|
+
const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
|
|
40
41
|
const languageServiceHost = createLanguageServiceHost();
|
|
41
42
|
const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
|
|
42
43
|
onWorkspaceFilesChanged(params.changes);
|
|
@@ -69,31 +70,36 @@ function createProject(context) {
|
|
|
69
70
|
plugins: Object.assign({}, (_b = context.serverConfig) === null || _b === void 0 ? void 0 : _b.plugins),
|
|
70
71
|
lint: Object.assign(Object.assign({}, (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.lint), { rules: Object.assign({}, (_e = (_d = context.serverConfig) === null || _d === void 0 ? void 0 : _d.lint) === null || _e === void 0 ? void 0 : _e.rules) }),
|
|
71
72
|
};
|
|
72
|
-
const
|
|
73
|
+
const options = {
|
|
74
|
+
uriToFileName,
|
|
75
|
+
fileNameToUri,
|
|
73
76
|
rootUri: context.rootUri,
|
|
77
|
+
host: languageServiceHost,
|
|
78
|
+
config,
|
|
74
79
|
locale: context.workspace.workspaces.initParams.locale,
|
|
75
80
|
configurationHost: context.workspace.workspaces.configurationHost,
|
|
76
81
|
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
77
|
-
documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
|
|
82
|
+
documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
|
|
78
83
|
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
var _g;
|
|
79
85
|
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
80
86
|
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
81
87
|
if (builtInHandler) {
|
|
82
|
-
return yield builtInHandler(uri);
|
|
88
|
+
return (_g = yield builtInHandler(uri)) !== null && _g !== void 0 ? _g : '';
|
|
83
89
|
}
|
|
84
90
|
return '';
|
|
85
91
|
}),
|
|
86
92
|
};
|
|
87
93
|
const lsCtx = {
|
|
88
94
|
project: context,
|
|
89
|
-
|
|
95
|
+
options,
|
|
90
96
|
sys,
|
|
91
97
|
host: languageServiceHost,
|
|
92
98
|
};
|
|
93
99
|
for (const plugin of context.workspace.workspaces.plugins) {
|
|
94
100
|
(_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
|
|
95
101
|
}
|
|
96
|
-
languageService = embeddedLS.createLanguageService(
|
|
102
|
+
languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
|
|
97
103
|
}
|
|
98
104
|
return languageService;
|
|
99
105
|
}
|
|
@@ -113,14 +119,16 @@ function createProject(context) {
|
|
|
113
119
|
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
114
120
|
scripts.uriDelete(change.uri);
|
|
115
121
|
}
|
|
116
|
-
if (script
|
|
122
|
+
if (script
|
|
123
|
+
|| change.uri.endsWith('.d.ts')
|
|
124
|
+
|| change.uri.endsWith('/package.json')) {
|
|
117
125
|
projectVersion++;
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
121
129
|
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
122
130
|
if (creates.length || deletes.length) {
|
|
123
|
-
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys,
|
|
131
|
+
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
124
132
|
projectVersion++;
|
|
125
133
|
typeRootVersion++;
|
|
126
134
|
}
|
|
@@ -147,7 +155,7 @@ function createProject(context) {
|
|
|
147
155
|
readDirectory: sys.readDirectory,
|
|
148
156
|
realpath: sys.realpath,
|
|
149
157
|
fileExists: sys.fileExists,
|
|
150
|
-
getCurrentDirectory: () =>
|
|
158
|
+
getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
|
|
151
159
|
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
152
160
|
getCancellationToken: () => token,
|
|
153
161
|
// custom
|
|
@@ -158,7 +166,8 @@ function createProject(context) {
|
|
|
158
166
|
}
|
|
159
167
|
catch (_a) {
|
|
160
168
|
// web
|
|
161
|
-
|
|
169
|
+
const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
|
|
170
|
+
return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
173
|
return '';
|
|
@@ -256,7 +265,7 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
256
265
|
// https://github.com/microsoft/TypeScript/issues/30457
|
|
257
266
|
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
258
267
|
content.options.outDir = undefined;
|
|
259
|
-
content.fileNames = content.fileNames.map(
|
|
268
|
+
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
|
260
269
|
return content;
|
|
261
270
|
}
|
|
262
271
|
catch (_a) {
|
|
@@ -269,13 +278,13 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
|
269
278
|
options: {},
|
|
270
279
|
};
|
|
271
280
|
}
|
|
272
|
-
function getDocumentContext(ts, host, rootUri) {
|
|
281
|
+
function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
|
|
273
282
|
const documentContext = {
|
|
274
283
|
resolveReference: (ref, base) => {
|
|
275
284
|
var _a, _b;
|
|
276
285
|
if (ts && host) { // support tsconfig.json paths
|
|
277
286
|
const isUri = base.indexOf('://') >= 0;
|
|
278
|
-
const resolveResult = ts.resolveModuleName(ref, isUri ?
|
|
287
|
+
const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
|
|
279
288
|
const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
|
|
280
289
|
const dirs = new Set();
|
|
281
290
|
if (!failedLookupLocations) {
|
|
@@ -293,12 +302,12 @@ function getDocumentContext(ts, host, rootUri) {
|
|
|
293
302
|
continue;
|
|
294
303
|
}
|
|
295
304
|
if (host.fileExists(failed)) {
|
|
296
|
-
return isUri ?
|
|
305
|
+
return isUri ? fileNameToUri(failed) : failed;
|
|
297
306
|
}
|
|
298
307
|
}
|
|
299
308
|
for (const dir of dirs) {
|
|
300
309
|
if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
|
|
301
|
-
return isUri ?
|
|
310
|
+
return isUri ? fileNameToUri(dir) : dir;
|
|
302
311
|
}
|
|
303
312
|
}
|
|
304
313
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function handler(uri: string): Promise<string>;
|
|
1
|
+
export default function handler(uri: string): Promise<string | undefined>;
|
|
@@ -3,6 +3,9 @@ const request_light_1 = require("request-light");
|
|
|
3
3
|
function handler(uri) {
|
|
4
4
|
const headers = { 'Accept-Encoding': 'gzip, deflate' };
|
|
5
5
|
return (0, request_light_1.xhr)({ url: uri, followRedirects: 5, headers }).then(response => {
|
|
6
|
+
if (response.status !== 200) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
6
9
|
return response.responseText;
|
|
7
10
|
}, (error) => {
|
|
8
11
|
return Promise.reject(error.responseText || (0, request_light_1.getErrorStatusDescription)(error.status) || error.toString());
|
package/out/common/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver';
|
|
2
|
-
import { LanguageServerPlugin, RuntimeEnvironment } from '../types';
|
|
2
|
+
import { LanguageServerInitializationOptions, LanguageServerPlugin, RuntimeEnvironment } from '../types';
|
|
3
3
|
export interface ServerContext {
|
|
4
4
|
connection: vscode.Connection;
|
|
5
5
|
runtimeEnv: RuntimeEnvironment;
|
|
6
6
|
plugins: LanguageServerPlugin[];
|
|
7
7
|
}
|
|
8
|
-
export declare function startCommonLanguageServer(
|
|
8
|
+
export declare function startCommonLanguageServer(connection: vscode.Connection, getCtx: (initOptions: LanguageServerInitializationOptions) => ServerContext): void;
|
package/out/common/server.js
CHANGED
|
@@ -18,7 +18,7 @@ const documents_1 = require("./documents");
|
|
|
18
18
|
const registerFeatures_1 = require("./utils/registerFeatures");
|
|
19
19
|
const workspaces_1 = require("./workspaces");
|
|
20
20
|
const l10n = require("@vscode/l10n");
|
|
21
|
-
function startCommonLanguageServer(
|
|
21
|
+
function startCommonLanguageServer(connection, getCtx) {
|
|
22
22
|
let initParams;
|
|
23
23
|
let options;
|
|
24
24
|
let roots = [];
|
|
@@ -26,12 +26,15 @@ function startCommonLanguageServer(context) {
|
|
|
26
26
|
let projects;
|
|
27
27
|
let configurationHost;
|
|
28
28
|
let plugins;
|
|
29
|
-
|
|
30
|
-
context
|
|
29
|
+
let documents;
|
|
30
|
+
let context;
|
|
31
|
+
connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
|
|
31
32
|
var _a, _b, _c, _d;
|
|
32
33
|
initParams = _params;
|
|
33
34
|
options = initParams.initializationOptions;
|
|
35
|
+
context = getCtx(options);
|
|
34
36
|
plugins = context.plugins.map(plugin => plugin(options));
|
|
37
|
+
documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
|
|
35
38
|
if (options.l10n) {
|
|
36
39
|
yield l10n.config({ uri: options.l10n.location });
|
|
37
40
|
}
|
|
@@ -49,7 +52,7 @@ function startCommonLanguageServer(context) {
|
|
|
49
52
|
textDocumentSync: (_b = options.textDocumentSync) !== null && _b !== void 0 ? _b : vscode.TextDocumentSyncKind.Incremental,
|
|
50
53
|
},
|
|
51
54
|
};
|
|
52
|
-
configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams,
|
|
55
|
+
configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
|
|
53
56
|
(0, registerFeatures_1.setupCapabilities)(initParams.capabilities, result.capabilities, options, plugins, getSemanticTokensLegend());
|
|
54
57
|
yield createLanguageServiceHost();
|
|
55
58
|
try {
|
|
@@ -62,16 +65,16 @@ function startCommonLanguageServer(context) {
|
|
|
62
65
|
}
|
|
63
66
|
catch (_e) { }
|
|
64
67
|
for (const plugin of plugins) {
|
|
65
|
-
(_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result);
|
|
68
|
+
(_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result, context.runtimeEnv);
|
|
66
69
|
}
|
|
67
70
|
return result;
|
|
68
71
|
}));
|
|
69
|
-
|
|
72
|
+
connection.onInitialized(() => {
|
|
70
73
|
var _a, _b, _c;
|
|
71
|
-
fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(
|
|
74
|
+
fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
|
|
72
75
|
configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.ready();
|
|
73
76
|
if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
|
|
74
|
-
|
|
77
|
+
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
75
78
|
for (const folder of e.added) {
|
|
76
79
|
projects === null || projects === void 0 ? void 0 : projects.add(vscode_uri_1.URI.parse(folder.uri));
|
|
77
80
|
}
|
|
@@ -85,7 +88,7 @@ function startCommonLanguageServer(context) {
|
|
|
85
88
|
&& ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
|
|
86
89
|
const exts = plugins.map(plugin => { var _a; return (_a = plugin.extensions.fileWatcher) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
87
90
|
if (exts.length) {
|
|
88
|
-
|
|
91
|
+
connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
|
89
92
|
watchers: [
|
|
90
93
|
{
|
|
91
94
|
globPattern: `**/*.{${exts.join(',')}}`
|
|
@@ -95,19 +98,19 @@ function startCommonLanguageServer(context) {
|
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
});
|
|
98
|
-
|
|
101
|
+
connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
|
|
99
102
|
if (projects) {
|
|
100
103
|
for (const workspace of projects.workspaces) {
|
|
101
104
|
(yield workspace[1]).dispose();
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
}));
|
|
105
|
-
|
|
108
|
+
connection.listen();
|
|
106
109
|
function createLanguageServiceHost() {
|
|
107
110
|
var _a;
|
|
108
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
112
|
const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
|
|
110
|
-
fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities) : undefined;
|
|
113
|
+
fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
|
|
111
114
|
const tsLocalized = options.typescript && initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
|
|
112
115
|
const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
|
|
113
116
|
const _projects = (0, workspaces_1.createWorkspaces)({
|
|
@@ -126,10 +129,10 @@ function startCommonLanguageServer(context) {
|
|
|
126
129
|
for (const root of roots) {
|
|
127
130
|
projects.add(root);
|
|
128
131
|
}
|
|
129
|
-
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(
|
|
130
|
-
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(
|
|
132
|
+
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
|
|
133
|
+
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
|
|
131
134
|
for (const plugin of plugins) {
|
|
132
|
-
(_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService);
|
|
135
|
+
(_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService, context.runtimeEnv);
|
|
133
136
|
}
|
|
134
137
|
function getLanguageService(uri) {
|
|
135
138
|
var _a;
|
|
@@ -7,7 +7,7 @@ interface Options<T> {
|
|
|
7
7
|
clear(): void;
|
|
8
8
|
values(): IterableIterator<T>;
|
|
9
9
|
}
|
|
10
|
-
export declare function createUriMap<T>(map?: Options<T>): {
|
|
10
|
+
export declare function createUriMap<T>(fileNameToUri: (fileName: string) => string, map?: Options<T>): {
|
|
11
11
|
clear: () => void;
|
|
12
12
|
values: () => IterableIterator<T>;
|
|
13
13
|
uriDelete: (_uri: string) => boolean;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
2
|
exports.createUriMap = exports._ = void 0;
|
|
3
3
|
const vscode_uri_1 = require("vscode-uri");
|
|
4
|
-
const shared = require("@volar/shared");
|
|
5
4
|
exports._ = require("vscode-uri");
|
|
6
|
-
function createUriMap(map = new Map()) {
|
|
5
|
+
function createUriMap(fileNameToUri, map = new Map()) {
|
|
7
6
|
const uriToUri = new Map();
|
|
8
7
|
const pathToUri = new Map();
|
|
9
8
|
return {
|
|
@@ -25,7 +24,7 @@ function createUriMap(map = new Map()) {
|
|
|
25
24
|
}
|
|
26
25
|
function getUriByPath(path) {
|
|
27
26
|
if (!pathToUri.has(path)) {
|
|
28
|
-
pathToUri.set(path,
|
|
27
|
+
pathToUri.set(path, fileNameToUri(path).toLowerCase());
|
|
29
28
|
}
|
|
30
29
|
return pathToUri.get(path);
|
|
31
30
|
}
|