aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/rust-analyzer-api.ts
blob: c5a010e94722075a7cb8d4857135e78a51c6f322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
 * This file mirrors `crates/rust-analyzer/src/req.rs` declarations.
 */

import * as lc from "vscode-languageclient";

type Option<T> = null | T;
type Vec<T> = T[];
type FxHashMap<K extends PropertyKey, V> = Record<K, V>;

function request<TParams, TResult>(method: string) {
    return new lc.RequestType<TParams, TResult, unknown>(`rust-analyzer/${method}`);
}
function notification<TParam>(method: string) {
    return new lc.NotificationType<TParam>(method);
}


export const analyzerStatus = request<null, string>("analyzerStatus");


export const collectGarbage = request<null, null>("collectGarbage");


export interface SyntaxTreeParams {
    textDocument: lc.TextDocumentIdentifier;
    range: Option<lc.Range>;
}
export const syntaxTree = request<SyntaxTreeParams, string>("syntaxTree");


export interface ExpandMacroParams {
    textDocument: lc.TextDocumentIdentifier;
    position: Option<lc.Position>;
}
export interface ExpandedMacro {
    name: string;
    expansion: string;
}
export const expandMacro = request<ExpandMacroParams, Option<ExpandedMacro>>("expandMacro");


export interface FindMatchingBraceParams {
    textDocument: lc.TextDocumentIdentifier;
    offsets: Vec<lc.Position>;
}
export const findMatchingBrace = request<FindMatchingBraceParams, Vec<lc.Position>>("findMatchingBrace");


export interface PublishDecorationsParams {
    uri: string;
    decorations: Vec<Decoration>;
}
export interface Decoration {
    range: lc.Range;
    tag: string;
    bindingHash: Option<string>;
}
export const decorationsRequest = request<lc.TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest");


export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Location>>("parentModule");


export interface JoinLinesParams {
    textDocument: lc.TextDocumentIdentifier;
    range: lc.Range;
}
export const joinLines = request<JoinLinesParams, SourceChange>("joinLines");


export const onEnter = request<lc.TextDocumentPositionParams, Option<SourceChange>>("onEnter");

export interface RunnablesParams {
    textDocument: lc.TextDocumentIdentifier;
    position: Option<lc.Position>;
}
export interface Runnable {
    range: lc.Range;
    label: string;
    bin: string;
    args: Vec<string>;
    env: FxHashMap<string, string>;
    cwd: Option<string>;
}
export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables");


export const enum InlayKind {
    TypeHint = "TypeHint",
    ParameterHint = "ParameterHint",
}
export interface InlayHint {
    range: lc.Range;
    kind: InlayKind;
    label: string;
}
export interface InlayHintsParams {
    textDocument: lc.TextDocumentIdentifier;
}
export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints");


export interface SsrParams {
    arg: string;
}
export const ssr = request<SsrParams, SourceChange>("ssr");


export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations");


export interface SourceChange {
    label: string;
    workspaceEdit: lc.WorkspaceEdit;
    cursorPosition: Option<lc.TextDocumentPositionParams>;
}