aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs47
1 files changed, 21 insertions, 26 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 0dda9548a..5f4b27149 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,7 +9,7 @@ use languageserver_types::{
9 SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, 9 SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, 12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity,
13}; 13};
14use ra_syntax::{TextUnit, AstNode}; 14use ra_syntax::{TextUnit, AstNode};
15use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
@@ -92,35 +92,30 @@ pub fn handle_on_type_formatting(
92 world: ServerWorld, 92 world: ServerWorld,
93 params: req::DocumentOnTypeFormattingParams, 93 params: req::DocumentOnTypeFormattingParams,
94) -> Result<Option<Vec<TextEdit>>> { 94) -> Result<Option<Vec<TextEdit>>> {
95 let analysis: Option<Box<Fn(FilePosition) -> Option<SourceChange>>> = match params.ch.as_str() { 95 let file_id = params.text_document.try_conv_with(&world)?;
96 "=" => Some(Box::new(|pos| world.analysis().on_eq_typed(pos))), 96 let line_index = world.analysis().file_line_index(file_id);
97 "." => Some(Box::new(|pos| world.analysis().on_dot_typed(pos))), 97 let position = FilePosition {
98 _ => None, 98 file_id,
99 /// in `ra_ide_api`, the `on_type` invariant is that
100 /// `text.char_at(position) == typed_char`.
101 offset: params.position.conv_with(&line_index) - TextUnit::of_char('.'),
99 }; 102 };
100 103
101 if let Some(ana) = analysis { 104 let edit = match params.ch.as_str() {
102 let file_id = params.text_document.try_conv_with(&world)?; 105 "=" => world.analysis().on_eq_typed(position),
103 let line_index = world.analysis().file_line_index(file_id); 106 "." => world.analysis().on_dot_typed(position),
104 let position = FilePosition { 107 _ => return Ok(None),
105 file_id, 108 };
106 offset: params.position.conv_with(&line_index), 109 let mut edit = match edit {
107 }; 110 Some(it) => it,
111 None => return Ok(None),
112 };
108 113
109 if let Some(mut action) = ana(position) { 114 // This should be a single-file edit
110 let change: Vec<TextEdit> = action 115 let edit = edit.source_file_edits.pop().unwrap();
111 .source_file_edits
112 .pop()
113 .unwrap()
114 .edit
115 .as_atoms()
116 .iter()
117 .map_conv_with(&line_index)
118 .collect();
119 return Ok(Some(change));
120 }
121 }
122 116
123 return Ok(None); 117 let change: Vec<TextEdit> = edit.edit.conv_with(&line_index);
118 return Ok(Some(change));
124} 119}
125 120
126pub fn handle_document_symbol( 121pub fn handle_document_symbol(