diff options
author | Simon Vandel Sillesen <[email protected]> | 2019-01-06 08:41:11 +0000 |
---|---|---|
committer | Simon Vandel Sillesen <[email protected]> | 2019-01-06 08:41:11 +0000 |
commit | 2e52b27e7139095393c7e4eebd7da0c6c26b053e (patch) | |
tree | 12fdc917449058fde414dcab0f1d5ae1c5737289 /crates/ra_lsp_server | |
parent | bb8624dff65dca10997e3eec62df975e6e347558 (diff) |
refactor
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 14 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 47 |
2 files changed, 26 insertions, 35 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 60d9671de..2dc1be26a 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -1,13 +1,11 @@ | |||
1 | mod handlers; | 1 | mod handlers; |
2 | mod subscriptions; | 2 | mod subscriptions; |
3 | 3 | ||
4 | use std::{ | 4 | use std::{fmt, path::PathBuf, sync::Arc}; |
5 | fmt, | ||
6 | path::PathBuf, | ||
7 | sync::Arc, | ||
8 | }; | ||
9 | 5 | ||
10 | use crossbeam_channel::{unbounded, select, Receiver, Sender, RecvError}; | 6 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; |
7 | use failure::{bail, format_err}; | ||
8 | use failure_derive::Fail; | ||
11 | use gen_lsp_server::{ | 9 | use gen_lsp_server::{ |
12 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, | 10 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, |
13 | }; | 11 | }; |
@@ -15,11 +13,9 @@ use languageserver_types::NumberOrString; | |||
15 | use ra_analysis::{Canceled, FileId, LibraryData}; | 13 | use ra_analysis::{Canceled, FileId, LibraryData}; |
16 | use ra_vfs::VfsTask; | 14 | use ra_vfs::VfsTask; |
17 | use rayon; | 15 | use rayon; |
18 | use threadpool::ThreadPool; | ||
19 | use rustc_hash::FxHashSet; | 16 | use rustc_hash::FxHashSet; |
20 | use serde::{de::DeserializeOwned, Serialize}; | 17 | use serde::{de::DeserializeOwned, Serialize}; |
21 | use failure::{format_err, bail}; | 18 | use threadpool::ThreadPool; |
22 | use failure_derive::Fail; | ||
23 | 19 | ||
24 | use crate::{ | 20 | use crate::{ |
25 | main_loop::subscriptions::Subscriptions, | 21 | main_loop::subscriptions::Subscriptions, |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2ec9073e4..51f134e8a 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -93,36 +93,31 @@ pub fn handle_on_type_formatting( | |||
93 | world: ServerWorld, | 93 | world: ServerWorld, |
94 | params: req::DocumentOnTypeFormattingParams, | 94 | params: req::DocumentOnTypeFormattingParams, |
95 | ) -> Result<Option<Vec<TextEdit>>> { | 95 | ) -> Result<Option<Vec<TextEdit>>> { |
96 | if params.ch != "=" || params.ch != "." { | 96 | let analysis: Option<Box<Fn(FilePosition) -> Option<SourceChange>>> = match params.ch.as_str() { |
97 | return Ok(None); | 97 | "=" => Some(Box::new(|pos| world.analysis().on_eq_typed(pos))), |
98 | } | 98 | "." => Some(Box::new(|pos| world.analysis().on_dot_typed(pos))), |
99 | 99 | _ => None, | |
100 | let file_id = params.text_document.try_conv_with(&world)?; | ||
101 | let line_index = world.analysis().file_line_index(file_id); | ||
102 | let position = FilePosition { | ||
103 | file_id, | ||
104 | offset: params.position.conv_with(&line_index), | ||
105 | }; | 100 | }; |
106 | 101 | ||
107 | let analysis: Vec<Box<Fn(FilePosition) -> Option<SourceChange>>> = vec![ | 102 | if let Some(ana) = analysis { |
108 | Box::new(|pos| world.analysis().on_eq_typed(pos)), | 103 | let file_id = params.text_document.try_conv_with(&world)?; |
109 | Box::new(|pos| world.analysis().on_dot_typed(pos)), | 104 | let line_index = world.analysis().file_line_index(file_id); |
110 | ]; | 105 | let position = FilePosition { |
106 | file_id, | ||
107 | offset: params.position.conv_with(&line_index), | ||
108 | }; | ||
111 | 109 | ||
112 | // try all analysis until one succeeds | ||
113 | for ana in analysis { | ||
114 | if let Some(mut action) = ana(position) { | 110 | if let Some(mut action) = ana(position) { |
115 | return Ok(Some( | 111 | let change: Vec<TextEdit> = action |
116 | action | 112 | .source_file_edits |
117 | .source_file_edits | 113 | .pop() |
118 | .pop() | 114 | .unwrap() |
119 | .unwrap() | 115 | .edit |
120 | .edit | 116 | .as_atoms() |
121 | .as_atoms() | 117 | .iter() |
122 | .iter() | 118 | .map_conv_with(&line_index) |
123 | .map_conv_with(&line_index) | 119 | .collect(); |
124 | .collect(), | 120 | return Ok(Some(change)); |
125 | )); | ||
126 | } | 121 | } |
127 | } | 122 | } |
128 | 123 | ||