@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,273 @@
|
|
|
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.createProject = void 0;
|
|
12
|
+
const shared = require("@volar/shared");
|
|
13
|
+
const embeddedLS = require("@volar/language-service");
|
|
14
|
+
const embedded = require("@volar/language-core");
|
|
15
|
+
const vscode = require("vscode-languageserver");
|
|
16
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
17
|
+
const config_1 = require("./config");
|
|
18
|
+
const requests_1 = require("../requests");
|
|
19
|
+
const upath = require("upath");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
function createProject(runtimeEnv, plugins, fsHost, sys, ts, options, rootUri, rootPath, tsConfig, tsLocalized, documents, connection, configHost) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let typeRootVersion = 0;
|
|
24
|
+
let projectVersion = 0;
|
|
25
|
+
let vueLs;
|
|
26
|
+
let parsedCommandLine = createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins);
|
|
27
|
+
const scripts = shared.createUriMap();
|
|
28
|
+
const languageServiceHost = createLanguageServiceHost();
|
|
29
|
+
const disposeWatchEvent = fsHost.onDidChangeWatchedFiles(params => {
|
|
30
|
+
onWorkspaceFilesChanged(params.changes);
|
|
31
|
+
});
|
|
32
|
+
const disposeDocChange = documents.onDidChangeContent(params => {
|
|
33
|
+
projectVersion++;
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
getLanguageService,
|
|
37
|
+
getLanguageServiceDontCreate: () => vueLs,
|
|
38
|
+
getParsedCommandLine: () => parsedCommandLine,
|
|
39
|
+
dispose,
|
|
40
|
+
};
|
|
41
|
+
function getLanguageService() {
|
|
42
|
+
if (!vueLs) {
|
|
43
|
+
const languageModules = plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.languageService) === null || _a === void 0 ? void 0 : _a.getLanguageModules) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost)) !== null && _c !== void 0 ? _c : []; }).flat();
|
|
44
|
+
const languageContext = embedded.createEmbeddedLanguageServiceHost(languageServiceHost, languageModules);
|
|
45
|
+
const languageServiceContext = embeddedLS.createLanguageServiceContext({
|
|
46
|
+
host: languageServiceHost,
|
|
47
|
+
context: languageContext,
|
|
48
|
+
getPlugins() {
|
|
49
|
+
return [
|
|
50
|
+
...(0, config_1.loadCustomPlugins)(languageServiceHost.getCurrentDirectory()),
|
|
51
|
+
...plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.languageService) === null || _a === void 0 ? void 0 : _a.getServicePlugins) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost, vueLs)) !== null && _c !== void 0 ? _c : []; }).flat(),
|
|
52
|
+
];
|
|
53
|
+
},
|
|
54
|
+
env: {
|
|
55
|
+
rootUri,
|
|
56
|
+
configurationHost: configHost,
|
|
57
|
+
fileSystemProvider: runtimeEnv.fileSystemProvide,
|
|
58
|
+
documentContext: getHTMLDocumentContext(ts, languageServiceHost),
|
|
59
|
+
schemaRequestService: uri => {
|
|
60
|
+
var _a;
|
|
61
|
+
const protocol = uri.substring(0, uri.indexOf(':'));
|
|
62
|
+
const builtInHandler = runtimeEnv.schemaRequestHandlers[protocol];
|
|
63
|
+
if (builtInHandler) {
|
|
64
|
+
return builtInHandler(uri);
|
|
65
|
+
}
|
|
66
|
+
if (typeof options === 'object' && ((_a = options.languageFeatures) === null || _a === void 0 ? void 0 : _a.schemaRequestService)) {
|
|
67
|
+
return connection.sendRequest(requests_1.GetDocumentContentRequest.type, { uri }).then(responseText => {
|
|
68
|
+
return responseText;
|
|
69
|
+
}, error => {
|
|
70
|
+
return Promise.reject(error.message);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return Promise.reject('clientHandledGetDocumentContentRequest is false');
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
vueLs = embeddedLS.createLanguageService(languageServiceContext);
|
|
80
|
+
}
|
|
81
|
+
return vueLs;
|
|
82
|
+
}
|
|
83
|
+
function onWorkspaceFilesChanged(changes) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
for (const change of changes) {
|
|
86
|
+
const script = scripts.uriGet(change.uri);
|
|
87
|
+
if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
|
|
88
|
+
if (script.version >= 0) {
|
|
89
|
+
script.version = -1;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
script.version--;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (script && change.type === vscode.FileChangeType.Deleted) {
|
|
96
|
+
scripts.uriDelete(change.uri);
|
|
97
|
+
}
|
|
98
|
+
if (script) {
|
|
99
|
+
projectVersion++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
|
|
103
|
+
const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
|
|
104
|
+
if (creates.length || deletes.length) {
|
|
105
|
+
parsedCommandLine = createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins);
|
|
106
|
+
typeRootVersion++;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function createLanguageServiceHost() {
|
|
111
|
+
var _a;
|
|
112
|
+
let host = {
|
|
113
|
+
// ts
|
|
114
|
+
getNewLine: () => sys.newLine,
|
|
115
|
+
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
|
116
|
+
readFile: sys.readFile,
|
|
117
|
+
writeFile: sys.writeFile,
|
|
118
|
+
directoryExists: sys.directoryExists,
|
|
119
|
+
getDirectories: sys.getDirectories,
|
|
120
|
+
readDirectory: sys.readDirectory,
|
|
121
|
+
realpath: sys.realpath,
|
|
122
|
+
fileExists: sys.fileExists,
|
|
123
|
+
getCurrentDirectory: () => rootPath,
|
|
124
|
+
getProjectReferences: () => parsedCommandLine.projectReferences,
|
|
125
|
+
// custom
|
|
126
|
+
getDefaultLibFileName: options => {
|
|
127
|
+
try {
|
|
128
|
+
return ts.getDefaultLibFilePath(options);
|
|
129
|
+
}
|
|
130
|
+
catch (_a) {
|
|
131
|
+
return sys.resolvePath('node_modules/typescript/lib/' + ts.getDefaultLibFileName(options)); // web
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
getProjectVersion: () => projectVersion.toString(),
|
|
135
|
+
getTypeRootsVersion: () => typeRootVersion,
|
|
136
|
+
getScriptFileNames: () => {
|
|
137
|
+
const fileNames = new Set(parsedCommandLine.fileNames);
|
|
138
|
+
for (const script of scripts.values()) {
|
|
139
|
+
fileNames.add(script.fileName);
|
|
140
|
+
}
|
|
141
|
+
return [...fileNames];
|
|
142
|
+
},
|
|
143
|
+
getCompilationSettings: () => parsedCommandLine.options,
|
|
144
|
+
getScriptVersion,
|
|
145
|
+
getScriptSnapshot,
|
|
146
|
+
getTypeScriptModule: () => ts,
|
|
147
|
+
};
|
|
148
|
+
if (tsLocalized) {
|
|
149
|
+
host.getLocalizedDiagnosticMessages = () => tsLocalized;
|
|
150
|
+
}
|
|
151
|
+
for (const plugin of plugins) {
|
|
152
|
+
if ((_a = plugin.languageService) === null || _a === void 0 ? void 0 : _a.resolveLanguageServiceHost) {
|
|
153
|
+
host = plugin.languageService.resolveLanguageServiceHost(ts, sys, tsConfig, host);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return host;
|
|
157
|
+
function getScriptVersion(fileName) {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
const doc = documents.data.pathGet(rootUri, fileName);
|
|
160
|
+
if (doc) {
|
|
161
|
+
return doc.version.toString();
|
|
162
|
+
}
|
|
163
|
+
return (_b = (_a = scripts.pathGet(rootUri, fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : '';
|
|
164
|
+
}
|
|
165
|
+
function getScriptSnapshot(fileName) {
|
|
166
|
+
const doc = documents.data.pathGet(rootUri, fileName);
|
|
167
|
+
if (doc) {
|
|
168
|
+
return doc.getSnapshot();
|
|
169
|
+
}
|
|
170
|
+
const script = scripts.pathGet(rootUri, fileName);
|
|
171
|
+
if (script && script.snapshotVersion === script.version) {
|
|
172
|
+
return script.snapshot;
|
|
173
|
+
}
|
|
174
|
+
if (sys.fileExists(fileName)) {
|
|
175
|
+
const text = sys.readFile(fileName, 'utf8');
|
|
176
|
+
if (text !== undefined) {
|
|
177
|
+
const snapshot = ts.ScriptSnapshot.fromString(text);
|
|
178
|
+
if (script) {
|
|
179
|
+
script.snapshot = snapshot;
|
|
180
|
+
script.snapshotVersion = script.version;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
scripts.pathSet(rootUri, fileName, {
|
|
184
|
+
version: -1,
|
|
185
|
+
fileName: fileName,
|
|
186
|
+
snapshot: snapshot,
|
|
187
|
+
snapshotVersion: -1,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return snapshot;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function dispose() {
|
|
196
|
+
vueLs === null || vueLs === void 0 ? void 0 : vueLs.dispose();
|
|
197
|
+
scripts.clear();
|
|
198
|
+
disposeWatchEvent();
|
|
199
|
+
disposeDocChange();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
exports.createProject = createProject;
|
|
204
|
+
function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
|
|
205
|
+
const extraExts = plugins.map(plugin => plugin.extensions).flat();
|
|
206
|
+
try {
|
|
207
|
+
const parseConfigHost = {
|
|
208
|
+
useCaseSensitiveFileNames: sys.useCaseSensitiveFileNames,
|
|
209
|
+
readDirectory: (path, extensions, exclude, include, depth) => {
|
|
210
|
+
return sys.readDirectory(path, [...extensions, ...extraExts], exclude, include, depth);
|
|
211
|
+
},
|
|
212
|
+
fileExists: sys.fileExists,
|
|
213
|
+
readFile: sys.readFile,
|
|
214
|
+
};
|
|
215
|
+
let content;
|
|
216
|
+
if (typeof tsConfig === 'string') {
|
|
217
|
+
const config = ts.readJsonConfigFile(tsConfig, parseConfigHost.readFile);
|
|
218
|
+
content = ts.parseJsonSourceFileConfigFileContent(config, parseConfigHost, path_1.posix.dirname(tsConfig), {}, path_1.posix.basename(tsConfig));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
content = ts.parseJsonConfigFileContent({}, parseConfigHost, rootPath, tsConfig, 'jsconfig.json');
|
|
222
|
+
}
|
|
223
|
+
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
|
224
|
+
// https://github.com/microsoft/TypeScript/issues/30457
|
|
225
|
+
// patching ts server broke with outDir + rootDir + composite/incremental
|
|
226
|
+
content.options.outDir = undefined;
|
|
227
|
+
content.fileNames = content.fileNames.map(shared.normalizeFileName);
|
|
228
|
+
return content;
|
|
229
|
+
}
|
|
230
|
+
catch (_a) {
|
|
231
|
+
// will be failed if web fs host first result not ready
|
|
232
|
+
return {
|
|
233
|
+
errors: [],
|
|
234
|
+
fileNames: [],
|
|
235
|
+
options: {},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function getHTMLDocumentContext(ts, host) {
|
|
240
|
+
const documentContext = {
|
|
241
|
+
resolveReference(ref, base) {
|
|
242
|
+
var _a, _b;
|
|
243
|
+
const isUri = base.indexOf('://') >= 0;
|
|
244
|
+
const resolveResult = ts.resolveModuleName(ref, isUri ? shared.getPathOfUri(base) : base, host.getCompilationSettings(), host);
|
|
245
|
+
const failedLookupLocations = resolveResult.failedLookupLocations;
|
|
246
|
+
const dirs = new Set();
|
|
247
|
+
for (const failed of failedLookupLocations) {
|
|
248
|
+
let path = failed;
|
|
249
|
+
const fileName = upath.basename(path);
|
|
250
|
+
if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
|
|
251
|
+
dirs.add(upath.dirname(path));
|
|
252
|
+
}
|
|
253
|
+
if (path.endsWith('.d.ts')) {
|
|
254
|
+
path = path.substring(0, path.length - '.d.ts'.length);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (host.fileExists(path)) {
|
|
260
|
+
return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base), path) : path;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
for (const dir of dirs) {
|
|
264
|
+
if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
|
|
265
|
+
return isUri ? shared.getUriByPath(vscode_uri_1.URI.parse(base), dir) : dir;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
return documentContext;
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import * as vscode from 'vscode-languageserver';
|
|
3
|
+
import * as shared from '@volar/shared';
|
|
4
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
5
|
+
interface IncrementalScriptSnapshotChange {
|
|
6
|
+
applyed: boolean;
|
|
7
|
+
changeRange: ts.TextChangeRange | undefined;
|
|
8
|
+
version: number;
|
|
9
|
+
contentChange: {
|
|
10
|
+
range: vscode.Range;
|
|
11
|
+
text: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
snapshot: WeakRef<ts.IScriptSnapshot> | undefined;
|
|
14
|
+
}
|
|
15
|
+
declare class IncrementalScriptSnapshot {
|
|
16
|
+
private document;
|
|
17
|
+
uri: string;
|
|
18
|
+
changes: IncrementalScriptSnapshotChange[];
|
|
19
|
+
constructor(uri: string, languageId: string, version: number, text: string);
|
|
20
|
+
get version(): number;
|
|
21
|
+
update(params: vscode.DidChangeTextDocumentParams): void;
|
|
22
|
+
getSnapshot(): ts.IScriptSnapshot;
|
|
23
|
+
getDocument(): TextDocument;
|
|
24
|
+
clearUnReferenceVersions(): void;
|
|
25
|
+
applyVersionToRootDocument(version: number, removeBeforeVersions: boolean): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function combineContinuousChangeRanges(...changeRanges: ts.TextChangeRange[]): ts.TextChangeRange;
|
|
28
|
+
export declare function createSnapshots(connection: vscode.Connection): {
|
|
29
|
+
data: {
|
|
30
|
+
clear: () => void;
|
|
31
|
+
values: () => IterableIterator<IncrementalScriptSnapshot>;
|
|
32
|
+
uriDelete: (_uri: string) => boolean;
|
|
33
|
+
uriGet: (_uri: string) => IncrementalScriptSnapshot | undefined;
|
|
34
|
+
uriHas: (_uri: string) => boolean;
|
|
35
|
+
uriSet: (_uri: string, item: IncrementalScriptSnapshot) => void;
|
|
36
|
+
pathDelete: (rootUri: shared._.URI, path: string) => boolean;
|
|
37
|
+
pathGet: (rootUri: shared._.URI, path: string) => IncrementalScriptSnapshot | undefined;
|
|
38
|
+
pathHas: (rootUri: shared._.URI, path: string) => IncrementalScriptSnapshot | undefined;
|
|
39
|
+
pathSet: (rootUri: shared._.URI, path: string, item: IncrementalScriptSnapshot) => void;
|
|
40
|
+
};
|
|
41
|
+
onDidOpen: (cb: (params: vscode.DidOpenTextDocumentParams) => void) => () => boolean;
|
|
42
|
+
onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean;
|
|
43
|
+
onDidClose: (cb: (params: vscode.DidCloseTextDocumentParams) => void) => () => boolean;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.createSnapshots = exports.combineContinuousChangeRanges = void 0;
|
|
3
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
4
|
+
const vscode = require("vscode-languageserver");
|
|
5
|
+
const shared = require("@volar/shared");
|
|
6
|
+
class IncrementalScriptSnapshot {
|
|
7
|
+
constructor(uri, languageId, version, text) {
|
|
8
|
+
this.uri = uri;
|
|
9
|
+
this.document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, version, text);
|
|
10
|
+
this.changes = [
|
|
11
|
+
{
|
|
12
|
+
applyed: true,
|
|
13
|
+
changeRange: undefined,
|
|
14
|
+
version,
|
|
15
|
+
contentChange: undefined,
|
|
16
|
+
snapshot: undefined,
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
get version() {
|
|
21
|
+
return this.changes[this.changes.length - 1].version;
|
|
22
|
+
}
|
|
23
|
+
update(params) {
|
|
24
|
+
vscode_languageserver_textdocument_1.TextDocument.update(this.document, params.contentChanges, params.textDocument.version);
|
|
25
|
+
this.changes = [
|
|
26
|
+
{
|
|
27
|
+
applyed: true,
|
|
28
|
+
changeRange: undefined,
|
|
29
|
+
version: params.textDocument.version,
|
|
30
|
+
contentChange: undefined,
|
|
31
|
+
snapshot: undefined,
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
getSnapshot() {
|
|
36
|
+
this.clearUnReferenceVersions();
|
|
37
|
+
const lastChange = this.changes[this.changes.length - 1];
|
|
38
|
+
if (!lastChange.snapshot) {
|
|
39
|
+
this.applyVersionToRootDocument(lastChange.version, false);
|
|
40
|
+
const text = this.document.getText();
|
|
41
|
+
const cache = new WeakMap();
|
|
42
|
+
const snapshot = {
|
|
43
|
+
getText: (start, end) => text.substring(start, end),
|
|
44
|
+
getLength: () => text.length,
|
|
45
|
+
getChangeRange: (oldSnapshot) => {
|
|
46
|
+
if (!cache.has(oldSnapshot)) {
|
|
47
|
+
const start = this.changes.findIndex(change => { var _a; return ((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref()) === oldSnapshot; }) + 1;
|
|
48
|
+
const end = this.changes.indexOf(lastChange) + 1;
|
|
49
|
+
if (start >= 0 && end >= 0) {
|
|
50
|
+
const changeRanges = this.changes.slice(start, end).map(change => change.changeRange).filter(shared.notEmpty);
|
|
51
|
+
const result = combineContinuousChangeRanges.apply(null, changeRanges);
|
|
52
|
+
cache.set(oldSnapshot, result);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
cache.set(oldSnapshot, undefined);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return cache.get(oldSnapshot);
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
lastChange.snapshot = new WeakRef(snapshot);
|
|
62
|
+
}
|
|
63
|
+
return lastChange.snapshot.deref();
|
|
64
|
+
}
|
|
65
|
+
getDocument() {
|
|
66
|
+
this.clearUnReferenceVersions();
|
|
67
|
+
const lastChange = this.changes[this.changes.length - 1];
|
|
68
|
+
if (!lastChange.applyed) {
|
|
69
|
+
this.applyVersionToRootDocument(lastChange.version, false);
|
|
70
|
+
}
|
|
71
|
+
return this.document;
|
|
72
|
+
}
|
|
73
|
+
clearUnReferenceVersions() {
|
|
74
|
+
var _a;
|
|
75
|
+
let versionToApply;
|
|
76
|
+
const lastVersion = this.changes[this.changes.length - 1].version;
|
|
77
|
+
for (let i = 0; i <= this.changes.length - 2; i++) {
|
|
78
|
+
const change = this.changes[i];
|
|
79
|
+
if (change.version !== lastVersion && !((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref())) {
|
|
80
|
+
versionToApply = change.version;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (versionToApply !== undefined) {
|
|
87
|
+
this.applyVersionToRootDocument(versionToApply, true);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
applyVersionToRootDocument(version, removeBeforeVersions) {
|
|
91
|
+
let removeEnd = -1;
|
|
92
|
+
for (let i = 0; i < this.changes.length; i++) {
|
|
93
|
+
const change = this.changes[i];
|
|
94
|
+
if (change.version > version) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
if (!change.applyed) {
|
|
98
|
+
if (change.contentChange) {
|
|
99
|
+
change.changeRange = {
|
|
100
|
+
span: {
|
|
101
|
+
start: this.document.offsetAt(change.contentChange.range.start),
|
|
102
|
+
length: this.document.offsetAt(change.contentChange.range.end) - this.document.offsetAt(change.contentChange.range.start),
|
|
103
|
+
},
|
|
104
|
+
newLength: change.contentChange.text.length,
|
|
105
|
+
};
|
|
106
|
+
vscode_languageserver_textdocument_1.TextDocument.update(this.document, [change.contentChange], change.version);
|
|
107
|
+
}
|
|
108
|
+
change.applyed = true;
|
|
109
|
+
}
|
|
110
|
+
removeEnd = i + 1;
|
|
111
|
+
}
|
|
112
|
+
if (removeBeforeVersions && removeEnd >= 1) {
|
|
113
|
+
this.changes.splice(0, removeEnd);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function combineContinuousChangeRanges(...changeRanges) {
|
|
118
|
+
if (changeRanges.length === 1) {
|
|
119
|
+
return changeRanges[0];
|
|
120
|
+
}
|
|
121
|
+
let changeRange = changeRanges[0];
|
|
122
|
+
for (let i = 1; i < changeRanges.length; i++) {
|
|
123
|
+
const nextChangeRange = changeRanges[i];
|
|
124
|
+
changeRange = _combineContinuousChangeRanges(changeRange, nextChangeRange);
|
|
125
|
+
}
|
|
126
|
+
return changeRange;
|
|
127
|
+
}
|
|
128
|
+
exports.combineContinuousChangeRanges = combineContinuousChangeRanges;
|
|
129
|
+
// https://tsplay.dev/w6Paym - @browsnet
|
|
130
|
+
function _combineContinuousChangeRanges(a, b) {
|
|
131
|
+
const aStart = a.span.start;
|
|
132
|
+
const aEnd = a.span.start + a.span.length;
|
|
133
|
+
const aDiff = a.newLength - a.span.length;
|
|
134
|
+
const changeBegin = aStart + Math.min(a.span.length, a.newLength);
|
|
135
|
+
const rollback = (start) => start > changeBegin ? start - aDiff : start;
|
|
136
|
+
const bStart = rollback(b.span.start);
|
|
137
|
+
const bEnd = rollback(b.span.start + b.span.length);
|
|
138
|
+
const bDiff = b.newLength - b.span.length;
|
|
139
|
+
const start = Math.min(aStart, bStart);
|
|
140
|
+
const end = Math.max(aEnd, bEnd);
|
|
141
|
+
const length = end - start;
|
|
142
|
+
const newLength = aDiff + bDiff + length;
|
|
143
|
+
return { span: { start, length }, newLength };
|
|
144
|
+
}
|
|
145
|
+
function createSnapshots(connection) {
|
|
146
|
+
const snapshots = shared.createUriMap();
|
|
147
|
+
const onDidOpens = new Set();
|
|
148
|
+
const onDidChangeContents = new Set();
|
|
149
|
+
const onDidCloses = new Set();
|
|
150
|
+
connection.onDidOpenTextDocument(params => {
|
|
151
|
+
snapshots.uriSet(params.textDocument.uri, new IncrementalScriptSnapshot(params.textDocument.uri, params.textDocument.languageId, params.textDocument.version, params.textDocument.text));
|
|
152
|
+
for (const cb of onDidOpens) {
|
|
153
|
+
cb(params);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
connection.onDidChangeTextDocument(params => {
|
|
157
|
+
const incrementalSnapshot = snapshots.uriGet(params.textDocument.uri);
|
|
158
|
+
if (incrementalSnapshot) {
|
|
159
|
+
if (params.contentChanges.every(vscode.TextDocumentContentChangeEvent.isIncremental)) {
|
|
160
|
+
for (const contentChange of params.contentChanges) {
|
|
161
|
+
incrementalSnapshot.changes.push({
|
|
162
|
+
applyed: false,
|
|
163
|
+
changeRange: undefined,
|
|
164
|
+
contentChange,
|
|
165
|
+
version: params.textDocument.version,
|
|
166
|
+
snapshot: undefined,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
incrementalSnapshot.update(params);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const cb of onDidChangeContents) {
|
|
175
|
+
cb(params);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
connection.onDidCloseTextDocument(params => {
|
|
179
|
+
snapshots.uriDelete(params.textDocument.uri);
|
|
180
|
+
for (const cb of onDidCloses) {
|
|
181
|
+
cb(params);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
data: snapshots,
|
|
186
|
+
onDidOpen: (cb) => {
|
|
187
|
+
onDidOpens.add(cb);
|
|
188
|
+
return () => onDidOpens.delete(cb);
|
|
189
|
+
},
|
|
190
|
+
onDidChangeContent: (cb) => {
|
|
191
|
+
onDidChangeContents.add(cb);
|
|
192
|
+
return () => onDidChangeContents.delete(cb);
|
|
193
|
+
},
|
|
194
|
+
onDidClose: (cb) => {
|
|
195
|
+
onDidCloses.add(cb);
|
|
196
|
+
return () => onDidCloses.delete(cb);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
exports.createSnapshots = createSnapshots;
|
|
201
|
+
//# sourceMappingURL=snapshots.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Comparer, Comparison, SortedReadonlyArray } from "./corePublic";
|
|
2
|
+
/**
|
|
3
|
+
* Iterates through `array` by index and performs the callback on each element of array until the callback
|
|
4
|
+
* returns a falsey value, then returns false.
|
|
5
|
+
* If no such value is found, the callback is applied to each element of array and `true` is returned.
|
|
6
|
+
*/
|
|
7
|
+
export declare function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean;
|
|
8
|
+
/** Works like Array.prototype.findIndex, returning `-1` if no element satisfying the predicate is found. */
|
|
9
|
+
export declare function findIndex<T>(array: readonly T[] | undefined, predicate: (element: T, index: number) => boolean, startIndex?: number): number;
|
|
10
|
+
export declare function indexOfAnyCharCode(text: string, charCodes: readonly number[], start?: number): number;
|
|
11
|
+
export declare function map<T, U>(array: readonly T[], f: (x: T, i: number) => U): U[];
|
|
12
|
+
export declare function map<T, U>(array: readonly T[] | undefined, f: (x: T, i: number) => U): U[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Flattens an array containing a mix of array or non-array elements.
|
|
15
|
+
*
|
|
16
|
+
* @param array The array to flatten.
|
|
17
|
+
*/
|
|
18
|
+
export declare function flatten<T>(array: T[][] | readonly (T | readonly T[] | undefined)[]): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Maps an array. If the mapped value is an array, it is spread into the result.
|
|
21
|
+
*
|
|
22
|
+
* @param array The array to map.
|
|
23
|
+
* @param mapfn The callback used to map the result into one or more values.
|
|
24
|
+
*/
|
|
25
|
+
export declare function flatMap<T, U>(array: readonly T[] | undefined, mapfn: (x: T, i: number) => U | readonly U[] | undefined): readonly U[];
|
|
26
|
+
export declare function some<T>(array: readonly T[] | undefined): array is readonly T[];
|
|
27
|
+
export declare function some<T>(array: readonly T[] | undefined, predicate: (value: T) => boolean): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new sorted array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sort<T>(array: readonly T[], comparer?: Comparer<T>): SortedReadonlyArray<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the last element of an array if non-empty, `undefined` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export declare function lastOrUndefined<T>(array: readonly T[] | undefined): T | undefined;
|
|
36
|
+
export declare function last<T>(array: readonly T[]): T;
|
|
37
|
+
/**
|
|
38
|
+
* Compare the equality of two strings using a case-sensitive ordinal comparison.
|
|
39
|
+
*
|
|
40
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the integer
|
|
41
|
+
* value of each code-point after applying `toUpperCase` to each string. We always map both
|
|
42
|
+
* strings to their upper-case form as some unicode characters do not properly round-trip to
|
|
43
|
+
* lowercase (such as `ẞ` (German sharp capital s)).
|
|
44
|
+
*/
|
|
45
|
+
export declare function equateStringsCaseInsensitive(a: string, b: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Compare the equality of two strings using a case-sensitive ordinal comparison.
|
|
48
|
+
*
|
|
49
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the
|
|
50
|
+
* integer value of each code-point.
|
|
51
|
+
*/
|
|
52
|
+
export declare function equateStringsCaseSensitive(a: string, b: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Compare two strings using a case-insensitive ordinal comparison.
|
|
55
|
+
*
|
|
56
|
+
* Ordinal comparisons are based on the difference between the unicode code points of both
|
|
57
|
+
* strings. Characters with multiple unicode representations are considered unequal. Ordinal
|
|
58
|
+
* comparisons provide predictable ordering, but place "a" after "B".
|
|
59
|
+
*
|
|
60
|
+
* Case-insensitive comparisons compare both strings one code-point at a time using the integer
|
|
61
|
+
* value of each code-point after applying `toUpperCase` to each string. We always map both
|
|
62
|
+
* strings to their upper-case form as some unicode characters do not properly round-trip to
|
|
63
|
+
* lowercase (such as `ẞ` (German sharp capital s)).
|
|
64
|
+
*/
|
|
65
|
+
declare function compareStringsCaseInsensitive(a: string, b: string): Comparison;
|
|
66
|
+
/**
|
|
67
|
+
* Compare two strings using a case-sensitive ordinal comparison.
|
|
68
|
+
*
|
|
69
|
+
* Ordinal comparisons are based on the difference between the unicode code points of both
|
|
70
|
+
* strings. Characters with multiple unicode representations are considered unequal. Ordinal
|
|
71
|
+
* comparisons provide predictable ordering, but place "a" after "B".
|
|
72
|
+
*
|
|
73
|
+
* Case-sensitive comparisons compare both strings one code-point at a time using the integer
|
|
74
|
+
* value of each code-point.
|
|
75
|
+
*/
|
|
76
|
+
export declare function compareStringsCaseSensitive(a: string | undefined, b: string | undefined): Comparison;
|
|
77
|
+
export declare function getStringComparer(ignoreCase?: boolean): typeof compareStringsCaseInsensitive;
|
|
78
|
+
export declare function endsWith(str: string, suffix: string): boolean;
|
|
79
|
+
export declare function stringContains(str: string, substring: string): boolean;
|
|
80
|
+
declare type GetCanonicalFileName = (fileName: string) => string;
|
|
81
|
+
export declare function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName;
|
|
82
|
+
export declare function startsWith(str: string, prefix: string): boolean;
|
|
83
|
+
export {};
|