diff options
Diffstat (limited to 'crates/rust-analyzer/src/lsp_ext.rs')
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 313a8c769..0fd60caf4 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}; |
@@ -87,22 +87,22 @@ pub enum JoinLines {} | |||
87 | 87 | ||
88 | impl Request for JoinLines { | 88 | impl Request for JoinLines { |
89 | type Params = JoinLinesParams; | 89 | type Params = JoinLinesParams; |
90 | type Result = SourceChange; | 90 | type Result = Vec<lsp_types::TextEdit>; |
91 | const METHOD: &'static str = "rust-analyzer/joinLines"; | 91 | const METHOD: &'static str = "experimental/joinLines"; |
92 | } | 92 | } |
93 | 93 | ||
94 | #[derive(Deserialize, Serialize, Debug)] | 94 | #[derive(Deserialize, Serialize, Debug)] |
95 | #[serde(rename_all = "camelCase")] | 95 | #[serde(rename_all = "camelCase")] |
96 | pub struct JoinLinesParams { | 96 | pub struct JoinLinesParams { |
97 | pub text_document: TextDocumentIdentifier, | 97 | pub text_document: TextDocumentIdentifier, |
98 | pub range: Range, | 98 | pub ranges: Vec<Range>, |
99 | } | 99 | } |
100 | 100 | ||
101 | pub enum OnEnter {} | 101 | pub enum OnEnter {} |
102 | 102 | ||
103 | impl Request for OnEnter { | 103 | impl Request for OnEnter { |
104 | type Params = lsp_types::TextDocumentPositionParams; | 104 | type Params = lsp_types::TextDocumentPositionParams; |
105 | type Result = Option<SourceChange>; | 105 | type Result = Option<SnippetWorkspaceEdit>; |
106 | const METHOD: &'static str = "rust-analyzer/onEnter"; | 106 | const METHOD: &'static str = "rust-analyzer/onEnter"; |
107 | } | 107 | } |
108 | 108 | ||
@@ -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 | ||
@@ -173,8 +173,8 @@ pub enum Ssr {} | |||
173 | 173 | ||
174 | impl Request for Ssr { | 174 | impl Request for Ssr { |
175 | type Params = SsrParams; | 175 | type Params = SsrParams; |
176 | type Result = SourceChange; | 176 | type Result = lsp_types::WorkspaceEdit; |
177 | const METHOD: &'static str = "rust-analyzer/ssr"; | 177 | const METHOD: &'static str = "experimental/ssr"; |
178 | } | 178 | } |
179 | 179 | ||
180 | #[derive(Debug, Deserialize, Serialize)] | 180 | #[derive(Debug, Deserialize, Serialize)] |
@@ -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 | } | ||