aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs1
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs23
-rw-r--r--crates/ra_lsp_server/src/req.rs27
3 files changed, 50 insertions, 1 deletions
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(
362 .on::<req::References>(handlers::handle_references)? 362 .on::<req::References>(handlers::handle_references)?
363 .on::<req::Formatting>(handlers::handle_formatting)? 363 .on::<req::Formatting>(handlers::handle_formatting)?
364 .on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)? 364 .on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)?
365 .on::<req::InlayHints>(handlers::handle_inlay_hints)?
365 .finish(); 366 .finish();
366 Ok(()) 367 Ok(())
367} 368}
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}
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 {
196 pub workspace_edit: WorkspaceEdit, 196 pub workspace_edit: WorkspaceEdit,
197 pub cursor_position: Option<TextDocumentPositionParams>, 197 pub cursor_position: Option<TextDocumentPositionParams>,
198} 198}
199
200pub enum InlayHints {}
201
202impl Request for InlayHints {
203 type Params = InlayHintsParams;
204 type Result = Vec<InlayHint>;
205 const METHOD: &'static str = "rust-analyzer/inlayHints";
206}
207
208#[derive(Serialize, Deserialize, Debug)]
209#[serde(rename_all = "camelCase")]
210pub struct InlayHintsParams {
211 pub text_document: TextDocumentIdentifier,
212}
213
214#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
215pub enum InlayKind {
216 LetBindingType,
217 ClosureParameterType,
218}
219
220#[derive(Debug, Deserialize, Serialize)]
221pub struct InlayHint {
222 pub range: Range,
223 pub kind: InlayKind,
224 pub label: String,
225}