aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Vandel Sillesen <[email protected]>2019-01-06 08:41:11 +0000
committerSimon Vandel Sillesen <[email protected]>2019-01-06 08:41:11 +0000
commit2e52b27e7139095393c7e4eebd7da0c6c26b053e (patch)
tree12fdc917449058fde414dcab0f1d5ae1c5737289
parentbb8624dff65dca10997e3eec62df975e6e347558 (diff)
refactor
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs14
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs47
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 @@
1mod handlers; 1mod handlers;
2mod subscriptions; 2mod subscriptions;
3 3
4use std::{ 4use std::{fmt, path::PathBuf, sync::Arc};
5 fmt,
6 path::PathBuf,
7 sync::Arc,
8};
9 5
10use crossbeam_channel::{unbounded, select, Receiver, Sender, RecvError}; 6use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
7use failure::{bail, format_err};
8use failure_derive::Fail;
11use gen_lsp_server::{ 9use 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;
15use ra_analysis::{Canceled, FileId, LibraryData}; 13use ra_analysis::{Canceled, FileId, LibraryData};
16use ra_vfs::VfsTask; 14use ra_vfs::VfsTask;
17use rayon; 15use rayon;
18use threadpool::ThreadPool;
19use rustc_hash::FxHashSet; 16use rustc_hash::FxHashSet;
20use serde::{de::DeserializeOwned, Serialize}; 17use serde::{de::DeserializeOwned, Serialize};
21use failure::{format_err, bail}; 18use threadpool::ThreadPool;
22use failure_derive::Fail;
23 19
24use crate::{ 20use 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