mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 23:24:29 +00:00
Revert ide highlighting changes (addressing on another branch)
This commit is contained in:
parent
2fc92fa28c
commit
2ca52bbb32
10 changed files with 10 additions and 104 deletions
|
@ -671,10 +671,6 @@ impl Function {
|
||||||
db.function_data(self.id).params.clone()
|
db.function_data(self.id).params.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
|
|
||||||
db.function_data(self.id).is_unsafe
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
||||||
let _p = profile("Function::diagnostics");
|
let _p = profile("Function::diagnostics");
|
||||||
let infer = db.infer(self.id.into());
|
let infer = db.infer(self.id.into());
|
||||||
|
|
|
@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
.field { color: #94BFF3; }
|
.field { color: #94BFF3; }
|
||||||
.function { color: #93E0E3; }
|
.function { color: #93E0E3; }
|
||||||
.function.unsafe { color: #E28C14; }
|
.function.unsafe { color: #E28C14; }
|
||||||
.operator.unsafe { color: #BC8383; }
|
.operator.unsafe { color: #E28C14; }
|
||||||
.parameter { color: #94BFF3; }
|
.parameter { color: #94BFF3; }
|
||||||
.text { color: #DCDCCC; }
|
.text { color: #DCDCCC; }
|
||||||
.type { color: #7CB8BB; }
|
.type { color: #7CB8BB; }
|
||||||
|
|
|
@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
.field { color: #94BFF3; }
|
.field { color: #94BFF3; }
|
||||||
.function { color: #93E0E3; }
|
.function { color: #93E0E3; }
|
||||||
.function.unsafe { color: #E28C14; }
|
.function.unsafe { color: #E28C14; }
|
||||||
.operator.unsafe { color: #BC8383; }
|
.operator.unsafe { color: #E28C14; }
|
||||||
.parameter { color: #94BFF3; }
|
.parameter { color: #94BFF3; }
|
||||||
.text { color: #DCDCCC; }
|
.text { color: #DCDCCC; }
|
||||||
.type { color: #7CB8BB; }
|
.type { color: #7CB8BB; }
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
|
|
||||||
<style>
|
|
||||||
body { margin: 0; }
|
|
||||||
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
|
||||||
|
|
||||||
.lifetime { color: #DFAF8F; font-style: italic; }
|
|
||||||
.comment { color: #7F9F7F; }
|
|
||||||
.documentation { color: #629755; }
|
|
||||||
.injected { opacity: 0.65 ; }
|
|
||||||
.struct, .enum { color: #7CB8BB; }
|
|
||||||
.enum_variant { color: #BDE0F3; }
|
|
||||||
.string_literal { color: #CC9393; }
|
|
||||||
.field { color: #94BFF3; }
|
|
||||||
.function { color: #93E0E3; }
|
|
||||||
.function.unsafe { color: #E28C14; }
|
|
||||||
.operator.unsafe { color: #BC8383; }
|
|
||||||
.parameter { color: #94BFF3; }
|
|
||||||
.text { color: #DCDCCC; }
|
|
||||||
.type { color: #7CB8BB; }
|
|
||||||
.builtin_type { color: #8CD0D3; }
|
|
||||||
.type_param { color: #DFAF8F; }
|
|
||||||
.attribute { color: #94BFF3; }
|
|
||||||
.numeric_literal { color: #BFEBBF; }
|
|
||||||
.bool_literal { color: #BFE6EB; }
|
|
||||||
.macro { color: #94BFF3; }
|
|
||||||
.module { color: #AFD8AF; }
|
|
||||||
.variable { color: #DCDCCC; }
|
|
||||||
.format_specifier { color: #CC696B; }
|
|
||||||
.mutable { text-decoration: underline; }
|
|
||||||
.unresolved_reference { color: #FC5555; }
|
|
||||||
.escape_sequence { color: #94BFF3; }
|
|
||||||
|
|
||||||
.keyword { color: #F0DFAF; font-weight: bold; }
|
|
||||||
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
|
||||||
.control { font-style: italic; }
|
|
||||||
</style>
|
|
||||||
<pre><code><span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_fn</span>() {}
|
|
||||||
|
|
||||||
<span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span>;
|
|
||||||
|
|
||||||
<span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> {
|
|
||||||
<span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration unsafe">unsafe_method</span>(&<span class="self_keyword">self</span>) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
<span class="keyword">fn</span> <span class="function declaration">main</span>() {
|
|
||||||
<span class="keyword">let</span> <span class="variable declaration">x</span> = &<span class="numeric_literal">5</span> <span class="keyword">as</span> *<span class="keyword">const</span> <span class="builtin_type">usize</span>;
|
|
||||||
<span class="keyword unsafe">unsafe</span> {
|
|
||||||
<span class="function unsafe">unsafe_fn</span>();
|
|
||||||
<span class="struct">HasUnsafeFn</span>.<span class="function unsafe">unsafe_method</span>();
|
|
||||||
<span class="keyword">let</span> <span class="variable declaration">y</span> = <span class="function unsafe">*</span><span class="variable">x</span>;
|
|
||||||
<span class="keyword">let</span> <span class="variable declaration">z</span> = -<span class="variable">x</span>;
|
|
||||||
}
|
|
||||||
}</code></pre>
|
|
|
@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
.field { color: #94BFF3; }
|
.field { color: #94BFF3; }
|
||||||
.function { color: #93E0E3; }
|
.function { color: #93E0E3; }
|
||||||
.function.unsafe { color: #E28C14; }
|
.function.unsafe { color: #E28C14; }
|
||||||
.operator.unsafe { color: #BC8383; }
|
.operator.unsafe { color: #E28C14; }
|
||||||
.parameter { color: #94BFF3; }
|
.parameter { color: #94BFF3; }
|
||||||
.text { color: #DCDCCC; }
|
.text { color: #DCDCCC; }
|
||||||
.type { color: #7CB8BB; }
|
.type { color: #7CB8BB; }
|
||||||
|
|
|
@ -13,7 +13,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
.field { color: #94BFF3; }
|
.field { color: #94BFF3; }
|
||||||
.function { color: #93E0E3; }
|
.function { color: #93E0E3; }
|
||||||
.function.unsafe { color: #E28C14; }
|
.function.unsafe { color: #E28C14; }
|
||||||
.operator.unsafe { color: #BC8383; }
|
.operator.unsafe { color: #E28C14; }
|
||||||
.parameter { color: #94BFF3; }
|
.parameter { color: #94BFF3; }
|
||||||
.text { color: #DCDCCC; }
|
.text { color: #DCDCCC; }
|
||||||
.type { color: #7CB8BB; }
|
.type { color: #7CB8BB; }
|
||||||
|
|
|
@ -605,13 +605,7 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
|
||||||
Definition::Field(_) => HighlightTag::Field,
|
Definition::Field(_) => HighlightTag::Field,
|
||||||
Definition::ModuleDef(def) => match def {
|
Definition::ModuleDef(def) => match def {
|
||||||
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
||||||
hir::ModuleDef::Function(func) => {
|
hir::ModuleDef::Function(_) => HighlightTag::Function,
|
||||||
let mut h = HighlightTag::Function.into();
|
|
||||||
if func.is_unsafe(db) {
|
|
||||||
h |= HighlightModifier::Unsafe;
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
|
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
|
||||||
hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
|
hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
|
||||||
hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
|
hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
|
||||||
|
|
|
@ -72,7 +72,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
.field { color: #94BFF3; }
|
.field { color: #94BFF3; }
|
||||||
.function { color: #93E0E3; }
|
.function { color: #93E0E3; }
|
||||||
.function.unsafe { color: #E28C14; }
|
.function.unsafe { color: #E28C14; }
|
||||||
.operator.unsafe { color: #BC8383; }
|
.operator.unsafe { color: #E28C14; }
|
||||||
.parameter { color: #94BFF3; }
|
.parameter { color: #94BFF3; }
|
||||||
.text { color: #DCDCCC; }
|
.text { color: #DCDCCC; }
|
||||||
.type { color: #7CB8BB; }
|
.type { color: #7CB8BB; }
|
||||||
|
|
|
@ -25,7 +25,6 @@ pub enum HighlightTag {
|
||||||
EnumVariant,
|
EnumVariant,
|
||||||
EscapeSequence,
|
EscapeSequence,
|
||||||
Field,
|
Field,
|
||||||
FormatSpecifier,
|
|
||||||
Function,
|
Function,
|
||||||
Generic,
|
Generic,
|
||||||
Keyword,
|
Keyword,
|
||||||
|
@ -33,7 +32,6 @@ pub enum HighlightTag {
|
||||||
Macro,
|
Macro,
|
||||||
Module,
|
Module,
|
||||||
NumericLiteral,
|
NumericLiteral,
|
||||||
Operator,
|
|
||||||
SelfKeyword,
|
SelfKeyword,
|
||||||
SelfType,
|
SelfType,
|
||||||
Static,
|
Static,
|
||||||
|
@ -45,6 +43,8 @@ pub enum HighlightTag {
|
||||||
Union,
|
Union,
|
||||||
Local,
|
Local,
|
||||||
UnresolvedReference,
|
UnresolvedReference,
|
||||||
|
FormatSpecifier,
|
||||||
|
Operator,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
@ -77,7 +77,6 @@ impl HighlightTag {
|
||||||
HighlightTag::EnumVariant => "enum_variant",
|
HighlightTag::EnumVariant => "enum_variant",
|
||||||
HighlightTag::EscapeSequence => "escape_sequence",
|
HighlightTag::EscapeSequence => "escape_sequence",
|
||||||
HighlightTag::Field => "field",
|
HighlightTag::Field => "field",
|
||||||
HighlightTag::FormatSpecifier => "format_specifier",
|
|
||||||
HighlightTag::Function => "function",
|
HighlightTag::Function => "function",
|
||||||
HighlightTag::Generic => "generic",
|
HighlightTag::Generic => "generic",
|
||||||
HighlightTag::Keyword => "keyword",
|
HighlightTag::Keyword => "keyword",
|
||||||
|
@ -85,7 +84,6 @@ impl HighlightTag {
|
||||||
HighlightTag::Macro => "macro",
|
HighlightTag::Macro => "macro",
|
||||||
HighlightTag::Module => "module",
|
HighlightTag::Module => "module",
|
||||||
HighlightTag::NumericLiteral => "numeric_literal",
|
HighlightTag::NumericLiteral => "numeric_literal",
|
||||||
HighlightTag::Operator => "operator",
|
|
||||||
HighlightTag::SelfKeyword => "self_keyword",
|
HighlightTag::SelfKeyword => "self_keyword",
|
||||||
HighlightTag::SelfType => "self_type",
|
HighlightTag::SelfType => "self_type",
|
||||||
HighlightTag::Static => "static",
|
HighlightTag::Static => "static",
|
||||||
|
@ -97,6 +95,8 @@ impl HighlightTag {
|
||||||
HighlightTag::Union => "union",
|
HighlightTag::Union => "union",
|
||||||
HighlightTag::Local => "variable",
|
HighlightTag::Local => "variable",
|
||||||
HighlightTag::UnresolvedReference => "unresolved_reference",
|
HighlightTag::UnresolvedReference => "unresolved_reference",
|
||||||
|
HighlightTag::FormatSpecifier => "format_specifier",
|
||||||
|
HighlightTag::Operator => "operator",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,34 +370,3 @@ fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
|
||||||
fs::write(dst_file, &actual_html).unwrap();
|
fs::write(dst_file, &actual_html).unwrap();
|
||||||
assert_eq_text!(expected_html, actual_html);
|
assert_eq_text!(expected_html, actual_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_unsafe_highlighting() {
|
|
||||||
let (analysis, file_id) = single_file(
|
|
||||||
r#"
|
|
||||||
unsafe fn unsafe_fn() {}
|
|
||||||
|
|
||||||
struct HasUnsafeFn;
|
|
||||||
|
|
||||||
impl HasUnsafeFn {
|
|
||||||
unsafe fn unsafe_method(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = &5 as *const usize;
|
|
||||||
unsafe {
|
|
||||||
unsafe_fn();
|
|
||||||
HasUnsafeFn.unsafe_method();
|
|
||||||
let y = *x;
|
|
||||||
let z = -x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#
|
|
||||||
.trim(),
|
|
||||||
);
|
|
||||||
let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_unsafe.html");
|
|
||||||
let actual_html = &analysis.highlight_as_html(file_id, false).unwrap();
|
|
||||||
let expected_html = &read_text(&dst_file);
|
|
||||||
fs::write(dst_file, &actual_html).unwrap();
|
|
||||||
assert_eq_text!(expected_html, actual_html);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue