diff options
author | Aleksey Kladov <[email protected]> | 2018-08-27 18:58:38 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-27 18:58:38 +0100 |
commit | aaca7d003bd969785be53d8f312b67bfa26f6272 (patch) | |
tree | 9e3ab4d75d631fb1055fb6ab5c05f0a78153fadd /crates/server/src/main_loop/handlers.rs | |
parent | 846114a6e95da696deb6a0f3243ad23c45074a00 (diff) |
move scopes to file
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index e7ac53028..350eda7df 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -7,7 +7,7 @@ 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}; | 10 | use libanalysis::{Query, QuickFix}; |
11 | use libeditor; | 11 | use libeditor; |
12 | use libsyntax2::{ | 12 | use libsyntax2::{ |
13 | TextUnit, | 13 | TextUnit, |
@@ -177,6 +177,30 @@ pub fn handle_code_action( | |||
177 | }; | 177 | }; |
178 | res.push(cmd); | 178 | res.push(cmd); |
179 | } | 179 | } |
180 | |||
181 | for (diag, quick_fix) in world.analysis().diagnostics(file_id)? { | ||
182 | let quick_fix = match quick_fix { | ||
183 | Some(quick_fix) => quick_fix, | ||
184 | None => continue, | ||
185 | }; | ||
186 | if !contains_offset_nonstrict(diag.range, offset) { | ||
187 | continue; | ||
188 | } | ||
189 | let cmd = match quick_fix { | ||
190 | QuickFix::CreateFile(path) => { | ||
191 | let path = &path.to_str().unwrap()[3..]; // strip `../` b/c url is weird | ||
192 | let uri = params.text_document.uri.join(path) | ||
193 | .unwrap(); | ||
194 | let uri = ::url_serde::Ser::new(&uri); | ||
195 | Command { | ||
196 | title: "Create file".to_string(), | ||
197 | command: "libsyntax-rust.createFile".to_string(), | ||
198 | arguments: Some(vec![to_value(uri).unwrap()]), | ||
199 | } | ||
200 | } | ||
201 | }; | ||
202 | res.push(cmd) | ||
203 | } | ||
180 | return Ok(Some(res)); | 204 | return Ok(Some(res)); |
181 | } | 205 | } |
182 | 206 | ||
@@ -355,11 +379,10 @@ pub fn publish_diagnostics( | |||
355 | uri: Url | 379 | uri: Url |
356 | ) -> Result<req::PublishDiagnosticsParams> { | 380 | ) -> Result<req::PublishDiagnosticsParams> { |
357 | let file_id = world.uri_to_file_id(&uri)?; | 381 | let file_id = world.uri_to_file_id(&uri)?; |
358 | let file = world.analysis().file_syntax(file_id)?; | ||
359 | let line_index = world.analysis().file_line_index(file_id)?; | 382 | let line_index = world.analysis().file_line_index(file_id)?; |
360 | let diagnostics = libeditor::diagnostics(&file) | 383 | let diagnostics = world.analysis().diagnostics(file_id)? |
361 | .into_iter() | 384 | .into_iter() |
362 | .map(|d| Diagnostic { | 385 | .map(|(d, _quick_fix)| Diagnostic { |
363 | range: d.range.conv_with(&line_index), | 386 | range: d.range.conv_with(&line_index), |
364 | severity: Some(DiagnosticSeverity::Error), | 387 | severity: Some(DiagnosticSeverity::Error), |
365 | code: None, | 388 | code: None, |