From dc65219ae1216e747215fe937b248ebf2469f33f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 09:00:30 +0300 Subject: document feature flags --- crates/ra_lsp_server/src/config.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 579d4c692..9871a3b37 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs @@ -1,4 +1,11 @@ -//! FIXME: write short doc here +//! Config used by the language server. +//! +//! We currently get this config from `initialize` LSP request, which is not the +//! best way to do it, but was the simplest thing we could implement. +//! +//! Of particular interest is the `feature_flags` hash map: while other fields +//! configure the server itself, feature flags are passed into analysis, and +//! tweak things like automatic insertion of `()` in completions. use rustc_hash::FxHashMap; @@ -72,10 +79,7 @@ mod test { assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); assert_eq!( default, - serde_json::from_str( - r#"{"publishDecorations":null, "showWorkspaceLoaded":null, "lruCapacity":null}"# - ) - .unwrap() + serde_json::from_str(r#"{"publishDecorations":null, "lruCapacity":null}"#).unwrap() ); } } -- cgit v1.2.3 From 8d2fd59cfb00211573419b0a59cf91d92d636f5a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 11:19:26 +0300 Subject: make typing infra slightly more extensible --- crates/ra_lsp_server/src/main_loop/handlers.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a29971d10..530c4d8b6 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -144,12 +144,8 @@ pub fn handle_on_type_formatting( // in `ra_ide_api`, the `on_type` invariant is that // `text.char_at(position) == typed_char`. position.offset = position.offset - TextUnit::of_char('.'); - - let edit = match params.ch.as_str() { - "=" => world.analysis().on_eq_typed(position), - "." => world.analysis().on_dot_typed(position), - _ => return Ok(None), - }?; + let char_typed = params.ch.chars().next().unwrap_or('\0'); + let edit = world.analysis().on_char_typed(position, char_typed)?; let mut edit = match edit { Some(it) => it, None => return Ok(None), -- cgit v1.2.3 From 53e3bee0cfcd7541b5ee882ab4b47c9dde9780b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 12:16:56 +0300 Subject: insert space after `->` --- crates/ra_lsp_server/src/caps.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server') 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 { document_range_formatting_provider: None, document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions { first_trigger_character: "=".to_string(), - more_trigger_character: Some(vec![".".to_string()]), + more_trigger_character: Some(vec![".".to_string(), ">".to_string()]), }), selection_range_provider: Some(GenericCapability::default()), 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 530c4d8b6..6f1e59b4b 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( } } +// Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`. pub fn handle_on_type_formatting( world: WorldSnapshot, params: req::DocumentOnTypeFormattingParams, -- cgit v1.2.3 From d5cd8b5be2a146abe75c0aa322f2313240c8f23c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 13:03:57 +0300 Subject: disable the new typing handler for `->` It doesn't actually work with LSP --- crates/ra_lsp_server/src/main_loop/handlers.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 6f1e59b4b..16fb07266 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -146,6 +146,15 @@ pub fn handle_on_type_formatting( // `text.char_at(position) == typed_char`. position.offset = position.offset - TextUnit::of_char('.'); let char_typed = params.ch.chars().next().unwrap_or('\0'); + + // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`, + // but it requires precise cursor positioning to work, and one can't + // position the cursor with on_type formatting. So, let's just toggle this + // feature off here, hoping that we'll enable it one day, 😿. + if char_typed == '>' { + return Ok(None); + } + let edit = world.analysis().on_char_typed(position, char_typed)?; let mut edit = match edit { Some(it) => it, -- cgit v1.2.3 From 3c140050ff469364db88b4f582533937a8a7fe61 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 29 Oct 2019 16:08:36 -0400 Subject: Profile all request handlers --- crates/ra_lsp_server/src/main_loop/handlers.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 16fb07266..20f9aee13 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -27,6 +27,7 @@ use crate::{ }; pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result { + let _p = profile("handle_analyzer_status"); let mut buf = world.status(); writeln!(buf, "\n\nrequests:").unwrap(); let requests = world.latest_requests.read(); @@ -38,6 +39,7 @@ pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result { } pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result { + let _p = profile("handle_syntax_tree"); let id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(id)?; let text_range = params.range.map(|p| p.conv_with(&line_index)); @@ -172,6 +174,7 @@ pub fn handle_document_symbol( world: WorldSnapshot, params: req::DocumentSymbolParams, ) -> Result> { + let _p = profile("handle_document_symbol"); let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id)?; @@ -210,6 +213,7 @@ pub fn handle_workspace_symbol( world: WorldSnapshot, params: req::WorkspaceSymbolParams, ) -> Result>> { + let _p = profile("handle_workspace_symbol"); let all_symbols = params.query.contains('#'); let libs = params.query.contains('*'); let query = { @@ -253,6 +257,7 @@ pub fn handle_goto_definition( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_goto_definition"); let position = params.try_conv_with(&world)?; let nav_info = match world.analysis().goto_definition(position)? { None => return Ok(None), @@ -266,6 +271,7 @@ pub fn handle_goto_implementation( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_goto_implementation"); let position = params.try_conv_with(&world)?; let nav_info = match world.analysis().goto_implementation(position)? { None => return Ok(None), @@ -279,6 +285,7 @@ pub fn handle_goto_type_definition( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_goto_type_definition"); let position = params.try_conv_with(&world)?; let nav_info = match world.analysis().goto_type_definition(position)? { None => return Ok(None), @@ -292,6 +299,7 @@ pub fn handle_parent_module( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_parent_module"); let position = params.try_conv_with(&world)?; world.analysis().parent_module(position)?.iter().try_conv_with_to_vec(&world) } @@ -300,6 +308,7 @@ pub fn handle_runnables( world: WorldSnapshot, params: req::RunnablesParams, ) -> Result> { + let _p = profile("handle_runnables"); let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id)?; let offset = params.position.map(|it| it.conv_with(&line_index)); @@ -341,6 +350,7 @@ pub fn handle_decorations( world: WorldSnapshot, params: TextDocumentIdentifier, ) -> Result> { + let _p = profile("handle_decorations"); let file_id = params.try_conv_with(&world)?; highlight(&world, file_id) } @@ -389,6 +399,7 @@ pub fn handle_folding_range( world: WorldSnapshot, params: FoldingRangeParams, ) -> Result>> { + let _p = profile("handle_folding_range"); let file_id = params.text_document.try_conv_with(&world)?; let folds = world.analysis().folding_ranges(file_id)?; let text = world.analysis().file_text(file_id)?; @@ -406,6 +417,7 @@ pub fn handle_signature_help( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_signature_help"); let position = params.try_conv_with(&world)?; if let Some(call_info) = world.analysis().call_info(position)? { let active_parameter = call_info.active_parameter.map(|it| it as i64); @@ -425,6 +437,7 @@ pub fn handle_hover( world: WorldSnapshot, params: req::TextDocumentPositionParams, ) -> Result> { + let _p = profile("handle_hover"); let position = params.try_conv_with(&world)?; let info = match world.analysis().hover(position)? { None => return Ok(None), @@ -523,6 +536,7 @@ pub fn handle_formatting( world: WorldSnapshot, params: DocumentFormattingParams, ) -> Result>> { + let _p = profile("handle_formatting"); let file_id = params.text_document.try_conv_with(&world)?; let file = world.analysis().file_text(file_id)?; @@ -645,6 +659,7 @@ pub fn handle_code_lens( world: WorldSnapshot, params: req::CodeLensParams, ) -> Result>> { + let _p = profile("handle_code_lens"); let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id)?; @@ -705,6 +720,7 @@ enum CodeLensResolveData { } pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result { + let _p = profile("handle_code_lens_resolve"); let data = code_lens.data.unwrap(); let resolve = serde_json::from_value(data)?; match resolve { @@ -776,6 +792,7 @@ pub fn publish_diagnostics( world: &WorldSnapshot, file_id: FileId, ) -> Result { + let _p = profile("publish_diagnostics"); let uri = world.file_id_to_uri(file_id)?; let line_index = world.analysis().file_line_index(file_id)?; let diagnostics = world @@ -798,6 +815,7 @@ pub fn publish_decorations( world: &WorldSnapshot, file_id: FileId, ) -> Result { + let _p = profile("publish_decorations"); let uri = world.file_id_to_uri(file_id)?; Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) } @@ -847,6 +865,7 @@ pub fn handle_inlay_hints( world: WorldSnapshot, params: InlayHintsParams, ) -> Result> { + let _p = profile("handle_inlay_hints"); let file_id = params.text_document.try_conv_with(&world)?; let analysis = world.analysis(); let line_index = analysis.file_line_index(file_id)?; -- cgit v1.2.3 From b441b4e8effeaf4532fd2e45c4d864480857c49e Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 13:36:37 -0400 Subject: Some clippy fixes --- crates/ra_lsp_server/src/main_loop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 1a87706fe..379dab438 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -196,7 +196,7 @@ pub fn main_loop( task_receiver.into_iter().for_each(|task| { on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) }); - libdata_receiver.into_iter().for_each(|lib| drop(lib)); + libdata_receiver.into_iter().for_each(drop); log::info!("...tasks have finished"); log::info!("joining threadpool..."); drop(pool); -- cgit v1.2.3