diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands.ts | 2 | ||||
-rw-r--r-- | editors/code/src/debug.ts | 2 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 2 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 84 | ||||
-rw-r--r-- | editors/code/src/run.ts | 2 | ||||
-rw-r--r-- | editors/code/src/rust-analyzer-api.ts | 123 |
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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as ra from './rust-analyzer-api'; | 3 | import * as ra from './lsp_ext'; |
4 | 4 | ||
5 | import { Ctx, Cmd } from './ctx'; | 5 | import { Ctx, Cmd } from './ctx'; |
6 | import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets'; | 6 | import { 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 @@ | |||
1 | import * as os from "os"; | 1 | import * as os from "os"; |
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import * as path from 'path'; | 3 | import * as path from 'path'; |
4 | import * as ra from './rust-analyzer-api'; | 4 | import * as ra from './lsp_ext'; |
5 | 5 | ||
6 | import { Cargo } from './cargo'; | 6 | import { Cargo } from './cargo'; |
7 | import { Ctx } from "./ctx"; | 7 | import { 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 @@ | |||
1 | import * as lc from "vscode-languageclient"; | 1 | import * as lc from "vscode-languageclient"; |
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import * as ra from './rust-analyzer-api'; | 3 | import * as ra from './lsp_ext'; |
4 | 4 | ||
5 | import { Ctx, Disposable } from './ctx'; | 5 | import { Ctx, Disposable } from './ctx'; |
6 | import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util'; | 6 | import { 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 | |||
5 | import * as lc from "vscode-languageclient"; | ||
6 | |||
7 | export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus"); | ||
8 | |||
9 | export const collectGarbage = new lc.RequestType<null, null, void>("rust-analyzer/collectGarbage"); | ||
10 | |||
11 | export interface SyntaxTreeParams { | ||
12 | textDocument: lc.TextDocumentIdentifier; | ||
13 | range: lc.Range | null; | ||
14 | } | ||
15 | export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>("rust-analyzer/syntaxTree"); | ||
16 | |||
17 | |||
18 | export interface ExpandMacroParams { | ||
19 | textDocument: lc.TextDocumentIdentifier; | ||
20 | position: lc.Position; | ||
21 | } | ||
22 | export interface ExpandedMacro { | ||
23 | name: string; | ||
24 | expansion: string; | ||
25 | } | ||
26 | export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>("rust-analyzer/expandMacro"); | ||
27 | |||
28 | export interface MatchingBraceParams { | ||
29 | textDocument: lc.TextDocumentIdentifier; | ||
30 | positions: lc.Position[]; | ||
31 | } | ||
32 | export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>("experimental/matchingBrace"); | ||
33 | |||
34 | export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc.Location[], void>("rust-analyzer/parentModule"); | ||
35 | |||
36 | export interface JoinLinesParams { | ||
37 | textDocument: lc.TextDocumentIdentifier; | ||
38 | ranges: lc.Range[]; | ||
39 | } | ||
40 | export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>("experimental/joinLines"); | ||
41 | |||
42 | export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>("experimental/onEnter"); | ||
43 | |||
44 | export interface RunnablesParams { | ||
45 | textDocument: lc.TextDocumentIdentifier; | ||
46 | position: lc.Position | null; | ||
47 | } | ||
48 | export 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 | } | ||
57 | export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("rust-analyzer/runnables"); | ||
58 | |||
59 | export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint; | ||
60 | |||
61 | export 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 | } | ||
75 | export interface InlayHintsParams { | ||
76 | textDocument: lc.TextDocumentIdentifier; | ||
77 | } | ||
78 | export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints"); | ||
79 | |||
80 | export interface SsrParams { | ||
81 | query: string; | ||
82 | parseOnly: boolean; | ||
83 | } | ||
84 | export 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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as ra from './rust-analyzer-api'; | 3 | import * as ra from './lsp_ext'; |
4 | 4 | ||
5 | import { Ctx, Cmd } from './ctx'; | 5 | import { Ctx, Cmd } from './ctx'; |
6 | import { startDebugSession, getDebugConfiguration } from './debug'; | 6 | import { 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 | |||
5 | import * as lc from "vscode-languageclient"; | ||
6 | |||
7 | type Option<T> = null | T; | ||
8 | type Vec<T> = T[]; | ||
9 | type FxHashMap<K extends PropertyKey, V> = Record<K, V>; | ||
10 | |||
11 | function request<TParams, TResult>(method: string) { | ||
12 | return new lc.RequestType<TParams, TResult, unknown>(`rust-analyzer/${method}`); | ||
13 | } | ||
14 | function notification<TParam>(method: string) { | ||
15 | return new lc.NotificationType<TParam>(method); | ||
16 | } | ||
17 | |||
18 | |||
19 | export const analyzerStatus = request<null, string>("analyzerStatus"); | ||
20 | |||
21 | |||
22 | export const collectGarbage = request<null, null>("collectGarbage"); | ||
23 | |||
24 | |||
25 | export interface SyntaxTreeParams { | ||
26 | textDocument: lc.TextDocumentIdentifier; | ||
27 | range: Option<lc.Range>; | ||
28 | } | ||
29 | export const syntaxTree = request<SyntaxTreeParams, string>("syntaxTree"); | ||
30 | |||
31 | |||
32 | export interface ExpandMacroParams { | ||
33 | textDocument: lc.TextDocumentIdentifier; | ||
34 | position: Option<lc.Position>; | ||
35 | } | ||
36 | export interface ExpandedMacro { | ||
37 | name: string; | ||
38 | expansion: string; | ||
39 | } | ||
40 | export const expandMacro = request<ExpandMacroParams, Option<ExpandedMacro>>("expandMacro"); | ||
41 | |||
42 | |||
43 | export interface MatchingBraceParams { | ||
44 | textDocument: lc.TextDocumentIdentifier; | ||
45 | positions: lc.Position[]; | ||
46 | } | ||
47 | export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], unknown>('experimental/matchingBrace'); | ||
48 | |||
49 | export interface PublishDecorationsParams { | ||
50 | uri: string; | ||
51 | decorations: Vec<Decoration>; | ||
52 | } | ||
53 | export interface Decoration { | ||
54 | range: lc.Range; | ||
55 | tag: string; | ||
56 | bindingHash: Option<string>; | ||
57 | } | ||
58 | export const decorationsRequest = request<lc.TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest"); | ||
59 | |||
60 | |||
61 | export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Location>>("parentModule"); | ||
62 | |||
63 | |||
64 | export interface JoinLinesParams { | ||
65 | textDocument: lc.TextDocumentIdentifier; | ||
66 | ranges: lc.Range[]; | ||
67 | } | ||
68 | export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines'); | ||
69 | |||
70 | export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], unknown>('experimental/onEnter'); | ||
71 | |||
72 | export interface RunnablesParams { | ||
73 | textDocument: lc.TextDocumentIdentifier; | ||
74 | position: Option<lc.Position>; | ||
75 | } | ||
76 | export 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 | } | ||
85 | export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables"); | ||
86 | |||
87 | export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint; | ||
88 | |||
89 | export 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 | } | ||
103 | export interface InlayHintsParams { | ||
104 | textDocument: lc.TextDocumentIdentifier; | ||
105 | } | ||
106 | export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints"); | ||
107 | |||
108 | |||
109 | export interface SsrParams { | ||
110 | query: string; | ||
111 | parseOnly: boolean; | ||
112 | } | ||
113 | export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, unknown>('experimental/ssr'); | ||
114 | |||
115 | |||
116 | export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations"); | ||
117 | |||
118 | |||
119 | export interface SourceChange { | ||
120 | label: string; | ||
121 | workspaceEdit: lc.WorkspaceEdit; | ||
122 | cursorPosition: Option<lc.TextDocumentPositionParams>; | ||
123 | } | ||