@volar/language-server 1.0.0-beta.0 → 1.0.0-beta.2
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 +7 -18
- package/out/features/languageFeatures.d.ts +1 -2
- package/out/features/languageFeatures.js +2 -6
- package/out/node.js +11 -7
- package/out/registerFeatures.d.ts +5 -0
- package/out/registerFeatures.js +174 -0
- package/out/requests.d.ts +0 -11
- package/out/requests.js +1 -9
- package/out/server.js +47 -23
- package/out/types.d.ts +21 -75
- package/out/types.js +13 -0
- package/out/utils/nodeFileSystemHost.js +51 -42
- package/out/utils/project.d.ts +4 -4
- package/out/utils/project.js +19 -31
- package/out/utils/webFileSystemHost.js +137 -127
- package/out/utils/workspaceProjects.d.ts +4 -4
- package/out/utils/workspaceProjects.js +2 -2
- package/out/utils/workspaces.d.ts +8 -8
- package/out/utils/workspaces.js +6 -5
- package/package.json +5 -5
|
@@ -9,10 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createNodeFileSystemHost = void 0;
|
|
12
|
+
const shared = require("@volar/shared");
|
|
12
13
|
const vscode = require("vscode-languageserver");
|
|
13
14
|
const iterableWeakSet_1 = require("./iterableWeakSet");
|
|
14
15
|
let currentCwd = '';
|
|
15
16
|
function createNodeFileSystemHost(ts, capabilities) {
|
|
17
|
+
const instances = shared.createUriMap();
|
|
16
18
|
const onDidChangeWatchedFilesCb = new Set();
|
|
17
19
|
const caches = new iterableWeakSet_1.IterableWeakSet();
|
|
18
20
|
return {
|
|
@@ -36,60 +38,67 @@ function createNodeFileSystemHost(ts, capabilities) {
|
|
|
36
38
|
});
|
|
37
39
|
},
|
|
38
40
|
getWorkspaceFileSystem(rootUri) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
let sys = instances.uriGet(rootUri.toString());
|
|
42
|
+
if (!sys) {
|
|
43
|
+
sys = createWorkspaceFileSystem(rootUri);
|
|
44
|
+
instances.uriSet(rootUri.toString(), sys);
|
|
45
|
+
}
|
|
46
|
+
return sys;
|
|
47
|
+
},
|
|
48
|
+
onDidChangeWatchedFiles: cb => {
|
|
49
|
+
onDidChangeWatchedFilesCb.add(cb);
|
|
50
|
+
return () => onDidChangeWatchedFilesCb.delete(cb);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
function createWorkspaceFileSystem(rootUri) {
|
|
54
|
+
var _a;
|
|
55
|
+
const workspaceSys = new Proxy(ts.sys, {
|
|
56
|
+
get(target, prop) {
|
|
57
|
+
const fn = target[prop];
|
|
58
|
+
if (typeof fn === 'function') {
|
|
59
|
+
return new Proxy(fn, {
|
|
60
|
+
apply(target, thisArg, args) {
|
|
61
|
+
if (currentCwd !== rootUri.fsPath) {
|
|
62
|
+
process.chdir(rootUri.fsPath);
|
|
63
|
+
currentCwd = rootUri.fsPath;
|
|
51
64
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
return target.apply(thisArg, args);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return fn;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const fileExistsCache = new Map();
|
|
73
|
+
const directoryExistsCache = new Map();
|
|
74
|
+
// don't cache fs result if client did not supports file watcher
|
|
75
|
+
const sys = ((_a = capabilities.workspace) === null || _a === void 0 ? void 0 : _a.didChangeWatchedFiles)
|
|
76
|
+
? new Proxy({
|
|
60
77
|
fileExists(path) {
|
|
61
78
|
if (!fileExistsCache.has(path)) {
|
|
62
|
-
fileExistsCache.set(path,
|
|
79
|
+
fileExistsCache.set(path, workspaceSys.fileExists(path));
|
|
63
80
|
}
|
|
64
81
|
return fileExistsCache.get(path);
|
|
65
82
|
},
|
|
66
83
|
directoryExists(path) {
|
|
67
84
|
if (!directoryExistsCache.has(path)) {
|
|
68
|
-
directoryExistsCache.set(path,
|
|
85
|
+
directoryExistsCache.set(path, workspaceSys.directoryExists(path));
|
|
69
86
|
}
|
|
70
87
|
return directoryExistsCache.get(path);
|
|
71
88
|
},
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
? new Proxy(workspaceSys, {
|
|
76
|
-
get(target, prop) {
|
|
77
|
-
if (prop in sysWithCache) {
|
|
78
|
-
return sysWithCache[prop];
|
|
79
|
-
}
|
|
89
|
+
}, {
|
|
90
|
+
get(target, prop) {
|
|
91
|
+
if (prop in target) {
|
|
80
92
|
return target[prop];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return () => onDidChangeWatchedFilesCb.delete(cb);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
+
}
|
|
94
|
+
return workspaceSys[prop];
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
: workspaceSys;
|
|
98
|
+
caches.add(fileExistsCache);
|
|
99
|
+
caches.add(directoryExistsCache);
|
|
100
|
+
return sys;
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
exports.createNodeFileSystemHost = createNodeFileSystemHost;
|
|
95
104
|
//# sourceMappingURL=nodeFileSystemHost.js.map
|
package/out/utils/project.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ 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 {
|
|
5
|
+
import { FileSystemHost, LanguageServerPlugin, RuntimeEnvironment, InitializationOptions } from '../types';
|
|
6
6
|
import { createSnapshots } from './snapshots';
|
|
7
7
|
import { ConfigurationHost } from '@volar/vue-language-service';
|
|
8
8
|
export interface Project extends ReturnType<typeof createProject> {
|
|
9
9
|
}
|
|
10
|
-
export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost,
|
|
10
|
+
export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, ts: typeof import('typescript/lib/tsserverlibrary'), options: InitializationOptions, rootUri: URI, tsConfig: string | ts.CompilerOptions, tsLocalized: ts.MapLike<string> | undefined, documents: ReturnType<typeof createSnapshots>, connection: vscode.Connection, configHost: ConfigurationHost | undefined, documentRegistry: ts.DocumentRegistry | undefined): Promise<{
|
|
11
11
|
getLanguageService: () => {
|
|
12
12
|
doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken | undefined) => Promise<vscode.Diagnostic[]>;
|
|
13
13
|
findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
@@ -26,7 +26,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
26
26
|
}>;
|
|
27
27
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
28
28
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
29
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
29
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
30
30
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
31
31
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
32
32
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
@@ -69,7 +69,7 @@ export declare function createProject(runtimeEnv: RuntimeEnvironment, plugins: R
|
|
|
69
69
|
}>;
|
|
70
70
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
71
71
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
72
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
72
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
73
73
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
74
74
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
75
75
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
package/out/utils/project.js
CHANGED
|
@@ -15,15 +15,15 @@ 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 requests_1 = require("../requests");
|
|
19
18
|
const upath = require("upath");
|
|
20
19
|
const path_1 = require("path");
|
|
21
|
-
function createProject(runtimeEnv, plugins, fsHost,
|
|
20
|
+
function createProject(runtimeEnv, plugins, fsHost, ts, options, rootUri, tsConfig, tsLocalized, documents, connection, configHost, documentRegistry) {
|
|
22
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const sys = fsHost.getWorkspaceFileSystem(rootUri);
|
|
23
23
|
let typeRootVersion = 0;
|
|
24
24
|
let projectVersion = 0;
|
|
25
25
|
let vueLs;
|
|
26
|
-
let parsedCommandLine = createParsedCommandLine(ts, sys,
|
|
26
|
+
let parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
|
|
27
27
|
const scripts = shared.createUriMap();
|
|
28
28
|
const languageServiceHost = createLanguageServiceHost();
|
|
29
29
|
const disposeWatchEvent = fsHost.onDidChangeWatchedFiles(params => {
|
|
@@ -56,24 +56,14 @@ function createProject(runtimeEnv, plugins, fsHost, sys, ts, options, rootUri, r
|
|
|
56
56
|
configurationHost: configHost,
|
|
57
57
|
fileSystemProvider: runtimeEnv.fileSystemProvide,
|
|
58
58
|
documentContext: getHTMLDocumentContext(ts, languageServiceHost),
|
|
59
|
-
schemaRequestService: uri => {
|
|
60
|
-
var _a;
|
|
59
|
+
schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
|
|
61
60
|
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
62
61
|
const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
|
|
63
62
|
if (builtInHandler) {
|
|
64
|
-
return builtInHandler(uri);
|
|
63
|
+
return yield builtInHandler(uri);
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return responseText;
|
|
69
|
-
}, error => {
|
|
70
|
-
return Promise.reject(error.message);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return Promise.reject('clientHandledGetDocumentContentRequest is false');
|
|
75
|
-
}
|
|
76
|
-
},
|
|
65
|
+
return '';
|
|
66
|
+
}),
|
|
77
67
|
},
|
|
78
68
|
documentRegistry,
|
|
79
69
|
});
|
|
@@ -103,7 +93,7 @@ function createProject(runtimeEnv, plugins, fsHost, sys, ts, options, rootUri, r
|
|
|
103
93
|
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
104
94
|
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
105
95
|
if (creates.length || deletes.length) {
|
|
106
|
-
parsedCommandLine = createParsedCommandLine(ts, sys,
|
|
96
|
+
parsedCommandLine = createParsedCommandLine(ts, sys, shared.getPathOfUri(rootUri.toString()), tsConfig, plugins);
|
|
107
97
|
typeRootVersion++;
|
|
108
98
|
}
|
|
109
99
|
});
|
|
@@ -121,7 +111,7 @@ function createProject(runtimeEnv, plugins, fsHost, sys, ts, options, rootUri, r
|
|
|
121
111
|
readDirectory: sys.readDirectory,
|
|
122
112
|
realpath: sys.realpath,
|
|
123
113
|
fileExists: sys.fileExists,
|
|
124
|
-
getCurrentDirectory: () =>
|
|
114
|
+
getCurrentDirectory: () => shared.getPathOfUri(rootUri.toString()),
|
|
125
115
|
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
126
116
|
// custom
|
|
127
117
|
getDefaultLibFileName: options => {
|
|
@@ -197,23 +187,21 @@ function createProject(runtimeEnv, plugins, fsHost, sys, ts, options, rootUri, r
|
|
|
197
187
|
}
|
|
198
188
|
exports.createProject = createProject;
|
|
199
189
|
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
200
|
-
const
|
|
190
|
+
const extraFileExtensions = plugins.map(plugin => plugin.extensions)
|
|
191
|
+
.flat()
|
|
192
|
+
.map(ext => ({
|
|
193
|
+
extension: ext.substring(1),
|
|
194
|
+
isMixedContent: true,
|
|
195
|
+
scriptKind: ts.ScriptKind.Deferred,
|
|
196
|
+
}));
|
|
201
197
|
try {
|
|
202
|
-
const parseConfigHost = {
|
|
203
|
-
useCaseSensitiveFileNames: sys.useCaseSensitiveFileNames,
|
|
204
|
-
readDirectory: (path, extensions, exclude, include, depth) => {
|
|
205
|
-
return sys.readDirectory(path, [...extensions, ...extraExts], exclude, include, depth);
|
|
206
|
-
},
|
|
207
|
-
fileExists: sys.fileExists,
|
|
208
|
-
readFile: sys.readFile,
|
|
209
|
-
};
|
|
210
198
|
let content;
|
|
211
199
|
if (typeof tsConfig === 'string') {
|
|
212
|
-
const config = ts.readJsonConfigFile(tsConfig,
|
|
213
|
-
content = ts.parseJsonSourceFileConfigFileContent(config,
|
|
200
|
+
const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
|
|
201
|
+
content = ts.parseJsonSourceFileConfigFileContent(config, sys, path_1.posix.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
|
|
214
202
|
}
|
|
215
203
|
else {
|
|
216
|
-
content = ts.parseJsonConfigFileContent({},
|
|
204
|
+
content = ts.parseJsonConfigFileContent({}, sys, rootPath, tsConfig, path_1.posix.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
|
|
217
205
|
}
|
|
218
206
|
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
219
207
|
// https://github.com/microsoft/TypeScript/issues/30457
|
|
@@ -9,14 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.createWebFileSystemHost = void 0;
|
|
12
|
-
const
|
|
12
|
+
const shared = require("@volar/shared");
|
|
13
|
+
const path_1 = require("path");
|
|
13
14
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
15
|
+
const vscode = require("vscode-languageserver");
|
|
14
16
|
const vscode_uri_1 = require("vscode-uri");
|
|
15
|
-
const path_1 = require("path");
|
|
16
17
|
const requests_1 = require("../requests");
|
|
17
18
|
const utilities_1 = require("./ts/utilities");
|
|
18
19
|
let currentCwd = '/';
|
|
19
20
|
function createWebFileSystemHost() {
|
|
21
|
+
const instances = shared.createUriMap();
|
|
20
22
|
const onDidChangeWatchedFilesCb = new Set();
|
|
21
23
|
const root = {
|
|
22
24
|
dirs: new Map(),
|
|
@@ -62,148 +64,156 @@ function createWebFileSystemHost() {
|
|
|
62
64
|
root.searched = false;
|
|
63
65
|
},
|
|
64
66
|
getWorkspaceFileSystem(rootUri) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
fileExists,
|
|
70
|
-
readFile,
|
|
71
|
-
readDirectory,
|
|
72
|
-
getDirectories,
|
|
73
|
-
resolvePath,
|
|
74
|
-
realpath: path => path, // TODO: cannot implement with vscode
|
|
75
|
-
};
|
|
76
|
-
function resolvePath(fsPath) {
|
|
77
|
-
if (currentCwd !== rootUri.fsPath) {
|
|
78
|
-
process.chdir(rootUri.fsPath);
|
|
79
|
-
currentCwd = rootUri.fsPath;
|
|
80
|
-
}
|
|
81
|
-
return path_1.posix.resolve(fsPath);
|
|
67
|
+
let sys = instances.uriGet(rootUri.toString());
|
|
68
|
+
if (!sys) {
|
|
69
|
+
sys = createWorkspaceFileSystem(rootUri);
|
|
70
|
+
instances.uriSet(rootUri.toString(), sys);
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
72
|
+
return sys;
|
|
73
|
+
},
|
|
74
|
+
onDidChangeWatchedFiles: cb => {
|
|
75
|
+
onDidChangeWatchedFilesCb.add(cb);
|
|
76
|
+
return () => onDidChangeWatchedFilesCb.delete(cb);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
function createWorkspaceFileSystem(rootUri) {
|
|
80
|
+
return {
|
|
81
|
+
newLine: '\n',
|
|
82
|
+
useCaseSensitiveFileNames: false,
|
|
83
|
+
getCurrentDirectory: () => rootUri.fsPath,
|
|
84
|
+
fileExists,
|
|
85
|
+
readFile,
|
|
86
|
+
readDirectory,
|
|
87
|
+
getDirectories,
|
|
88
|
+
resolvePath,
|
|
89
|
+
realpath: path => path, // TODO: cannot implement with vscode
|
|
90
|
+
};
|
|
91
|
+
function resolvePath(fsPath) {
|
|
92
|
+
if (currentCwd !== rootUri.fsPath) {
|
|
93
|
+
process.chdir(rootUri.fsPath);
|
|
94
|
+
currentCwd = rootUri.fsPath;
|
|
98
95
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
dir.
|
|
107
|
-
if (connection) {
|
|
108
|
-
addPending(readFileAsync(connection, fsPath, dir));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir)));
|
|
112
|
-
}
|
|
113
|
-
return '';
|
|
96
|
+
return path_1.posix.resolve(fsPath);
|
|
97
|
+
}
|
|
98
|
+
function fileExists(fsPath) {
|
|
99
|
+
fsPath = resolvePath(fsPath);
|
|
100
|
+
const dir = getDir(path_1.posix.dirname(fsPath));
|
|
101
|
+
const name = path_1.posix.basename(fsPath);
|
|
102
|
+
if (dir.fileTypes.has(name)) {
|
|
103
|
+
return dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.File || dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.SymbolicLink;
|
|
114
104
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
dirPath = resolvePath(dirPath);
|
|
119
|
-
const dir = getDir(dirPath);
|
|
120
|
-
const files = [...dir.fileTypes];
|
|
121
|
-
if (!dir.searched) {
|
|
122
|
-
dir.searched = true;
|
|
123
|
-
if (connection) {
|
|
124
|
-
addPending(readDirectoryAsync(connection, dirPath, dir));
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
onReadys.push((connection) => addPending(readDirectoryAsync(connection, dirPath, dir)));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
files: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.File).map(file => file[0]),
|
|
132
|
-
directories: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]),
|
|
133
|
-
};
|
|
134
|
-
}, path => path);
|
|
105
|
+
dir.fileTypes.set(name, undefined);
|
|
106
|
+
if (connection) {
|
|
107
|
+
addPending(statAsync(connection, fsPath, dir));
|
|
135
108
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
109
|
+
else {
|
|
110
|
+
onReadys.push((connection) => addPending(statAsync(connection, fsPath, dir)));
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
function readFile(fsPath) {
|
|
115
|
+
fsPath = resolvePath(fsPath);
|
|
116
|
+
const dir = getDir(path_1.posix.dirname(fsPath));
|
|
117
|
+
const name = path_1.posix.basename(fsPath);
|
|
118
|
+
if (dir.fileTexts.has(name)) {
|
|
119
|
+
return dir.fileTexts.get(name);
|
|
120
|
+
}
|
|
121
|
+
dir.fileTexts.set(name, '');
|
|
122
|
+
if (connection) {
|
|
123
|
+
addPending(readFileAsync(connection, fsPath, dir));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir)));
|
|
127
|
+
}
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
function readDirectory(fsPath, extensions, exclude, include, depth) {
|
|
131
|
+
fsPath = resolvePath(fsPath);
|
|
132
|
+
return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth, dirPath => {
|
|
133
|
+
dirPath = resolvePath(dirPath);
|
|
134
|
+
const dir = getDir(dirPath);
|
|
140
135
|
const files = [...dir.fileTypes];
|
|
141
136
|
if (!dir.searched) {
|
|
142
137
|
dir.searched = true;
|
|
143
138
|
if (connection) {
|
|
144
|
-
addPending(readDirectoryAsync(connection,
|
|
139
|
+
addPending(readDirectoryAsync(connection, dirPath, dir));
|
|
145
140
|
}
|
|
146
141
|
else {
|
|
147
|
-
onReadys.push((connection) => addPending(readDirectoryAsync(connection,
|
|
142
|
+
onReadys.push((connection) => addPending(readDirectoryAsync(connection, dirPath, dir)));
|
|
148
143
|
}
|
|
149
144
|
}
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
return {
|
|
146
|
+
files: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.File).map(file => file[0]),
|
|
147
|
+
directories: files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]),
|
|
148
|
+
};
|
|
149
|
+
}, path => path);
|
|
150
|
+
}
|
|
151
|
+
// for import path completion
|
|
152
|
+
function getDirectories(fsPath) {
|
|
153
|
+
fsPath = resolvePath(fsPath);
|
|
154
|
+
const dir = getDir(fsPath);
|
|
155
|
+
const files = [...dir.fileTypes];
|
|
156
|
+
if (!dir.searched) {
|
|
157
|
+
dir.searched = true;
|
|
158
|
+
if (connection) {
|
|
159
|
+
addPending(readDirectoryAsync(connection, fsPath, dir));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
onReadys.push((connection) => addPending(readDirectoryAsync(connection, fsPath, dir)));
|
|
163
|
+
}
|
|
157
164
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
|
|
166
|
+
}
|
|
167
|
+
function getFsPathUri(fsPath) {
|
|
168
|
+
return vscode_uri_1.URI.file(fsPath).with({
|
|
169
|
+
scheme: rootUri.scheme,
|
|
170
|
+
authority: rootUri.authority,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function statAsync(connection, fsPath, dir) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const uri = getFsPathUri(fsPath);
|
|
176
|
+
const result = yield connection.sendRequest(requests_1.FsStatRequest.type, uri.toString());
|
|
177
|
+
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 = path_1.posix.basename(fsPath);
|
|
179
|
+
dir.fileTypes.set(name, result.type);
|
|
180
|
+
changes.push({
|
|
181
|
+
uri: uri.toString(),
|
|
182
|
+
type: vscode.FileChangeType.Created,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function readFileAsync(connection, fsPath, dir) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
const uri = getFsPathUri(fsPath);
|
|
190
|
+
const text = yield connection.sendRequest(requests_1.FsReadFileRequest.type, uri.toString());
|
|
191
|
+
if (text) {
|
|
192
|
+
const name = path_1.posix.basename(fsPath);
|
|
193
|
+
dir.fileTexts.set(name, text);
|
|
194
|
+
changes.push({
|
|
195
|
+
uri: uri.toString(),
|
|
196
|
+
type: vscode.FileChangeType.Changed,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function readDirectoryAsync(connection, fsPath, dir) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const uri = getFsPathUri(fsPath);
|
|
204
|
+
const result = yield connection.sendRequest(requests_1.FsReadDirectoryRequest.type, uri.toString());
|
|
205
|
+
for (const [name, fileType] of result) {
|
|
206
|
+
if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
|
|
165
207
|
changes.push({
|
|
166
|
-
uri:
|
|
208
|
+
uri: getFsPathUri(path_1.posix.join(fsPath, name)).toString(),
|
|
167
209
|
type: vscode.FileChangeType.Created,
|
|
168
210
|
});
|
|
169
211
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const text = yield connection.sendRequest(requests_1.FsReadFileRequest.type, uri.toString());
|
|
176
|
-
if (text) {
|
|
177
|
-
const name = path_1.posix.basename(fsPath);
|
|
178
|
-
dir.fileTexts.set(name, text);
|
|
179
|
-
changes.push({
|
|
180
|
-
uri: uri.toString(),
|
|
181
|
-
type: vscode.FileChangeType.Changed,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
function readDirectoryAsync(connection, fsPath, dir) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const uri = getFsPathUri(fsPath);
|
|
189
|
-
const result = yield connection.sendRequest(requests_1.FsReadDirectoryRequest.type, uri.toString());
|
|
190
|
-
for (const [name, fileType] of result) {
|
|
191
|
-
if (dir.fileTypes.get(name) !== fileType && (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink)) {
|
|
192
|
-
changes.push({
|
|
193
|
-
uri: getFsPathUri(path_1.posix.join(fsPath, name)).toString(),
|
|
194
|
-
type: vscode.FileChangeType.Created,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
dir.fileTypes.set(name, fileType);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
onDidChangeWatchedFiles: cb => {
|
|
203
|
-
onDidChangeWatchedFilesCb.add(cb);
|
|
204
|
-
return () => onDidChangeWatchedFilesCb.delete(cb);
|
|
205
|
-
},
|
|
206
|
-
};
|
|
212
|
+
dir.fileTypes.set(name, fileType);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
207
217
|
function addPending(p) {
|
|
208
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
219
|
pendings.add(p);
|
|
@@ -2,12 +2,12 @@ import * as shared from '@volar/shared';
|
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
import * as vscode from 'vscode-languageserver';
|
|
4
4
|
import { Project } from './project';
|
|
5
|
-
import { LanguageServerPlugin, RuntimeEnvironment, FileSystemHost,
|
|
5
|
+
import { LanguageServerPlugin, RuntimeEnvironment, FileSystemHost, InitializationOptions } from '../types';
|
|
6
6
|
import { createSnapshots } from './snapshots';
|
|
7
7
|
import { URI } from 'vscode-uri';
|
|
8
8
|
import { ConfigurationHost } from '@volar/vue-language-service';
|
|
9
9
|
export declare const rootTsConfigNames: string[];
|
|
10
|
-
export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, rootUri: URI, ts: typeof import('typescript/lib/tsserverlibrary'), tsLocalized: ts.MapLike<string> | undefined, options:
|
|
10
|
+
export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment, plugins: ReturnType<LanguageServerPlugin>[], fsHost: FileSystemHost, rootUri: URI, ts: typeof import('typescript/lib/tsserverlibrary'), tsLocalized: ts.MapLike<string> | undefined, options: InitializationOptions, documents: ReturnType<typeof createSnapshots>, connection: vscode.Connection, configHost: ConfigurationHost | undefined): Promise<{
|
|
11
11
|
projects: {
|
|
12
12
|
clear: () => void;
|
|
13
13
|
values: () => IterableIterator<Project>;
|
|
@@ -41,7 +41,7 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
|
|
|
41
41
|
}>;
|
|
42
42
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
43
43
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
44
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
44
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
45
45
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
46
46
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
47
47
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
@@ -84,7 +84,7 @@ export declare function createWorkspaceProjects(runtimeEnv: RuntimeEnvironment,
|
|
|
84
84
|
}>;
|
|
85
85
|
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
86
86
|
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
87
|
-
doCompletionResolve: (item: vscode.CompletionItem
|
|
87
|
+
doCompletionResolve: (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
|
|
88
88
|
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
89
89
|
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
90
90
|
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
@@ -88,7 +88,7 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
88
88
|
if (!inferredProject) {
|
|
89
89
|
inferredProject = (() => __awaiter(this, void 0, void 0, function* () {
|
|
90
90
|
const inferOptions = yield (0, inferredCompilerOptions_1.getInferredCompilerOptions)(ts, configHost);
|
|
91
|
-
return (0, project_1.createProject)(runtimeEnv, plugins, fsHost,
|
|
91
|
+
return (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, options, rootUri, inferOptions, tsLocalized, documents, connection, configHost, documentRegistry);
|
|
92
92
|
}))();
|
|
93
93
|
}
|
|
94
94
|
return inferredProject;
|
|
@@ -198,7 +198,7 @@ function createWorkspaceProjects(runtimeEnv, plugins, fsHost, rootUri, ts, tsLoc
|
|
|
198
198
|
function getProjectByCreate(tsConfig) {
|
|
199
199
|
let project = projects.pathGet(rootUri, tsConfig);
|
|
200
200
|
if (!project) {
|
|
201
|
-
project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost,
|
|
201
|
+
project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, options, vscode_uri_1.URI.parse(shared.getUriByPath(rootUri, path.dirname(tsConfig))), tsConfig, tsLocalized, documents, connection, configHost, documentRegistry);
|
|
202
202
|
projects.pathSet(rootUri, tsConfig, project);
|
|
203
203
|
}
|
|
204
204
|
return project;
|