Replace some SmolStr usages with String as the conversion happens anyways
This commit is contained in:
parent
91833f1974
commit
0756719a30
@ -8,7 +8,7 @@
|
|||||||
use stdx::to_lower_snake_case;
|
use stdx::to_lower_snake_case;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, HasArgList, HasGenericParams, HasName, UnaryOp},
|
ast::{self, AstNode, HasArgList, HasGenericParams, HasName, UnaryOp},
|
||||||
match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, SyntaxNode, TextRange, T,
|
match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::FileId;
|
use crate::FileId;
|
||||||
@ -60,7 +60,7 @@ pub enum InlayKind {
|
|||||||
pub struct InlayHint {
|
pub struct InlayHint {
|
||||||
pub range: TextRange,
|
pub range: TextRange,
|
||||||
pub kind: InlayKind,
|
pub kind: InlayKind,
|
||||||
pub label: SmolStr,
|
pub label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feature: Inlay Hints
|
// Feature: Inlay Hints
|
||||||
@ -248,7 +248,7 @@ fn closing_brace_hints(
|
|||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: closing_token.text_range(),
|
range: closing_token.text_range(),
|
||||||
kind: InlayKind::ClosingBraceHint,
|
kind: InlayKind::ClosingBraceHint,
|
||||||
label: label.into(),
|
label,
|
||||||
});
|
});
|
||||||
|
|
||||||
None
|
None
|
||||||
@ -262,6 +262,13 @@ fn lifetime_fn_hints(
|
|||||||
if config.lifetime_elision_hints == LifetimeElisionHints::Never {
|
if config.lifetime_elision_hints == LifetimeElisionHints::Never {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mk_lt_hint = |t: SyntaxToken, label| InlayHint {
|
||||||
|
range: t.text_range(),
|
||||||
|
kind: InlayKind::LifetimeHint,
|
||||||
|
label,
|
||||||
|
};
|
||||||
|
|
||||||
let param_list = func.param_list()?;
|
let param_list = func.param_list()?;
|
||||||
let generic_param_list = func.generic_param_list();
|
let generic_param_list = func.generic_param_list();
|
||||||
let ret_type = func.ret_type();
|
let ret_type = func.ret_type();
|
||||||
@ -378,11 +385,7 @@ fn lifetime_fn_hints(
|
|||||||
ast::Type::RefType(ty) if ty.lifetime().is_none() => {
|
ast::Type::RefType(ty) if ty.lifetime().is_none() => {
|
||||||
if let Some(amp) = ty.amp_token() {
|
if let Some(amp) = ty.amp_token() {
|
||||||
is_trivial = false;
|
is_trivial = false;
|
||||||
acc.push(InlayHint {
|
acc.push(mk_lt_hint(amp, output_lt.to_string()));
|
||||||
range: amp.text_range(),
|
|
||||||
kind: InlayKind::LifetimeHint,
|
|
||||||
label: output_lt.clone(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@ -398,8 +401,8 @@ fn lifetime_fn_hints(
|
|||||||
for (_, amp_token, _, is_elided) in potential_lt_refs {
|
for (_, amp_token, _, is_elided) in potential_lt_refs {
|
||||||
if is_elided {
|
if is_elided {
|
||||||
let t = amp_token?;
|
let t = amp_token?;
|
||||||
let lt = a.next()?.clone();
|
let lt = a.next()?;
|
||||||
acc.push(InlayHint { range: t.text_range(), kind: InlayKind::LifetimeHint, label: lt });
|
acc.push(mk_lt_hint(t, lt.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,16 +412,14 @@ fn lifetime_fn_hints(
|
|||||||
(Some(gpl), allocated_lifetimes) => {
|
(Some(gpl), allocated_lifetimes) => {
|
||||||
let angle_tok = gpl.l_angle_token()?;
|
let angle_tok = gpl.l_angle_token()?;
|
||||||
let is_empty = gpl.generic_params().next().is_none();
|
let is_empty = gpl.generic_params().next().is_none();
|
||||||
acc.push(InlayHint {
|
acc.push(mk_lt_hint(
|
||||||
range: angle_tok.text_range(),
|
angle_tok,
|
||||||
kind: InlayKind::GenericParamListHint,
|
format!(
|
||||||
label: format!(
|
|
||||||
"{}{}",
|
"{}{}",
|
||||||
allocated_lifetimes.iter().format(", "),
|
allocated_lifetimes.iter().format(", "),
|
||||||
if is_empty { "" } else { ", " }
|
if is_empty { "" } else { ", " }
|
||||||
)
|
),
|
||||||
.into(),
|
));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
(None, allocated_lifetimes) => acc.push(InlayHint {
|
(None, allocated_lifetimes) => acc.push(InlayHint {
|
||||||
range: func.name()?.syntax().text_range(),
|
range: func.name()?.syntax().text_range(),
|
||||||
@ -456,7 +457,7 @@ fn closure_ret_hints(
|
|||||||
range: param_list.syntax().text_range(),
|
range: param_list.syntax().text_range(),
|
||||||
kind: InlayKind::ClosureReturnTypeHint,
|
kind: InlayKind::ClosureReturnTypeHint,
|
||||||
label: hint_iterator(sema, &famous_defs, config, &ty)
|
label: hint_iterator(sema, &famous_defs, config, &ty)
|
||||||
.unwrap_or_else(|| ty.display_truncated(sema.db, config.max_length).to_string().into()),
|
.unwrap_or_else(|| ty.display_truncated(sema.db, config.max_length).to_string()),
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
@ -482,7 +483,7 @@ fn reborrow_hints(
|
|||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::ImplicitReborrowHint,
|
kind: InlayKind::ImplicitReborrowHint,
|
||||||
label: SmolStr::new_inline(label),
|
label: label.to_string(),
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
@ -539,7 +540,7 @@ fn chaining_hints(
|
|||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::ChainingHint,
|
kind: InlayKind::ChainingHint,
|
||||||
label: hint_iterator(sema, &famous_defs, config, &ty).unwrap_or_else(|| {
|
label: hint_iterator(sema, &famous_defs, config, &ty).unwrap_or_else(|| {
|
||||||
ty.display_truncated(sema.db, config.max_length).to_string().into()
|
ty.display_truncated(sema.db, config.max_length).to_string()
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -606,11 +607,7 @@ fn binding_mode_hints(
|
|||||||
(true, false) => "&",
|
(true, false) => "&",
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint { range, kind: InlayKind::BindingModeHint, label: r.to_string() });
|
||||||
range,
|
|
||||||
kind: InlayKind::BindingModeHint,
|
|
||||||
label: SmolStr::new_inline(r),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
match pat {
|
match pat {
|
||||||
ast::Pat::IdentPat(pat) if pat.ref_token().is_none() && pat.mut_token().is_none() => {
|
ast::Pat::IdentPat(pat) if pat.ref_token().is_none() && pat.mut_token().is_none() => {
|
||||||
@ -620,11 +617,7 @@ fn binding_mode_hints(
|
|||||||
hir::BindingMode::Ref(Mutability::Mut) => "ref mut",
|
hir::BindingMode::Ref(Mutability::Mut) => "ref mut",
|
||||||
hir::BindingMode::Ref(Mutability::Shared) => "ref",
|
hir::BindingMode::Ref(Mutability::Shared) => "ref",
|
||||||
};
|
};
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint { range, kind: InlayKind::BindingModeHint, label: bm.to_string() });
|
||||||
range,
|
|
||||||
kind: InlayKind::BindingModeHint,
|
|
||||||
label: SmolStr::new_inline(bm),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
@ -663,7 +656,7 @@ fn bind_pat_hints(
|
|||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
ty_name.into()
|
ty_name
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -738,7 +731,7 @@ fn hint_iterator(
|
|||||||
famous_defs: &FamousDefs,
|
famous_defs: &FamousDefs,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
ty: &hir::Type,
|
ty: &hir::Type,
|
||||||
) -> Option<SmolStr> {
|
) -> Option<String> {
|
||||||
let db = sema.db;
|
let db = sema.db;
|
||||||
let strukt = ty.strip_references().as_adt()?;
|
let strukt = ty.strip_references().as_adt()?;
|
||||||
let krate = strukt.module(db).krate();
|
let krate = strukt.module(db).krate();
|
||||||
@ -775,7 +768,7 @@ fn hint_iterator(
|
|||||||
)
|
)
|
||||||
.to_string()
|
.to_string()
|
||||||
});
|
});
|
||||||
return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
|
return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,24 +433,6 @@ pub(crate) fn inlay_hint(
|
|||||||
| InlayKind::LifetimeHint
|
| InlayKind::LifetimeHint
|
||||||
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
|
| InlayKind::ClosingBraceHint => position(line_index, inlay_hint.range.end()),
|
||||||
},
|
},
|
||||||
label: lsp_types::InlayHintLabel::String(match inlay_hint.kind {
|
|
||||||
InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
|
|
||||||
InlayKind::TypeHint if render_colons => format!(": {}", inlay_hint.label),
|
|
||||||
InlayKind::ClosureReturnTypeHint => format!(" -> {}", inlay_hint.label),
|
|
||||||
_ => inlay_hint.label.to_string(),
|
|
||||||
}),
|
|
||||||
kind: match inlay_hint.kind {
|
|
||||||
InlayKind::ParameterHint => Some(lsp_types::InlayHintKind::PARAMETER),
|
|
||||||
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
|
|
||||||
Some(lsp_types::InlayHintKind::TYPE)
|
|
||||||
}
|
|
||||||
InlayKind::BindingModeHint
|
|
||||||
| InlayKind::GenericParamListHint
|
|
||||||
| InlayKind::LifetimeHint
|
|
||||||
| InlayKind::ImplicitReborrowHint
|
|
||||||
| InlayKind::ClosingBraceHint => None,
|
|
||||||
},
|
|
||||||
tooltip: None,
|
|
||||||
padding_left: Some(match inlay_hint.kind {
|
padding_left: Some(match inlay_hint.kind {
|
||||||
InlayKind::TypeHint => !render_colons,
|
InlayKind::TypeHint => !render_colons,
|
||||||
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
|
InlayKind::ChainingHint | InlayKind::ClosingBraceHint => true,
|
||||||
@ -471,7 +453,25 @@ pub(crate) fn inlay_hint(
|
|||||||
InlayKind::BindingModeHint => inlay_hint.label != "&",
|
InlayKind::BindingModeHint => inlay_hint.label != "&",
|
||||||
InlayKind::ParameterHint | InlayKind::LifetimeHint => true,
|
InlayKind::ParameterHint | InlayKind::LifetimeHint => true,
|
||||||
}),
|
}),
|
||||||
|
label: lsp_types::InlayHintLabel::String(match inlay_hint.kind {
|
||||||
|
InlayKind::ParameterHint if render_colons => format!("{}:", inlay_hint.label),
|
||||||
|
InlayKind::TypeHint if render_colons => format!(": {}", inlay_hint.label),
|
||||||
|
InlayKind::ClosureReturnTypeHint => format!(" -> {}", inlay_hint.label),
|
||||||
|
_ => inlay_hint.label,
|
||||||
|
}),
|
||||||
|
kind: match inlay_hint.kind {
|
||||||
|
InlayKind::ParameterHint => Some(lsp_types::InlayHintKind::PARAMETER),
|
||||||
|
InlayKind::ClosureReturnTypeHint | InlayKind::TypeHint | InlayKind::ChainingHint => {
|
||||||
|
Some(lsp_types::InlayHintKind::TYPE)
|
||||||
|
}
|
||||||
|
InlayKind::BindingModeHint
|
||||||
|
| InlayKind::GenericParamListHint
|
||||||
|
| InlayKind::LifetimeHint
|
||||||
|
| InlayKind::ImplicitReborrowHint
|
||||||
|
| InlayKind::ClosingBraceHint => None,
|
||||||
|
},
|
||||||
text_edits: None,
|
text_edits: None,
|
||||||
|
tooltip: None,
|
||||||
data: None,
|
data: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user