]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/editors/code/src/lsp_ext.ts
:arrow_up: rust-analyzer
[rust.git] / src / tools / rust-analyzer / editors / code / src / lsp_ext.ts
1 /**
2  * This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
3  */
4
5 import * as lc from "vscode-languageclient";
6
7 export interface AnalyzerStatusParams {
8     textDocument?: lc.TextDocumentIdentifier;
9 }
10 export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>(
11     "rust-analyzer/analyzerStatus"
12 );
13 export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
14 export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph");
15
16 export interface ServerStatusParams {
17     health: "ok" | "warning" | "error";
18     quiescent: boolean;
19     message?: string;
20 }
21 export const serverStatus = new lc.NotificationType<ServerStatusParams>(
22     "experimental/serverStatus"
23 );
24
25 export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
26
27 export const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>("textDocument/hover");
28
29 export interface HoverParams extends lc.WorkDoneProgressParams {
30     textDocument: lc.TextDocumentIdentifier;
31     position: lc.Range | lc.Position;
32 }
33
34 export interface SyntaxTreeParams {
35     textDocument: lc.TextDocumentIdentifier;
36     range: lc.Range | null;
37 }
38 export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>(
39     "rust-analyzer/syntaxTree"
40 );
41
42 export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
43     "rust-analyzer/viewHir"
44 );
45
46 export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>(
47     "rust-analyzer/viewFileText"
48 );
49
50 export interface ViewItemTreeParams {
51     textDocument: lc.TextDocumentIdentifier;
52 }
53
54 export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
55     "rust-analyzer/viewItemTree"
56 );
57
58 export interface ViewCrateGraphParams {
59     full: boolean;
60 }
61
62 export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
63     "rust-analyzer/viewCrateGraph"
64 );
65
66 export interface ExpandMacroParams {
67     textDocument: lc.TextDocumentIdentifier;
68     position: lc.Position;
69 }
70 export interface ExpandedMacro {
71     name: string;
72     expansion: string;
73 }
74 export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
75     "rust-analyzer/expandMacro"
76 );
77
78 export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
79     "rust-analyzer/relatedTests"
80 );
81
82 export const cancelFlycheck = new lc.RequestType0<void, void>("rust-analyzer/cancelFlycheck");
83
84 // Experimental extensions
85
86 export interface SsrParams {
87     query: string;
88     parseOnly: boolean;
89     textDocument: lc.TextDocumentIdentifier;
90     position: lc.Position;
91     selections: readonly lc.Range[];
92 }
93 export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
94
95 export interface MatchingBraceParams {
96     textDocument: lc.TextDocumentIdentifier;
97     positions: lc.Position[];
98 }
99 export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>(
100     "experimental/matchingBrace"
101 );
102
103 export const parentModule = new lc.RequestType<
104     lc.TextDocumentPositionParams,
105     lc.LocationLink[] | null,
106     void
107 >("experimental/parentModule");
108
109 export interface JoinLinesParams {
110     textDocument: lc.TextDocumentIdentifier;
111     ranges: lc.Range[];
112 }
113 export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
114     "experimental/joinLines"
115 );
116
117 export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
118     "experimental/onEnter"
119 );
120
121 export interface RunnablesParams {
122     textDocument: lc.TextDocumentIdentifier;
123     position: lc.Position | null;
124 }
125
126 export interface Runnable {
127     label: string;
128     location?: lc.LocationLink;
129     kind: "cargo";
130     args: {
131         workspaceRoot?: string;
132         cargoArgs: string[];
133         cargoExtraArgs: string[];
134         executableArgs: string[];
135         expectTest?: boolean;
136         overrideCargo?: string;
137     };
138 }
139 export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
140     "experimental/runnables"
141 );
142
143 export interface TestInfo {
144     runnable: Runnable;
145 }
146
147 export interface CommandLink extends lc.Command {
148     /**
149      * A tooltip for the command, when represented in the UI.
150      */
151     tooltip?: string;
152 }
153
154 export interface CommandLinkGroup {
155     title?: string;
156     commands: CommandLink[];
157 }
158
159 export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
160     "experimental/externalDocs"
161 );
162
163 export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
164     "experimental/openCargoToml"
165 );
166
167 export interface OpenCargoTomlParams {
168     textDocument: lc.TextDocumentIdentifier;
169 }
170
171 export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
172     "experimental/moveItem"
173 );
174
175 export interface MoveItemParams {
176     textDocument: lc.TextDocumentIdentifier;
177     range: lc.Range;
178     direction: Direction;
179 }
180
181 export const enum Direction {
182     Up = "Up",
183     Down = "Down",
184 }