mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Merge #7080
7080: Implement ConstParams for HIR r=Veykril a=Veykril r? @flodiebold Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
0e5fe47153
28 changed files with 238 additions and 41 deletions
|
@ -24,6 +24,7 @@ pub enum SymbolKind {
|
|||
Impl,
|
||||
Field,
|
||||
TypeParam,
|
||||
ConstParam,
|
||||
LifetimeParam,
|
||||
ValueParam,
|
||||
SelfParam,
|
||||
|
@ -225,6 +226,7 @@ impl TryToNav for Definition {
|
|||
Definition::TypeParam(it) => Some(it.to_nav(db)),
|
||||
Definition::LifetimeParam(it) => Some(it.to_nav(db)),
|
||||
Definition::Label(it) => Some(it.to_nav(db)),
|
||||
Definition::ConstParam(it) => Some(it.to_nav(db)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -485,6 +487,23 @@ impl ToNav for hir::LifetimeParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToNav for hir::ConstParam {
|
||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||
let src = self.source(db);
|
||||
let full_range = src.value.syntax().text_range();
|
||||
NavigationTarget {
|
||||
file_id: src.file_id.original_file(db),
|
||||
name: self.name(db).to_string().into(),
|
||||
kind: Some(SymbolKind::ConstParam),
|
||||
full_range,
|
||||
focus_range: src.value.name().map(|n| n.syntax().text_range()),
|
||||
container_name: None,
|
||||
description: None,
|
||||
docs: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a description of a symbol.
|
||||
///
|
||||
/// e.g. `struct Name`, `enum Name`, `fn Name`
|
||||
|
|
|
@ -193,6 +193,7 @@ fn rewrite_intra_doc_link(
|
|||
Definition::SelfType(_)
|
||||
| Definition::Local(_)
|
||||
| Definition::TypeParam(_)
|
||||
| Definition::ConstParam(_)
|
||||
| Definition::LifetimeParam(_)
|
||||
| Definition::Label(_) => return None,
|
||||
}?;
|
||||
|
|
|
@ -370,7 +370,10 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
|
|||
Adt::Enum(it) => from_def_source(db, it, mod_path),
|
||||
})
|
||||
}
|
||||
Definition::TypeParam(_) | Definition::LifetimeParam(_) | Definition::Label(_) => {
|
||||
Definition::TypeParam(_)
|
||||
| Definition::LifetimeParam(_)
|
||||
| Definition::ConstParam(_)
|
||||
| Definition::Label(_) => {
|
||||
// FIXME: Hover for generic param
|
||||
None
|
||||
}
|
||||
|
|
|
@ -1144,4 +1144,20 @@ fn foo<'a>() -> &'a () {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_const_param() {
|
||||
check(
|
||||
r#"
|
||||
fn foo<const FOO<|>: usize>() -> usize {
|
||||
FOO
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
FOO ConstParam FileId(0) 7..23 13..16 Other
|
||||
|
||||
FileId(0) 42..45 Other
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -819,6 +819,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
|||
},
|
||||
Definition::SelfType(_) => HighlightTag::Symbol(SymbolKind::Impl),
|
||||
Definition::TypeParam(_) => HighlightTag::Symbol(SymbolKind::TypeParam),
|
||||
Definition::ConstParam(_) => HighlightTag::Symbol(SymbolKind::ConstParam),
|
||||
Definition::Local(local) => {
|
||||
let tag = if local.is_param(db) {
|
||||
HighlightTag::Symbol(SymbolKind::ValueParam)
|
||||
|
|
|
@ -77,6 +77,7 @@ impl HighlightTag {
|
|||
SymbolKind::Function => "function",
|
||||
SymbolKind::TypeAlias => "type_alias",
|
||||
SymbolKind::TypeParam => "type_param",
|
||||
SymbolKind::ConstParam => "const_param",
|
||||
SymbolKind::LifetimeParam => "lifetime",
|
||||
SymbolKind::Macro => "macro",
|
||||
SymbolKind::Local => "variable",
|
||||
|
|
|
@ -118,6 +118,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="keyword control">loop</span> <span class="punctuation">{</span><span class="punctuation">}</span>
|
||||
<span class="punctuation">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function declaration">const_param</span><span class="punctuation"><</span><span class="keyword">const</span> <span class="const_param declaration">FOO</span><span class="punctuation">:</span> <span class="builtin_type">usize</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="builtin_type">usize</span> <span class="punctuation">{</span>
|
||||
<span class="const_param">FOO</span>
|
||||
<span class="punctuation">}</span>
|
||||
|
||||
<span class="keyword">use</span> <span class="module">ops</span><span class="operator">::</span><span class="trait">Fn</span><span class="punctuation">;</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration">baz</span><span class="punctuation"><</span><span class="type_param declaration">F</span><span class="punctuation">:</span> <span class="trait">Fn</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">></span><span class="punctuation">(</span><span class="value_param declaration callable">f</span><span class="punctuation">:</span> <span class="type_param">F</span><span class="punctuation">)</span> <span class="punctuation">{</span>
|
||||
<span class="value_param callable">f</span><span class="punctuation">(</span><span class="punctuation">)</span>
|
||||
|
|
|
@ -91,6 +91,10 @@ fn never() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
fn const_param<const FOO: usize>() -> usize {
|
||||
FOO
|
||||
}
|
||||
|
||||
use ops::Fn;
|
||||
fn baz<F: Fn() -> ()>(f: F) {
|
||||
f()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue