-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to latest version of vscode-languageserver-protocol Removes vscode-monaco-jsonrpc dependency Replaces references to vscode-languageserver-types with references to vscode-languageserver-protocol Refactors existing code to match new interfaces Co-authored-by: Paul Maréchal <[email protected] Co-authored-by: Colin Grant <[email protected]>
- Loading branch information
Colin Grant
committed
Nov 30, 2021
1 parent
6b9e099
commit 96a7521
Showing
106 changed files
with
746 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import * as rpc from 'vscode-languageserver-protocol'; | ||
import { RpcMessageRelay } from './rpc-message-relay'; | ||
import { Disposable } from '../disposable'; | ||
|
||
/** | ||
* A `Channel` represents a bidirectional logical connection to a remote. | ||
*/ | ||
export interface Channel<T = unknown> extends Disposable { | ||
send(content: T): void; | ||
onMessage(cb: (data: T) => void): void; | ||
onError(cb: (reason: any) => void): void; | ||
onClose(cb: (code: number, reason: string) => void): void; | ||
} | ||
|
||
export namespace Channel { | ||
|
||
export class MessageReader extends rpc.AbstractMessageReader implements rpc.MessageReader { | ||
constructor(protected channel: Channel<string>) { | ||
super(); | ||
channel.onError(error => this.fireError(error)); | ||
channel.onClose(() => this.fireClose()); | ||
} | ||
listen(callback: rpc.DataCallback): rpc.Disposable { | ||
this.channel.onMessage(data => callback(JSON.parse(data))); | ||
return rpc.Disposable.create(() => { | ||
throw new Error('not supported'); | ||
}); | ||
} | ||
} | ||
|
||
export class MessageWriter extends rpc.AbstractMessageWriter implements rpc.MessageWriter { | ||
constructor(protected channel: Channel<string>) { | ||
super(); | ||
channel.onError(error => this.fireError(error)); | ||
channel.onClose(() => this.fireClose()); | ||
} | ||
async write(message: rpc.Message): Promise<void> { | ||
this.channel.send(JSON.stringify(message)); | ||
} | ||
end(): void { } | ||
} | ||
|
||
export function createMessageConnection(channel: Channel<string>, logger?: rpc.Logger, options?: rpc.ConnectionOptions): rpc.MessageConnection { | ||
const reader = new MessageReader(channel); | ||
const writer = new MessageWriter(channel); | ||
return rpc.createMessageConnection(reader, writer, logger, options); | ||
} | ||
|
||
export function createRpcMessageRelay(channel: Channel<string>, onDispose: () => void = () => { }): RpcMessageRelay { | ||
const reader = new MessageReader(channel); | ||
const writer = new MessageWriter(channel); | ||
return RpcMessageRelay.create(reader, writer, onDispose); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { MaybePromise, Unpromise } from '../types'; | ||
|
||
export type UndefinedOrNull<T> = T extends object | ||
? { [K in keyof T]: UndefinedOrNull<T[K]> } | ||
: T extends undefined ? undefined | null : T; | ||
|
||
export interface JsonRpcMethods { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[method: string]: (...args: any[]) => MaybePromise<any> | ||
} | ||
|
||
/** | ||
* Use this type to wrap your JSON-RPC service APIs to ensure you only use types that can be serialized through JSON-RPC. | ||
* | ||
* It replaces any occurence of `undefined` in the signature with `undefined | null` because when passing `undefined` it | ||
* becomes `null` when serialized in JSON. The implementations must be able to handle both cases. | ||
*/ | ||
export type JsonRpcService<T extends JsonRpcMethods> = { | ||
[K in keyof T]: (...args: UndefinedOrNull<Parameters<T[K]>>) => Promise<UndefinedOrNull<Unpromise<ReturnType<T[K]>>>> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.