aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-11 12:49:09 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-11 12:49:09 +0000
commit0f4bc7589c40732fb78cb59525a6b4dcfb515567 (patch)
tree4ff25038c52dc1767579135bb5387b0fb184c83d /crates/ra_lsp_server
parentdd122145b57513cf57076ae3235d70215b226039 (diff)
parenta1b661faec69e5c643924bf672ac61ff4ff12202 (diff)
Merge #495
495: Fix on type handlers r=matklad a=matklad Looks like our on type handlers didn't actually worked, this shoud fix that! Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-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(