8024: Updated the implementation for trait modifier.
Fixed the test cases.
This commit is contained in:
parent
f269fe7156
commit
56f624532a
@ -276,6 +276,11 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
||||
hir::ModuleDef::Function(func) => {
|
||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
|
||||
if let Some(item) = func.as_assoc_item(db) {
|
||||
h |= HlMod::Associated;
|
||||
if func.self_param(db).is_none() {
|
||||
h |= HlMod::Static
|
||||
}
|
||||
|
||||
match item.container(db) {
|
||||
AssocItemContainer::Impl(i) => {
|
||||
if i.target_trait(db).is_some() {
|
||||
@ -288,12 +293,6 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
||||
}
|
||||
}
|
||||
|
||||
if func.as_assoc_item(db).is_some() {
|
||||
h |= HlMod::Associated;
|
||||
if func.self_param(db).is_none() {
|
||||
h |= HlMod::Static
|
||||
}
|
||||
}
|
||||
if func.is_unsafe(db) {
|
||||
h |= HlMod::Unsafe;
|
||||
}
|
||||
@ -305,9 +304,20 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
||||
hir::ModuleDef::Variant(_) => HlTag::Symbol(SymbolKind::Variant),
|
||||
hir::ModuleDef::Const(konst) => {
|
||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const));
|
||||
if konst.as_assoc_item(db).is_some() {
|
||||
h |= HlMod::Associated
|
||||
if let Some(item) = konst.as_assoc_item(db) {
|
||||
h |= HlMod::Associated;
|
||||
match item.container(db) {
|
||||
AssocItemContainer::Impl(i) => {
|
||||
if i.target_trait(db).is_some() {
|
||||
h |= HlMod::Trait;
|
||||
}
|
||||
}
|
||||
AssocItemContainer::Trait(_t) => {
|
||||
h |= HlMod::Trait;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait),
|
||||
@ -375,7 +385,7 @@ fn highlight_method_call(
|
||||
if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
|
||||
h |= HlMod::Unsafe;
|
||||
}
|
||||
if let Some(_t) = func.as_assoc_item(sema.db)?.containing_trait(sema.db) {
|
||||
if func.as_assoc_item(sema.db).and_then(|it| it.containing_trait(sema.db)).is_some() {
|
||||
h |= HlMod::Trait
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ pub enum HlMod {
|
||||
Associated,
|
||||
/// Used for intra doc links in doc injection.
|
||||
IntraDocLink,
|
||||
/// Used for trait items in impls.
|
||||
/// Used for items in traits and trait impls.
|
||||
Trait,
|
||||
|
||||
/// Keep this last!
|
||||
|
@ -47,12 +47,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration static associated">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration static associated trait">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated trait">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated trait">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated trait">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
</code></pre>
|
@ -42,7 +42,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="function">fixture</span><span class="parenthesis">(</span><span class="string_literal">r#"</span>
|
||||
<span class="keyword">trait</span> <span class="trait declaration">Foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration static associated">foo</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration static associated trait">foo</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
<span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"2 + 2 = {}"</span><span class="comma">,</span> <span class="numeric_literal">4</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span><span class="string_literal">"#</span>
|
||||
|
@ -62,11 +62,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
|
||||
@ -96,6 +96,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="keyword">let</span> <span class="struct">Packed</span> <span class="brace">{</span> <span class="field">a</span><span class="colon">:</span> <span class="keyword unsafe">ref</span> <span class="variable declaration">_a</span> <span class="brace">}</span> <span class="operator">=</span> <span class="variable">packed</span><span class="semicolon">;</span>
|
||||
|
||||
<span class="comment">// unsafe auto ref of packed field</span>
|
||||
<span class="variable">packed</span><span class="operator">.</span><span class="field">a</span><span class="operator">.</span><span class="function associated unsafe">calls_autoref</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="variable">packed</span><span class="operator">.</span><span class="field">a</span><span class="operator">.</span><span class="function associated trait unsafe">calls_autoref</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span></code></pre>
|
@ -67,11 +67,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration associated trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span>
|
||||
<span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
Loading…
Reference in New Issue
Block a user