diff options
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index ca5cd5ab1..92ffb30c3 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -7,7 +7,8 @@ use languageserver_types::{ | |||
7 | CompletionItem, | 7 | CompletionItem, |
8 | }; | 8 | }; |
9 | use serde_json::{to_value, from_value}; | 9 | use serde_json::{to_value, from_value}; |
10 | use libanalysis::{Query, QuickFix, FileId}; | 10 | use url_serde; |
11 | use libanalysis::{self, Query, FileId}; | ||
11 | use libeditor; | 12 | use libeditor; |
12 | use libsyntax2::{ | 13 | use libsyntax2::{ |
13 | TextUnit, | 14 | TextUnit, |
@@ -144,24 +145,49 @@ pub fn handle_code_action( | |||
144 | if !contains_offset_nonstrict(diag.range, offset) { | 145 | if !contains_offset_nonstrict(diag.range, offset) { |
145 | continue; | 146 | continue; |
146 | } | 147 | } |
147 | let cmd = match quick_fix { | 148 | let mut ops = Vec::new(); |
148 | QuickFix::CreateFile(path) => { | 149 | for op in quick_fix.fs_ops { |
149 | let path = &path.to_str().unwrap()[3..]; // strip `../` b/c url is weird | 150 | let op = match op { |
150 | let uri = params.text_document.uri.join(path) | 151 | libanalysis::FsOp::CreateFile { anchor, path } => { |
151 | .unwrap(); | 152 | let uri = world.file_id_to_uri(anchor)?; |
152 | let uri = ::url_serde::Ser::new(&uri); | 153 | let path = &path.as_str()[3..]; // strip `../` b/c url is weird |
153 | Command { | 154 | let uri = uri.join(path)?; |
154 | title: "Create file".to_string(), | 155 | FsOp::CreateFile { uri } |
155 | command: "libsyntax-rust.createFile".to_string(), | 156 | }, |
156 | arguments: Some(vec![to_value(uri).unwrap()]), | 157 | libanalysis::FsOp::MoveFile { file, path } => { |
157 | } | 158 | let src = world.file_id_to_uri(file)?; |
158 | } | 159 | let path = &path.as_str()[3..]; // strip `../` b/c url is weird |
160 | let dst = src.join(path)?; | ||
161 | FsOp::MoveFile { src, dst } | ||
162 | }, | ||
163 | }; | ||
164 | ops.push(op) | ||
165 | } | ||
166 | let cmd = Command { | ||
167 | title: "Create module".to_string(), | ||
168 | command: "libsyntax-rust.fsEdit".to_string(), | ||
169 | arguments: Some(vec![to_value(ops).unwrap()]), | ||
159 | }; | 170 | }; |
160 | res.push(cmd) | 171 | res.push(cmd) |
161 | } | 172 | } |
162 | return Ok(Some(res)); | 173 | return Ok(Some(res)); |
163 | } | 174 | } |
164 | 175 | ||
176 | #[derive(Serialize)] | ||
177 | #[serde(tag = "type", rename_all = "camelCase")] | ||
178 | enum FsOp { | ||
179 | CreateFile { | ||
180 | #[serde(with = "url_serde")] | ||
181 | uri: Url | ||
182 | }, | ||
183 | MoveFile { | ||
184 | #[serde(with = "url_serde")] | ||
185 | src: Url, | ||
186 | #[serde(with = "url_serde")] | ||
187 | dst: Url, | ||
188 | } | ||
189 | } | ||
190 | |||
165 | pub fn handle_runnables( | 191 | pub fn handle_runnables( |
166 | world: ServerWorld, | 192 | world: ServerWorld, |
167 | params: req::RunnablesParams, | 193 | params: req::RunnablesParams, |