Skip to content

Commit 26c9ee4

Browse files
committed
[880] ws
1 parent 0f9be07 commit 26c9ee4

File tree

7 files changed

+81
-106
lines changed

7 files changed

+81
-106
lines changed

packages/lsp-ws-connection/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# lsp-ws-connection
22

3-
> This is a fork of [lsp-editor-adapter](https://github.com/wylieconlon/lsp-editor-adapter), with
4-
> a number of modifications made to make it more easily integrated into [jupyterlab-lsp](https://github.com/jupyter-lsp/jupyterlab-lsp)
3+
> This is a fork of
4+
> [lsp-editor-adapter](https://github.com/wylieconlon/lsp-editor-adapter), with a number
5+
> of modifications made to make it more easily integrated into
6+
> [jupyterlab-lsp](https://github.com/jupyter-lsp/jupyterlab-lsp)
57
68
## Installation
79

810
> TBD
911
1012
## Developing
1113

12-
This library is built and tested as part of the [`jupyterlab-lsp` monorepo](https://github.com/jupyter-lsp/jupyterlab-lsp).
14+
This library is built and tested as part of the
15+
[`jupyterlab-lsp` monorepo](https://github.com/jupyter-lsp/jupyterlab-lsp).

packages/lsp-ws-connection/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@
2424
"lsp",
2525
"languageserver"
2626
],
27-
"homepage": "https://github.com/jupyter-lsp/jupyterlab-lsp/tree/master/packages/lsp-ws-connection",
28-
"repository": "github:jupyter-lsp/jupyterlab-lsp",
27+
"homepage": "https://github.com/krassowski/jupyterlab-lsp/tree/master/packages/lsp-ws-connection",
28+
"repository": "github:krassowski/jupyterlab-lsp",
2929
"dependencies": {
30+
"vscode-jsonrpc": "^6.0.0",
3031
"vscode-languageserver-protocol": "^3.16.0",
3132
"vscode-languageserver-types": "^3.16.0",
32-
"vscode-ws-jsonrpc": "~1.0.2"
33+
"vscode-ws-jsonrpc": "0.2.0"
3334
},
3435
"devDependencies": {
3536
"@types/chai": "^4.1.7",
3637
"@types/mocha": "^5.2.7",
3738
"@types/node": "^12.0.7",
3839
"@types/sinon": "^7.0.12",
40+
"buffer": "^6.0.3",
3941
"chai": "^4.2.0",
4042
"file-loader": "~3.0.1",
4143
"mocha": "^6.1.4",
4244
"rimraf": "^3.0.2",
4345
"sinon": "^7.3.2",
44-
"typescript": "~4.1.3",
45-
"webpack": "^5.54.0",
46-
"webpack-cli": "^4.1.0"
46+
"stream-browserify": "^3.0.0",
47+
"setimmediate": "^1.0.5",
48+
"typescript": "~4.9.4",
49+
"webpack-cli": "^5.0.1",
50+
"webpack": "^5.54.0"
4751
}
4852
}

packages/lsp-ws-connection/src/test/connection.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ describe('LspWsConnection', () => {
180180

181181
// Send the messages
182182
expect(mockSocket.send.callCount).equal(1);
183-
expect(JSON.parse(mockSocket.send.firstCall.args[0]).method).equal(
184-
'initialize'
185-
);
183+
expect(JSON.parse(mockSocket.send.firstCall.args[0]).method).equal('initialize');
186184
});
187185

188186
describe('register/unregister capability', () => {

packages/lsp-ws-connection/src/test/server-capability-registration.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ describe('ServerCapabilities client registration', () => {
6767

6868
if (typeof capabilityOptions === 'boolean') {
6969
// eslint-disable-next-line jest/no-conditional-expect
70-
expect((newServerCapabilities as any)[capability]).equal(
71-
capabilityOptions
72-
);
70+
expect((newServerCapabilities as any)[capability]).equal(capabilityOptions);
7371
} else {
7472
// eslint-disable-next-line jest/no-conditional-expect
7573
expect((newServerCapabilities as any)[capability]).to.deep.equal(

packages/lsp-ws-connection/src/types.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export type AnyLocation =
2525
| undefined
2626
| null;
2727

28-
export type AnyCompletion =
29-
| lsProtocol.CompletionList
30-
| lsProtocol.CompletionItem[];
28+
export type AnyCompletion = lsProtocol.CompletionList | lsProtocol.CompletionItem[];
3129

3230
export enum CompletionTriggerKind {
3331
Invoked = 1,
@@ -47,10 +45,7 @@ type ConnectionEvent =
4745
| 'logging';
4846

4947
export interface ILspConnection {
50-
on(
51-
event: 'completion',
52-
callback: (items: lsProtocol.CompletionItem[]) => void
53-
): void;
48+
on(event: 'completion', callback: (items: lsProtocol.CompletionItem[]) => void): void;
5449
on(
5550
event: 'completionResolved',
5651
callback: (item: lsProtocol.CompletionItem) => void
@@ -65,10 +60,7 @@ export interface ILspConnection {
6560
): void;
6661
on(
6762
event: 'highlight',
68-
callback: (
69-
highlights: lsProtocol.DocumentHighlight[],
70-
documentUri: string
71-
) => void
63+
callback: (highlights: lsProtocol.DocumentHighlight[], documentUri: string) => void
7264
): void;
7365
on(
7466
event: 'signature',
@@ -78,10 +70,7 @@ export interface ILspConnection {
7870
event: 'goTo',
7971
callback: (location: AnyLocation, documentUri: string) => void
8072
): void;
81-
on(
82-
event: 'rename',
83-
callback: (edit: lsProtocol.WorkspaceEdit | null) => void
84-
): void;
73+
on(event: 'rename', callback: (edit: lsProtocol.WorkspaceEdit | null) => void): void;
8574
on(event: 'error', callback: (error: any) => void): void;
8675
on(event: 'logging', callback: (log: any) => void): void;
8776

packages/lsp-ws-connection/src/ws-connection.ts

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as events from 'events';
22

3+
import 'setimmediate';
34
import type * as protocol from 'vscode-languageserver-protocol';
45
import type { LocationLink } from 'vscode-languageserver-types';
5-
import { ConsoleLogger, MessageConnection, listen } from 'vscode-ws-jsonrpc';
6+
import type * as rpc from 'vscode-ws-jsonrpc';
7+
import { listen, ConsoleLogger } from 'vscode-ws-jsonrpc';
68

79
import {
810
registerServerCapability,
@@ -27,16 +29,13 @@ import {
2729
* - initializeParams() was extracted, and can be modified by subclasses
2830
* - typescript 3.7 was adopted to clean up deep references
2931
*/
30-
export class LspWsConnection
31-
extends events.EventEmitter
32-
implements ILspConnection
33-
{
32+
export class LspWsConnection extends events.EventEmitter implements ILspConnection {
3433
public isConnected = false;
3534
public isInitialized = false;
3635
public documentInfo: ILspOptions;
3736
public serverCapabilities: protocol.ServerCapabilities;
3837
protected socket: WebSocket;
39-
protected connection: MessageConnection;
38+
protected connection: rpc.MessageConnection;
4039
protected openedUris = new Map<string, boolean>();
4140
private rootUri: string;
4241

@@ -58,7 +57,7 @@ export class LspWsConnection
5857
listen({
5958
webSocket: this.socket,
6059
logger: new ConsoleLogger(),
61-
onConnection: (connection: MessageConnection) => {
60+
onConnection: (connection: rpc.MessageConnection) => {
6261
connection.listen();
6362
this.isConnected = true;
6463

@@ -165,16 +164,14 @@ export class LspWsConnection
165164

166165
const message: protocol.InitializeParams = this.initializeParams();
167166

168-
this.connection
169-
.sendRequest<protocol.InitializeResult>('initialize', message)
170-
.then(
171-
params => {
172-
this.onServerInitialized(params);
173-
},
174-
e => {
175-
console.warn('lsp-ws-connection initialization failure', e);
176-
}
177-
);
167+
this.connection.sendRequest<protocol.InitializeResult>('initialize', message).then(
168+
params => {
169+
this.onServerInitialized(params);
170+
},
171+
e => {
172+
console.warn('lsp-ws-connection initialization failure', e);
173+
}
174+
);
178175
}
179176

180177
sendOpen(documentInfo: IDocumentInfo) {
@@ -186,10 +183,7 @@ export class LspWsConnection
186183
version: documentInfo.version
187184
} as protocol.TextDocumentItem
188185
};
189-
void this.connection.sendNotification(
190-
'textDocument/didOpen',
191-
textDocumentMessage
192-
);
186+
this.connection.sendNotification('textDocument/didOpen', textDocumentMessage);
193187
this.openedUris.set(documentInfo.uri, true);
194188
this.sendChange(documentInfo);
195189
}
@@ -209,10 +203,7 @@ export class LspWsConnection
209203
} as protocol.VersionedTextDocumentIdentifier,
210204
contentChanges: [{ text: documentInfo.text }]
211205
};
212-
void this.connection.sendNotification(
213-
'textDocument/didChange',
214-
textDocumentChange
215-
);
206+
this.connection.sendNotification('textDocument/didChange', textDocumentChange);
216207
documentInfo.version++;
217208
}
218209

@@ -228,28 +219,17 @@ export class LspWsConnection
228219
} as protocol.VersionedTextDocumentIdentifier,
229220
text: documentInfo.text
230221
};
231-
void this.connection.sendNotification(
232-
'textDocument/didSave',
233-
textDocumentChange
234-
);
222+
this.connection.sendNotification('textDocument/didSave', textDocumentChange);
235223
}
236224

237-
public sendConfigurationChange(
238-
settings: protocol.DidChangeConfigurationParams
239-
) {
225+
public sendConfigurationChange(settings: protocol.DidChangeConfigurationParams) {
240226
if (!this.isReady) {
241227
return;
242228
}
243229

244-
void this.connection.sendNotification(
245-
'workspace/didChangeConfiguration',
246-
settings
247-
);
230+
this.connection.sendNotification('workspace/didChangeConfiguration', settings);
248231
}
249232

250-
/**
251-
* @deprecated
252-
*/
253233
public async getHoverTooltip(
254234
location: IPosition,
255235
documentInfo: IDocumentInfo,
@@ -281,9 +261,6 @@ export class LspWsConnection
281261
return hover;
282262
}
283263

284-
/**
285-
* @deprecated
286-
*/
287264
public async getCompletion(
288265
location: IPosition,
289266
token: ITokenInfo,
@@ -328,10 +305,7 @@ export class LspWsConnection
328305
return;
329306
}
330307
void this.connection
331-
.sendRequest<protocol.CompletionItem>(
332-
'completionItem/resolve',
333-
completionItem
334-
)
308+
.sendRequest<protocol.CompletionItem>('completionItem/resolve', completionItem)
335309
.then(result => {
336310
this.emit('completionResolved', result);
337311
});
@@ -384,7 +358,6 @@ export class LspWsConnection
384358

385359
/**
386360
* Request the locations of all matching document symbols
387-
* @deprecated
388361
*/
389362
public async getDocumentHighlights(
390363
location: IPosition,
@@ -395,17 +368,18 @@ export class LspWsConnection
395368
return;
396369
}
397370

398-
const highlights = await this.connection.sendRequest<
399-
protocol.DocumentHighlight[]
400-
>('textDocument/documentHighlight', {
401-
textDocument: {
402-
uri: documentInfo.uri
403-
},
404-
position: {
405-
line: location.line,
406-
character: location.ch
407-
}
408-
} as protocol.TextDocumentPositionParams);
371+
const highlights = await this.connection.sendRequest<protocol.DocumentHighlight[]>(
372+
'textDocument/documentHighlight',
373+
{
374+
textDocument: {
375+
uri: documentInfo.uri
376+
},
377+
position: {
378+
line: location.line,
379+
character: location.ch
380+
}
381+
} as protocol.TextDocumentPositionParams
382+
);
409383

410384
if (emit) {
411385
this.emit('highlight', highlights, documentInfo.uri);
@@ -417,7 +391,6 @@ export class LspWsConnection
417391
/**
418392
* Request a link to the definition of the current symbol. The results will not be displayed
419393
* unless they are within the same file URI
420-
* @deprecated
421394
*/
422395
public async getDefinition(
423396
location: IPosition,
@@ -453,7 +426,6 @@ export class LspWsConnection
453426
/**
454427
* Request a link to the type definition of the current symbol. The results will not be displayed
455428
* unless they are within the same file URI
456-
* @deprecated
457429
*/
458430
public async getTypeDefinition(
459431
location: IPosition,
@@ -489,7 +461,6 @@ export class LspWsConnection
489461
/**
490462
* Request a link to the implementation of the current symbol. The results will not be displayed
491463
* unless they are within the same file URI
492-
* @deprecated
493464
*/
494465
public getImplementation(location: IPosition, documentInfo: IDocumentInfo) {
495466
if (!this.isReady || !this.isImplementationSupported()) {
@@ -517,7 +488,6 @@ export class LspWsConnection
517488
/**
518489
* Request a link to all references to the current symbol. The results will not be displayed
519490
* unless they are within the same file URI
520-
* @deprecated
521491
*/
522492
public async getReferences(
523493
location: IPosition,
@@ -555,49 +525,41 @@ export class LspWsConnection
555525

556526
/**
557527
* The characters that trigger completion automatically.
558-
* @deprecated
559528
*/
560529
public getLanguageCompletionCharacters(): string[] {
561530
return this.serverCapabilities?.completionProvider?.triggerCharacters || [];
562531
}
563532

564533
/**
565534
* The characters that trigger signature help automatically.
566-
* @deprecated
567535
*/
568536
public getLanguageSignatureCharacters(): string[] {
569-
return (
570-
this.serverCapabilities?.signatureHelpProvider?.triggerCharacters || []
571-
);
537+
return this.serverCapabilities?.signatureHelpProvider?.triggerCharacters || [];
572538
}
573539

574540
/**
575541
* Does the server support go to definition?
576-
* @deprecated
577542
*/
578543
public isDefinitionSupported() {
579544
return !!this.serverCapabilities?.definitionProvider;
580545
}
581546

582547
/**
583548
* Does the server support go to type definition?
584-
* @deprecated
585549
*/
586550
public isTypeDefinitionSupported() {
587551
return !!this.serverCapabilities?.typeDefinitionProvider;
588552
}
589553

590554
/**
591555
* Does the server support go to implementation?
592-
* @deprecated
593556
*/
594557
public isImplementationSupported() {
595558
return !!this.serverCapabilities?.implementationProvider;
596559
}
597560

598561
/**
599562
* Does the server support find all references?
600-
* @deprecated
601563
*/
602564
public isReferencesSupported() {
603565
return !!this.serverCapabilities?.referencesProvider;
@@ -606,8 +568,8 @@ export class LspWsConnection
606568
protected onServerInitialized(params: protocol.InitializeResult) {
607569
this.isInitialized = true;
608570
this.serverCapabilities = params.capabilities;
609-
void this.connection.sendNotification('initialized', {});
610-
void this.connection.sendNotification('workspace/didChangeConfiguration', {
571+
this.connection.sendNotification('initialized', {});
572+
this.connection.sendNotification('workspace/didChangeConfiguration', {
611573
settings: {}
612574
});
613575
this.emit('serverInitialized', this.serverCapabilities);

0 commit comments

Comments
 (0)