mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Use smallvec for inlay-hint parts
This commit is contained in:
parent
a119352ada
commit
aafb0f1f8d
4 changed files with 17 additions and 5 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -645,6 +645,7 @@ dependencies = [
|
|||
"profile",
|
||||
"pulldown-cmark",
|
||||
"pulldown-cmark-to-cmark",
|
||||
"smallvec",
|
||||
"stdx",
|
||||
"syntax",
|
||||
"test-utils",
|
||||
|
|
|
@ -20,6 +20,7 @@ pulldown-cmark-to-cmark = "10.0.4"
|
|||
pulldown-cmark = { version = "0.9.1", default-features = false }
|
||||
url = "2.3.1"
|
||||
dot = "0.1.4"
|
||||
smallvec = "1.10.0"
|
||||
|
||||
stdx = { path = "../stdx", version = "0.0.0" }
|
||||
syntax = { path = "../syntax", version = "0.0.0" }
|
||||
|
|
|
@ -7,6 +7,7 @@ use either::Either;
|
|||
use hir::{known, HasVisibility, HirDisplay, HirWrite, ModuleDef, ModuleDefId, Semantics};
|
||||
use ide_db::{base_db::FileRange, famous_defs::FamousDefs, RootDatabase};
|
||||
use itertools::Itertools;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use stdx::never;
|
||||
use syntax::{
|
||||
ast::{self, AstNode},
|
||||
|
@ -83,7 +84,7 @@ pub enum AdjustmentHintsMode {
|
|||
PreferPostfix,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum InlayKind {
|
||||
BindingModeHint,
|
||||
ChainingHint,
|
||||
|
@ -102,9 +103,15 @@ pub enum InlayKind {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct InlayHint {
|
||||
/// The text range this inlay hint applies to.
|
||||
pub range: TextRange,
|
||||
/// The kind of this inlay hint. This is used to determine side and padding of the hint for
|
||||
/// rendering purposes.
|
||||
pub kind: InlayKind,
|
||||
/// The actual label to show in the inlay hint.
|
||||
pub label: InlayHintLabel,
|
||||
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
|
||||
/// hover requests to show.
|
||||
pub tooltip: Option<InlayTooltip>,
|
||||
}
|
||||
|
||||
|
@ -117,7 +124,7 @@ pub enum InlayTooltip {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct InlayHintLabel {
|
||||
pub parts: Vec<InlayHintLabelPart>,
|
||||
pub parts: SmallVec<[InlayHintLabelPart; 1]>,
|
||||
}
|
||||
|
||||
impl InlayHintLabel {
|
||||
|
@ -145,13 +152,13 @@ impl InlayHintLabel {
|
|||
|
||||
impl From<String> for InlayHintLabel {
|
||||
fn from(s: String) -> Self {
|
||||
Self { parts: vec![InlayHintLabelPart { text: s, linked_location: None }] }
|
||||
Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None }] }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for InlayHintLabel {
|
||||
fn from(s: &str) -> Self {
|
||||
Self { parts: vec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
|
||||
Self { parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
//! ```
|
||||
use hir::{HirDisplay, Semantics};
|
||||
use ide_db::{base_db::FileRange, RootDatabase};
|
||||
use smallvec::smallvec;
|
||||
use syntax::{
|
||||
ast::{self, AstNode, HasName},
|
||||
match_ast, SyntaxKind, SyntaxNode, T,
|
||||
|
@ -116,7 +117,9 @@ pub(super) fn hints(
|
|||
acc.push(InlayHint {
|
||||
range: closing_token.text_range(),
|
||||
kind: InlayKind::ClosingBraceHint,
|
||||
label: InlayHintLabel { parts: vec![InlayHintLabelPart { text: label, linked_location }] },
|
||||
label: InlayHintLabel {
|
||||
parts: smallvec![InlayHintLabelPart { text: label, linked_location }],
|
||||
},
|
||||
tooltip: None, // provided by label part location
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue