Disable broken struct field rainbowing

This commit is contained in:
Pascal Hertleif 2019-05-25 16:29:39 +02:00
parent 43d5a49653
commit 2b200f6e1a
No known key found for this signature in database
GPG Key ID: EDBB1A8D2047A074
3 changed files with 7 additions and 23 deletions

View File

@ -463,8 +463,8 @@ impl Analysis {
}
/// Computes syntax highlighting for the given file.
pub fn highlight_as_html(&self, file_id: FileId) -> Cancelable<String> {
self.with_db(|db| syntax_highlighting::highlight_as_html(db, file_id, true))
pub fn highlight_as_html(&self, file_id: FileId, rainbow: bool) -> Cancelable<String> {
self.with_db(|db| syntax_highlighting::highlight_as_html(db, file_id, rainbow))
}
/// Computes completions at the given position.
@ -472,7 +472,7 @@ impl Analysis {
self.with_db(|db| completion::completions(db, position).map(Into::into))
}
/// Computes assists (aks code actons aka intentions) for the given
/// Computes assists (aka code actions aka intentions) for the given
/// position.
pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> {
self.with_db(|db| assists::assists(db, frange))

View File

@ -19,8 +19,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
</style>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
<span class="keyword">struct</span> <span class="function">Foo</span> {
<span class="keyword">pub</span> <span class="variable" data-binding-hash="12067179602561426350" style="color: hsl(78,84%,47%);">x</span>: <span class="text">i32</span>,
<span class="keyword">pub</span> <span class="variable" data-binding-hash="15562018766631452210" style="color: hsl(318,95%,78%);">y</span>: <span class="text">i32</span>,
<span class="keyword">pub</span> <span class="function">x</span>: <span class="text">i32</span>,
<span class="keyword">pub</span> <span class="function">y</span>: <span class="text">i32</span>,
}
<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type function">T</span>&gt;() -&gt; <span class="type">T</span> {
@ -33,7 +33,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable" data-binding-hash="9636295041291189729" style="color: hsl(51,57%,74%);">vec</span> = <span class="text">Vec</span>::<span class="text">new</span>();
<span class="keyword.control">if</span> <span class="keyword">true</span> {
<span class="variable" data-binding-hash="8496027264380925433" style="color: hsl(18,48%,55%);">vec</span>.<span class="text">push</span>(<span class="type">Foo</span> { <span class="field" data-binding-hash="17368948500121423555" style="color: hsl(49,97%,70%);">x</span>: <span class="literal">0</span>, <span class="field" data-binding-hash="13663097548341495469" style="color: hsl(26,51%,46%);">y</span>: <span class="literal">1</span> });
<span class="variable" data-binding-hash="8496027264380925433" style="color: hsl(18,48%,55%);">vec</span>.<span class="text">push</span>(<span class="type">Foo</span> { <span class="field">x</span>: <span class="literal">0</span>, <span class="field">y</span>: <span class="literal">1</span> });
}
<span class="keyword.unsafe">unsafe</span> { <span class="variable" data-binding-hash="8496027264380925433" style="color: hsl(18,48%,55%);">vec</span>.<span class="text">set_len</span>(<span class="literal">0</span>); }
}</code></pre>

View File

@ -68,16 +68,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
match classify_name_ref(db, &analyzer, name_ref) {
Some(Method(_)) => "function",
Some(Macro(_)) => "macro",
Some(FieldAccess(field)) => {
let (hir_file_id, src) = field.source(db);
if let hir::FieldSource::Named(name) = src {
let text = name.syntax().text().to_smol_string();
let shadow_count = 0; // potentially even from different file
binding_hash = Some(calc_binding_hash(hir_file_id.original_file(db), &text, shadow_count));
}
"field"
},
Some(FieldAccess(_)) => "field",
Some(AssocItem(ImplItem::Method(_))) => "function",
Some(AssocItem(ImplItem::Const(_))) => "constant",
Some(AssocItem(ImplItem::TypeAlias(_))) => "type",
@ -119,13 +110,6 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
calc_binding_hash(file_id, &text, *shadow_count)
});
"variable"
} else if name.syntax().ancestors().any(|x| ast::NamedFieldDef::cast(x).is_some()) {
binding_hash = Some({
let text = name.syntax().text().to_smol_string();
let shadow_count = 0;
calc_binding_hash(file_id, &text, shadow_count)
});
"variable"
} else {
"function"
}