Skip to content

Commit 6a412e5

Browse files
committed
fix(vscode): don't rely on language-server/protocol
1 parent c5d727b commit 6a412e5

File tree

11 files changed

+187
-38
lines changed

11 files changed

+187
-38
lines changed

extensions/labs/src/views/serversView.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { LoadedTSFilesMetaRequest } from '@volar/language-server/protocol';
21
import type { LabsInfo } from '@volar/vscode';
32
import * as lsp from '@volar/vscode';
43
import * as fs from 'fs';
@@ -114,7 +113,7 @@ export function activate(context: vscode.ExtensionContext) {
114113
command: {
115114
command: '_volar.action.tsMemoryTreemap',
116115
title: '',
117-
arguments: [element.client],
116+
arguments: [element.client, element.extension.exports.volarLabs.languageServerProtocol],
118117
},
119118
};
120119
}
@@ -179,7 +178,7 @@ export function activate(context: vscode.ExtensionContext) {
179178
await client.stop();
180179
await client.start();
181180
}),
182-
vscode.commands.registerCommand('_volar.action.tsMemoryTreemap', async (client: lsp.BaseLanguageClient) => {
181+
vscode.commands.registerCommand('_volar.action.tsMemoryTreemap', async (client: lsp.BaseLanguageClient, protocol: typeof import('@volar/vscode/protocol')) => {
183182

184183
const select = await quickPick([
185184
{
@@ -210,7 +209,7 @@ export function activate(context: vscode.ExtensionContext) {
210209

211210
progress.report({ increment: 0 });
212211

213-
const meta = await client.sendRequest(LoadedTSFilesMetaRequest.type);
212+
const meta = await client.sendRequest(protocol.LoadedTSFilesMetaRequest.type);
214213
const { visualizer } = await import('esbuild-visualizer/dist/plugin/index.js');
215214
const fileContent = await visualizer(meta as any);
216215

packages/language-server/protocol.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CodeMapping } from '@volar/language-core';
22
import type { DocumentDropEdit } from '@volar/language-service';
3-
import * as vscode from 'vscode-languageserver-protocol';
3+
import * as protocol from 'vscode-languageserver-protocol';
44

55
export * from 'vscode-languageserver-protocol';
66

@@ -10,24 +10,24 @@ export * from 'vscode-languageserver-protocol';
1010

1111
export namespace FindFileReferenceRequest {
1212
export type ParamsType = {
13-
textDocument: vscode.TextDocumentIdentifier;
13+
textDocument: protocol.TextDocumentIdentifier;
1414
};
15-
export type ResponseType = vscode.Location[] | null | undefined;
15+
export type ResponseType = protocol.Location[] | null | undefined;
1616
export type ErrorType = never;
17-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/findFileReference');
17+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/findFileReference');
1818
}
1919

2020
export namespace GetMatchTsConfigRequest {
21-
export type ParamsType = vscode.TextDocumentIdentifier;
21+
export type ParamsType = protocol.TextDocumentIdentifier;
2222
export type ResponseType = { uri: string; } | null | undefined;
2323
export type ErrorType = never;
24-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/tsconfig');
24+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/tsconfig');
2525
}
2626

2727
export namespace AutoInsertRequest {
2828
export type ParamsType = {
29-
textDocument: vscode.TextDocumentIdentifier;
30-
selection: vscode.Position;
29+
textDocument: protocol.TextDocumentIdentifier;
30+
selection: protocol.Position;
3131
change: {
3232
rangeOffset: number;
3333
rangeLength: number;
@@ -36,23 +36,23 @@ export namespace AutoInsertRequest {
3636
};
3737
export type ResponseType = string | null | undefined;
3838
export type ErrorType = never;
39-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/autoInsert');
39+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/autoInsert');
4040
}
4141

4242
export namespace WriteVirtualFilesNotification {
43-
export const type = new vscode.NotificationType<vscode.TextDocumentIdentifier>('volar/client/writeVirtualFiles');
43+
export const type = new protocol.NotificationType<protocol.TextDocumentIdentifier>('volar/client/writeVirtualFiles');
4444
}
4545

4646
export namespace ReloadProjectNotification {
47-
export const type = new vscode.NotificationType<vscode.TextDocumentIdentifier>('volar/client/reloadProject');
47+
export const type = new protocol.NotificationType<protocol.TextDocumentIdentifier>('volar/client/reloadProject');
4848
}
4949

5050
/**
5151
* Document Drop
5252
*/
5353

5454
export namespace DocumentDropRequest {
55-
export type ParamsType = vscode.TextDocumentPositionParams & {
55+
export type ParamsType = protocol.TextDocumentPositionParams & {
5656
dataTransfer: {
5757
mimeType: string;
5858
value: any;
@@ -64,7 +64,7 @@ export namespace DocumentDropRequest {
6464
};
6565
export type ResponseType = DocumentDropEdit | null | undefined;
6666
export type ErrorType = never;
67-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop');
67+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop');
6868
}
6969

7070
export namespace DocumentDrop_DataTransferItemAsStringRequest {
@@ -73,7 +73,7 @@ export namespace DocumentDrop_DataTransferItemAsStringRequest {
7373
};
7474
export type ResponseType = string;
7575
export type ErrorType = never;
76-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop/asString');
76+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop/asString');
7777
}
7878

7979
export namespace DocumentDrop_DataTransferItemFileDataRequest {
@@ -82,7 +82,7 @@ export namespace DocumentDrop_DataTransferItemFileDataRequest {
8282
};
8383
export type ResponseType = Uint8Array;
8484
export type ErrorType = never;
85-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop/fileData');
85+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/documentDrop/fileData');
8686
}
8787

8888
/**
@@ -95,7 +95,7 @@ export namespace UpdateVirtualCodeStateNotification {
9595
virtualCodeId: string;
9696
disabled: boolean;
9797
};
98-
export const type = new vscode.NotificationType<ParamsType>('volar/client/labs/updateVirtualFileState');
98+
export const type = new protocol.NotificationType<ParamsType>('volar/client/labs/updateVirtualFileState');
9999
}
100100

101101
export namespace UpdateServicePluginStateNotification {
@@ -104,19 +104,19 @@ export namespace UpdateServicePluginStateNotification {
104104
serviceId: number;
105105
disabled: boolean;
106106
};
107-
export const type = new vscode.NotificationType<ParamsType>('volar/client/labs/updateServicePluginState');
107+
export const type = new protocol.NotificationType<ParamsType>('volar/client/labs/updateServicePluginState');
108108
}
109109

110110
export namespace GetServicePluginsRequest {
111-
export type ParamsType = vscode.TextDocumentIdentifier;
111+
export type ParamsType = protocol.TextDocumentIdentifier;
112112
export type ResponseType = {
113113
id: number;
114114
name?: string;
115115
features: string[];
116116
disabled: boolean;
117117
}[] | null | undefined;
118118
export type ErrorType = never;
119-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/servicePlugins');
119+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/servicePlugins');
120120
}
121121

122122
export namespace GetVirtualFileRequest {
@@ -128,10 +128,10 @@ export namespace GetVirtualFileRequest {
128128
disabled: boolean;
129129
embeddedCodes: VirtualCodeInfo[];
130130
};
131-
export type ParamsType = vscode.TextDocumentIdentifier;
131+
export type ParamsType = protocol.TextDocumentIdentifier;
132132
export type ResponseType = VirtualCodeInfo | null | undefined;
133133
export type ErrorType = never;
134-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/virtualFiles');
134+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/virtualFiles');
135135
}
136136

137137
export namespace GetVirtualCodeRequest {
@@ -144,9 +144,9 @@ export namespace GetVirtualCodeRequest {
144144
mappings: Record<string, CodeMapping[]>;
145145
};
146146
export type ErrorType = never;
147-
export const type = new vscode.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/virtualFile');
147+
export const type = new protocol.RequestType<ParamsType, ResponseType, ErrorType>('volar/client/virtualFile');
148148
}
149149

150150
export namespace LoadedTSFilesMetaRequest {
151-
export const type = new vscode.RequestType0('volar/client/loadedTsFiles');
151+
export const type = new protocol.RequestType0('volar/client/loadedTsFiles');
152152
}

packages/vscode/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as protocol from './protocol.js';
23

34
export { activate as activateAutoInsertion } from './lib/features/autoInsertion';
45
export { activate as activateDocumentDropEdit } from './lib/features/documentDropEdits';
@@ -80,13 +81,13 @@ export function parseServerCommand(command: vscode.Command) {
8081

8182
export const currentLabsVersion = '2.3.1';
8283

83-
export function createLabsInfo(languageServerProtocol: typeof import('@volar/language-server/protocol')) {
84+
export function createLabsInfo(_?: typeof import('@volar/language-server/protocol')) {
8485
const onDidAddLanguageClientEmitter = new vscode.EventEmitter<BaseLanguageClient>();
8586
const extensionExports: LabsInfo = {
8687
volarLabs: {
8788
version: currentLabsVersion,
8889
languageClients: [] as BaseLanguageClient[],
89-
languageServerProtocol,
90+
languageServerProtocol: protocol,
9091
onDidAddLanguageClient: onDidAddLanguageClientEmitter.event,
9192
},
9293
};
@@ -104,6 +105,6 @@ export interface LabsInfo {
104105
version: typeof currentLabsVersion;
105106
languageClients: BaseLanguageClient[];
106107
onDidAddLanguageClient: vscode.Event<BaseLanguageClient>;
107-
languageServerProtocol: typeof import('@volar/language-server/protocol');
108+
languageServerProtocol: typeof import('./protocol.js');
108109
};
109110
}

packages/vscode/lib/features/autoInsertion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ExperimentalFeatures } from '@volar/language-server';
2-
import { AutoInsertRequest } from '@volar/language-server/protocol';
2+
import { AutoInsertRequest } from '../../protocol.js';
33
import * as vscode from 'vscode';
44
import type { BaseLanguageClient, ServerCapabilities } from 'vscode-languageclient';
55

packages/vscode/lib/features/documentDropEdits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import type { BaseLanguageClient } from 'vscode-languageclient';
3-
import { DocumentDropRequest, DocumentDrop_DataTransferItemAsStringRequest, DocumentDrop_DataTransferItemFileDataRequest } from '@volar/language-server/protocol';
3+
import { DocumentDropRequest, DocumentDrop_DataTransferItemAsStringRequest, DocumentDrop_DataTransferItemFileDataRequest } from '../../protocol.js';
44

55
export function activate(selector: vscode.DocumentSelector, client: BaseLanguageClient) {
66

packages/vscode/lib/features/fileReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import type { BaseLanguageClient } from 'vscode-languageclient';
33
import * as nls from 'vscode-nls';
4-
import { FindFileReferenceRequest } from '@volar/language-server/protocol';
4+
import { FindFileReferenceRequest } from '../../protocol.js';
55

66
const localize = nls.loadMessageBundle();
77

packages/vscode/lib/features/reloadProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import type { BaseLanguageClient } from 'vscode-languageclient';
3-
import { ReloadProjectNotification } from '@volar/language-server/protocol';
3+
import { ReloadProjectNotification } from '../../protocol.js';
44

55
export function activate(cmd: string, client: BaseLanguageClient) {
66
return vscode.commands.registerCommand(cmd, () => {

packages/vscode/lib/features/tsconfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import type { BaseLanguageClient } from 'vscode-languageclient';
3-
import { GetMatchTsConfigRequest } from '@volar/language-server/protocol';
3+
import { GetMatchTsConfigRequest } from '../../protocol.js';
44
import * as path from 'path-browserify';
55

66
export function activate(

packages/vscode/lib/features/writeVirtualFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import type { BaseLanguageClient } from 'vscode-languageclient';
3-
import { WriteVirtualFilesNotification } from '@volar/language-server/protocol';
3+
import { WriteVirtualFilesNotification } from '../../protocol.js';
44

55
export function activate(cmd: string, client: BaseLanguageClient) {
66
return vscode.commands.registerCommand(cmd, () => {

packages/vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
"directory": "packages/vscode"
1313
},
1414
"dependencies": {
15-
"@volar/language-server": "2.4.13",
1615
"path-browserify": "^1.0.1",
1716
"vscode-languageclient": "^9.0.1",
1817
"vscode-nls": "^5.2.0"
1918
},
2019
"devDependencies": {
2120
"@types/node": "latest",
2221
"@types/path-browserify": "latest",
23-
"@types/vscode": "^1.82.0"
22+
"@types/vscode": "^1.82.0",
23+
"@volar/language-server": "2.4.13"
2424
}
2525
}

0 commit comments

Comments
 (0)