aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-25 13:56:26 +0100
committerAleksey Kladov <[email protected]>2020-05-25 13:56:26 +0100
commita30bdd9795770329e4562d8bfca60ebe2e52dea1 (patch)
tree510b580723f06fd3ae1e4c641001afa82a426b60 /editors
parent8686d0b0ac765c2144b22b897de1d8fda68ecc6e (diff)
Cleanup lsp extensions on the client side
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands.ts2
-rw-r--r--editors/code/src/debug.ts2
-rw-r--r--editors/code/src/inlay_hints.ts2
-rw-r--r--editors/code/src/lsp_ext.ts84
-rw-r--r--editors/code/src/run.ts2
-rw-r--r--editors/code/src/rust-analyzer-api.ts123
6 files changed, 88 insertions, 127 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index e08030140..49e3845d5 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import * as ra from './rust-analyzer-api'; 3import * as ra from './lsp_ext';
4 4
5import { Ctx, Cmd } from './ctx'; 5import { Ctx, Cmd } from './ctx';
6import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; 6import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts
index d3fe588e8..027504ecd 100644
--- a/editors/code/src/debug.ts
+++ b/editors/code/src/debug.ts
@@ -1,7 +1,7 @@
1import * as os from "os"; 1import * as os from "os";
2import * as vscode from 'vscode'; 2import * as vscode from 'vscode';
3import * as path from 'path'; 3import * as path from 'path';
4import * as ra from './rust-analyzer-api'; 4import * as ra from './lsp_ext';
5 5
6import { Cargo } from './cargo'; 6import { Cargo } from './cargo';
7import { Ctx } from "./ctx"; 7import { Ctx } from "./ctx";
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index a2b07d003..9e6d6045f 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -1,6 +1,6 @@
1import * as lc from "vscode-languageclient"; 1import * as lc from "vscode-languageclient";
2import * as vscode from 'vscode'; 2import * as vscode from 'vscode';
3import * as ra from './rust-analyzer-api'; 3import * as ra from './lsp_ext';
4 4
5import { Ctx, Disposable } from './ctx'; 5import { Ctx, Disposable } from './ctx';
6import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; 6import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util';
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
new file mode 100644
index 000000000..2a0663261
--- /dev/null
+++ b/editors/code/src/lsp_ext.ts
@@ -0,0 +1,84 @@
1/**
2 * This file mirrors `crates/rust-analyzer/src/req.rs` declarations.
3 */
4
5import * as lc from "vscode-languageclient";
6
7export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus");
8
9export const collectGarbage = new lc.RequestType<null, null, void>("rust-analyzer/collectGarbage");
10
11export interface SyntaxTreeParams {
12 textDocument: lc.TextDocumentIdentifier;
13 range: lc.Range | null;
14}
15export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>("rust-analyzer/syntaxTree");
16
17
18export interface ExpandMacroParams {
19 textDocument: lc.TextDocumentIdentifier;
20 position: lc.Position;
21}
22export interface ExpandedMacro {
23 name: string;
24 expansion: string;
25}
26export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>("rust-analyzer/expandMacro");
27
28export interface MatchingBraceParams {
29 textDocument: lc.TextDocumentIdentifier;
30 positions: lc.Position[];
31}
32export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>("experimental/matchingBrace");
33
34export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc.Location[], void>("rust-analyzer/parentModule");
35
36export interface JoinLinesParams {
37 textDocument: lc.TextDocumentIdentifier;
38 ranges: lc.Range[];
39}
40export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>("experimental/joinLines");
41
42export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>("experimental/onEnter");
43
44export interface RunnablesParams {
45 textDocument: lc.TextDocumentIdentifier;
46 position: lc.Position | null;
47}
48export interface Runnable {
49 range: lc.Range;
50 label: string;
51 bin: string;
52 args: string[];
53 extraArgs: string[];
54 env: { [key: string]: string };
55 cwd: string | null;
56}
57export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("rust-analyzer/runnables");
58
59export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
60
61export namespace InlayHint {
62 export const enum Kind {
63 TypeHint = "TypeHint",
64 ParamHint = "ParameterHint",
65 ChainingHint = "ChainingHint",
66 }
67 interface Common {
68 range: lc.Range;
69 label: string;
70 }
71 export type TypeHint = Common & { kind: Kind.TypeHint };
72 export type ParamHint = Common & { kind: Kind.ParamHint };
73 export type ChainingHint = Common & { kind: Kind.ChainingHint };
74}
75export interface InlayHintsParams {
76 textDocument: lc.TextDocumentIdentifier;
77}
78export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints");
79
80export interface SsrParams {
81 query: string;
82 parseOnly: boolean;
83}
84export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>('experimental/ssr');
diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts
index 8f0487d74..2a7a429cf 100644
--- a/editors/code/src/run.ts
+++ b/editors/code/src/run.ts
@@ -1,6 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import * as ra from './rust-analyzer-api'; 3import * as ra from './lsp_ext';
4 4
5import { Ctx, Cmd } from './ctx'; 5import { Ctx, Cmd } from './ctx';
6import { startDebugSession, getDebugConfiguration } from './debug'; 6import { startDebugSession, getDebugConfiguration } from './debug';
diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts
deleted file mode 100644
index c10c0fa78..000000000
--- a/editors/code/src/rust-analyzer-api.ts
+++ /dev/null
@@ -1,123 +0,0 @@
1/**
2 * This file mirrors `crates/rust-analyzer/src/req.rs` declarations.
3 */
4
5import * as lc from "vscode-languageclient";
6
7type Option<T> = null | T;
8type Vec<T> = T[];
9type FxHashMap<K extends PropertyKey, V> = Record<K, V>;
10
11function request<TParams, TResult>(method: string) {
12 return new lc.RequestType<TParams, TResult, unknown>(`rust-analyzer/${method}`);
13}
14function notification<TParam>(method: string) {
15 return new lc.NotificationType<TParam>(method);
16}
17
18
19export const analyzerStatus = request<null, string>("analyzerStatus");
20
21
22export const collectGarbage = request<null, null>("collectGarbage");
23
24
25export interface SyntaxTreeParams {
26 textDocument: lc.TextDocumentIdentifier;
27 range: Option<lc.Range>;
28}
29export const syntaxTree = request<SyntaxTreeParams, string>("syntaxTree");
30
31
32export interface ExpandMacroParams {
33 textDocument: lc.TextDocumentIdentifier;
34 position: Option<lc.Position>;
35}
36export interface ExpandedMacro {
37 name: string;
38 expansion: string;
39}
40export const expandMacro = request<ExpandMacroParams, Option<ExpandedMacro>>("expandMacro");
41
42
43export interface MatchingBraceParams {
44 textDocument: lc.TextDocumentIdentifier;
45 positions: lc.Position[];
46}
47export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], unknown>('experimental/matchingBrace');
48
49export interface PublishDecorationsParams {
50 uri: string;
51 decorations: Vec<Decoration>;
52}
53export interface Decoration {
54 range: lc.Range;
55 tag: string;
56 bindingHash: Option<string>;
57}
58export const decorationsRequest = request<lc.TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest");
59
60
61export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Location>>("parentModule");
62
63
64export interface JoinLinesParams {
65 textDocument: lc.TextDocumentIdentifier;
66 ranges: lc.Range[];
67}
68export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines');
69
70export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], unknown>('experimental/onEnter');
71
72export interface RunnablesParams {
73 textDocument: lc.TextDocumentIdentifier;
74 position: Option<lc.Position>;
75}
76export interface Runnable {
77 range: lc.Range;
78 label: string;
79 bin: string;
80 args: Vec<string>;
81 extraArgs: Vec<string>;
82 env: FxHashMap<string, string>;
83 cwd: Option<string>;
84}
85export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables");
86
87export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
88
89export namespace InlayHint {
90 export const enum Kind {
91 TypeHint = "TypeHint",
92 ParamHint = "ParameterHint",
93 ChainingHint = "ChainingHint",
94 }
95 interface Common {
96 range: lc.Range;
97 label: string;
98 }
99 export type TypeHint = Common & { kind: Kind.TypeHint };
100 export type ParamHint = Common & { kind: Kind.ParamHint };
101 export type ChainingHint = Common & { kind: Kind.ChainingHint };
102}
103export interface InlayHintsParams {
104 textDocument: lc.TextDocumentIdentifier;
105}
106export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints");
107
108
109export interface SsrParams {
110 query: string;
111 parseOnly: boolean;
112}
113export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, unknown>('experimental/ssr');
114
115
116export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations");
117
118
119export interface SourceChange {
120 label: string;
121 workspaceEdit: lc.WorkspaceEdit;
122 cursorPosition: Option<lc.TextDocumentPositionParams>;
123}