-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
lsp_client.ts
44 lines (38 loc) · 1.22 KB
/
lsp_client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ResponseError, ResponseMessage } from 'vscode-jsonrpc/lib/messages';
export { TextDocumentMethods } from './text_document_methods';
import { kfetch } from 'ui/kfetch';
export interface LspClient {
sendRequest(method: string, params: any, singal?: AbortSignal): Promise<ResponseMessage>;
}
export class LspRestClient implements LspClient {
private baseUri: string;
constructor(baseUri: string) {
this.baseUri = baseUri;
}
public async sendRequest(
method: string,
params: any,
signal?: AbortSignal
): Promise<ResponseMessage> {
try {
const response = await kfetch({
pathname: `${this.baseUri}/${method}`,
method: 'POST',
body: JSON.stringify(params),
signal,
});
return response as ResponseMessage;
} catch (e) {
let error = e;
if (error.body && error.body.error) {
error = error.body.error;
}
throw new ResponseError<any>(error.code, error.message, error.data);
}
}
}