]> git.lizzy.rs Git - rust.git/blob - crates/ra_lsp_server/src/req.rs
Merge #1179
[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, CodeLensParams,
8     CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
9     DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
10     PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit,
11     TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams,
12     MessageType, ShowMessageParams,
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 }
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 }