aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-28 16:22:52 +0100
committerAleksey Kladov <[email protected]>2018-08-28 16:22:59 +0100
commitd34588bf83898870d7f9b4b49ac2a5f71c77dabb (patch)
treea0b6eb7b41cb586d1c10e408a4791edf7c341a1f /crates/server/src/main_loop
parent748a4cacd24d9ecdca995e66117a10a1562e7d5d (diff)
create module smartly
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r--crates/server/src/main_loop/handlers.rs52
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};
9use serde_json::{to_value, from_value}; 9use serde_json::{to_value, from_value};
10use libanalysis::{Query, QuickFix, FileId}; 10use url_serde;
11use libanalysis::{self, Query, FileId};
11use libeditor; 12use libeditor;
12use libsyntax2::{ 13use 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")]
178enum 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
165pub fn handle_runnables( 191pub fn handle_runnables(
166 world: ServerWorld, 192 world: ServerWorld,
167 params: req::RunnablesParams, 193 params: req::RunnablesParams,