Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit aafb0f1

Browse files
committed
Use smallvec for inlay-hint parts
1 parent a119352 commit aafb0f1

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ide/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pulldown-cmark-to-cmark = "10.0.4"
2020
pulldown-cmark = { version = "0.9.1", default-features = false }
2121
url = "2.3.1"
2222
dot = "0.1.4"
23+
smallvec = "1.10.0"
2324

2425
stdx = { path = "../stdx", version = "0.0.0" }
2526
syntax = { path = "../syntax", version = "0.0.0" }

crates/ide/src/inlay_hints.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use either::Either;
77
use hir::{known, HasVisibility, HirDisplay, HirWrite, ModuleDef, ModuleDefId, Semantics};
88
use ide_db::{base_db::FileRange, famous_defs::FamousDefs, RootDatabase};
99
use itertools::Itertools;
10+
use smallvec::{smallvec, SmallVec};
1011
use stdx::never;
1112
use syntax::{
1213
ast::{self, AstNode},
@@ -83,7 +84,7 @@ pub enum AdjustmentHintsMode {
8384
PreferPostfix,
8485
}
8586

86-
#[derive(Clone, Debug, PartialEq, Eq)]
87+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
8788
pub enum InlayKind {
8889
BindingModeHint,
8990
ChainingHint,
@@ -102,9 +103,15 @@ pub enum InlayKind {
102103

103104
#[derive(Debug)]
104105
pub struct InlayHint {
106+
/// The text range this inlay hint applies to.
105107
pub range: TextRange,
108+
/// The kind of this inlay hint. This is used to determine side and padding of the hint for
109+
/// rendering purposes.
106110
pub kind: InlayKind,
111+
/// The actual label to show in the inlay hint.
107112
pub label: InlayHintLabel,
113+
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
114+
/// hover requests to show.
108115
pub tooltip: Option<InlayTooltip>,
109116
}
110117

@@ -117,7 +124,7 @@ pub enum InlayTooltip {
117124

118125
#[derive(Default)]
119126
pub struct InlayHintLabel {
120-
pub parts: Vec<InlayHintLabelPart>,
127+
pub parts: SmallVec<[InlayHintLabelPart; 1]>,
121128
}
122129

123130
impl InlayHintLabel {
@@ -145,13 +152,13 @@ impl InlayHintLabel {
145152

146153
impl From<String> for InlayHintLabel {
147154
fn from(s: String) -> Self {
148-
Self { parts: vec![InlayHintLabelPart { text: s, linked_location: None }] }
155+
Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None }] }
149156
}
150157
}
151158

152159
impl From<&str> for InlayHintLabel {
153160
fn from(s: &str) -> Self {
154-
Self { parts: vec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
161+
Self { parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
155162
}
156163
}
157164

crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! ```
66
use hir::{HirDisplay, Semantics};
77
use ide_db::{base_db::FileRange, RootDatabase};
8+
use smallvec::smallvec;
89
use syntax::{
910
ast::{self, AstNode, HasName},
1011
match_ast, SyntaxKind, SyntaxNode, T,
@@ -116,7 +117,9 @@ pub(super) fn hints(
116117
acc.push(InlayHint {
117118
range: closing_token.text_range(),
118119
kind: InlayKind::ClosingBraceHint,
119-
label: InlayHintLabel { parts: vec![InlayHintLabelPart { text: label, linked_location }] },
120+
label: InlayHintLabel {
121+
parts: smallvec![InlayHintLabelPart { text: label, linked_location }],
122+
},
120123
tooltip: None, // provided by label part location
121124
});
122125

0 commit comments

Comments
 (0)