aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-23 10:51:40 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-23 10:51:40 +0100
commit5f3ff157e3efe9f4fe2461bca1a0caaa5d2c72e5 (patch)
tree38108566787198f9a1391cbf016b05016f3fbda0 /crates/ra_lsp_server/src/main_loop/handlers.rs
parent08efe6cf92e7058ba38833dbfab8940a57a2cbfe (diff)
parent8f3377d9f93a256f8e68ae183808fd767b529d18 (diff)
Merge #1549
1549: Show type lenses for the resolved let bindings r=matklad a=SomeoneToIgnore Types that are fully unresolved are not displayed: <img width="279" alt="image" src="https://user-images.githubusercontent.com/2690773/61518122-8e4ba980-aa11-11e9-9249-6d9f9b202e6a.png"> A few concerns that I have about the current implementation: * I've adjusted the `file_structure` API method to return the information about the `let` bindings. Although it works fine, I have a feeling that adding a new API method would be the better way. But this requires some prior discussion, so I've decided to go for an easy way with an MVP. Would be nice to hear your suggestions. * There's a hardcoded `{undersolved}` check that I was forced to use, since the method that resolves types returns a `String`. Is there a better typed API I can use? This will help, for instance, to add an action to the type lenses that will allow us to navigate to the type. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 68865b755..5bf950a53 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -21,7 +21,7 @@ use url_serde::Ser;
21use crate::{ 21use crate::{
22 cargo_target_spec::{runnable_args, CargoTargetSpec}, 22 cargo_target_spec::{runnable_args, CargoTargetSpec},
23 conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec}, 23 conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec},
24 req::{self, Decoration}, 24 req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind},
25 world::WorldSnapshot, 25 world::WorldSnapshot,
26 LspError, Result, 26 LspError, Result,
27}; 27};
@@ -874,3 +874,24 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
874 WeakWarning => DiagnosticSeverity::Hint, 874 WeakWarning => DiagnosticSeverity::Hint,
875 } 875 }
876} 876}
877
878pub fn handle_inlay_hints(
879 world: WorldSnapshot,
880 params: InlayHintsParams,
881) -> Result<Vec<InlayHint>> {
882 let file_id = params.text_document.try_conv_with(&world)?;
883 let analysis = world.analysis();
884 let line_index = analysis.file_line_index(file_id);
885 Ok(analysis
886 .inlay_hints(file_id)?
887 .into_iter()
888 .map(|api_type| InlayHint {
889 label: api_type.label.to_string(),
890 range: api_type.range.conv_with(&line_index),
891 kind: match api_type.kind {
892 ra_ide_api::InlayKind::LetBindingType => InlayKind::LetBindingType,
893 ra_ide_api::InlayKind::ClosureParameterType => InlayKind::ClosureParameterType,
894 },
895 })
896 .collect())
897}