diff options
Diffstat (limited to 'crates/rust-analyzer/src/lsp_ext.rs')
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 313a8c769..f75a26eb7 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! rust-analyzer extensions to the LSP. | 1 | //! rust-analyzer extensions to the LSP. |
2 | 2 | ||
3 | use std::path::PathBuf; | 3 | use std::{collections::HashMap, path::PathBuf}; |
4 | 4 | ||
5 | use lsp_types::request::Request; | 5 | use lsp_types::request::Request; |
6 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier}; | 6 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier}; |
@@ -137,7 +137,7 @@ pub struct Runnable { | |||
137 | #[serde(rename_all = "camelCase")] | 137 | #[serde(rename_all = "camelCase")] |
138 | pub struct SourceChange { | 138 | pub struct SourceChange { |
139 | pub label: String, | 139 | pub label: String, |
140 | pub workspace_edit: lsp_types::WorkspaceEdit, | 140 | pub workspace_edit: SnippetWorkspaceEdit, |
141 | pub cursor_position: Option<lsp_types::TextDocumentPositionParams>, | 141 | pub cursor_position: Option<lsp_types::TextDocumentPositionParams>, |
142 | } | 142 | } |
143 | 143 | ||
@@ -183,3 +183,54 @@ pub struct SsrParams { | |||
183 | pub query: String, | 183 | pub query: String, |
184 | pub parse_only: bool, | 184 | pub parse_only: bool, |
185 | } | 185 | } |
186 | |||
187 | pub enum CodeActionRequest {} | ||
188 | |||
189 | impl Request for CodeActionRequest { | ||
190 | type Params = lsp_types::CodeActionParams; | ||
191 | type Result = Option<Vec<CodeAction>>; | ||
192 | const METHOD: &'static str = "textDocument/codeAction"; | ||
193 | } | ||
194 | |||
195 | #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] | ||
196 | pub struct CodeAction { | ||
197 | pub title: String, | ||
198 | #[serde(skip_serializing_if = "Option::is_none")] | ||
199 | pub kind: Option<String>, | ||
200 | #[serde(skip_serializing_if = "Option::is_none")] | ||
201 | pub command: Option<lsp_types::Command>, | ||
202 | #[serde(skip_serializing_if = "Option::is_none")] | ||
203 | pub edit: Option<SnippetWorkspaceEdit>, | ||
204 | } | ||
205 | |||
206 | #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] | ||
207 | #[serde(rename_all = "camelCase")] | ||
208 | pub struct SnippetWorkspaceEdit { | ||
209 | #[serde(skip_serializing_if = "Option::is_none")] | ||
210 | pub changes: Option<HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>>>, | ||
211 | #[serde(skip_serializing_if = "Option::is_none")] | ||
212 | pub document_changes: Option<Vec<SnippetDocumentChangeOperation>>, | ||
213 | } | ||
214 | |||
215 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] | ||
216 | #[serde(untagged, rename_all = "lowercase")] | ||
217 | pub enum SnippetDocumentChangeOperation { | ||
218 | Op(lsp_types::ResourceOp), | ||
219 | Edit(SnippetTextDocumentEdit), | ||
220 | } | ||
221 | |||
222 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] | ||
223 | #[serde(rename_all = "camelCase")] | ||
224 | pub struct SnippetTextDocumentEdit { | ||
225 | pub text_document: lsp_types::VersionedTextDocumentIdentifier, | ||
226 | pub edits: Vec<SnippetTextEdit>, | ||
227 | } | ||
228 | |||
229 | #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] | ||
230 | #[serde(rename_all = "camelCase")] | ||
231 | pub struct SnippetTextEdit { | ||
232 | pub range: Range, | ||
233 | pub new_text: String, | ||
234 | #[serde(skip_serializing_if = "Option::is_none")] | ||
235 | pub insert_text_format: Option<lsp_types::InsertTextFormat>, | ||
236 | } | ||