From 8f3377d9f93a256f8e68ae183808fd767b529d18 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 22 Jul 2019 21:52:47 +0300 Subject: Code review fixes --- crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 23 +++++++++++++++++++++- crates/ra_lsp_server/src/req.rs | 27 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 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 668d2fd72..8e830c8b8 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -362,6 +362,7 @@ fn on_request( .on::(handlers::handle_references)? .on::(handlers::handle_formatting)? .on::(handlers::handle_document_highlight)? + .on::(handlers::handle_inlay_hints)? .finish(); Ok(()) } 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; use crate::{ cargo_target_spec::{runnable_args, CargoTargetSpec}, conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith, TryConvWithToVec}, - req::{self, Decoration}, + req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, world::WorldSnapshot, LspError, Result, }; @@ -874,3 +874,24 @@ fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity { WeakWarning => DiagnosticSeverity::Hint, } } + +pub fn handle_inlay_hints( + world: WorldSnapshot, + params: InlayHintsParams, +) -> Result> { + let file_id = params.text_document.try_conv_with(&world)?; + let analysis = world.analysis(); + let line_index = analysis.file_line_index(file_id); + Ok(analysis + .inlay_hints(file_id)? + .into_iter() + .map(|api_type| InlayHint { + label: api_type.label.to_string(), + range: api_type.range.conv_with(&line_index), + kind: match api_type.kind { + ra_ide_api::InlayKind::LetBindingType => InlayKind::LetBindingType, + ra_ide_api::InlayKind::ClosureParameterType => InlayKind::ClosureParameterType, + }, + }) + .collect()) +} diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 8d39b04a7..916185f99 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -196,3 +196,30 @@ pub struct SourceChange { pub workspace_edit: WorkspaceEdit, pub cursor_position: Option, } + +pub enum InlayHints {} + +impl Request for InlayHints { + type Params = InlayHintsParams; + type Result = Vec; + const METHOD: &'static str = "rust-analyzer/inlayHints"; +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct InlayHintsParams { + pub text_document: TextDocumentIdentifier, +} + +#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] +pub enum InlayKind { + LetBindingType, + ClosureParameterType, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct InlayHint { + pub range: Range, + pub kind: InlayKind, + pub label: String, +} -- cgit v1.2.3