@volar/language-server 2.4.0-alpha.9 → 2.4.1

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 (44) hide show
  1. package/browser.d.ts +43 -21
  2. package/browser.js +16 -31
  3. package/lib/features/configurations.d.ts +8 -0
  4. package/lib/features/configurations.js +49 -0
  5. package/lib/features/editorFeatures.d.ts +2 -0
  6. package/lib/features/editorFeatures.js +186 -0
  7. package/lib/features/fileSystem.d.ts +8 -0
  8. package/lib/features/fileSystem.js +61 -0
  9. package/lib/features/fileWatcher.d.ts +9 -0
  10. package/lib/features/fileWatcher.js +63 -0
  11. package/lib/features/languageFeatures.d.ts +4 -0
  12. package/lib/features/languageFeatures.js +730 -0
  13. package/lib/features/textDocuments.d.ts +12 -0
  14. package/lib/features/textDocuments.js +54 -0
  15. package/lib/features/workspaceFolders.d.ts +10 -0
  16. package/lib/features/workspaceFolders.js +67 -0
  17. package/lib/fileSystemProviders/http.d.ts +6 -0
  18. package/lib/fileSystemProviders/http.js +46 -0
  19. package/lib/fileSystemProviders/node.d.ts +2 -0
  20. package/lib/fileSystemProviders/node.js +49 -0
  21. package/lib/project/inferredCompilerOptions.js +2 -2
  22. package/lib/project/simpleProject.js +7 -8
  23. package/lib/project/typescriptProject.d.ts +7 -4
  24. package/lib/project/typescriptProject.js +49 -40
  25. package/lib/project/typescriptProjectLs.d.ts +8 -7
  26. package/lib/project/typescriptProjectLs.js +140 -85
  27. package/lib/server.d.ts +46 -27
  28. package/lib/server.js +59 -479
  29. package/lib/types.d.ts +20 -5
  30. package/lib/utils/combineChangeRanges.d.ts +2 -0
  31. package/lib/utils/combineChangeRanges.js +28 -0
  32. package/lib/utils/snapshotDocument.d.ts +28 -0
  33. package/lib/utils/snapshotDocument.js +138 -0
  34. package/node.d.ts +43 -23
  35. package/node.js +16 -58
  36. package/package.json +5 -6
  37. package/protocol.d.ts +1 -13
  38. package/protocol.js +1 -16
  39. package/lib/register/registerEditorFeatures.d.ts +0 -2
  40. package/lib/register/registerEditorFeatures.js +0 -208
  41. package/lib/register/registerLanguageFeatures.d.ts +0 -3
  42. package/lib/register/registerLanguageFeatures.js +0 -435
  43. package/lib/schemaRequestHandlers/http.d.ts +0 -2
  44. package/lib/schemaRequestHandlers/http.js +0 -16
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapshotDocument = void 0;
4
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
5
+ const combineChangeRanges_1 = require("./combineChangeRanges");
6
+ class SnapshotDocument {
7
+ constructor(uri, languageId, version, text) {
8
+ this.snapshots = [];
9
+ this.document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, version, text);
10
+ this.resetChanges();
11
+ }
12
+ get uri() {
13
+ return this.document.uri;
14
+ }
15
+ get languageId() {
16
+ return this.document.languageId;
17
+ }
18
+ get version() {
19
+ return this.document.version;
20
+ }
21
+ get lineCount() {
22
+ return this.document.lineCount;
23
+ }
24
+ getText(range) {
25
+ return this.document.getText(range);
26
+ }
27
+ positionAt(offset) {
28
+ return this.document.positionAt(offset);
29
+ }
30
+ offsetAt(position) {
31
+ return this.document.offsetAt(position);
32
+ }
33
+ /**
34
+ * Update the document with the given content changes and version.
35
+ * If all changes is incremental, calculate the change range and add a new snapshot.
36
+ * Otherwise, reset the changes.
37
+ */
38
+ update(contentChanges, version) {
39
+ if (contentChanges.every(change => 'range' in change)) {
40
+ const { minStart, oldLength, lengthDiff } = this.calculateChangeRange(contentChanges);
41
+ vscode_languageserver_textdocument_1.TextDocument.update(this.document, contentChanges, version);
42
+ this.snapshots.push({
43
+ changeRange: {
44
+ span: {
45
+ start: minStart,
46
+ length: oldLength,
47
+ },
48
+ newLength: oldLength + lengthDiff,
49
+ },
50
+ version,
51
+ ref: undefined,
52
+ });
53
+ }
54
+ else {
55
+ vscode_languageserver_textdocument_1.TextDocument.update(this.document, contentChanges, version);
56
+ this.resetChanges();
57
+ }
58
+ }
59
+ getSnapshot() {
60
+ this.clearUnreferencedVersions();
61
+ const lastChange = this.snapshots[this.snapshots.length - 1];
62
+ if (!lastChange.ref) {
63
+ const text = this.document.getText();
64
+ const changeRangeCache = new WeakMap();
65
+ const snapshot = {
66
+ getText: (start, end) => text.substring(start, end),
67
+ getLength: () => text.length,
68
+ getChangeRange: oldSnapshot => {
69
+ if (!changeRangeCache.has(oldSnapshot)) {
70
+ const oldIndex = this.snapshots.findIndex(change => change.ref?.deref() === oldSnapshot);
71
+ if (oldIndex >= 0) {
72
+ const start = oldIndex + 1;
73
+ const end = this.snapshots.indexOf(lastChange) + 1;
74
+ const changeRanges = this.snapshots
75
+ .slice(start, end)
76
+ .map(change => change.changeRange);
77
+ const changeRange = (0, combineChangeRanges_1.combineChangeRanges)(...changeRanges);
78
+ changeRangeCache.set(oldSnapshot, changeRange);
79
+ }
80
+ else {
81
+ changeRangeCache.set(oldSnapshot, undefined);
82
+ }
83
+ }
84
+ return changeRangeCache.get(oldSnapshot);
85
+ },
86
+ };
87
+ lastChange.ref = new WeakRef(snapshot);
88
+ }
89
+ return lastChange.ref.deref();
90
+ }
91
+ resetChanges() {
92
+ this.snapshots = [
93
+ {
94
+ changeRange: {
95
+ span: {
96
+ start: 0,
97
+ length: 0,
98
+ },
99
+ newLength: this.document.getText().length,
100
+ },
101
+ version: this.document.version,
102
+ ref: undefined,
103
+ }
104
+ ];
105
+ }
106
+ /**
107
+ * Calculate the change range from the given content changes.
108
+ */
109
+ calculateChangeRange(contentChanges) {
110
+ let lengthDiff = 0;
111
+ const starts = [];
112
+ const ends = [];
113
+ for (const contentChange of contentChanges) {
114
+ if (!('range' in contentChange)) {
115
+ continue;
116
+ }
117
+ const start = this.offsetAt(contentChange.range.start);
118
+ const length = contentChange.rangeLength ?? this.offsetAt(contentChange.range.end) - start;
119
+ const end = start + length;
120
+ starts.push(start);
121
+ ends.push(end);
122
+ lengthDiff += contentChange.text.length - length;
123
+ }
124
+ const minStart = Math.min(...starts);
125
+ const maxEnd = Math.max(...ends);
126
+ const oldLength = maxEnd - minStart;
127
+ return { minStart, oldLength, lengthDiff };
128
+ }
129
+ clearUnreferencedVersions() {
130
+ let firstReferencedIndex = 0;
131
+ while (firstReferencedIndex < this.snapshots.length - 1 && !this.snapshots[firstReferencedIndex].ref?.deref()) {
132
+ firstReferencedIndex++;
133
+ }
134
+ this.snapshots = this.snapshots.slice(firstReferencedIndex);
135
+ }
136
+ }
137
+ exports.SnapshotDocument = SnapshotDocument;
138
+ //# sourceMappingURL=snapshotDocument.js.map
package/node.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { FileSystem } from '@volar/language-service';
2
1
  import * as vscode from 'vscode-languageserver/node';
3
2
  export * from 'vscode-languageserver/node';
4
3
  export * from './index';
@@ -7,33 +6,54 @@ export * from './lib/project/typescriptProject';
7
6
  export * from './lib/server';
8
7
  export declare function createConnection(): vscode._Connection<vscode._, vscode._, vscode._, vscode._, vscode._, vscode._, import("vscode-languageserver/lib/common/inlineCompletion.proposed").InlineCompletionFeatureShape, vscode._>;
9
8
  export declare function createServer(connection: vscode.Connection): {
10
- connection: vscode.Connection;
11
- fs: FileSystem;
12
9
  initializeParams: vscode.InitializeParams;
13
- initializeResult: import("./index").VolarInitializeResult;
14
- languageServicePlugins: import("@volar/language-service").LanguageServicePlugin[];
15
10
  project: import("./index").LanguageServerProject;
16
- pullModelDiagnostics: boolean;
17
- documents: vscode.TextDocuments<import("@volar/snapshot-document/lib/snapshotDocument").SnapshotDocument>;
18
- workspaceFolders: Map<import("vscode-uri").URI, boolean>;
19
- getSyncedDocumentKey: (uri: import("vscode-uri").URI) => string | undefined;
20
- initialize: (initializeParams: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service").LanguageServicePlugin[], options?: {
21
- pullModelDiagnostics?: boolean;
22
- }) => import("./index").VolarInitializeResult;
23
- initialized: () => void;
24
- shutdown: () => void;
25
- watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
26
- getConfiguration: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
27
- onDidChangeConfiguration: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
28
- dispose(): void;
11
+ languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin<any>[];
12
+ initialize(params: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin[]): vscode.InitializeResult<import("./index").ExperimentalFeatures>;
13
+ initialized(): void;
14
+ shutdown(): void;
15
+ configurations: {
16
+ get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
17
+ onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
18
+ dispose(): void;
19
+ };
20
+ };
21
+ editorFeatures: void;
22
+ documents: {
23
+ all: () => import("./lib/utils/snapshotDocument").SnapshotDocument[];
24
+ onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
25
+ onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
26
+ onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
27
+ onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
28
+ get(uri: import("vscode-uri").URI): import("./lib/utils/snapshotDocument").SnapshotDocument | undefined;
29
+ };
30
+ workspaceFolders: {
31
+ readonly all: import("vscode-uri").URI[];
32
+ has(uri: import("vscode-uri").URI): boolean;
33
+ onDidChange: (cb: vscode.NotificationHandler<vscode.WorkspaceFoldersChangeEvent>) => {
34
+ dispose(): void;
35
+ };
29
36
  };
30
- onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
31
- dispose: () => void;
37
+ fileWatcher: {
38
+ watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
39
+ onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
40
+ dispose: () => void;
41
+ };
32
42
  };
33
- clearPushDiagnostics: () => void;
34
- refresh: (project: import("./index").LanguageServerProject) => Promise<void>;
43
+ languageFeatures: {
44
+ requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
45
+ };
46
+ fileSystem: {
47
+ readFile(uri: import("vscode-uri").URI): string | Thenable<string | undefined>;
48
+ stat(uri: import("vscode-uri").URI): import("@volar/language-service/lib/types").FileStat | Thenable<import("@volar/language-service/lib/types").FileStat | undefined>;
49
+ readDirectory(uri: import("vscode-uri").URI): import("@volar/language-service/lib/types").ProviderResult<[string, import("@volar/language-service/lib/types").FileType][]>;
50
+ install(scheme: string, provider: import("@volar/language-service/lib/types").FileSystem): void;
51
+ };
52
+ env: import("./index").LanguageServerEnvironment;
53
+ connection: vscode.Connection;
54
+ onInitialize(callback: (serverCapabilities: vscode.ServerCapabilities<import("./index").ExperimentalFeatures>) => void): void;
55
+ onInitialized(callback: () => void): void;
35
56
  };
36
- export declare const fs: FileSystem;
37
57
  export declare function loadTsdkByPath(tsdk: string, locale: string | undefined): {
38
58
  typescript: typeof import("typescript");
39
59
  diagnosticMessages: import("typescript").MapLike<string> | undefined;
package/node.js CHANGED
@@ -14,14 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.fs = void 0;
18
17
  exports.createConnection = createConnection;
19
18
  exports.createServer = createServer;
20
19
  exports.loadTsdkByPath = loadTsdkByPath;
21
- const language_service_1 = require("@volar/language-service");
22
- const _fs = require("fs");
23
20
  const vscode = require("vscode-languageserver/node");
24
- const http_1 = require("./lib/schemaRequestHandlers/http");
21
+ const http_1 = require("./lib/fileSystemProviders/http");
22
+ const node_1 = require("./lib/fileSystemProviders/node");
25
23
  const server_1 = require("./lib/server");
26
24
  __exportStar(require("vscode-languageserver/node"), exports);
27
25
  __exportStar(require("./index"), exports);
@@ -32,62 +30,19 @@ function createConnection() {
32
30
  return vscode.createConnection(vscode.ProposedFeatures.all);
33
31
  }
34
32
  function createServer(connection) {
35
- return (0, server_1.createServerBase)(connection, exports.fs);
33
+ const server = (0, server_1.createServerBase)(connection, {
34
+ timer: {
35
+ setImmediate: setImmediate,
36
+ },
37
+ });
38
+ server.fileSystem.install('file', node_1.provider);
39
+ server.fileSystem.install('http', http_1.provider);
40
+ server.fileSystem.install('https', http_1.provider);
41
+ server.onInitialized(() => (0, http_1.listenEditorSettings)(server));
42
+ return server;
36
43
  }
37
- exports.fs = {
38
- stat(uri) {
39
- if (uri.scheme === 'file') {
40
- try {
41
- const stats = _fs.statSync(uri.fsPath, { throwIfNoEntry: false });
42
- if (stats) {
43
- return {
44
- type: stats.isFile() ? language_service_1.FileType.File
45
- : stats.isDirectory() ? language_service_1.FileType.Directory
46
- : stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
47
- : language_service_1.FileType.Unknown,
48
- ctime: stats.ctimeMs,
49
- mtime: stats.mtimeMs,
50
- size: stats.size,
51
- };
52
- }
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- }
58
- },
59
- readFile(uri, encoding) {
60
- if (uri.scheme === 'file') {
61
- try {
62
- return _fs.readFileSync(uri.fsPath, { encoding: encoding ?? 'utf-8' });
63
- }
64
- catch {
65
- return undefined;
66
- }
67
- }
68
- if (uri.scheme === 'http' || uri.scheme === 'https') {
69
- return (0, http_1.default)(uri);
70
- }
71
- },
72
- readDirectory(uri) {
73
- if (uri.scheme === 'file') {
74
- try {
75
- const files = _fs.readdirSync(uri.fsPath, { withFileTypes: true });
76
- return files.map(file => {
77
- return [file.name, file.isFile() ? language_service_1.FileType.File
78
- : file.isDirectory() ? language_service_1.FileType.Directory
79
- : file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
80
- : language_service_1.FileType.Unknown];
81
- });
82
- }
83
- catch {
84
- return [];
85
- }
86
- }
87
- return [];
88
- },
89
- };
90
44
  function loadTsdkByPath(tsdk, locale) {
45
+ locale = locale?.toLowerCase();
91
46
  // webpack compatibility
92
47
  const _require = eval('require');
93
48
  return {
@@ -111,6 +66,9 @@ function loadTsdkByPath(tsdk, locale) {
111
66
  throw new Error(`Can't find typescript.js or tsserverlibrary.js in ${JSON.stringify(tsdk)}`);
112
67
  }
113
68
  function loadLocalizedDiagnosticMessages() {
69
+ if (locale === 'en') {
70
+ return;
71
+ }
114
72
  try {
115
73
  const path = _require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
116
74
  return _require(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "2.4.0-alpha.9",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,10 +12,9 @@
12
12
  "directory": "packages/language-server"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.4.0-alpha.9",
16
- "@volar/language-service": "2.4.0-alpha.9",
17
- "@volar/snapshot-document": "2.4.0-alpha.9",
18
- "@volar/typescript": "2.4.0-alpha.9",
15
+ "@volar/language-core": "2.4.1",
16
+ "@volar/language-service": "2.4.1",
17
+ "@volar/typescript": "2.4.1",
19
18
  "path-browserify": "^1.0.1",
20
19
  "request-light": "^0.7.0",
21
20
  "vscode-languageserver": "^9.0.1",
@@ -26,5 +25,5 @@
26
25
  "devDependencies": {
27
26
  "@types/path-browserify": "latest"
28
27
  },
29
- "gitHead": "4a3fc1bf36eb12ccd58bc8cb25f11f1a9f7b2300"
28
+ "gitHead": "b920b6c4a3e4b2d8f46c676ea414e94c437cb5b7"
30
29
  }
package/protocol.d.ts CHANGED
@@ -1,19 +1,7 @@
1
1
  import type { CodeMapping } from '@volar/language-core';
2
- import type { FileStat, FileType, DocumentDropEdit } from '@volar/language-service';
2
+ import type { DocumentDropEdit } from '@volar/language-service';
3
3
  import * as vscode from 'vscode-languageserver-protocol';
4
4
  export * from 'vscode-languageserver-protocol';
5
- /**
6
- * Server request client
7
- */
8
- export declare namespace FsReadFileRequest {
9
- const type: vscode.RequestType<string, string | null | undefined, unknown>;
10
- }
11
- export declare namespace FsReadDirectoryRequest {
12
- const type: vscode.RequestType<string, [string, FileType][], unknown>;
13
- }
14
- export declare namespace FsStatRequest {
15
- const type: vscode.RequestType<string, FileStat, unknown>;
16
- }
17
5
  /**
18
6
  * Client request server
19
7
  */
package/protocol.js CHANGED
@@ -14,24 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.LoadedTSFilesMetaRequest = exports.GetVirtualCodeRequest = exports.GetVirtualFileRequest = exports.GetServicePluginsRequest = exports.UpdateServicePluginStateNotification = exports.UpdateVirtualCodeStateNotification = exports.DocumentDrop_DataTransferItemFileDataRequest = exports.DocumentDrop_DataTransferItemAsStringRequest = exports.DocumentDropRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.FsStatRequest = exports.FsReadDirectoryRequest = exports.FsReadFileRequest = void 0;
17
+ exports.LoadedTSFilesMetaRequest = exports.GetVirtualCodeRequest = exports.GetVirtualFileRequest = exports.GetServicePluginsRequest = exports.UpdateServicePluginStateNotification = exports.UpdateVirtualCodeStateNotification = exports.DocumentDrop_DataTransferItemFileDataRequest = exports.DocumentDrop_DataTransferItemAsStringRequest = exports.DocumentDropRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = void 0;
18
18
  const vscode = require("vscode-languageserver-protocol");
19
19
  __exportStar(require("vscode-languageserver-protocol"), exports);
20
- /**
21
- * Server request client
22
- */
23
- var FsReadFileRequest;
24
- (function (FsReadFileRequest) {
25
- FsReadFileRequest.type = new vscode.RequestType('volar/server/fs/readFile');
26
- })(FsReadFileRequest || (exports.FsReadFileRequest = FsReadFileRequest = {}));
27
- var FsReadDirectoryRequest;
28
- (function (FsReadDirectoryRequest) {
29
- FsReadDirectoryRequest.type = new vscode.RequestType('volar/server/fs/readDirectory');
30
- })(FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = FsReadDirectoryRequest = {}));
31
- var FsStatRequest;
32
- (function (FsStatRequest) {
33
- FsStatRequest.type = new vscode.RequestType('volar/server/fs/stat');
34
- })(FsStatRequest || (exports.FsStatRequest = FsStatRequest = {}));
35
20
  /**
36
21
  * Client request server
37
22
  */
@@ -1,2 +0,0 @@
1
- import type { LanguageServer } from '../types';
2
- export declare function registerEditorFeatures(server: LanguageServer): void;
@@ -1,208 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerEditorFeatures = registerEditorFeatures;
4
- const language_service_1 = require("@volar/language-service");
5
- const protocol_1 = require("../../protocol");
6
- const vscode_uri_1 = require("vscode-uri");
7
- function registerEditorFeatures(server) {
8
- const scriptVersions = (0, language_service_1.createUriMap)();
9
- const scriptVersionSnapshots = new WeakSet();
10
- server.connection.onRequest(protocol_1.DocumentDropRequest.type, async ({ textDocument, position, dataTransfer }, token) => {
11
- const dataTransferMap = new Map();
12
- for (const item of dataTransfer) {
13
- dataTransferMap.set(item.mimeType, {
14
- value: item.value,
15
- asString() {
16
- return server.connection.sendRequest(protocol_1.DocumentDrop_DataTransferItemAsStringRequest.type, { mimeType: item.mimeType });
17
- },
18
- asFile() {
19
- if (item.file) {
20
- return {
21
- name: item.file.name,
22
- uri: item.file.uri,
23
- data() {
24
- return server.connection.sendRequest(protocol_1.DocumentDrop_DataTransferItemFileDataRequest.type, { mimeType: item.mimeType });
25
- },
26
- };
27
- }
28
- },
29
- });
30
- }
31
- const uri = vscode_uri_1.URI.parse(textDocument.uri);
32
- const languageService = (await server.project.getLanguageService(uri));
33
- return languageService.getDocumentDropEdits(uri, position, dataTransferMap, token);
34
- });
35
- server.connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
36
- const uri = vscode_uri_1.URI.parse(params.uri);
37
- const languageService = (await server.project.getLanguageService(uri));
38
- const tsProject = languageService.context.project.typescript;
39
- if (tsProject?.configFileName) {
40
- const { configFileName, asUri } = tsProject;
41
- return { uri: asUri(configFileName).toString() };
42
- }
43
- });
44
- server.connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (document) => {
45
- const uri = vscode_uri_1.URI.parse(document.uri);
46
- const languageService = (await server.project.getLanguageService(uri));
47
- const documentUri = vscode_uri_1.URI.parse(document.uri);
48
- const sourceScript = languageService.context.language.scripts.get(documentUri);
49
- if (sourceScript?.generated) {
50
- return prune(sourceScript.generated.root);
51
- }
52
- function prune(virtualCode) {
53
- const uri = languageService.context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
54
- let version = scriptVersions.get(uri) ?? 0;
55
- if (!scriptVersionSnapshots.has(virtualCode.snapshot)) {
56
- version++;
57
- scriptVersions.set(uri, version);
58
- scriptVersionSnapshots.add(virtualCode.snapshot);
59
- }
60
- return {
61
- fileUri: sourceScript.id.toString(),
62
- virtualCodeId: virtualCode.id,
63
- languageId: virtualCode.languageId,
64
- embeddedCodes: virtualCode.embeddedCodes?.map(prune) || [],
65
- version,
66
- disabled: languageService.context.disabledEmbeddedDocumentUris.has(uri),
67
- };
68
- }
69
- });
70
- server.connection.onRequest(protocol_1.GetVirtualCodeRequest.type, async (params) => {
71
- const uri = vscode_uri_1.URI.parse(params.fileUri);
72
- const languageService = (await server.project.getLanguageService(uri));
73
- const sourceScript = languageService.context.language.scripts.get(vscode_uri_1.URI.parse(params.fileUri));
74
- const virtualCode = sourceScript?.generated?.embeddedCodes.get(params.virtualCodeId);
75
- if (virtualCode) {
76
- const mappings = {};
77
- for (const [sourceScript, map] of languageService.context.language.maps.forEach(virtualCode)) {
78
- mappings[sourceScript.id.toString()] = map.mappings;
79
- }
80
- return {
81
- content: virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength()),
82
- mappings,
83
- };
84
- }
85
- });
86
- server.connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
87
- // webpack compatibility
88
- const _require = eval('require');
89
- const fs = _require('fs');
90
- const uri = vscode_uri_1.URI.parse(params.uri);
91
- const languageService = (await server.project.getLanguageService(uri));
92
- const tsProject = languageService.context.project.typescript;
93
- if (tsProject) {
94
- const { languageServiceHost } = tsProject;
95
- for (const fileName of languageServiceHost.getScriptFileNames()) {
96
- if (!fs.existsSync(fileName)) {
97
- // global virtual files
98
- const snapshot = languageServiceHost.getScriptSnapshot(fileName);
99
- if (snapshot) {
100
- fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
101
- }
102
- }
103
- else {
104
- const uri = tsProject.asUri(fileName);
105
- const sourceScript = languageService.context.language.scripts.get(uri);
106
- if (sourceScript?.generated) {
107
- const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
108
- if (serviceScript) {
109
- const { snapshot } = serviceScript.code;
110
- fs.writeFile(fileName + serviceScript.extension, snapshot.getText(0, snapshot.getLength()), () => { });
111
- }
112
- if (sourceScript.generated.languagePlugin.typescript?.getExtraServiceScripts) {
113
- for (const extraServiceScript of sourceScript.generated.languagePlugin.typescript.getExtraServiceScripts(uri.toString(), sourceScript.generated.root)) {
114
- const { snapshot } = extraServiceScript.code;
115
- fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
116
- }
117
- }
118
- }
119
- }
120
- }
121
- }
122
- });
123
- server.connection.onRequest(protocol_1.LoadedTSFilesMetaRequest.type, async () => {
124
- const sourceFilesData = new Map();
125
- for (const languageService of await server.project.getExistingLanguageServices()) {
126
- const tsLanguageService = languageService.context.inject('typescript/languageService');
127
- const program = tsLanguageService?.getProgram();
128
- const tsProject = languageService.context.project.typescript;
129
- if (program && tsProject) {
130
- const { languageServiceHost, configFileName } = tsProject;
131
- const projectName = configFileName ?? (languageServiceHost.getCurrentDirectory() + '(inferred)');
132
- const sourceFiles = program.getSourceFiles() ?? [];
133
- for (const sourceFile of sourceFiles) {
134
- if (!sourceFilesData.has(sourceFile)) {
135
- let nodes = 0;
136
- sourceFile.forEachChild(function walk(node) {
137
- nodes++;
138
- node.forEachChild(walk);
139
- });
140
- sourceFilesData.set(sourceFile, {
141
- projectNames: [],
142
- size: nodes * 128,
143
- });
144
- }
145
- sourceFilesData.get(sourceFile).projectNames.push(projectName);
146
- }
147
- ;
148
- }
149
- }
150
- const result = {
151
- inputs: {},
152
- outputs: {},
153
- };
154
- for (const [sourceFile, fileData] of sourceFilesData) {
155
- let key = fileData.projectNames.sort().join(', ');
156
- if (fileData.projectNames.length >= 2) {
157
- key = `Shared in ${fileData.projectNames.length} projects (${key})`;
158
- }
159
- result.outputs[key] ??= {
160
- imports: [],
161
- exports: [],
162
- entryPoint: '',
163
- inputs: {},
164
- bytes: 0,
165
- };
166
- result.outputs[key].inputs[sourceFile.fileName] = { bytesInOutput: fileData.size };
167
- }
168
- return result;
169
- });
170
- server.connection.onNotification(protocol_1.UpdateVirtualCodeStateNotification.type, async (params) => {
171
- const uri = vscode_uri_1.URI.parse(params.fileUri);
172
- const languageService = await server.project.getLanguageService(uri);
173
- const virtualFileUri = languageService.context.encodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(params.fileUri), params.virtualCodeId);
174
- if (params.disabled) {
175
- languageService.context.disabledEmbeddedDocumentUris.set(virtualFileUri, true);
176
- }
177
- else {
178
- languageService.context.disabledEmbeddedDocumentUris.delete(virtualFileUri);
179
- }
180
- });
181
- server.connection.onNotification(protocol_1.UpdateServicePluginStateNotification.type, async (params) => {
182
- const uri = vscode_uri_1.URI.parse(params.uri);
183
- const languageService = await server.project.getLanguageService(uri);
184
- const plugin = languageService.context.plugins[params.serviceId][1];
185
- if (params.disabled) {
186
- languageService.context.disabledServicePlugins.add(plugin);
187
- }
188
- else {
189
- languageService.context.disabledServicePlugins.delete(plugin);
190
- }
191
- });
192
- server.connection.onRequest(protocol_1.GetServicePluginsRequest.type, async (params) => {
193
- const uri = vscode_uri_1.URI.parse(params.uri);
194
- const languageService = await server.project.getLanguageService(uri);
195
- const result = [];
196
- for (let pluginIndex = 0; pluginIndex < languageService.context.plugins.length; pluginIndex++) {
197
- const plugin = languageService.context.plugins[pluginIndex];
198
- result.push({
199
- id: pluginIndex,
200
- name: plugin[0].name,
201
- disabled: languageService.context.disabledServicePlugins.has(plugin[1]),
202
- features: Object.keys(plugin[1]),
203
- });
204
- }
205
- return result;
206
- });
207
- }
208
- //# sourceMappingURL=registerEditorFeatures.js.map
@@ -1,3 +0,0 @@
1
- import type { LanguageServer } from '../types';
2
- export declare function registerLanguageFeatures(server: LanguageServer): void;
3
- export declare function sleep(ms: number): Promise<unknown>;