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