]> git.lizzy.rs Git - rust.git/blob - crates/ra_lsp_server/src/req.rs
Merge #1652
[rust.git] / crates / ra_lsp_server / src / req.rs
1 use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
2 use rustc_hash::FxHashMap;
3 use serde::{Deserialize, Serialize};
4 use url_serde;
5
6 pub use lsp_types::{
7     notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
8     CodeLensParams, CompletionParams, CompletionResponse, DidChangeConfigurationParams,
9     DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, Hover,
10     InitializeResult, MessageType, PublishDiagnosticsParams, ReferenceParams, ShowMessageParams,
11     SignatureHelp, TextDocumentEdit, TextDocumentPositionParams, TextEdit, WorkspaceEdit,
12     WorkspaceSymbolParams,
13 };
14
15 pub enum AnalyzerStatus {}
16
17 impl Request for AnalyzerStatus {
18     type Params = ();
19     type Result = String;
20     const METHOD: &'static str = "rust-analyzer/analyzerStatus";
21 }
22
23 pub enum CollectGarbage {}
24
25 impl Request for CollectGarbage {
26     type Params = ();
27     type Result = ();
28     const METHOD: &'static str = "rust-analyzer/collectGarbage";
29 }
30
31 pub enum SyntaxTree {}
32
33 impl Request for SyntaxTree {
34     type Params = SyntaxTreeParams;
35     type Result = String;
36     const METHOD: &'static str = "rust-analyzer/syntaxTree";
37 }
38
39 #[derive(Deserialize, Debug)]
40 #[serde(rename_all = "camelCase")]
41 pub struct SyntaxTreeParams {
42     pub text_document: TextDocumentIdentifier,
43     pub range: Option<Range>,
44 }
45
46 pub enum ExtendSelection {}
47
48 impl Request for ExtendSelection {
49     type Params = ExtendSelectionParams;
50     type Result = ExtendSelectionResult;
51     const METHOD: &'static str = "rust-analyzer/extendSelection";
52 }
53
54 #[derive(Deserialize, Debug)]
55 #[serde(rename_all = "camelCase")]
56 pub struct ExtendSelectionParams {
57     pub text_document: TextDocumentIdentifier,
58     pub selections: Vec<Range>,
59 }
60
61 #[derive(Serialize, Debug)]
62 #[serde(rename_all = "camelCase")]
63 pub struct ExtendSelectionResult {
64     pub selections: Vec<Range>,
65 }
66
67 pub enum SelectionRangeRequest {}
68
69 impl Request for SelectionRangeRequest {
70     type Params = SelectionRangeParams;
71     type Result = Vec<SelectionRange>;
72     const METHOD: &'static str = "textDocument/selectionRange";
73 }
74
75 #[derive(Deserialize, Debug)]
76 #[serde(rename_all = "camelCase")]
77 pub struct SelectionRangeParams {
78     pub text_document: TextDocumentIdentifier,
79     pub positions: Vec<Position>,
80 }
81
82 #[derive(Serialize, Debug)]
83 #[serde(rename_all = "camelCase")]
84 pub struct SelectionRange {
85     pub range: Range,
86     pub parent: Option<Box<SelectionRange>>,
87 }
88
89 pub enum FindMatchingBrace {}
90
91 impl Request for FindMatchingBrace {
92     type Params = FindMatchingBraceParams;
93     type Result = Vec<Position>;
94     const METHOD: &'static str = "rust-analyzer/findMatchingBrace";
95 }
96
97 #[derive(Deserialize, Debug)]
98 #[serde(rename_all = "camelCase")]
99 pub struct FindMatchingBraceParams {
100     pub text_document: TextDocumentIdentifier,
101     pub offsets: Vec<Position>,
102 }
103
104 pub enum DecorationsRequest {}
105
106 impl Request for DecorationsRequest {
107     type Params = TextDocumentIdentifier;
108     type Result = Vec<Decoration>;
109     const METHOD: &'static str = "rust-analyzer/decorationsRequest";
110 }
111
112 pub enum PublishDecorations {}
113
114 impl Notification for PublishDecorations {
115     type Params = PublishDecorationsParams;
116     const METHOD: &'static str = "rust-analyzer/publishDecorations";
117 }
118
119 #[derive(Serialize, Debug)]
120 #[serde(rename_all = "camelCase")]
121 pub struct PublishDecorationsParams {
122     #[serde(with = "url_serde")]
123     pub uri: Url,
124     pub decorations: Vec<Decoration>,
125 }
126
127 #[derive(Serialize, Debug)]
128 #[serde(rename_all = "camelCase")]
129 pub struct Decoration {
130     pub range: Range,
131     pub tag: &'static str,
132     pub binding_hash: Option<String>,
133 }
134
135 pub enum ParentModule {}
136
137 impl Request for ParentModule {
138     type Params = TextDocumentPositionParams;
139     type Result = Vec<Location>;
140     const METHOD: &'static str = "rust-analyzer/parentModule";
141 }
142
143 pub enum JoinLines {}
144
145 impl Request for JoinLines {
146     type Params = JoinLinesParams;
147     type Result = SourceChange;
148     const METHOD: &'static str = "rust-analyzer/joinLines";
149 }
150
151 #[derive(Deserialize, Debug)]
152 #[serde(rename_all = "camelCase")]
153 pub struct JoinLinesParams {
154     pub text_document: TextDocumentIdentifier,
155     pub range: Range,
156 }
157
158 pub enum OnEnter {}
159
160 impl Request for OnEnter {
161     type Params = TextDocumentPositionParams;
162     type Result = Option<SourceChange>;
163     const METHOD: &'static str = "rust-analyzer/onEnter";
164 }
165
166 pub enum Runnables {}
167
168 impl Request for Runnables {
169     type Params = RunnablesParams;
170     type Result = Vec<Runnable>;
171     const METHOD: &'static str = "rust-analyzer/runnables";
172 }
173
174 #[derive(Serialize, Deserialize, Debug)]
175 #[serde(rename_all = "camelCase")]
176 pub struct RunnablesParams {
177     pub text_document: TextDocumentIdentifier,
178     pub position: Option<Position>,
179 }
180
181 #[derive(Serialize, Debug)]
182 #[serde(rename_all = "camelCase")]
183 pub struct Runnable {
184     pub range: Range,
185     pub label: String,
186     pub bin: String,
187     pub args: Vec<String>,
188     pub env: FxHashMap<String, String>,
189     pub cwd: Option<String>,
190 }
191
192 #[derive(Serialize, Debug)]
193 #[serde(rename_all = "camelCase")]
194 pub struct SourceChange {
195     pub label: String,
196     pub workspace_edit: WorkspaceEdit,
197     pub cursor_position: Option<TextDocumentPositionParams>,
198 }
199
200 pub enum InlayHints {}
201
202 impl Request for InlayHints {
203     type Params = InlayHintsParams;
204     type Result = Vec<InlayHint>;
205     const METHOD: &'static str = "rust-analyzer/inlayHints";
206 }
207
208 #[derive(Serialize, Deserialize, Debug)]
209 #[serde(rename_all = "camelCase")]
210 pub struct InlayHintsParams {
211     pub text_document: TextDocumentIdentifier,
212 }
213
214 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
215 pub enum InlayKind {
216     TypeHint,
217 }
218
219 #[derive(Debug, Deserialize, Serialize)]
220 pub struct InlayHint {
221     pub range: Range,
222     pub kind: InlayKind,
223     pub label: String,
224 }