@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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/out/browser.d.ts +3 -0
  3. package/out/browser.js +47 -0
  4. package/out/features/customFeatures.d.ts +4 -0
  5. package/out/features/customFeatures.js +83 -0
  6. package/out/features/documentFeatures.d.ts +4 -0
  7. package/out/features/documentFeatures.js +73 -0
  8. package/out/features/languageFeatures.d.ts +4 -0
  9. package/out/features/languageFeatures.js +274 -0
  10. package/out/index.d.ts +3 -0
  11. package/out/index.js +19 -0
  12. package/out/node.d.ts +3 -0
  13. package/out/node.js +88 -0
  14. package/out/registers/registerDocumentFeatures.d.ts +3 -0
  15. package/out/registers/registerDocumentFeatures.js +30 -0
  16. package/out/registers/registerlanguageFeatures.d.ts +3 -0
  17. package/out/registers/registerlanguageFeatures.js +144 -0
  18. package/out/requests.d.ts +81 -0
  19. package/out/requests.js +65 -0
  20. package/out/schemaRequestHandlers/file.d.ts +2 -0
  21. package/out/schemaRequestHandlers/file.js +12 -0
  22. package/out/schemaRequestHandlers/http.d.ts +1 -0
  23. package/out/schemaRequestHandlers/http.js +12 -0
  24. package/out/server.d.ts +3 -0
  25. package/out/server.js +99 -0
  26. package/out/types.d.ts +112 -0
  27. package/out/types.js +2 -0
  28. package/out/utils/config.d.ts +2 -0
  29. package/out/utils/config.js +17 -0
  30. package/out/utils/configurationHost.d.ts +5 -0
  31. package/out/utils/configurationHost.js +38 -0
  32. package/out/utils/documentServiceHost.d.ts +30 -0
  33. package/out/utils/documentServiceHost.js +51 -0
  34. package/out/utils/inferredCompilerOptions.d.ts +3 -0
  35. package/out/utils/inferredCompilerOptions.js +71 -0
  36. package/out/utils/iterableWeakSet.d.ts +7 -0
  37. package/out/utils/iterableWeakSet.js +40 -0
  38. package/out/utils/nodeFileSystemHost.d.ts +3 -0
  39. package/out/utils/nodeFileSystemHost.js +95 -0
  40. package/out/utils/project.d.ts +99 -0
  41. package/out/utils/project.js +273 -0
  42. package/out/utils/snapshots.d.ts +45 -0
  43. package/out/utils/snapshots.js +201 -0
  44. package/out/utils/ts/core.d.ts +83 -0
  45. package/out/utils/ts/core.js +319 -0
  46. package/out/utils/ts/corePublic.d.ts +91 -0
  47. package/out/utils/ts/corePublic.js +50 -0
  48. package/out/utils/ts/path.d.ts +112 -0
  49. package/out/utils/ts/path.js +416 -0
  50. package/out/utils/ts/types.d.ts +129 -0
  51. package/out/utils/ts/types.js +2 -0
  52. package/out/utils/ts/utilities.d.ts +7 -0
  53. package/out/utils/ts/utilities.js +249 -0
  54. package/out/utils/webFileSystemHost.d.ts +2 -0
  55. package/out/utils/webFileSystemHost.js +265 -0
  56. package/out/utils/workspaceProjects.d.ts +120 -0
  57. package/out/utils/workspaceProjects.js +226 -0
  58. package/out/utils/workspaces.d.ts +309 -0
  59. package/out/utils/workspaces.js +154 -0
  60. package/package.json +27 -0
@@ -0,0 +1,154 @@
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.createWorkspaces = void 0;
12
+ const shared = require("@volar/shared");
13
+ const vscode_uri_1 = require("vscode-uri");
14
+ const workspaceProjects_1 = require("./workspaceProjects");
15
+ function createWorkspaces(runtimeEnv, plugins, fsHost, configurationHost, ts, tsLocalized, options, documents, connection) {
16
+ var _a;
17
+ let semanticTokensReq = 0;
18
+ let documentUpdatedReq = 0;
19
+ const workspaces = new Map();
20
+ documents.onDidOpen(params => {
21
+ updateDiagnostics(params.textDocument.uri);
22
+ });
23
+ documents.onDidChangeContent((params) => __awaiter(this, void 0, void 0, function* () {
24
+ updateDiagnostics(params.textDocument.uri);
25
+ }));
26
+ documents.onDidClose(params => {
27
+ connection.sendDiagnostics({ uri: params.textDocument.uri, diagnostics: [] });
28
+ });
29
+ fsHost.onDidChangeWatchedFiles(params => {
30
+ const tsConfigChanges = params.changes.filter(change => workspaceProjects_1.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
31
+ if (tsConfigChanges.length) {
32
+ for (const doc of documents.data.values()) {
33
+ connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
34
+ }
35
+ }
36
+ onDriveFileUpdated();
37
+ });
38
+ (_a = runtimeEnv.onDidChangeConfiguration) === null || _a === void 0 ? void 0 : _a.call(runtimeEnv, () => __awaiter(this, void 0, void 0, function* () {
39
+ onDriveFileUpdated();
40
+ }));
41
+ return {
42
+ workspaces,
43
+ getProject,
44
+ reloadProject,
45
+ add: (rootUri) => {
46
+ workspaces.set(rootUri.toString(), (0, workspaceProjects_1.createWorkspaceProjects)(runtimeEnv, plugins, fsHost, rootUri, ts, tsLocalized, options, documents, connection, configurationHost));
47
+ },
48
+ remove: (rootUri) => {
49
+ const _workspace = workspaces.get(rootUri.toString());
50
+ workspaces.delete(rootUri.toString());
51
+ (() => __awaiter(this, void 0, void 0, function* () {
52
+ var _a;
53
+ (_a = (yield _workspace)) === null || _a === void 0 ? void 0 : _a.dispose();
54
+ }))();
55
+ },
56
+ };
57
+ function reloadProject() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ fsHost.clearCache();
60
+ for (const [_, workspace] of workspaces) {
61
+ (yield workspace).reload();
62
+ }
63
+ });
64
+ }
65
+ function onDriveFileUpdated() {
66
+ var _a, _b;
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const req = ++semanticTokensReq;
69
+ yield updateDiagnostics();
70
+ if (req === semanticTokensReq) {
71
+ if ((_a = options.languageFeatures) === null || _a === void 0 ? void 0 : _a.semanticTokens) {
72
+ connection.languages.semanticTokens.refresh();
73
+ }
74
+ if ((_b = options.languageFeatures) === null || _b === void 0 ? void 0 : _b.inlayHints) {
75
+ connection.languages.semanticTokens.refresh();
76
+ }
77
+ }
78
+ });
79
+ }
80
+ function updateDiagnostics(docUri) {
81
+ var _a;
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!((_a = options.languageFeatures) === null || _a === void 0 ? void 0 : _a.diagnostics))
84
+ return;
85
+ const req = ++documentUpdatedReq;
86
+ const delay = yield (configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.getConfiguration('volar.diagnostics.delay'));
87
+ const cancel = {
88
+ get isCancellationRequested() {
89
+ return req !== documentUpdatedReq;
90
+ },
91
+ // @ts-ignore
92
+ onCancellationRequested: undefined,
93
+ };
94
+ const changeDoc = docUri ? documents.data.uriGet(docUri) : undefined;
95
+ const otherDocs = [...documents.data.values()].filter(doc => doc !== changeDoc);
96
+ if (changeDoc) {
97
+ yield shared.sleep(delay !== null && delay !== void 0 ? delay : 200);
98
+ yield sendDocumentDiagnostics(changeDoc.uri, changeDoc.version, cancel);
99
+ }
100
+ for (const doc of otherDocs) {
101
+ yield shared.sleep(delay !== null && delay !== void 0 ? delay : 200);
102
+ yield sendDocumentDiagnostics(doc.uri, doc.version, cancel);
103
+ if (cancel.isCancellationRequested) {
104
+ break;
105
+ }
106
+ }
107
+ function sendDocumentDiagnostics(uri, version, cancel) {
108
+ var _a;
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const project = (_a = (yield getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
111
+ if (!project)
112
+ return;
113
+ const languageService = project.getLanguageService();
114
+ const errors = yield languageService.doValidation(uri, result => {
115
+ connection.sendDiagnostics({ uri: uri, diagnostics: result.map(addVersion), version });
116
+ }, cancel);
117
+ connection.sendDiagnostics({ uri: uri, diagnostics: errors.map(addVersion), version });
118
+ function addVersion(error) {
119
+ if (error.data === undefined) {
120
+ error.data = { version };
121
+ }
122
+ else if (typeof error.data === 'object') {
123
+ error.data.version = version;
124
+ }
125
+ return error;
126
+ }
127
+ });
128
+ }
129
+ });
130
+ }
131
+ function getProject(uri) {
132
+ var _a;
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const rootUris = [...workspaces.keys()]
135
+ .filter(rootUri => shared.isFileInDir(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(rootUri).fsPath))
136
+ .sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(a).fsPath, vscode_uri_1.URI.parse(b).fsPath));
137
+ for (const rootUri of rootUris) {
138
+ const workspace = yield workspaces.get(rootUri);
139
+ const project = yield (workspace === null || workspace === void 0 ? void 0 : workspace.getProjectAndTsConfig(uri));
140
+ if (project) {
141
+ return project;
142
+ }
143
+ }
144
+ if (rootUris.length) {
145
+ return {
146
+ tsconfig: undefined,
147
+ project: yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject()),
148
+ };
149
+ }
150
+ });
151
+ }
152
+ }
153
+ exports.createWorkspaces = createWorkspaces;
154
+ //# sourceMappingURL=workspaces.js.map
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@volar/language-server",
3
+ "version": "1.0.0-alpha.0",
4
+ "main": "out/index.js",
5
+ "license": "MIT",
6
+ "files": [
7
+ "out/**/*.js",
8
+ "out/**/*.d.ts"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/johnsoncodehk/volar.git",
13
+ "directory": "packages/language-server"
14
+ },
15
+ "dependencies": {
16
+ "@volar/language-core": "1.0.0-alpha.0",
17
+ "@volar/language-service": "1.0.0-alpha.0",
18
+ "@volar/shared": "1.0.0-alpha.0",
19
+ "request-light": "^0.5.8",
20
+ "upath": "^2.0.1",
21
+ "vscode-html-languageservice": "^5.0.1",
22
+ "vscode-languageserver": "^8.0.2",
23
+ "vscode-languageserver-protocol": "^3.17.2",
24
+ "vscode-languageserver-textdocument": "^1.0.7",
25
+ "vscode-uri": "^3.0.3"
26
+ }
27
+ }