aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/rust-analyzer-api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/rust-analyzer-api.ts')
-rw-r--r--editors/code/src/rust-analyzer-api.ts117
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..c5a010e94
--- /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
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 FindMatchingBraceParams {
44 textDocument: lc.TextDocumentIdentifier;
45 offsets: Vec<lc.Position>;
46}
47export const findMatchingBrace = request<FindMatchingBraceParams, Vec<lc.Position>>("findMatchingBrace");
48
49
50export interface PublishDecorationsParams {
51 uri: string;
52 decorations: Vec<Decoration>;
53}
54export interface Decoration {
55 range: lc.Range;
56 tag: string;
57 bindingHash: Option<string>;
58}
59export const decorationsRequest = request<lc.TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest");
60
61
62export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Location>>("parentModule");
63
64
65export interface JoinLinesParams {
66 textDocument: lc.TextDocumentIdentifier;
67 range: lc.Range;
68}
69export const joinLines = request<JoinLinesParams, SourceChange>("joinLines");
70
71
72export const onEnter = request<lc.TextDocumentPositionParams, Option<SourceChange>>("onEnter");
73
74export interface RunnablesParams {
75 textDocument: lc.TextDocumentIdentifier;
76 position: Option<lc.Position>;
77}
78export interface Runnable {
79 range: lc.Range;
80 label: string;
81 bin: string;
82 args: Vec<string>;
83 env: FxHashMap<string, string>;
84 cwd: Option<string>;
85}
86export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables");
87
88
89export const enum InlayKind {
90 TypeHint = "TypeHint",
91 ParameterHint = "ParameterHint",
92}
93export interface InlayHint {
94 range: lc.Range;
95 kind: InlayKind;
96 label: string;
97}
98export interface InlayHintsParams {
99 textDocument: lc.TextDocumentIdentifier;
100}
101export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints");
102
103
104export interface SsrParams {
105 arg: string;
106}
107export const ssr = request<SsrParams, SourceChange>("ssr");
108
109
110export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations");
111
112
113export interface SourceChange {
114 label: string;
115 workspaceEdit: lc.WorkspaceEdit;
116 cursorPosition: Option<lc.TextDocumentPositionParams>;
117}