aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-25 13:58:50 +0100
committerGitHub <[email protected]>2020-05-25 13:58:50 +0100
commit00172d0b555d22a42a2cbf8785eb7b2592507c4f (patch)
tree510b580723f06fd3ae1e4c641001afa82a426b60
parent8686d0b0ac765c2144b22b897de1d8fda68ecc6e (diff)
parenta30bdd9795770329e4562d8bfca60ebe2e52dea1 (diff)
Merge #4610
4610: Cleanup lsp extensions on the client side r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs11
-rw-r--r--docs/dev/lsp-extensions.md2
-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
9 files changed, 93 insertions, 137 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 1cce1baa4..c571c62ae 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -50,7 +50,7 @@ impl Request for ExpandMacro {
50#[serde(rename_all = "camelCase")] 50#[serde(rename_all = "camelCase")]
51pub struct ExpandMacroParams { 51pub struct ExpandMacroParams {
52 pub text_document: TextDocumentIdentifier, 52 pub text_document: TextDocumentIdentifier,
53 pub position: Option<Position>, 53 pub position: Position,
54} 54}
55 55
56#[derive(Deserialize, Serialize, Debug)] 56#[derive(Deserialize, Serialize, Debug)]
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index a13a0e1f5..3ccc95c23 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -72,15 +72,10 @@ pub fn handle_expand_macro(
72 let _p = profile("handle_expand_macro"); 72 let _p = profile("handle_expand_macro");
73 let file_id = from_proto::file_id(&world, &params.text_document.uri)?; 73 let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
74 let line_index = world.analysis().file_line_index(file_id)?; 74 let line_index = world.analysis().file_line_index(file_id)?;
75 let offset = params.position.map(|p| from_proto::offset(&line_index, p)); 75 let offset = from_proto::offset(&line_index, params.position);
76 76
77 match offset { 77 let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
78 None => Ok(None), 78 Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
79 Some(offset) => {
80 let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
81 Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
82 }
83 }
84} 79}
85 80
86pub fn handle_selection_range( 81pub fn handle_selection_range(
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index e4b9fb2c2..48147b173 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -318,7 +318,7 @@ Primarily for debugging, but very useful for all people working on rust-analyzer
318```typescript 318```typescript
319interface ExpandMacroParams { 319interface ExpandMacroParams {
320 textDocument: TextDocumentIdentifier, 320 textDocument: TextDocumentIdentifier,
321 position?: Position, 321 position: Position,
322} 322}
323``` 323```
324 324
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}