mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
Code review fixes
This commit is contained in:
parent
25398ad30d
commit
8f3377d9f9
4 changed files with 70 additions and 30 deletions
|
@ -362,6 +362,7 @@ fn on_request(
|
|||
.on::<req::References>(handlers::handle_references)?
|
||||
.on::<req::Formatting>(handlers::handle_formatting)?
|
||||
.on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)?
|
||||
.on::<req::InlayHints>(handlers::handle_inlay_hints)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -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<Vec<InlayHint>> {
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -196,3 +196,30 @@ pub struct SourceChange {
|
|||
pub workspace_edit: WorkspaceEdit,
|
||||
pub cursor_position: Option<TextDocumentPositionParams>,
|
||||
}
|
||||
|
||||
pub enum InlayHints {}
|
||||
|
||||
impl Request for InlayHints {
|
||||
type Params = InlayHintsParams;
|
||||
type Result = Vec<InlayHint>;
|
||||
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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue