aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-25 12:24:43 +0100
committerGitHub <[email protected]>2019-10-25 12:24:43 +0100
commit5f779f6c46f29c63483c0e2be732377b1b87e685 (patch)
tree10e0a683d2426b7fba25bccc50f3808371202e56 /crates/ra_lsp_server
parent4ab384c19d30e2ea1ead5886dfc1efc05521f075 (diff)
parentd5cd8b5be2a146abe75c0aa322f2313240c8f23c (diff)
Merge #2066
2066: insert space after `->` r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/caps.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs16
2 files changed, 12 insertions, 6 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 30bcbd7a8..eea0965ed 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -38,7 +38,7 @@ pub fn server_capabilities() -> ServerCapabilities {
38 document_range_formatting_provider: None, 38 document_range_formatting_provider: None,
39 document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { 39 document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions {
40 first_trigger_character: "=".to_string(), 40 first_trigger_character: "=".to_string(),
41 more_trigger_character: Some(vec![".".to_string()]), 41 more_trigger_character: Some(vec![".".to_string(), ">".to_string()]),
42 }), 42 }),
43 selection_range_provider: Some(GenericCapability::default()), 43 selection_range_provider: Some(GenericCapability::default()),
44 folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), 44 folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index a29971d10..16fb07266 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -132,6 +132,7 @@ pub fn handle_on_enter(
132 } 132 }
133} 133}
134 134
135// Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`.
135pub fn handle_on_type_formatting( 136pub fn handle_on_type_formatting(
136 world: WorldSnapshot, 137 world: WorldSnapshot,
137 params: req::DocumentOnTypeFormattingParams, 138 params: req::DocumentOnTypeFormattingParams,
@@ -144,12 +145,17 @@ pub fn handle_on_type_formatting(
144 // in `ra_ide_api`, the `on_type` invariant is that 145 // in `ra_ide_api`, the `on_type` invariant is that
145 // `text.char_at(position) == typed_char`. 146 // `text.char_at(position) == typed_char`.
146 position.offset = position.offset - TextUnit::of_char('.'); 147 position.offset = position.offset - TextUnit::of_char('.');
148 let char_typed = params.ch.chars().next().unwrap_or('\0');
147 149
148 let edit = match params.ch.as_str() { 150 // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
149 "=" => world.analysis().on_eq_typed(position), 151 // but it requires precise cursor positioning to work, and one can't
150 "." => world.analysis().on_dot_typed(position), 152 // position the cursor with on_type formatting. So, let's just toggle this
151 _ => return Ok(None), 153 // feature off here, hoping that we'll enable it one day, 😿.
152 }?; 154 if char_typed == '>' {
155 return Ok(None);
156 }
157
158 let edit = world.analysis().on_char_typed(position, char_typed)?;
153 let mut edit = match edit { 159 let mut edit = match edit {
154 Some(it) => it, 160 Some(it) => it,
155 None => return Ok(None), 161 None => return Ok(None),