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