@volar/language-server 1.0.18 → 1.0.20
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/index.d.ts +3 -1
- package/out/browser/index.js +8 -4
- package/out/common/features/customFeatures.js +16 -16
- package/out/common/features/languageFeatures.js +45 -0
- package/out/common/project.d.ts +32 -12
- package/out/common/project.js +96 -77
- package/out/common/server.d.ts +2 -2
- package/out/common/server.js +25 -49
- package/out/common/utils/inferredCompilerOptions.d.ts +1 -1
- package/out/common/utils/inferredCompilerOptions.js +5 -5
- package/out/common/utils/registerFeatures.d.ts +1 -2
- package/out/common/utils/registerFeatures.js +68 -51
- package/out/common/utils/serverConfig.d.ts +4 -1
- package/out/common/utils/serverConfig.js +5 -7
- package/out/common/workspace.d.ts +231 -51
- package/out/common/workspace.js +31 -34
- package/out/common/workspaces.d.ts +285 -64
- package/out/common/workspaces.js +66 -62
- package/out/node/index.d.ts +3 -1
- package/out/node/index.js +8 -5
- package/out/types.d.ts +7 -13
- package/package.json +5 -5
- package/out/common/features/documentFeatures.d.ts +0 -4
- package/out/common/features/documentFeatures.js +0 -73
- package/out/common/syntaxServicesHost.d.ts +0 -29
- package/out/common/syntaxServicesHost.js +0 -51
package/out/browser/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as vscode from 'vscode-languageserver/browser';
|
|
1
2
|
import { LanguageServerPlugin } from '../types';
|
|
2
3
|
export * from '../index';
|
|
3
|
-
export declare function
|
|
4
|
+
export declare function createConnection(): vscode.Connection;
|
|
5
|
+
export declare function startLanguageServer(connection: vscode.Connection, ...plugins: LanguageServerPlugin[]): void;
|
package/out/browser/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.startLanguageServer = exports.createConnection = void 0;
|
|
26
26
|
const request_light_1 = require("request-light");
|
|
27
27
|
const ts = require("typescript/lib/tsserverlibrary"); // bundle typescript lib in web
|
|
28
28
|
const vscode = require("vscode-languageserver/browser");
|
|
@@ -31,11 +31,15 @@ const http_1 = require("../common/schemaRequestHandlers/http");
|
|
|
31
31
|
const fileSystems_1 = require("./fileSystems");
|
|
32
32
|
const shared = require("@volar/shared");
|
|
33
33
|
__exportStar(require("../index"), exports);
|
|
34
|
-
function
|
|
34
|
+
function createConnection() {
|
|
35
35
|
const messageReader = new vscode.BrowserMessageReader(self);
|
|
36
36
|
const messageWriter = new vscode.BrowserMessageWriter(self);
|
|
37
37
|
const connection = vscode.createConnection(messageReader, messageWriter);
|
|
38
|
-
|
|
38
|
+
return connection;
|
|
39
|
+
}
|
|
40
|
+
exports.createConnection = createConnection;
|
|
41
|
+
function startLanguageServer(connection, ...plugins) {
|
|
42
|
+
(0, server_1.startCommonLanguageServer)({
|
|
39
43
|
plugins,
|
|
40
44
|
connection,
|
|
41
45
|
runtimeEnv: {
|
|
@@ -64,5 +68,5 @@ function createLanguageServer(plugins) {
|
|
|
64
68
|
},
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
|
-
exports.
|
|
71
|
+
exports.startLanguageServer = startLanguageServer;
|
|
68
72
|
//# sourceMappingURL=index.js.map
|
|
@@ -14,11 +14,11 @@ const protocol_1 = require("../../protocol");
|
|
|
14
14
|
const language_core_1 = require("@volar/language-core");
|
|
15
15
|
function register(connection, projects) {
|
|
16
16
|
connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
18
18
|
for (const [rootUri, _workspace] of projects.workspaces) {
|
|
19
19
|
connection.console.log('workspace: ' + rootUri);
|
|
20
20
|
const workspace = yield _workspace;
|
|
21
|
-
connection.console.log('documentRegistry stats: ' + workspace.documentRegistry.reportStats());
|
|
21
|
+
connection.console.log('documentRegistry stats: ' + ((_a = workspace.documentRegistry) === null || _a === void 0 ? void 0 : _a.reportStats()));
|
|
22
22
|
connection.console.log('');
|
|
23
23
|
connection.console.log('tsconfig: inferred');
|
|
24
24
|
const _inferredProject = workspace.getInferredProjectDontCreate();
|
|
@@ -30,13 +30,13 @@ function register(connection, projects) {
|
|
|
30
30
|
.sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
|
|
31
31
|
.slice(0, 10)) {
|
|
32
32
|
connection.console.log(' - ' + script.fileName);
|
|
33
|
-
connection.console.log(` size: ${(
|
|
33
|
+
connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
|
|
34
34
|
}
|
|
35
35
|
connection.console.log('files:');
|
|
36
36
|
for (const script of inferredProject.scripts.values()) {
|
|
37
37
|
connection.console.log(' - ' + script.fileName);
|
|
38
|
-
connection.console.log(` size: ${(
|
|
39
|
-
connection.console.log(` ref counts: "${(
|
|
38
|
+
connection.console.log(` size: ${(_c = script.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()}`);
|
|
39
|
+
connection.console.log(` ref counts: "${(_e = (_d = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _e === void 0 ? void 0 : _e.call(_d, script.fileName, (_g = (_f = inferredProject.languageServiceHost).getScriptKind) === null || _g === void 0 ? void 0 : _g.call(_f, script.fileName))})"`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
@@ -52,13 +52,13 @@ function register(connection, projects) {
|
|
|
52
52
|
.sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
|
|
53
53
|
.slice(0, 10)) {
|
|
54
54
|
connection.console.log(' - ' + script.fileName);
|
|
55
|
-
connection.console.log(` size: ${(
|
|
55
|
+
connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
|
|
56
56
|
}
|
|
57
57
|
connection.console.log('files:');
|
|
58
58
|
for (const script of project.scripts.values()) {
|
|
59
59
|
connection.console.log(' - ' + script.fileName);
|
|
60
|
-
connection.console.log(` size: ${(
|
|
61
|
-
connection.console.log(` ref counts: "${(
|
|
60
|
+
connection.console.log(` size: ${(_j = script.snapshot) === null || _j === void 0 ? void 0 : _j.getLength()}`);
|
|
61
|
+
connection.console.log(` ref counts: "${(_l = (_k = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _l === void 0 ? void 0 : _l.call(_k, script.fileName, (_o = (_m = project.languageServiceHost).getScriptKind) === null || _o === void 0 ? void 0 : _o.call(_m, script.fileName))})"`);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
connection.console.log('');
|
|
@@ -71,11 +71,11 @@ function register(connection, projects) {
|
|
|
71
71
|
}
|
|
72
72
|
}));
|
|
73
73
|
connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
var
|
|
74
|
+
var _p, _q;
|
|
75
75
|
const project = yield projects.getProject(document.uri);
|
|
76
76
|
const fileNames = [];
|
|
77
77
|
if (project) {
|
|
78
|
-
const sourceFile = (
|
|
78
|
+
const sourceFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.get(shared.getPathOfUri(document.uri))) === null || _q === void 0 ? void 0 : _q[1];
|
|
79
79
|
if (sourceFile) {
|
|
80
80
|
(0, language_core_1.forEachEmbeddedFile)(sourceFile, e => {
|
|
81
81
|
if (e.snapshot.getLength() && e.kind === 1) {
|
|
@@ -87,16 +87,16 @@ 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 _r, _s, _t;
|
|
91
91
|
const project = yield projects.getProject(params.sourceFileUri);
|
|
92
92
|
if (project) {
|
|
93
|
-
const sourceAndVirtual = (
|
|
93
|
+
const sourceAndVirtual = (_r = project.project) === null || _r === void 0 ? void 0 : _r.getLanguageService().context.core.virtualFiles.getSourceByVirtualFileName(params.virtualFileName);
|
|
94
94
|
if (sourceAndVirtual) {
|
|
95
95
|
const virtualFile = sourceAndVirtual[2];
|
|
96
96
|
const mappings = {};
|
|
97
97
|
for (const mapping of virtualFile.mappings) {
|
|
98
|
-
const sourceUri = shared.getUriByPath((
|
|
99
|
-
(
|
|
98
|
+
const sourceUri = shared.getUriByPath((_s = mapping.source) !== null && _s !== void 0 ? _s : sourceAndVirtual[0]);
|
|
99
|
+
(_t = mappings[sourceUri]) !== null && _t !== void 0 ? _t : (mappings[sourceUri] = []);
|
|
100
100
|
mappings[sourceUri].push(mapping);
|
|
101
101
|
}
|
|
102
102
|
return {
|
|
@@ -110,11 +110,11 @@ function register(connection, projects) {
|
|
|
110
110
|
projects.reloadProject();
|
|
111
111
|
});
|
|
112
112
|
connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
var
|
|
113
|
+
var _u;
|
|
114
114
|
const fs = yield Promise.resolve().then(() => require('fs'));
|
|
115
115
|
const project = yield projects.getProject(params.uri);
|
|
116
116
|
if (project) {
|
|
117
|
-
const ls = (
|
|
117
|
+
const ls = (_u = (yield project.project)) === null || _u === void 0 ? void 0 : _u.getLanguageServiceDontCreate();
|
|
118
118
|
if (ls) {
|
|
119
119
|
const sourceFiles = new Set(ls.context.host.getScriptFileNames());
|
|
120
120
|
for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
|
|
@@ -19,6 +19,51 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
|
|
|
19
19
|
let lastCodeLensLs;
|
|
20
20
|
let lastCodeActionLs;
|
|
21
21
|
let lastCallHierarchyLs;
|
|
22
|
+
connection.onDocumentFormatting((params) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
24
|
+
return vueLs.format(params.textDocument.uri, params.options);
|
|
25
|
+
});
|
|
26
|
+
}));
|
|
27
|
+
connection.onDocumentRangeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
29
|
+
return vueLs.format(params.textDocument.uri, params.options, params.range);
|
|
30
|
+
});
|
|
31
|
+
}));
|
|
32
|
+
connection.onDocumentOnTypeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
34
|
+
return vueLs.format(params.textDocument.uri, params.options, undefined, params);
|
|
35
|
+
});
|
|
36
|
+
}));
|
|
37
|
+
connection.onSelectionRanges((params) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
39
|
+
return vueLs.getSelectionRanges(params.textDocument.uri, params.positions);
|
|
40
|
+
});
|
|
41
|
+
}));
|
|
42
|
+
connection.onFoldingRanges((params) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
44
|
+
return vueLs.getFoldingRanges(params.textDocument.uri);
|
|
45
|
+
});
|
|
46
|
+
}));
|
|
47
|
+
connection.languages.onLinkedEditingRange((params) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
49
|
+
return vueLs.findLinkedEditingRanges(params.textDocument.uri, params.position);
|
|
50
|
+
});
|
|
51
|
+
}));
|
|
52
|
+
connection.onDocumentSymbol((params) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
54
|
+
return vueLs.findDocumentSymbols(params.textDocument.uri);
|
|
55
|
+
});
|
|
56
|
+
}));
|
|
57
|
+
connection.onDocumentColor((params) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
59
|
+
return vueLs.findDocumentColors(params.textDocument.uri);
|
|
60
|
+
});
|
|
61
|
+
}));
|
|
62
|
+
connection.onColorPresentation((params) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return worker(params.textDocument.uri, vueLs => {
|
|
64
|
+
return vueLs.getColorPresentations(params.textDocument.uri, params.color, params.range);
|
|
65
|
+
});
|
|
66
|
+
}));
|
|
22
67
|
connection.onCompletion((params) => __awaiter(this, void 0, void 0, function* () {
|
|
23
68
|
return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
|
|
24
69
|
lastCompleteUri = params.textDocument.uri;
|
package/out/common/project.d.ts
CHANGED
|
@@ -3,18 +3,18 @@ import * as embeddedLS from '@volar/language-service';
|
|
|
3
3
|
import * as path from 'typesafe-path';
|
|
4
4
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
5
|
import { URI } from 'vscode-uri';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
export interface
|
|
9
|
-
workspace:
|
|
6
|
+
import { WorkspaceContext } from './workspace';
|
|
7
|
+
import { ServerConfig } from './utils/serverConfig';
|
|
8
|
+
export interface ProjectContext {
|
|
9
|
+
workspace: WorkspaceContext;
|
|
10
10
|
rootUri: URI;
|
|
11
11
|
tsConfig: path.PosixPath | ts.CompilerOptions;
|
|
12
|
-
documentRegistry: ts.DocumentRegistry;
|
|
13
|
-
|
|
12
|
+
documentRegistry: ts.DocumentRegistry | undefined;
|
|
13
|
+
serverConfig: ServerConfig | undefined;
|
|
14
14
|
}
|
|
15
15
|
export type Project = ReturnType<typeof createProject>;
|
|
16
|
-
export declare function createProject(
|
|
17
|
-
tsConfig:
|
|
16
|
+
export declare function createProject(context: ProjectContext): Promise<{
|
|
17
|
+
tsConfig: ts.CompilerOptions | path.PosixPath;
|
|
18
18
|
scripts: {
|
|
19
19
|
clear: () => void;
|
|
20
20
|
values: () => IterableIterator<{
|
|
@@ -59,6 +59,16 @@ export declare function createProject(params: ProjectParams): Promise<{
|
|
|
59
59
|
};
|
|
60
60
|
languageServiceHost: embedded.LanguageServiceHost;
|
|
61
61
|
getLanguageService: () => {
|
|
62
|
+
format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
|
|
63
|
+
ch: string;
|
|
64
|
+
position: embeddedLS.Position;
|
|
65
|
+
} | undefined) => Promise<embeddedLS.TextEdit[] | undefined>;
|
|
66
|
+
getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
|
|
67
|
+
getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
|
|
68
|
+
findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
|
|
69
|
+
findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
|
|
70
|
+
findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
|
|
71
|
+
getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
|
|
62
72
|
doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
|
|
63
73
|
findReferences: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.Location[] | undefined>;
|
|
64
74
|
findFileReferences: (uri: string) => embeddedLS.NullableResult<embeddedLS.Location[]>;
|
|
@@ -95,10 +105,20 @@ export declare function createProject(params: ProjectParams): Promise<{
|
|
|
95
105
|
getIncomingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
|
|
96
106
|
getOutgoingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyOutgoingCall[]>;
|
|
97
107
|
};
|
|
98
|
-
dispose: () => void;
|
|
99
|
-
context: embeddedLS.LanguageServiceRuntimeContext
|
|
108
|
+
dispose: () => void | undefined;
|
|
109
|
+
context: embeddedLS.LanguageServiceRuntimeContext<embedded.LanguageServiceHost>;
|
|
100
110
|
};
|
|
101
111
|
getLanguageServiceDontCreate: () => {
|
|
112
|
+
format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
|
|
113
|
+
ch: string;
|
|
114
|
+
position: embeddedLS.Position;
|
|
115
|
+
} | undefined) => Promise<embeddedLS.TextEdit[] | undefined>;
|
|
116
|
+
getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
|
|
117
|
+
getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
|
|
118
|
+
findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
|
|
119
|
+
findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
|
|
120
|
+
findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
|
|
121
|
+
getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
|
|
102
122
|
doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
|
|
103
123
|
findReferences: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.Location[] | undefined>;
|
|
104
124
|
findFileReferences: (uri: string) => embeddedLS.NullableResult<embeddedLS.Location[]>;
|
|
@@ -135,8 +155,8 @@ export declare function createProject(params: ProjectParams): Promise<{
|
|
|
135
155
|
getIncomingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
|
|
136
156
|
getOutgoingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyOutgoingCall[]>;
|
|
137
157
|
};
|
|
138
|
-
dispose: () => void;
|
|
139
|
-
context: embeddedLS.LanguageServiceRuntimeContext
|
|
158
|
+
dispose: () => void | undefined;
|
|
159
|
+
context: embeddedLS.LanguageServiceRuntimeContext<embedded.LanguageServiceHost>;
|
|
140
160
|
} | undefined;
|
|
141
161
|
getParsedCommandLine: () => ts.ParsedCommandLine;
|
|
142
162
|
tryAddFile: (fileName: string) => void;
|
package/out/common/project.js
CHANGED
|
@@ -14,76 +14,89 @@ const embeddedLS = require("@volar/language-service");
|
|
|
14
14
|
const shared = require("@volar/shared");
|
|
15
15
|
const path = require("typesafe-path");
|
|
16
16
|
const vscode = require("vscode-languageserver");
|
|
17
|
+
const types_1 = require("../types");
|
|
17
18
|
const uriMap_1 = require("./utils/uriMap");
|
|
18
|
-
function createProject(
|
|
19
|
+
function createProject(context) {
|
|
20
|
+
var _a;
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
|
|
23
|
+
? {
|
|
24
|
+
newLine: '\n',
|
|
25
|
+
useCaseSensitiveFileNames: false,
|
|
26
|
+
fileExists: () => false,
|
|
27
|
+
readFile: () => undefined,
|
|
28
|
+
readDirectory: () => [],
|
|
29
|
+
getCurrentDirectory: () => '',
|
|
30
|
+
realpath: () => '',
|
|
31
|
+
resolvePath: () => '',
|
|
32
|
+
}
|
|
33
|
+
: context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
|
|
25
34
|
let typeRootVersion = 0;
|
|
26
35
|
let projectVersion = 0;
|
|
27
|
-
let projectVersionUpdateTime = cancelTokenHost.getMtime();
|
|
28
|
-
let
|
|
29
|
-
let parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
|
|
36
|
+
let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
37
|
+
let languageService;
|
|
38
|
+
let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.getPathOfUri(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
30
39
|
const scripts = (0, uriMap_1.createUriMap)();
|
|
31
40
|
const languageServiceHost = createLanguageServiceHost();
|
|
32
|
-
const disposeWatchEvent = fileSystemHost.onDidChangeWatchedFiles(params => {
|
|
41
|
+
const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
|
|
33
42
|
onWorkspaceFilesChanged(params.changes);
|
|
34
43
|
});
|
|
35
|
-
const disposeDocChange = documents.onDidChangeContent(() => {
|
|
44
|
+
const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
|
|
36
45
|
projectVersion++;
|
|
37
|
-
projectVersionUpdateTime = cancelTokenHost.getMtime();
|
|
46
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
38
47
|
});
|
|
39
48
|
return {
|
|
40
|
-
tsConfig,
|
|
49
|
+
tsConfig: context.tsConfig,
|
|
41
50
|
scripts,
|
|
42
51
|
languageServiceHost,
|
|
43
52
|
getLanguageService,
|
|
44
|
-
getLanguageServiceDontCreate: () =>
|
|
53
|
+
getLanguageServiceDontCreate: () => languageService,
|
|
45
54
|
getParsedCommandLine: () => parsedCommandLine,
|
|
46
55
|
tryAddFile: (fileName) => {
|
|
47
56
|
if (!parsedCommandLine.fileNames.includes(fileName)) {
|
|
48
57
|
parsedCommandLine.fileNames.push(fileName);
|
|
49
58
|
projectVersion++;
|
|
50
|
-
projectVersionUpdateTime = cancelTokenHost.getMtime();
|
|
59
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
51
60
|
}
|
|
52
61
|
},
|
|
53
62
|
dispose,
|
|
54
63
|
};
|
|
55
64
|
function getLanguageService() {
|
|
56
|
-
if (!
|
|
57
|
-
const languageModules = plugins.map(plugin => { var _a, _b
|
|
65
|
+
if (!languageService) {
|
|
66
|
+
const languageModules = context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageModules) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost)) !== null && _b !== void 0 ? _b : []; }).flat();
|
|
58
67
|
const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
|
|
59
68
|
const languageServiceContext = embeddedLS.createLanguageServiceContext({
|
|
60
69
|
host: languageServiceHost,
|
|
61
70
|
context: languageContext,
|
|
62
71
|
getPlugins() {
|
|
72
|
+
var _a, _b;
|
|
63
73
|
return [
|
|
64
|
-
...
|
|
65
|
-
...plugins.map(plugin => { var _a, _b
|
|
74
|
+
...(_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [],
|
|
75
|
+
...context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageServicePlugins) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost, languageServiceContext)) !== null && _b !== void 0 ? _b : []; }).flat(),
|
|
66
76
|
];
|
|
67
77
|
},
|
|
68
78
|
env: {
|
|
69
|
-
rootUri,
|
|
70
|
-
configurationHost: configurationHost,
|
|
71
|
-
fileSystemProvider: runtimeEnv.fileSystemProvide,
|
|
72
|
-
documentContext:
|
|
79
|
+
rootUri: context.rootUri,
|
|
80
|
+
configurationHost: context.workspace.workspaces.configurationHost,
|
|
81
|
+
fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
|
|
82
|
+
documentContext: context.workspace.workspaces.ts
|
|
83
|
+
? getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost)
|
|
84
|
+
: undefined,
|
|
73
85
|
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
74
86
|
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
75
|
-
const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
|
|
87
|
+
const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
|
|
76
88
|
if (builtInHandler) {
|
|
77
89
|
return yield builtInHandler(uri);
|
|
78
90
|
}
|
|
79
91
|
return '';
|
|
80
92
|
}),
|
|
81
93
|
},
|
|
82
|
-
documentRegistry,
|
|
94
|
+
documentRegistry: context.documentRegistry,
|
|
95
|
+
getLanguageService: () => languageService,
|
|
83
96
|
});
|
|
84
|
-
|
|
97
|
+
languageService = embeddedLS.createLanguageService(languageServiceContext);
|
|
85
98
|
}
|
|
86
|
-
return
|
|
99
|
+
return languageService;
|
|
87
100
|
}
|
|
88
101
|
function onWorkspaceFilesChanged(changes) {
|
|
89
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -108,20 +121,19 @@ function createProject(params) {
|
|
|
108
121
|
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
109
122
|
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
110
123
|
if (creates.length || deletes.length) {
|
|
111
|
-
parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
|
|
124
|
+
parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.getPathOfUri(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
|
|
112
125
|
projectVersion++;
|
|
113
126
|
typeRootVersion++;
|
|
114
127
|
}
|
|
115
128
|
if (_projectVersion !== projectVersion) {
|
|
116
|
-
projectVersionUpdateTime = cancelTokenHost.getMtime();
|
|
129
|
+
projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
|
|
117
130
|
}
|
|
118
131
|
});
|
|
119
132
|
}
|
|
120
133
|
function createLanguageServiceHost() {
|
|
121
|
-
var _a;
|
|
122
134
|
const token = {
|
|
123
135
|
isCancellationRequested() {
|
|
124
|
-
return cancelTokenHost.getMtime() !== projectVersionUpdateTime;
|
|
136
|
+
return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
|
|
125
137
|
},
|
|
126
138
|
throwIfCancellationRequested() { },
|
|
127
139
|
};
|
|
@@ -136,18 +148,21 @@ function createProject(params) {
|
|
|
136
148
|
readDirectory: sys.readDirectory,
|
|
137
149
|
realpath: sys.realpath,
|
|
138
150
|
fileExists: sys.fileExists,
|
|
139
|
-
getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
|
|
151
|
+
getCurrentDirectory: () => shared.getPathOfUri(context.rootUri.toString()),
|
|
140
152
|
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
141
153
|
getCancellationToken: () => token,
|
|
142
154
|
// custom
|
|
143
155
|
getDefaultLibFileName: options => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
156
|
+
if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
|
|
157
|
+
try {
|
|
158
|
+
return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
|
|
159
|
+
}
|
|
160
|
+
catch (_a) {
|
|
161
|
+
// web
|
|
162
|
+
return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
|
|
163
|
+
}
|
|
150
164
|
}
|
|
165
|
+
return '';
|
|
151
166
|
},
|
|
152
167
|
getProjectVersion: () => projectVersion.toString(),
|
|
153
168
|
getTypeRootsVersion: () => typeRootVersion,
|
|
@@ -155,24 +170,26 @@ function createProject(params) {
|
|
|
155
170
|
getCompilationSettings: () => parsedCommandLine.options,
|
|
156
171
|
getScriptVersion,
|
|
157
172
|
getScriptSnapshot,
|
|
158
|
-
getTypeScriptModule: () =>
|
|
173
|
+
getTypeScriptModule: () => {
|
|
174
|
+
return context.workspace.workspaces.ts;
|
|
175
|
+
},
|
|
159
176
|
};
|
|
160
|
-
if (initOptions.noProjectReferences) {
|
|
177
|
+
if (context.workspace.workspaces.initOptions.noProjectReferences) {
|
|
161
178
|
host.getProjectReferences = undefined;
|
|
162
179
|
host.getCompilationSettings = () => (Object.assign(Object.assign({}, parsedCommandLine.options), { rootDir: undefined, composite: false }));
|
|
163
180
|
}
|
|
164
|
-
if (tsLocalized) {
|
|
165
|
-
host.getLocalizedDiagnosticMessages = () => tsLocalized;
|
|
181
|
+
if (context.workspace.workspaces.tsLocalized) {
|
|
182
|
+
host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
|
|
166
183
|
}
|
|
167
|
-
for (const plugin of plugins) {
|
|
168
|
-
if (
|
|
169
|
-
host = plugin.
|
|
184
|
+
for (const plugin of context.workspace.workspaces.plugins) {
|
|
185
|
+
if (context.workspace.workspaces.ts && plugin.resolveLanguageServiceHost) {
|
|
186
|
+
host = plugin.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
|
|
170
187
|
}
|
|
171
188
|
}
|
|
172
189
|
return host;
|
|
173
190
|
function getScriptVersion(fileName) {
|
|
174
191
|
var _a, _b;
|
|
175
|
-
const doc = documents.data.pathGet(fileName);
|
|
192
|
+
const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
|
|
176
193
|
if (doc) {
|
|
177
194
|
return doc.version.toString();
|
|
178
195
|
}
|
|
@@ -180,7 +197,7 @@ function createProject(params) {
|
|
|
180
197
|
}
|
|
181
198
|
function getScriptSnapshot(fileName) {
|
|
182
199
|
var _a;
|
|
183
|
-
const doc = documents.data.pathGet(fileName);
|
|
200
|
+
const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
|
|
184
201
|
if (doc) {
|
|
185
202
|
return doc.getSnapshot();
|
|
186
203
|
}
|
|
@@ -188,17 +205,17 @@ function createProject(params) {
|
|
|
188
205
|
if (script && script.snapshotVersion === script.version) {
|
|
189
206
|
return script.snapshot;
|
|
190
207
|
}
|
|
191
|
-
if (sys.fileExists(fileName)) {
|
|
192
|
-
if (initOptions.maxFileSize) {
|
|
208
|
+
if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
|
|
209
|
+
if (context.workspace.workspaces.initOptions.maxFileSize) {
|
|
193
210
|
const fileSize = (_a = sys.getFileSize) === null || _a === void 0 ? void 0 : _a.call(sys, fileName);
|
|
194
|
-
if (fileSize !== undefined && fileSize > initOptions.maxFileSize) {
|
|
195
|
-
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${initOptions.maxFileSize}bytes)`);
|
|
196
|
-
return ts.ScriptSnapshot.fromString('');
|
|
211
|
+
if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
|
|
212
|
+
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
|
|
213
|
+
return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
|
|
197
214
|
}
|
|
198
215
|
}
|
|
199
216
|
const text = sys.readFile(fileName, 'utf8');
|
|
200
217
|
if (text !== undefined) {
|
|
201
|
-
const snapshot = ts.ScriptSnapshot.fromString(text);
|
|
218
|
+
const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
|
|
202
219
|
if (script) {
|
|
203
220
|
script.snapshot = snapshot;
|
|
204
221
|
script.snapshotVersion = script.version;
|
|
@@ -217,40 +234,42 @@ function createProject(params) {
|
|
|
217
234
|
}
|
|
218
235
|
}
|
|
219
236
|
function dispose() {
|
|
220
|
-
|
|
237
|
+
languageService === null || languageService === void 0 ? void 0 : languageService.dispose();
|
|
221
238
|
scripts.clear();
|
|
222
|
-
disposeWatchEvent();
|
|
239
|
+
disposeWatchEvent === null || disposeWatchEvent === void 0 ? void 0 : disposeWatchEvent();
|
|
223
240
|
disposeDocChange();
|
|
224
241
|
}
|
|
225
242
|
});
|
|
226
243
|
}
|
|
227
244
|
exports.createProject = createProject;
|
|
228
245
|
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
229
|
-
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions).flat();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.extraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
|
|
247
|
+
if (ts) {
|
|
248
|
+
try {
|
|
249
|
+
let content;
|
|
250
|
+
if (typeof tsConfig === 'string') {
|
|
251
|
+
const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
|
|
252
|
+
content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
|
|
256
|
+
}
|
|
257
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
258
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
259
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
260
|
+
content.options.outDir = undefined;
|
|
261
|
+
content.fileNames = content.fileNames.map(shared.normalizeFileName);
|
|
262
|
+
return content;
|
|
235
263
|
}
|
|
236
|
-
|
|
237
|
-
|
|
264
|
+
catch (_a) {
|
|
265
|
+
// will be failed if web fs host first result not ready
|
|
238
266
|
}
|
|
239
|
-
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
240
|
-
// https://github.com/microsoft/TypeScript/issues/30457
|
|
241
|
-
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
242
|
-
content.options.outDir = undefined;
|
|
243
|
-
content.fileNames = content.fileNames.map(shared.normalizeFileName);
|
|
244
|
-
return content;
|
|
245
|
-
}
|
|
246
|
-
catch (_a) {
|
|
247
|
-
// will be failed if web fs host first result not ready
|
|
248
|
-
return {
|
|
249
|
-
errors: [],
|
|
250
|
-
fileNames: [],
|
|
251
|
-
options: {},
|
|
252
|
-
};
|
|
253
267
|
}
|
|
268
|
+
return {
|
|
269
|
+
errors: [],
|
|
270
|
+
fileNames: [],
|
|
271
|
+
options: {},
|
|
272
|
+
};
|
|
254
273
|
}
|
|
255
274
|
function getHTMLDocumentContext(ts, host) {
|
|
256
275
|
const documentContext = {
|
package/out/common/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as vscode from 'vscode-languageserver';
|
|
2
2
|
import { LanguageServerPlugin, RuntimeEnvironment } from '../types';
|
|
3
|
-
export interface
|
|
3
|
+
export interface ServerContext {
|
|
4
4
|
connection: vscode.Connection;
|
|
5
5
|
runtimeEnv: RuntimeEnvironment;
|
|
6
6
|
plugins: LanguageServerPlugin[];
|
|
7
7
|
}
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function startCommonLanguageServer(context: ServerContext): void;
|