@volar/language-server 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/features/customFeatures.d.ts +1 -2
- package/out/features/customFeatures.js +14 -25
- package/out/features/documentFeatures.js +2 -2
- package/out/features/languageFeatures.d.ts +2 -2
- package/out/features/languageFeatures.js +25 -16
- package/out/index.d.ts +3 -2
- package/out/index.js +4 -2
- package/out/node.js +11 -7
- package/out/{requests.d.ts → protocol.d.ts} +0 -11
- package/out/{requests.js → protocol.js} +2 -10
- package/out/registerFeatures.d.ts +5 -0
- package/out/registerFeatures.js +174 -0
- package/out/server.js +53 -23
- package/out/types.d.ts +23 -72
- package/out/types.js +13 -0
- package/out/utils/cancellationPipe.d.ts +6 -0
- package/out/utils/cancellationPipe.js +44 -0
- package/out/utils/project.d.ts +10 -8
- package/out/utils/project.js +25 -35
- package/out/utils/snapshots.d.ts +4 -4
- package/out/utils/webFileSystemHost.js +20 -19
- package/out/utils/workspaceProjects.d.ts +15 -13
- package/out/utils/workspaceProjects.js +9 -8
- package/out/utils/workspaces.d.ts +25 -24
- package/out/utils/workspaces.js +13 -12
- package/package.json +6 -6
- package/out/registers/registerDocumentFeatures.d.ts +0 -3
- package/out/registers/registerDocumentFeatures.js +0 -30
- package/out/registers/registerlanguageFeatures.d.ts +0 -3
- package/out/registers/registerlanguageFeatures.js +0 -144
package/out/server.js
CHANGED
|
@@ -11,10 +11,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.createCommonLanguageServer = void 0;
|
|
12
12
|
const vscode = require("vscode-languageserver");
|
|
13
13
|
const vscode_uri_1 = require("vscode-uri");
|
|
14
|
+
const types_1 = require("./types");
|
|
14
15
|
const configurationHost_1 = require("./utils/configurationHost");
|
|
15
16
|
const documentServiceHost_1 = require("./utils/documentServiceHost");
|
|
16
17
|
const snapshots_1 = require("./utils/snapshots");
|
|
17
18
|
const workspaces_1 = require("./utils/workspaces");
|
|
19
|
+
const registerFeatures_1 = require("./registerFeatures");
|
|
20
|
+
const cancellationPipe_1 = require("./utils/cancellationPipe");
|
|
18
21
|
function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
|
|
19
22
|
let params;
|
|
20
23
|
let options;
|
|
@@ -26,7 +29,7 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
|
|
|
26
29
|
let plugins;
|
|
27
30
|
const documents = (0, snapshots_1.createSnapshots)(connection);
|
|
28
31
|
connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
var _a, _b, _c;
|
|
32
|
+
var _a, _b, _c, _d;
|
|
30
33
|
params = _params;
|
|
31
34
|
options = params.initializationOptions;
|
|
32
35
|
plugins = _plugins.map(plugin => plugin(options));
|
|
@@ -44,26 +47,13 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
|
|
|
44
47
|
textDocumentSync: (_b = options.textDocumentSync) !== null && _b !== void 0 ? _b : vscode.TextDocumentSyncKind.Incremental,
|
|
45
48
|
},
|
|
46
49
|
};
|
|
47
|
-
const ts = runtimeEnv.loadTypescript(options);
|
|
48
50
|
configHost = ((_c = params.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(params, connection) : undefined;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(connection, documents, documentServiceHost);
|
|
56
|
-
}
|
|
57
|
-
if (options.languageFeatures) {
|
|
58
|
-
(yield Promise.resolve().then(() => require('./registers/registerlanguageFeatures'))).register(options.languageFeatures, result.capabilities, plugins);
|
|
59
|
-
fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities);
|
|
60
|
-
const tsLocalized = runtimeEnv.loadTypescriptLocalized(options);
|
|
61
|
-
projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, options, documents, connection);
|
|
62
|
-
for (const root of roots) {
|
|
63
|
-
projects.add(root);
|
|
64
|
-
}
|
|
65
|
-
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, plugins);
|
|
66
|
-
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, options.languageFeatures, params);
|
|
51
|
+
const serverMode = (_d = options.serverMode) !== null && _d !== void 0 ? _d : types_1.ServerMode.Semantic;
|
|
52
|
+
(0, registerFeatures_1.setupSyntacticCapabilities)(params.capabilities, result.capabilities);
|
|
53
|
+
yield createDocumenntServiceHost();
|
|
54
|
+
if (serverMode === types_1.ServerMode.Semantic) {
|
|
55
|
+
(0, registerFeatures_1.setupSemanticCapabilities)(params.capabilities, result.capabilities, options, plugins);
|
|
56
|
+
yield createLanguageServiceHost();
|
|
67
57
|
}
|
|
68
58
|
try {
|
|
69
59
|
// show version on LSP logs
|
|
@@ -73,14 +63,14 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
|
|
|
73
63
|
version: packageJson.version,
|
|
74
64
|
};
|
|
75
65
|
}
|
|
76
|
-
catch (
|
|
66
|
+
catch (_e) { }
|
|
77
67
|
return result;
|
|
78
68
|
}));
|
|
79
69
|
connection.onInitialized(() => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
var
|
|
70
|
+
var _f;
|
|
81
71
|
fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
|
|
82
72
|
configHost === null || configHost === void 0 ? void 0 : configHost.ready();
|
|
83
|
-
if ((
|
|
73
|
+
if ((_f = params.capabilities.workspace) === null || _f === void 0 ? void 0 : _f.workspaceFolders) {
|
|
84
74
|
connection.workspace.onDidChangeWorkspaceFolders(e => {
|
|
85
75
|
for (const folder of e.added) {
|
|
86
76
|
documentServiceHost === null || documentServiceHost === void 0 ? void 0 : documentServiceHost.add(vscode_uri_1.URI.parse(folder.uri));
|
|
@@ -94,6 +84,46 @@ function createCommonLanguageServer(connection, runtimeEnv, _plugins) {
|
|
|
94
84
|
}
|
|
95
85
|
}));
|
|
96
86
|
connection.listen();
|
|
87
|
+
function createDocumenntServiceHost() {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
|
|
91
|
+
documentServiceHost = (0, documentServiceHost_1.createDocumentServiceHost)(runtimeEnv, plugins, ts, configHost);
|
|
92
|
+
for (const root of roots) {
|
|
93
|
+
documentServiceHost.add(root);
|
|
94
|
+
}
|
|
95
|
+
(yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(connection, documents, documentServiceHost);
|
|
96
|
+
for (const plugin of plugins) {
|
|
97
|
+
(_b = (_a = plugin.documentService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function createLanguageServiceHost() {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const ts = runtimeEnv.loadTypescript(options.typescript.tsdk);
|
|
105
|
+
fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities);
|
|
106
|
+
const tsLocalized = params.locale ? runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined;
|
|
107
|
+
const cancelTokenHost = (0, cancellationPipe_1.createCancellactionTokenHost)(options.cancellationPipeName);
|
|
108
|
+
const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection, cancelTokenHost);
|
|
109
|
+
projects = _projects;
|
|
110
|
+
for (const root of roots) {
|
|
111
|
+
projects.add(root);
|
|
112
|
+
}
|
|
113
|
+
(yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects);
|
|
114
|
+
(yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, params, cancelTokenHost);
|
|
115
|
+
for (const plugin of plugins) {
|
|
116
|
+
(_b = (_a = plugin.languageService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, connection, getLanguageService);
|
|
117
|
+
}
|
|
118
|
+
function getLanguageService(uri) {
|
|
119
|
+
var _a;
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
|
|
122
|
+
return project === null || project === void 0 ? void 0 : project.getLanguageService();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
97
127
|
}
|
|
98
128
|
exports.createCommonLanguageServer = createCommonLanguageServer;
|
|
99
129
|
//# sourceMappingURL=server.js.map
|
package/out/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as embedded from '@volar/language-core';
|
|
|
4
4
|
import type { FileSystemProvider } from 'vscode-html-languageservice';
|
|
5
5
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
6
6
|
import * as vscode from 'vscode-languageserver';
|
|
7
|
-
import type * as Requests from './
|
|
7
|
+
import type * as Requests from './protocol';
|
|
8
8
|
import { URI } from 'vscode-uri';
|
|
9
9
|
export declare let __requests: typeof Requests;
|
|
10
10
|
export type FileSystemHost = {
|
|
@@ -15,8 +15,8 @@ export type FileSystemHost = {
|
|
|
15
15
|
};
|
|
16
16
|
export type FileSystem = Pick<ts.System, 'newLine' | 'useCaseSensitiveFileNames' | 'fileExists' | 'readFile' | 'readDirectory' | 'getCurrentDirectory' | 'realpath' | 'resolvePath'> & Partial<ts.System>;
|
|
17
17
|
export interface RuntimeEnvironment {
|
|
18
|
-
loadTypescript: (
|
|
19
|
-
loadTypescriptLocalized: (
|
|
18
|
+
loadTypescript: (tsdk: string) => typeof import('typescript/lib/tsserverlibrary');
|
|
19
|
+
loadTypescriptLocalized: (tsdk: string, locale: string) => any;
|
|
20
20
|
schemaRequestHandlers: {
|
|
21
21
|
[schema: string]: (uri: string, encoding?: BufferEncoding) => Promise<string>;
|
|
22
22
|
};
|
|
@@ -24,8 +24,8 @@ export interface RuntimeEnvironment {
|
|
|
24
24
|
fileSystemProvide: FileSystemProvider | undefined;
|
|
25
25
|
createFileSystemHost: (ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities) => FileSystemHost;
|
|
26
26
|
}
|
|
27
|
-
export type LanguageServerPlugin<A extends
|
|
28
|
-
|
|
27
|
+
export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
|
|
28
|
+
extraFileExtensions: ts.FileExtensionInfo[];
|
|
29
29
|
languageService?: {
|
|
30
30
|
semanticTokenLegend?: vscode.SemanticTokensLegend;
|
|
31
31
|
resolveLanguageServiceHost?(ts: typeof import('typescript/lib/tsserverlibrary'), sys: FileSystem, tsConfig: string | ts.CompilerOptions, host: embedded.LanguageServiceHost): B;
|
|
@@ -36,77 +36,28 @@ export type LanguageServerPlugin<A extends ServerInitializationOptions = ServerI
|
|
|
36
36
|
documentService?: {
|
|
37
37
|
getLanguageModules?(ts: typeof import('typescript/lib/tsserverlibrary'), env: embeddedLS.LanguageServicePluginContext['env']): embedded.EmbeddedLanguageModule[];
|
|
38
38
|
getServicePlugins?(context: embeddedLS.DocumentServiceRuntimeContext): embeddedLS.LanguageServicePlugin[];
|
|
39
|
+
onInitialize?(connection: vscode.Connection): void;
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
|
-
export
|
|
42
|
-
|
|
42
|
+
export declare enum ServerMode {
|
|
43
|
+
Semantic = 0,
|
|
44
|
+
Syntactic = 2
|
|
45
|
+
}
|
|
46
|
+
export declare enum DiagnosticModel {
|
|
47
|
+
None = 0,
|
|
48
|
+
Push = 1,
|
|
49
|
+
Pull = 2
|
|
50
|
+
}
|
|
51
|
+
export interface LanguageServerInitializationOptions {
|
|
43
52
|
typescript: {
|
|
44
|
-
|
|
45
|
-
* Path to tsserverlibrary.js / tsserver.js / typescript.js
|
|
46
|
-
* @example
|
|
47
|
-
* '/usr/local/lib/node_modules/typescript/lib/tsserverlibrary.js' // use global typescript install
|
|
48
|
-
* 'typescript/lib/tsserverlibrary.js' // if `typescript` exist in `@volar/vue-lannguage-server` itself node_modules directory
|
|
49
|
-
* '../../../typescript/lib/tsserverlibrary.js' // relative path to @volar/vue-language-server/out/index.js
|
|
50
|
-
*/
|
|
51
|
-
serverPath: string;
|
|
52
|
-
/**
|
|
53
|
-
* Path to lib/xxx/diagnosticMessages.generated.json
|
|
54
|
-
* @example
|
|
55
|
-
* '/usr/local/lib/node_modules/typescript/lib/ja/diagnosticMessages.generated.json' // use global typescript install
|
|
56
|
-
* 'typescript/lib/ja/diagnosticMessages.generated.json' // if `typescript` exist in `@volar/vue-lannguage-server` itself node_modules directory
|
|
57
|
-
* '../../../typescript/lib/ja/diagnosticMessages.generated.json' // relative path to @volar/vue-language-server/out/index.js
|
|
58
|
-
*/
|
|
59
|
-
localizedPath?: string;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* typescript, html, css... language service will be create in server if this option is not null
|
|
63
|
-
*/
|
|
64
|
-
languageFeatures?: {
|
|
65
|
-
references?: boolean;
|
|
66
|
-
implementation?: boolean;
|
|
67
|
-
definition?: boolean;
|
|
68
|
-
typeDefinition?: boolean;
|
|
69
|
-
callHierarchy?: boolean;
|
|
70
|
-
hover?: boolean;
|
|
71
|
-
rename?: boolean;
|
|
72
|
-
renameFileRefactoring?: boolean;
|
|
73
|
-
signatureHelp?: boolean;
|
|
74
|
-
completion?: boolean | {
|
|
75
|
-
/**
|
|
76
|
-
* {@link __requests.GetDocumentSelectionRequest}
|
|
77
|
-
* */
|
|
78
|
-
getDocumentSelectionRequest?: boolean;
|
|
79
|
-
ignoreTriggerCharacters?: string;
|
|
80
|
-
};
|
|
81
|
-
documentHighlight?: boolean;
|
|
82
|
-
documentLink?: boolean;
|
|
83
|
-
workspaceSymbol?: boolean;
|
|
84
|
-
codeLens?: boolean | {
|
|
85
|
-
/**
|
|
86
|
-
* {@link __requests.ShowReferencesNotification}
|
|
87
|
-
* */
|
|
88
|
-
showReferencesNotification?: boolean;
|
|
89
|
-
};
|
|
90
|
-
semanticTokens?: boolean;
|
|
91
|
-
codeAction?: boolean;
|
|
92
|
-
inlayHints?: boolean;
|
|
93
|
-
diagnostics?: boolean;
|
|
94
|
-
schemaRequestService?: boolean | {
|
|
95
|
-
/**
|
|
96
|
-
* {@link __requests.GetDocumentContentRequest}
|
|
97
|
-
* */
|
|
98
|
-
getDocumentContentRequest?: boolean;
|
|
99
|
-
};
|
|
53
|
+
tsdk: string;
|
|
100
54
|
};
|
|
55
|
+
serverMode?: ServerMode;
|
|
56
|
+
diagnosticModel?: DiagnosticModel;
|
|
57
|
+
textDocumentSync?: vscode.TextDocumentSyncKind | number;
|
|
58
|
+
ignoreTriggerCharacters?: string[];
|
|
101
59
|
/**
|
|
102
|
-
*
|
|
60
|
+
* https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29#cancellation
|
|
103
61
|
*/
|
|
104
|
-
|
|
105
|
-
selectionRange?: boolean;
|
|
106
|
-
foldingRange?: boolean;
|
|
107
|
-
linkedEditingRange?: boolean;
|
|
108
|
-
documentSymbol?: boolean;
|
|
109
|
-
documentColor?: boolean;
|
|
110
|
-
documentFormatting?: boolean;
|
|
111
|
-
};
|
|
62
|
+
cancellationPipeName?: string;
|
|
112
63
|
}
|
package/out/types.js
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.DiagnosticModel = exports.ServerMode = void 0;
|
|
3
|
+
var ServerMode;
|
|
4
|
+
(function (ServerMode) {
|
|
5
|
+
ServerMode[ServerMode["Semantic"] = 0] = "Semantic";
|
|
6
|
+
// PartialSemantic = 1, // not support yet
|
|
7
|
+
ServerMode[ServerMode["Syntactic"] = 2] = "Syntactic";
|
|
8
|
+
})(ServerMode = exports.ServerMode || (exports.ServerMode = {}));
|
|
9
|
+
var DiagnosticModel;
|
|
10
|
+
(function (DiagnosticModel) {
|
|
11
|
+
DiagnosticModel[DiagnosticModel["None"] = 0] = "None";
|
|
12
|
+
DiagnosticModel[DiagnosticModel["Push"] = 1] = "Push";
|
|
13
|
+
DiagnosticModel[DiagnosticModel["Pull"] = 2] = "Pull";
|
|
14
|
+
})(DiagnosticModel = exports.DiagnosticModel || (exports.DiagnosticModel = {}));
|
|
2
15
|
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as vscode from 'vscode-languageserver';
|
|
2
|
+
export type CancellactionTokenHost = ReturnType<typeof createCancellactionTokenHost>;
|
|
3
|
+
export declare function createCancellactionTokenHost(_cancellationPipeName: string | undefined): {
|
|
4
|
+
createCancellactionToken(original: vscode.CancellationToken): vscode.CancellationToken;
|
|
5
|
+
getMtime(): number;
|
|
6
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.createCancellactionTokenHost = void 0;
|
|
3
|
+
const vscode = require("vscode-languageserver");
|
|
4
|
+
function createCancellactionTokenHost(_cancellationPipeName) {
|
|
5
|
+
if (_cancellationPipeName === undefined) {
|
|
6
|
+
return {
|
|
7
|
+
createCancellactionToken(original) {
|
|
8
|
+
return original;
|
|
9
|
+
},
|
|
10
|
+
getMtime() {
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const cancellationPipeName = _cancellationPipeName;
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
return {
|
|
18
|
+
createCancellactionToken,
|
|
19
|
+
getMtime,
|
|
20
|
+
};
|
|
21
|
+
function createCancellactionToken(original) {
|
|
22
|
+
const mtime = getMtime();
|
|
23
|
+
const token = {
|
|
24
|
+
get isCancellationRequested() {
|
|
25
|
+
if (original.isCancellationRequested) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return getMtime() !== mtime;
|
|
29
|
+
},
|
|
30
|
+
onCancellationRequested: vscode.Event.None,
|
|
31
|
+
};
|
|
32
|
+
return token;
|
|
33
|
+
}
|
|
34
|
+
function getMtime() {
|
|
35
|
+
try {
|
|
36
|
+
return fs.statSync(cancellationPipeName).mtime.valueOf();
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.createCancellactionTokenHost = createCancellactionTokenHost;
|
|
44
|
+
//# sourceMappingURL=cancellationPipe.js.map
|
package/out/utils/project.d.ts
CHANGED
|
@@ -2,14 +2,16 @@ import * as embeddedLS from '@volar/language-service';
|
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
import * as vscode from 'vscode-languageserver';
|
|
4
4
|
import { URI } from 'vscode-uri';
|
|
5
|
-
import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment
|
|
5
|
+
import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment } from '../types';
|
|
6
6
|
import { createSnapshots } from './snapshots';
|
|
7
7
|
import { ConfigurationHost } from '@volar/vue-language-service';
|
|
8
|
+
import * as path from 'typesafe-path';
|
|
9
|
+
import { CancellactionTokenHost } from './cancellationPipe';
|
|
8
10
|
export interface Project extends ReturnType<typeof createProject> {
|
|
9
11
|
}
|
|
10
|
-
export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, ts: typeof import('typescript/lib/tsserverlibrary'),
|
|
12
|
+
export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, ts: typeof import('typescript/lib/tsserverlibrary'), rootUri: URI, tsConfig: path.PosixPath | ts.CompilerOptions, tsLocalized: ts.MapLike<string> | undefined, documents: ReturnType<typeof createSnapshots>, configHost: ConfigurationHost | undefined, documentRegistry: ts.DocumentRegistry | undefined, cancelTokenHost: CancellactionTokenHost): Promise<{
|
|
11
13
|
getLanguageService: () => {
|
|
12
|
-
doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined
|
|
14
|
+
doValidation: (uri: string, token?: vscode.CancellationToken | undefined, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
13
15
|
findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
14
16
|
findFileReferences: (uri: string) => embeddedLS.NullableResult<vscode.Location[]>;
|
|
15
17
|
findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
@@ -18,7 +20,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
18
20
|
prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
|
|
19
21
|
doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
20
22
|
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
21
|
-
getSemanticTokens: (uri: string, range
|
|
23
|
+
getSemanticTokens: (uri: string, range: vscode.Range | undefined, cancleToken: vscode.CancellationToken, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
|
|
22
24
|
doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
|
|
23
25
|
doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
|
|
24
26
|
isIncomplete: boolean;
|
|
@@ -26,7 +28,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
26
28
|
}>;
|
|
27
29
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
28
30
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
29
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
31
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
30
32
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
31
33
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
32
34
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
@@ -52,7 +54,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
52
54
|
context: embeddedLS.LanguageServiceRuntimeContext;
|
|
53
55
|
};
|
|
54
56
|
getLanguageServiceDontCreate: () => {
|
|
55
|
-
doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined
|
|
57
|
+
doValidation: (uri: string, token?: vscode.CancellationToken | undefined, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
|
|
56
58
|
findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
57
59
|
findFileReferences: (uri: string) => embeddedLS.NullableResult<vscode.Location[]>;
|
|
58
60
|
findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
@@ -61,7 +63,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
61
63
|
prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
|
|
62
64
|
doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
63
65
|
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
64
|
-
getSemanticTokens: (uri: string, range
|
|
66
|
+
getSemanticTokens: (uri: string, range: vscode.Range | undefined, cancleToken: vscode.CancellationToken, reportProgress?: ((tokens: embeddedLS.SemanticToken[]) => void) | undefined) => Promise<embeddedLS.SemanticToken[] | undefined> | undefined;
|
|
65
67
|
doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
|
|
66
68
|
doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
|
|
67
69
|
isIncomplete: boolean;
|
|
@@ -69,7 +71,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
69
71
|
}>;
|
|
70
72
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
71
73
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
72
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
74
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
73
75
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
74
76
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
75
77
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
package/out/utils/project.js
CHANGED
|
@@ -15,14 +15,13 @@ const embedded = require("@volar/language-core");
|
|
|
15
15
|
const vscode = require("vscode-languageserver");
|
|
16
16
|
const vscode_uri_1 = require("vscode-uri");
|
|
17
17
|
const config_1 = require("./config");
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const path_1 = require("path");
|
|
21
|
-
function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConfig, tsLocalized, documents, connection, configHost, documentRegistry) {
|
|
18
|
+
const path = require("typesafe-path");
|
|
19
|
+
function createProject(runtimeEnv, plugins, fsHost, ts, rootUri, tsConfig, tsLocalized, documents, configHost, documentRegistry, cancelTokenHost) {
|
|
22
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
21
|
const sys = fsHost.getWorkspaceFileSystem(rootUri);
|
|
24
22
|
let typeRootVersion = 0;
|
|
25
23
|
let projectVersion = 0;
|
|
24
|
+
let projectVersionUpdateTime = 0;
|
|
26
25
|
let vueLs;
|
|
27
26
|
let parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
|
|
28
27
|
const scripts = shared.createUriMap();
|
|
@@ -32,6 +31,7 @@ function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConf
|
|
|
32
31
|
});
|
|
33
32
|
const disposeDocChange = documents.onDidChangeContent(params => {
|
|
34
33
|
projectVersion++;
|
|
34
|
+
projectVersionUpdateTime = cancelTokenHost.getMtime();
|
|
35
35
|
});
|
|
36
36
|
return {
|
|
37
37
|
getLanguageService,
|
|
@@ -57,24 +57,14 @@ function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConf
|
|
|
57
57
|
configurationHost: configHost,
|
|
58
58
|
fileSystemProvider: runtimeEnv.fileSystemProvide,
|
|
59
59
|
documentContext: getHTMLDocumentContext(ts, languageServiceHost),
|
|
60
|
-
schemaRequestService: uri => {
|
|
61
|
-
var _a;
|
|
60
|
+
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
62
61
|
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
63
62
|
const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
|
|
64
63
|
if (builtInHandler) {
|
|
65
|
-
return builtInHandler(uri);
|
|
64
|
+
return yield builtInHandler(uri);
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return responseText;
|
|
70
|
-
}, error => {
|
|
71
|
-
return Promise.reject(error.message);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return Promise.reject('clientHandledGetDocumentContentRequest is false');
|
|
76
|
-
}
|
|
77
|
-
},
|
|
66
|
+
return '';
|
|
67
|
+
}),
|
|
78
68
|
},
|
|
79
69
|
documentRegistry,
|
|
80
70
|
});
|
|
@@ -111,6 +101,12 @@ function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConf
|
|
|
111
101
|
}
|
|
112
102
|
function createLanguageServiceHost() {
|
|
113
103
|
var _a;
|
|
104
|
+
const token = {
|
|
105
|
+
isCancellationRequested() {
|
|
106
|
+
return cancelTokenHost.getMtime() !== projectVersionUpdateTime;
|
|
107
|
+
},
|
|
108
|
+
throwIfCancellationRequested() { },
|
|
109
|
+
};
|
|
114
110
|
let host = {
|
|
115
111
|
// ts
|
|
116
112
|
getNewLine: () => sys.newLine,
|
|
@@ -124,6 +120,7 @@ function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConf
|
|
|
124
120
|
fileExists: sys.fileExists,
|
|
125
121
|
getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
|
|
126
122
|
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
123
|
+
getCancellationToken: () => token,
|
|
127
124
|
// custom
|
|
128
125
|
getDefaultLibFileName: options => {
|
|
129
126
|
try {
|
|
@@ -198,21 +195,15 @@ function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConf
|
|
|
198
195
|
}
|
|
199
196
|
exports.createProject = createProject;
|
|
200
197
|
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
201
|
-
const extraFileExtensions = plugins.map(plugin => plugin.
|
|
202
|
-
.flat()
|
|
203
|
-
.map(ext => ({
|
|
204
|
-
extension: ext.substring(1),
|
|
205
|
-
isMixedContent: true,
|
|
206
|
-
scriptKind: ts.ScriptKind.Deferred,
|
|
207
|
-
}));
|
|
198
|
+
const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions).flat();
|
|
208
199
|
try {
|
|
209
200
|
let content;
|
|
210
201
|
if (typeof tsConfig === 'string') {
|
|
211
202
|
const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
|
|
212
|
-
content = ts.parseJsonSourceFileConfigFileContent(config, sys,
|
|
203
|
+
content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
|
|
213
204
|
}
|
|
214
205
|
else {
|
|
215
|
-
content = ts.parseJsonConfigFileContent({}, sys, rootPath, tsConfig,
|
|
206
|
+
content = ts.parseJsonConfigFileContent({}, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
|
|
216
207
|
}
|
|
217
208
|
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
218
209
|
// https://github.com/microsoft/TypeScript/issues/30457
|
|
@@ -238,20 +229,19 @@ function getHTMLDocumentContext(ts, host) {
|
|
|
238
229
|
const resolveResult = ts.resolveModuleName(ref, isUri ? shared.getPathOfUri(base) : base, host.getCompilationSettings(), host);
|
|
239
230
|
const failedLookupLocations = resolveResult.failedLookupLocations;
|
|
240
231
|
const dirs = new Set();
|
|
241
|
-
for (
|
|
242
|
-
|
|
243
|
-
const fileName = upath.basename(path);
|
|
232
|
+
for (let failed of failedLookupLocations) {
|
|
233
|
+
const fileName = path.basename(failed);
|
|
244
234
|
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
245
|
-
dirs.add(
|
|
235
|
+
dirs.add(path.dirname(failed));
|
|
246
236
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
237
|
+
if (failed.endsWith('.d.ts')) {
|
|
238
|
+
failed = failed.substring(0, failed.length - '.d.ts'.length);
|
|
249
239
|
}
|
|
250
240
|
else {
|
|
251
241
|
continue;
|
|
252
242
|
}
|
|
253
|
-
if (host.fileExists(
|
|
254
|
-
return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base),
|
|
243
|
+
if (host.fileExists(failed)) {
|
|
244
|
+
return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base), failed) : failed;
|
|
255
245
|
}
|
|
256
246
|
}
|
|
257
247
|
for (const dir of dirs) {
|
package/out/utils/snapshots.d.ts
CHANGED
|
@@ -33,10 +33,10 @@ export declare function createSnapshots(connection: vscode.Connection): {
|
|
|
33
33
|
uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
|
|
34
34
|
uriHas: (_uri: string) => boolean;
|
|
35
35
|
uriSet: (_uri: string, item: IncrementalScriptSnapshot) => void;
|
|
36
|
-
pathDelete: (rootUri: shared.
|
|
37
|
-
pathGet: (rootUri: shared.
|
|
38
|
-
pathHas: (rootUri: shared.
|
|
39
|
-
pathSet: (rootUri: shared.
|
|
36
|
+
pathDelete: (rootUri: shared._2.URI, path: string) => boolean;
|
|
37
|
+
pathGet: (rootUri: shared._2.URI, path: string) => IncrementalScriptSnapshot | undefined;
|
|
38
|
+
pathHas: (rootUri: shared._2.URI, path: string) => IncrementalScriptSnapshot | undefined;
|
|
39
|
+
pathSet: (rootUri: shared._2.URI, path: string, item: IncrementalScriptSnapshot) => void;
|
|
40
40
|
};
|
|
41
41
|
onDidOpen: (cb: (params: vscode.DidOpenTextDocumentParams) => void) => () => boolean;
|
|
42
42
|
onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean;
|
|
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createWebFileSystemHost = void 0;
|
|
12
12
|
const shared = require("@volar/shared");
|
|
13
|
-
const
|
|
13
|
+
const path = require("typesafe-path");
|
|
14
14
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
15
15
|
const vscode = require("vscode-languageserver");
|
|
16
16
|
const vscode_uri_1 = require("vscode-uri");
|
|
17
|
-
const
|
|
17
|
+
const protocol_1 = require("../protocol");
|
|
18
18
|
const utilities_1 = require("./ts/utilities");
|
|
19
19
|
let currentCwd = '/';
|
|
20
20
|
function createWebFileSystemHost() {
|
|
@@ -37,8 +37,8 @@ function createWebFileSystemHost() {
|
|
|
37
37
|
connection.onDidChangeWatchedFiles(params => {
|
|
38
38
|
for (const change of params.changes) {
|
|
39
39
|
const fsPath = vscode_uri_1.URI.parse(change.uri).fsPath;
|
|
40
|
-
const dir = getDir(
|
|
41
|
-
const name =
|
|
40
|
+
const dir = getDir(path.dirname(fsPath));
|
|
41
|
+
const name = path.basename(fsPath);
|
|
42
42
|
if (change.type === vscode.FileChangeType.Created) {
|
|
43
43
|
dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
|
|
44
44
|
}
|
|
@@ -93,12 +93,12 @@ function createWebFileSystemHost() {
|
|
|
93
93
|
process.chdir(rootUri.fsPath);
|
|
94
94
|
currentCwd = rootUri.fsPath;
|
|
95
95
|
}
|
|
96
|
-
return
|
|
96
|
+
return path.resolve(fsPath);
|
|
97
97
|
}
|
|
98
98
|
function fileExists(fsPath) {
|
|
99
99
|
fsPath = resolvePath(fsPath);
|
|
100
|
-
const dir = getDir(
|
|
101
|
-
const name =
|
|
100
|
+
const dir = getDir(path.dirname(fsPath));
|
|
101
|
+
const name = path.basename(fsPath);
|
|
102
102
|
if (dir.fileTypes.has(name)) {
|
|
103
103
|
return dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.File || dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.SymbolicLink;
|
|
104
104
|
}
|
|
@@ -113,8 +113,8 @@ function createWebFileSystemHost() {
|
|
|
113
113
|
}
|
|
114
114
|
function readFile(fsPath) {
|
|
115
115
|
fsPath = resolvePath(fsPath);
|
|
116
|
-
const dir = getDir(
|
|
117
|
-
const name =
|
|
116
|
+
const dir = getDir(path.dirname(fsPath));
|
|
117
|
+
const name = path.basename(fsPath);
|
|
118
118
|
if (dir.fileTexts.has(name)) {
|
|
119
119
|
return dir.fileTexts.get(name);
|
|
120
120
|
}
|
|
@@ -129,7 +129,8 @@ function createWebFileSystemHost() {
|
|
|
129
129
|
}
|
|
130
130
|
function readDirectory(fsPath, extensions, exclude, include, depth) {
|
|
131
131
|
fsPath = resolvePath(fsPath);
|
|
132
|
-
return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth,
|
|
132
|
+
return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth, _dirPath => {
|
|
133
|
+
let dirPath = _dirPath;
|
|
133
134
|
dirPath = resolvePath(dirPath);
|
|
134
135
|
const dir = getDir(dirPath);
|
|
135
136
|
const files = [...dir.fileTypes];
|
|
@@ -173,9 +174,9 @@ function createWebFileSystemHost() {
|
|
|
173
174
|
function statAsync(connection, fsPath, dir) {
|
|
174
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
176
|
const uri = getFsPathUri(fsPath);
|
|
176
|
-
const result = yield connection.sendRequest(
|
|
177
|
+
const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri.toString());
|
|
177
178
|
if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) {
|
|
178
|
-
const name =
|
|
179
|
+
const name = path.basename(fsPath);
|
|
179
180
|
dir.fileTypes.set(name, result.type);
|
|
180
181
|
changes.push({
|
|
181
182
|
uri: uri.toString(),
|
|
@@ -187,9 +188,9 @@ function createWebFileSystemHost() {
|
|
|
187
188
|
function readFileAsync(connection, fsPath, dir) {
|
|
188
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
190
|
const uri = getFsPathUri(fsPath);
|
|
190
|
-
const text = yield connection.sendRequest(
|
|
191
|
+
const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri.toString());
|
|
191
192
|
if (text) {
|
|
192
|
-
const name =
|
|
193
|
+
const name = path.basename(fsPath);
|
|
193
194
|
dir.fileTexts.set(name, text);
|
|
194
195
|
changes.push({
|
|
195
196
|
uri: uri.toString(),
|
|
@@ -201,11 +202,11 @@ function createWebFileSystemHost() {
|
|
|
201
202
|
function readDirectoryAsync(connection, fsPath, dir) {
|
|
202
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
204
|
const uri = getFsPathUri(fsPath);
|
|
204
|
-
const result = yield connection.sendRequest(
|
|
205
|
+
const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, uri.toString());
|
|
205
206
|
for (const [name, fileType] of result) {
|
|
206
207
|
if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
|
|
207
208
|
changes.push({
|
|
208
|
-
uri: getFsPathUri(
|
|
209
|
+
uri: getFsPathUri(path.join(fsPath, name)).toString(),
|
|
209
210
|
type: vscode.FileChangeType.Created,
|
|
210
211
|
});
|
|
211
212
|
}
|
|
@@ -244,11 +245,11 @@ function createWebFileSystemHost() {
|
|
|
244
245
|
function getDir(dirPath) {
|
|
245
246
|
const dirNames = [];
|
|
246
247
|
let currentDirPath = dirPath;
|
|
247
|
-
let currentDirName =
|
|
248
|
+
let currentDirName = path.basename(currentDirPath);
|
|
248
249
|
while (currentDirName !== '') {
|
|
249
250
|
dirNames.push(currentDirName);
|
|
250
|
-
currentDirPath =
|
|
251
|
-
currentDirName =
|
|
251
|
+
currentDirPath = path.dirname(currentDirPath);
|
|
252
|
+
currentDirName = path.basename(currentDirPath);
|
|
252
253
|
}
|
|
253
254
|
let currentDir = root;
|
|
254
255
|
for (let i = dirNames.length - 1; i >= 0; i--) {
|