@volar/language-server 1.0.0-alpha.0
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/LICENSE +21 -0
- package/out/browser.d.ts +3 -0
- package/out/browser.js +47 -0
- package/out/features/customFeatures.d.ts +4 -0
- package/out/features/customFeatures.js +83 -0
- package/out/features/documentFeatures.d.ts +4 -0
- package/out/features/documentFeatures.js +73 -0
- package/out/features/languageFeatures.d.ts +4 -0
- package/out/features/languageFeatures.js +274 -0
- package/out/index.d.ts +3 -0
- package/out/index.js +19 -0
- package/out/node.d.ts +3 -0
- package/out/node.js +88 -0
- package/out/registers/registerDocumentFeatures.d.ts +3 -0
- package/out/registers/registerDocumentFeatures.js +30 -0
- package/out/registers/registerlanguageFeatures.d.ts +3 -0
- package/out/registers/registerlanguageFeatures.js +144 -0
- package/out/requests.d.ts +81 -0
- package/out/requests.js +65 -0
- package/out/schemaRequestHandlers/file.d.ts +2 -0
- package/out/schemaRequestHandlers/file.js +12 -0
- package/out/schemaRequestHandlers/http.d.ts +1 -0
- package/out/schemaRequestHandlers/http.js +12 -0
- package/out/server.d.ts +3 -0
- package/out/server.js +99 -0
- package/out/types.d.ts +112 -0
- package/out/types.js +2 -0
- package/out/utils/config.d.ts +2 -0
- package/out/utils/config.js +17 -0
- package/out/utils/configurationHost.d.ts +5 -0
- package/out/utils/configurationHost.js +38 -0
- package/out/utils/documentServiceHost.d.ts +30 -0
- package/out/utils/documentServiceHost.js +51 -0
- package/out/utils/inferredCompilerOptions.d.ts +3 -0
- package/out/utils/inferredCompilerOptions.js +71 -0
- package/out/utils/iterableWeakSet.d.ts +7 -0
- package/out/utils/iterableWeakSet.js +40 -0
- package/out/utils/nodeFileSystemHost.d.ts +3 -0
- package/out/utils/nodeFileSystemHost.js +95 -0
- package/out/utils/project.d.ts +99 -0
- package/out/utils/project.js +273 -0
- package/out/utils/snapshots.d.ts +45 -0
- package/out/utils/snapshots.js +201 -0
- package/out/utils/ts/core.d.ts +83 -0
- package/out/utils/ts/core.js +319 -0
- package/out/utils/ts/corePublic.d.ts +91 -0
- package/out/utils/ts/corePublic.js +50 -0
- package/out/utils/ts/path.d.ts +112 -0
- package/out/utils/ts/path.js +416 -0
- package/out/utils/ts/types.d.ts +129 -0
- package/out/utils/ts/types.js +2 -0
- package/out/utils/ts/utilities.d.ts +7 -0
- package/out/utils/ts/utilities.js +249 -0
- package/out/utils/webFileSystemHost.d.ts +2 -0
- package/out/utils/webFileSystemHost.js +265 -0
- package/out/utils/workspaceProjects.d.ts +120 -0
- package/out/utils/workspaceProjects.js +226 -0
- package/out/utils/workspaces.d.ts +309 -0
- package/out/utils/workspaces.js +154 -0
- package/package.json +27 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.matchFiles = void 0;
|
|
3
|
+
const core_1 = require("./core");
|
|
4
|
+
const path_1 = require("./path");
|
|
5
|
+
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
|
6
|
+
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
|
7
|
+
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
|
|
8
|
+
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
|
|
9
|
+
// proof.
|
|
10
|
+
const reservedCharacterPattern = /[^\w\s\/]/g;
|
|
11
|
+
const wildcardCharCodes = [42 /* CharacterCodes.asterisk */, 63 /* CharacterCodes.question */];
|
|
12
|
+
const commonPackageFolders = ["node_modules", "bower_components", "jspm_packages"];
|
|
13
|
+
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
|
|
14
|
+
const filesMatcher = {
|
|
15
|
+
/**
|
|
16
|
+
* Matches any single directory segment unless it is the last segment and a .min.js file
|
|
17
|
+
* Breakdown:
|
|
18
|
+
* [^./] # matches everything up to the first . character (excluding directory separators)
|
|
19
|
+
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
|
|
20
|
+
*/
|
|
21
|
+
singleAsteriskRegexFragment: "([^./]|(\\.(?!min\\.js$))?)*",
|
|
22
|
+
/**
|
|
23
|
+
* Regex for the ** wildcard. Matches any number of subdirectories. When used for including
|
|
24
|
+
* files or directories, does not match subdirectories that start with a . character
|
|
25
|
+
*/
|
|
26
|
+
doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
|
|
27
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, filesMatcher.singleAsteriskRegexFragment)
|
|
28
|
+
};
|
|
29
|
+
const directoriesMatcher = {
|
|
30
|
+
singleAsteriskRegexFragment: "[^/]*",
|
|
31
|
+
/**
|
|
32
|
+
* Regex for the ** wildcard. Matches any number of subdirectories. When used for including
|
|
33
|
+
* files or directories, does not match subdirectories that start with a . character
|
|
34
|
+
*/
|
|
35
|
+
doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
|
|
36
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, directoriesMatcher.singleAsteriskRegexFragment)
|
|
37
|
+
};
|
|
38
|
+
const excludeMatcher = {
|
|
39
|
+
singleAsteriskRegexFragment: "[^/]*",
|
|
40
|
+
doubleAsteriskRegexFragment: "(/.+?)?",
|
|
41
|
+
replaceWildcardCharacter: match => replaceWildcardCharacter(match, excludeMatcher.singleAsteriskRegexFragment)
|
|
42
|
+
};
|
|
43
|
+
const wildcardMatchers = {
|
|
44
|
+
files: filesMatcher,
|
|
45
|
+
directories: directoriesMatcher,
|
|
46
|
+
exclude: excludeMatcher
|
|
47
|
+
};
|
|
48
|
+
function getRegularExpressionForWildcard(specs, basePath, usage) {
|
|
49
|
+
const patterns = getRegularExpressionsForWildcards(specs, basePath, usage);
|
|
50
|
+
if (!patterns || !patterns.length) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const pattern = patterns.map(pattern => `(${pattern})`).join("|");
|
|
54
|
+
// If excluding, match "foo/bar/baz...", but if including, only allow "foo".
|
|
55
|
+
const terminator = usage === "exclude" ? "($|/)" : "$";
|
|
56
|
+
return `^(${pattern})${terminator}`;
|
|
57
|
+
}
|
|
58
|
+
function getRegularExpressionsForWildcards(specs, basePath, usage) {
|
|
59
|
+
if (specs === undefined || specs.length === 0) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return (0, core_1.flatMap)(specs, spec => spec && getSubPatternFromSpec(spec, basePath, usage, wildcardMatchers[usage]));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An "includes" path "foo" is implicitly a glob "foo/** /*" (without the space) if its last component has no extension,
|
|
66
|
+
* and does not contain any glob characters itself.
|
|
67
|
+
*/
|
|
68
|
+
function isImplicitGlob(lastPathComponent) {
|
|
69
|
+
return !/[.*?]/.test(lastPathComponent);
|
|
70
|
+
}
|
|
71
|
+
function getSubPatternFromSpec(spec, basePath, usage, { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }) {
|
|
72
|
+
let subpattern = "";
|
|
73
|
+
let hasWrittenComponent = false;
|
|
74
|
+
const components = (0, path_1.getNormalizedPathComponents)(spec, basePath);
|
|
75
|
+
const lastComponent = (0, core_1.last)(components);
|
|
76
|
+
if (usage !== "exclude" && lastComponent === "**") {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
// getNormalizedPathComponents includes the separator for the root component.
|
|
80
|
+
// We need to remove to create our regex correctly.
|
|
81
|
+
components[0] = (0, path_1.removeTrailingDirectorySeparator)(components[0]);
|
|
82
|
+
if (isImplicitGlob(lastComponent)) {
|
|
83
|
+
components.push("**", "*");
|
|
84
|
+
}
|
|
85
|
+
let optionalCount = 0;
|
|
86
|
+
for (let component of components) {
|
|
87
|
+
if (component === "**") {
|
|
88
|
+
subpattern += doubleAsteriskRegexFragment;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (usage === "directories") {
|
|
92
|
+
subpattern += "(";
|
|
93
|
+
optionalCount++;
|
|
94
|
+
}
|
|
95
|
+
if (hasWrittenComponent) {
|
|
96
|
+
subpattern += path_1.directorySeparator;
|
|
97
|
+
}
|
|
98
|
+
if (usage !== "exclude") {
|
|
99
|
+
let componentPattern = "";
|
|
100
|
+
// The * and ? wildcards should not match directories or files that start with . if they
|
|
101
|
+
// appear first in a component. Dotted directories and files can be included explicitly
|
|
102
|
+
// like so: **/.*/.*
|
|
103
|
+
if (component.charCodeAt(0) === 42 /* CharacterCodes.asterisk */) {
|
|
104
|
+
componentPattern += "([^./]" + singleAsteriskRegexFragment + ")?";
|
|
105
|
+
component = component.substr(1);
|
|
106
|
+
}
|
|
107
|
+
else if (component.charCodeAt(0) === 63 /* CharacterCodes.question */) {
|
|
108
|
+
componentPattern += "[^./]";
|
|
109
|
+
component = component.substr(1);
|
|
110
|
+
}
|
|
111
|
+
componentPattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
|
|
112
|
+
// Patterns should not include subfolders like node_modules unless they are
|
|
113
|
+
// explicitly included as part of the path.
|
|
114
|
+
//
|
|
115
|
+
// As an optimization, if the component pattern is the same as the component,
|
|
116
|
+
// then there definitely were no wildcard characters and we do not need to
|
|
117
|
+
// add the exclusion pattern.
|
|
118
|
+
if (componentPattern !== component) {
|
|
119
|
+
subpattern += implicitExcludePathRegexPattern;
|
|
120
|
+
}
|
|
121
|
+
subpattern += componentPattern;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
hasWrittenComponent = true;
|
|
128
|
+
}
|
|
129
|
+
while (optionalCount > 0) {
|
|
130
|
+
subpattern += ")?";
|
|
131
|
+
optionalCount--;
|
|
132
|
+
}
|
|
133
|
+
return subpattern;
|
|
134
|
+
}
|
|
135
|
+
function replaceWildcardCharacter(match, singleAsteriskRegexFragment) {
|
|
136
|
+
return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
|
|
137
|
+
}
|
|
138
|
+
/** @param path directory of the tsconfig.json */
|
|
139
|
+
function getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory) {
|
|
140
|
+
path = (0, path_1.normalizePath)(path);
|
|
141
|
+
currentDirectory = (0, path_1.normalizePath)(currentDirectory);
|
|
142
|
+
const absolutePath = (0, path_1.combinePaths)(currentDirectory, path);
|
|
143
|
+
return {
|
|
144
|
+
includeFilePatterns: (0, core_1.map)(getRegularExpressionsForWildcards(includes, absolutePath, "files"), pattern => `^${pattern}$`),
|
|
145
|
+
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
|
|
146
|
+
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
|
|
147
|
+
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
|
|
148
|
+
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function getRegexFromPattern(pattern, useCaseSensitiveFileNames) {
|
|
152
|
+
return new RegExp(pattern, useCaseSensitiveFileNames ? "" : "i");
|
|
153
|
+
}
|
|
154
|
+
/** @param path directory of the tsconfig.json */
|
|
155
|
+
function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath) {
|
|
156
|
+
path = (0, path_1.normalizePath)(path);
|
|
157
|
+
currentDirectory = (0, path_1.normalizePath)(currentDirectory);
|
|
158
|
+
const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
|
|
159
|
+
const includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map(pattern => getRegexFromPattern(pattern, useCaseSensitiveFileNames));
|
|
160
|
+
const includeDirectoryRegex = patterns.includeDirectoryPattern && getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames);
|
|
161
|
+
const excludeRegex = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames);
|
|
162
|
+
// Associate an array of results with each include regex. This keeps results in order of the "include" order.
|
|
163
|
+
// If there are no "includes", then just put everything in results[0].
|
|
164
|
+
const results = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
|
|
165
|
+
const visited = new Map();
|
|
166
|
+
const toCanonical = (0, core_1.createGetCanonicalFileName)(useCaseSensitiveFileNames);
|
|
167
|
+
for (const basePath of patterns.basePaths) {
|
|
168
|
+
visitDirectory(basePath, (0, path_1.combinePaths)(currentDirectory, basePath), depth);
|
|
169
|
+
}
|
|
170
|
+
return (0, core_1.flatten)(results);
|
|
171
|
+
function visitDirectory(path, absolutePath, depth) {
|
|
172
|
+
const canonicalPath = toCanonical(realpath(absolutePath));
|
|
173
|
+
if (visited.has(canonicalPath))
|
|
174
|
+
return;
|
|
175
|
+
visited.set(canonicalPath, true);
|
|
176
|
+
const { files, directories } = getFileSystemEntries(path);
|
|
177
|
+
for (const current of (0, core_1.sort)(files, core_1.compareStringsCaseSensitive)) {
|
|
178
|
+
const name = (0, path_1.combinePaths)(path, current);
|
|
179
|
+
const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
|
|
180
|
+
if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions))
|
|
181
|
+
continue;
|
|
182
|
+
if (excludeRegex && excludeRegex.test(absoluteName))
|
|
183
|
+
continue;
|
|
184
|
+
if (!includeFileRegexes) {
|
|
185
|
+
results[0].push(name);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const includeIndex = (0, core_1.findIndex)(includeFileRegexes, re => re.test(absoluteName));
|
|
189
|
+
if (includeIndex !== -1) {
|
|
190
|
+
results[includeIndex].push(name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (depth !== undefined) {
|
|
195
|
+
depth--;
|
|
196
|
+
if (depth === 0) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const current of (0, core_1.sort)(directories, core_1.compareStringsCaseSensitive)) {
|
|
201
|
+
const name = (0, path_1.combinePaths)(path, current);
|
|
202
|
+
const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
|
|
203
|
+
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
|
|
204
|
+
(!excludeRegex || !excludeRegex.test(absoluteName))) {
|
|
205
|
+
visitDirectory(name, absoluteName, depth);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.matchFiles = matchFiles;
|
|
211
|
+
/**
|
|
212
|
+
* Computes the unique non-wildcard base paths amongst the provided include patterns.
|
|
213
|
+
*/
|
|
214
|
+
function getBasePaths(path, includes, useCaseSensitiveFileNames) {
|
|
215
|
+
// Storage for our results in the form of literal paths (e.g. the paths as written by the user).
|
|
216
|
+
const basePaths = [path];
|
|
217
|
+
if (includes) {
|
|
218
|
+
// Storage for literal base paths amongst the include patterns.
|
|
219
|
+
const includeBasePaths = [];
|
|
220
|
+
for (const include of includes) {
|
|
221
|
+
// We also need to check the relative paths by converting them to absolute and normalizing
|
|
222
|
+
// in case they escape the base path (e.g "..\somedirectory")
|
|
223
|
+
const absolute = (0, path_1.isRootedDiskPath)(include) ? include : (0, path_1.normalizePath)((0, path_1.combinePaths)(path, include));
|
|
224
|
+
// Append the literal and canonical candidate base paths.
|
|
225
|
+
includeBasePaths.push(getIncludeBasePath(absolute));
|
|
226
|
+
}
|
|
227
|
+
// Sort the offsets array using either the literal or canonical path representations.
|
|
228
|
+
includeBasePaths.sort((0, core_1.getStringComparer)(!useCaseSensitiveFileNames));
|
|
229
|
+
// Iterate over each include base path and include unique base paths that are not a
|
|
230
|
+
// subpath of an existing base path
|
|
231
|
+
for (const includeBasePath of includeBasePaths) {
|
|
232
|
+
if ((0, core_1.every)(basePaths, basePath => !(0, path_1.containsPath)(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
|
|
233
|
+
basePaths.push(includeBasePath);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return basePaths;
|
|
238
|
+
}
|
|
239
|
+
function getIncludeBasePath(absolute) {
|
|
240
|
+
const wildcardOffset = (0, core_1.indexOfAnyCharCode)(absolute, wildcardCharCodes);
|
|
241
|
+
if (wildcardOffset < 0) {
|
|
242
|
+
// No "*" or "?" in the path
|
|
243
|
+
return !(0, path_1.hasExtension)(absolute)
|
|
244
|
+
? absolute
|
|
245
|
+
: (0, path_1.removeTrailingDirectorySeparator)((0, path_1.getDirectoryPath)(absolute));
|
|
246
|
+
}
|
|
247
|
+
return absolute.substring(0, absolute.lastIndexOf(path_1.directorySeparator, wildcardOffset));
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createWebFileSystemHost = void 0;
|
|
12
|
+
const vscode = require("vscode-languageserver");
|
|
13
|
+
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
14
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const requests_1 = require("../requests");
|
|
17
|
+
const utilities_1 = require("./ts/utilities");
|
|
18
|
+
let currentCwd = '/';
|
|
19
|
+
function createWebFileSystemHost() {
|
|
20
|
+
const onDidChangeWatchedFilesCb = new Set();
|
|
21
|
+
const root = {
|
|
22
|
+
dirs: new Map(),
|
|
23
|
+
fileTexts: new Map(),
|
|
24
|
+
fileTypes: new Map(),
|
|
25
|
+
searched: false,
|
|
26
|
+
};
|
|
27
|
+
const pendings = new Set();
|
|
28
|
+
const changes = [];
|
|
29
|
+
const onReadys = [];
|
|
30
|
+
let checking = false;
|
|
31
|
+
let connection;
|
|
32
|
+
return {
|
|
33
|
+
ready(_connection) {
|
|
34
|
+
connection = _connection;
|
|
35
|
+
connection.onDidChangeWatchedFiles(params => {
|
|
36
|
+
for (const change of params.changes) {
|
|
37
|
+
const fsPath = vscode_uri_1.URI.parse(change.uri).fsPath;
|
|
38
|
+
const dir = getDir(path_1.posix.dirname(fsPath));
|
|
39
|
+
const name = path_1.posix.basename(fsPath);
|
|
40
|
+
if (change.type === vscode.FileChangeType.Created) {
|
|
41
|
+
dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
|
|
42
|
+
}
|
|
43
|
+
else if (change.type === vscode.FileChangeType.Changed) {
|
|
44
|
+
dir.fileTexts.delete(name);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
dir.fileTypes.delete(name);
|
|
48
|
+
dir.fileTexts.delete(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
fireChanges(params, 'lsp');
|
|
52
|
+
});
|
|
53
|
+
for (const cb of onReadys) {
|
|
54
|
+
cb(connection);
|
|
55
|
+
}
|
|
56
|
+
onReadys.length = 0;
|
|
57
|
+
},
|
|
58
|
+
clearCache() {
|
|
59
|
+
root.dirs.clear();
|
|
60
|
+
root.fileTexts.clear();
|
|
61
|
+
root.fileTypes.clear();
|
|
62
|
+
root.searched = false;
|
|
63
|
+
},
|
|
64
|
+
getWorkspaceFileSystem(rootUri) {
|
|
65
|
+
return {
|
|
66
|
+
newLine: '\n',
|
|
67
|
+
useCaseSensitiveFileNames: false,
|
|
68
|
+
getCurrentDirectory: () => rootUri.fsPath,
|
|
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);
|
|
82
|
+
}
|
|
83
|
+
function fileExists(fsPath) {
|
|
84
|
+
fsPath = resolvePath(fsPath);
|
|
85
|
+
const dir = getDir(path_1.posix.dirname(fsPath));
|
|
86
|
+
const name = path_1.posix.basename(fsPath);
|
|
87
|
+
if (dir.fileTypes.has(name)) {
|
|
88
|
+
return dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.File || dir.fileTypes.get(name) === vscode_html_languageservice_1.FileType.SymbolicLink;
|
|
89
|
+
}
|
|
90
|
+
dir.fileTypes.set(name, undefined);
|
|
91
|
+
if (connection) {
|
|
92
|
+
addPending(statAsync(connection, fsPath, dir));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
onReadys.push((connection) => addPending(statAsync(connection, fsPath, dir)));
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
function readFile(fsPath) {
|
|
100
|
+
fsPath = resolvePath(fsPath);
|
|
101
|
+
const dir = getDir(path_1.posix.dirname(fsPath));
|
|
102
|
+
const name = path_1.posix.basename(fsPath);
|
|
103
|
+
if (dir.fileTexts.has(name)) {
|
|
104
|
+
return dir.fileTexts.get(name);
|
|
105
|
+
}
|
|
106
|
+
dir.fileTexts.set(name, '');
|
|
107
|
+
if (connection) {
|
|
108
|
+
addPending(readFileAsync(connection, fsPath, dir));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir)));
|
|
112
|
+
}
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
function readDirectory(fsPath, extensions, exclude, include, depth) {
|
|
116
|
+
fsPath = resolvePath(fsPath);
|
|
117
|
+
return (0, utilities_1.matchFiles)(fsPath, extensions, exclude, include, false, rootUri.fsPath, depth, dirPath => {
|
|
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);
|
|
135
|
+
}
|
|
136
|
+
// for import path completion
|
|
137
|
+
function getDirectories(fsPath) {
|
|
138
|
+
fsPath = resolvePath(fsPath);
|
|
139
|
+
const dir = getDir(fsPath);
|
|
140
|
+
const files = [...dir.fileTypes];
|
|
141
|
+
if (!dir.searched) {
|
|
142
|
+
dir.searched = true;
|
|
143
|
+
if (connection) {
|
|
144
|
+
addPending(readDirectoryAsync(connection, fsPath, dir));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
onReadys.push((connection) => addPending(readDirectoryAsync(connection, fsPath, dir)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return files.filter(file => file[1] === vscode_html_languageservice_1.FileType.Directory).map(file => file[0]);
|
|
151
|
+
}
|
|
152
|
+
function getFsPathUri(fsPath) {
|
|
153
|
+
return vscode_uri_1.URI.file(fsPath).with({
|
|
154
|
+
scheme: rootUri.scheme,
|
|
155
|
+
authority: rootUri.authority,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function statAsync(connection, fsPath, dir) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const uri = getFsPathUri(fsPath);
|
|
161
|
+
const result = yield connection.sendRequest(requests_1.FsStatRequest.type, uri.toString());
|
|
162
|
+
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) {
|
|
163
|
+
const name = path_1.posix.basename(fsPath);
|
|
164
|
+
dir.fileTypes.set(name, result.type);
|
|
165
|
+
changes.push({
|
|
166
|
+
uri: uri.toString(),
|
|
167
|
+
type: vscode.FileChangeType.Created,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function readFileAsync(connection, fsPath, dir) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const uri = getFsPathUri(fsPath);
|
|
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
|
+
};
|
|
207
|
+
function addPending(p) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
pendings.add(p);
|
|
210
|
+
if (checking === false) {
|
|
211
|
+
checking = true;
|
|
212
|
+
while (pendings.size > 0) {
|
|
213
|
+
const _pendings = [...pendings];
|
|
214
|
+
pendings.clear();
|
|
215
|
+
yield Promise.all(_pendings);
|
|
216
|
+
}
|
|
217
|
+
if (changes.length) {
|
|
218
|
+
fireChanges({ changes: [...changes] }, 'web-cache-updated');
|
|
219
|
+
changes.length = 0;
|
|
220
|
+
}
|
|
221
|
+
checking = false;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function fireChanges(params, reason) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
for (const cb of [...onDidChangeWatchedFilesCb]) {
|
|
228
|
+
if (onDidChangeWatchedFilesCb.has(cb)) {
|
|
229
|
+
yield cb(params, reason);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function getDir(dirPath) {
|
|
235
|
+
const dirNames = [];
|
|
236
|
+
let currentDirPath = dirPath;
|
|
237
|
+
let currentDirName = path_1.posix.basename(currentDirPath);
|
|
238
|
+
while (currentDirName !== '') {
|
|
239
|
+
dirNames.push(currentDirName);
|
|
240
|
+
currentDirPath = path_1.posix.dirname(currentDirPath);
|
|
241
|
+
currentDirName = path_1.posix.basename(currentDirPath);
|
|
242
|
+
}
|
|
243
|
+
let currentDir = root;
|
|
244
|
+
for (let i = dirNames.length - 1; i >= 0; i--) {
|
|
245
|
+
const nextDirName = dirNames[i];
|
|
246
|
+
currentDir = getDirFromDir(currentDir, nextDirName);
|
|
247
|
+
}
|
|
248
|
+
return currentDir;
|
|
249
|
+
}
|
|
250
|
+
function getDirFromDir(dir, name) {
|
|
251
|
+
let target = dir.dirs.get(name);
|
|
252
|
+
if (!target) {
|
|
253
|
+
target = {
|
|
254
|
+
dirs: new Map(),
|
|
255
|
+
fileTexts: new Map(),
|
|
256
|
+
fileTypes: new Map(),
|
|
257
|
+
searched: false,
|
|
258
|
+
};
|
|
259
|
+
dir.dirs.set(name, target);
|
|
260
|
+
}
|
|
261
|
+
return target;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
exports.createWebFileSystemHost = createWebFileSystemHost;
|
|
265
|
+
//# sourceMappingURL=webFileSystemHost.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as shared from '@volar/shared';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import * as vscode from 'vscode-languageserver';
|
|
4
|
+
import { Project } from './project';
|
|
5
|
+
import { LanguageServerPlugin, RuntimeEnvironment, FileSystemHost, ServerInitializationOptions } from '../types';
|
|
6
|
+
import { createSnapshots } from './snapshots';
|
|
7
|
+
import { URI } from 'vscode-uri';
|
|
8
|
+
import { ConfigurationHost } from '@volar/vue-language-service';
|
|
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: ServerInitializationOptions, documents: ReturnType<typeof createSnapshots>, connection: vscode.Connection, configHost: ConfigurationHost | undefined): Promise<{
|
|
11
|
+
projects: {
|
|
12
|
+
clear: () => void;
|
|
13
|
+
values: () => IterableIterator<Project>;
|
|
14
|
+
uriDelete: (_uri: string) => boolean;
|
|
15
|
+
uriGet: (_uri: string) => Project | undefined;
|
|
16
|
+
uriHas: (_uri: string) => boolean;
|
|
17
|
+
uriSet: (_uri: string, item: Project) => void;
|
|
18
|
+
pathDelete: (rootUri: shared._.URI, path: string) => boolean;
|
|
19
|
+
pathGet: (rootUri: shared._.URI, path: string) => Project | undefined;
|
|
20
|
+
pathHas: (rootUri: shared._.URI, path: string) => Project | undefined;
|
|
21
|
+
pathSet: (rootUri: shared._.URI, path: string, item: Project) => void;
|
|
22
|
+
};
|
|
23
|
+
getProjectAndTsConfig: (uri: string) => Promise<{
|
|
24
|
+
tsconfig: string;
|
|
25
|
+
project: {
|
|
26
|
+
getLanguageService: () => {
|
|
27
|
+
doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken | undefined) => Promise<vscode.Diagnostic[]>;
|
|
28
|
+
findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
29
|
+
findFileReferences: (uri: string) => import("@volar/language-service").NullableResult<vscode.Location[]>;
|
|
30
|
+
findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
31
|
+
findTypeDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
32
|
+
findImplementations: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
33
|
+
prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
|
|
34
|
+
doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
35
|
+
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
36
|
+
getSemanticTokens: (uri: string, range?: vscode.Range | undefined, cancleToken?: vscode.CancellationToken | undefined, reportProgress?: ((tokens: import("@volar/vue-language-service").SemanticToken[]) => void) | undefined) => Promise<import("@volar/vue-language-service").SemanticToken[] | undefined> | undefined;
|
|
37
|
+
doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
|
|
38
|
+
doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
|
|
39
|
+
isIncomplete: boolean;
|
|
40
|
+
items: vscode.CompletionItem[];
|
|
41
|
+
}>;
|
|
42
|
+
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
43
|
+
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
44
|
+
doCompletionResolve: (item: vscode.CompletionItem, newPosition?: vscode.Position | undefined) => Promise<vscode.CompletionItem>;
|
|
45
|
+
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
46
|
+
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
47
|
+
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
48
|
+
findDocumentHighlights: (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>;
|
|
49
|
+
findDocumentLinks: (uri: string) => Promise<vscode.DocumentLink[]>;
|
|
50
|
+
findWorkspaceSymbols: (query: string) => Promise<vscode.SymbolInformation[]>;
|
|
51
|
+
doAutoInsert: (uri: string, position: vscode.Position, autoInsertContext: {
|
|
52
|
+
lastChange: {
|
|
53
|
+
range: vscode.Range;
|
|
54
|
+
rangeOffset: number;
|
|
55
|
+
rangeLength: number;
|
|
56
|
+
text: string;
|
|
57
|
+
};
|
|
58
|
+
}) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
|
|
59
|
+
doExecuteCommand: (command: string, args: import("@volar/vue-language-service").ExecutePluginCommandArgs, executeCommandContext: import("@volar/language-service").ExecuteCommandContext) => Promise<void>;
|
|
60
|
+
getInlayHints: (uri: string, range: vscode.Range) => Promise<vscode.InlayHint[] | undefined>;
|
|
61
|
+
callHierarchy: {
|
|
62
|
+
doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>;
|
|
63
|
+
getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>;
|
|
64
|
+
getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>;
|
|
65
|
+
};
|
|
66
|
+
dispose: () => void;
|
|
67
|
+
context: import("@volar/language-service").LanguageServiceRuntimeContext;
|
|
68
|
+
};
|
|
69
|
+
getLanguageServiceDontCreate: () => {
|
|
70
|
+
doValidation: (uri: string, response?: ((result: vscode.Diagnostic[]) => void) | undefined, cancellationToken?: vscode.CancellationToken | undefined) => Promise<vscode.Diagnostic[]>;
|
|
71
|
+
findReferences: (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
|
|
72
|
+
findFileReferences: (uri: string) => import("@volar/language-service").NullableResult<vscode.Location[]>;
|
|
73
|
+
findDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
74
|
+
findTypeDefinition: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
75
|
+
findImplementations: (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
|
|
76
|
+
prepareRename: (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
|
|
77
|
+
doRename: (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
78
|
+
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
79
|
+
getSemanticTokens: (uri: string, range?: vscode.Range | undefined, cancleToken?: vscode.CancellationToken | undefined, reportProgress?: ((tokens: import("@volar/vue-language-service").SemanticToken[]) => void) | undefined) => Promise<import("@volar/vue-language-service").SemanticToken[] | undefined> | undefined;
|
|
80
|
+
doHover: (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
|
|
81
|
+
doComplete: (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext | undefined) => Promise<{
|
|
82
|
+
isIncomplete: boolean;
|
|
83
|
+
items: vscode.CompletionItem[];
|
|
84
|
+
}>;
|
|
85
|
+
doCodeActions: (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>;
|
|
86
|
+
doCodeActionResolve: (item: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
87
|
+
doCompletionResolve: (item: vscode.CompletionItem, newPosition?: vscode.Position | undefined) => Promise<vscode.CompletionItem>;
|
|
88
|
+
getSignatureHelp: (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext | undefined) => Promise<vscode.SignatureHelp | undefined>;
|
|
89
|
+
doCodeLens: (uri: string) => Promise<vscode.CodeLens[]>;
|
|
90
|
+
doCodeLensResolve: (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
|
|
91
|
+
findDocumentHighlights: (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>;
|
|
92
|
+
findDocumentLinks: (uri: string) => Promise<vscode.DocumentLink[]>;
|
|
93
|
+
findWorkspaceSymbols: (query: string) => Promise<vscode.SymbolInformation[]>;
|
|
94
|
+
doAutoInsert: (uri: string, position: vscode.Position, autoInsertContext: {
|
|
95
|
+
lastChange: {
|
|
96
|
+
range: vscode.Range;
|
|
97
|
+
rangeOffset: number;
|
|
98
|
+
rangeLength: number;
|
|
99
|
+
text: string;
|
|
100
|
+
};
|
|
101
|
+
}) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>;
|
|
102
|
+
doExecuteCommand: (command: string, args: import("@volar/vue-language-service").ExecutePluginCommandArgs, executeCommandContext: import("@volar/language-service").ExecuteCommandContext) => Promise<void>;
|
|
103
|
+
getInlayHints: (uri: string, range: vscode.Range) => Promise<vscode.InlayHint[] | undefined>;
|
|
104
|
+
callHierarchy: {
|
|
105
|
+
doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>;
|
|
106
|
+
getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>;
|
|
107
|
+
getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>;
|
|
108
|
+
};
|
|
109
|
+
dispose: () => void;
|
|
110
|
+
context: import("@volar/language-service").LanguageServiceRuntimeContext;
|
|
111
|
+
} | undefined;
|
|
112
|
+
getParsedCommandLine: () => ts.ParsedCommandLine;
|
|
113
|
+
dispose: () => void;
|
|
114
|
+
};
|
|
115
|
+
} | undefined>;
|
|
116
|
+
getInferredProject: () => Project;
|
|
117
|
+
reload: () => void;
|
|
118
|
+
dispose(): void;
|
|
119
|
+
}>;
|
|
120
|
+
export declare function sortTsConfigs(fsPath: string, a: string, b: string): number;
|