diff options
-rw-r--r-- | editors/code/src/rust-analyzer-api.ts | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts new file mode 100644 index 000000000..d2738fef3 --- /dev/null +++ b/editors/code/src/rust-analyzer-api.ts | |||
@@ -0,0 +1,117 @@ | |||
1 | /** | ||
2 | * This file mirrors `crates/rust-analyzer/src/req.rs` declarations. | ||
3 | */ | ||
4 | |||
5 | import { RequestType, TextDocumentIdentifier, Position, Range, TextDocumentPositionParams, Location, NotificationType, WorkspaceEdit } 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 RequestType<TParams, TResult, unknown>(`rust-analyzer/${method}`); | ||
13 | } | ||
14 | function notification<TParam>(method: string) { | ||
15 | return new 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: TextDocumentIdentifier; | ||
27 | range: Option<Range>; | ||
28 | } | ||
29 | export const syntaxTree = request<SyntaxTreeParams, string>("syntaxTree"); | ||
30 | |||
31 | |||
32 | export interface ExpandMacroParams { | ||
33 | textDocument: TextDocumentIdentifier; | ||
34 | position: Option<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 FindMatchingBraceParams { | ||
44 | textDocument: TextDocumentIdentifier; | ||
45 | offsets: Vec<Position>; | ||
46 | } | ||
47 | export const findMatchingBrace = request<FindMatchingBraceParams, Vec<Position>>("findMatchingBrace"); | ||
48 | |||
49 | |||
50 | export interface PublishDecorationsParams { | ||
51 | uri: string; | ||
52 | decorations: Vec<Decoration>; | ||
53 | } | ||
54 | export interface Decoration { | ||
55 | range: Range; | ||
56 | tag: string; | ||
57 | bindingHash: Option<string>; | ||
58 | } | ||
59 | export const decorationsRequest = request<TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest"); | ||
60 | |||
61 | |||
62 | export const parentModule = request<TextDocumentPositionParams, Vec<Location>>("parentModule"); | ||
63 | |||
64 | |||
65 | export interface JoinLinesParams { | ||
66 | textDocument: TextDocumentIdentifier; | ||
67 | range: Range; | ||
68 | } | ||
69 | export const joinLines = request<JoinLinesParams, SourceChange>("joinLines"); | ||
70 | |||
71 | |||
72 | export const onEnter = request<TextDocumentPositionParams, Option<SourceChange>>("onEnter"); | ||
73 | |||
74 | export interface RunnablesParams { | ||
75 | textDocument: TextDocumentIdentifier; | ||
76 | position: Option<Position>; | ||
77 | } | ||
78 | export interface Runnable { | ||
79 | range: Range; | ||
80 | label: string; | ||
81 | bin: string; | ||
82 | args: Vec<string>; | ||
83 | env: FxHashMap<string, string>; | ||
84 | cwd: Option<string>; | ||
85 | } | ||
86 | export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables"); | ||
87 | |||
88 | |||
89 | export const enum InlayKind { | ||
90 | TypeHint = "TypeHint", | ||
91 | ParameterHint = "ParameterHint", | ||
92 | } | ||
93 | export interface InlayHint { | ||
94 | range: Range; | ||
95 | kind: InlayKind; | ||
96 | label: string; | ||
97 | } | ||
98 | export interface InlayHintsParams { | ||
99 | textDocument: TextDocumentIdentifier; | ||
100 | } | ||
101 | export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints"); | ||
102 | |||
103 | |||
104 | export interface SsrParams { | ||
105 | arg: string; | ||
106 | } | ||
107 | export const ssr = request<SsrParams, SourceChange>("ssr"); | ||
108 | |||
109 | |||
110 | export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations"); | ||
111 | |||
112 | |||
113 | export interface SourceChange { | ||
114 | label: string; | ||
115 | workspaceEdit: WorkspaceEdit; | ||
116 | cursorPosition: Option<TextDocumentPositionParams>; | ||
117 | } | ||