Syntactic highlighting of NAME_REF for injections

This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage.
It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references.
It also adds a color to unresolved references in HTML encoding.
This commit is contained in:
Leander Tentrup 2020-06-14 14:43:43 +02:00
parent f4f51171ca
commit c4b3db0c2f
12 changed files with 102 additions and 16 deletions

View file

@ -287,7 +287,13 @@ fn main() {
fn test_highlight_doctest() {
check_highlighting(
r#"
struct Foo {
bar: bool,
}
impl Foo {
pub const bar: bool = true;
/// Constructs a new `Foo`.
///
/// # Examples
@ -297,7 +303,7 @@ impl Foo {
/// let mut foo: Foo = Foo::new();
/// ```
pub const fn new() -> Foo {
Foo { }
Foo { bar: true }
}
/// `bar` method on `Foo`.
@ -305,11 +311,15 @@ impl Foo {
/// # Examples
///
/// ```
/// use x::y;
///
/// let foo = Foo::new();
///
/// // calls bar on foo
/// assert!(foo.bar());
///
/// let bar = foo.bar || Foo::bar;
///
/// /* multi-line
/// comment */
///
@ -330,7 +340,7 @@ impl Foo {
.trim(),
"crates/ra_ide/src/snapshots/highlight_doctest.html",
false,
)
);
}
/// Highlights the code given by the `ra_fixture` argument, renders the