mirror of
https://github.com/oxalica/nil.git
synced 2024-11-23 03:57:06 +03:00
Fix Attr highlighting
This commit is contained in:
parent
e04b1b968d
commit
bb186c9d14
@ -1,7 +1,7 @@
|
||||
//! This is actually so-called "semantic highlighting".
|
||||
//! Ref: <https://github.com/rust-lang/rust-analyzer/blob/a670ff888437f4b6a3d24cc2996e9f969a87cbae/crates/ide/src/syntax_highlighting/tags.rs>
|
||||
use crate::builtin::BUILTINS;
|
||||
use crate::def::{AstPtr, NameKind, ResolveResult};
|
||||
use crate::def::{AstPtr, Expr, NameKind, ResolveResult};
|
||||
use crate::{BuiltinKind, DefDatabase, FileId};
|
||||
use rowan::{NodeOrToken, TextRange, WalkEvent};
|
||||
use syntax::{SyntaxKind, SyntaxToken, T};
|
||||
@ -18,6 +18,7 @@ pub enum HlTag {
|
||||
NameRef(NameKind),
|
||||
UnresolvedRef,
|
||||
|
||||
AttrField,
|
||||
Builtin(BuiltinKind),
|
||||
Comment,
|
||||
FloatLiteral,
|
||||
@ -118,8 +119,19 @@ pub(crate) fn highlight(
|
||||
}
|
||||
}
|
||||
Some(node) if node.kind() == SyntaxKind::NAME => {
|
||||
let name = source_map.node_name(AstPtr::new(&node))?;
|
||||
HlTag::NameDef(module[name].kind)
|
||||
let ptr = AstPtr::new(&node);
|
||||
match source_map.node_name(ptr.clone()) {
|
||||
Some(name) => HlTag::NameDef(module[name].kind),
|
||||
None => {
|
||||
match source_map.node_expr(ptr) {
|
||||
// `Attr`s are converted into string literals.
|
||||
Some(expr) if matches!(&module[expr], Expr::Literal(_)) => {
|
||||
HlTag::AttrField
|
||||
}
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
@ -245,4 +257,10 @@ mod tests {
|
||||
|
||||
check("$0not_found", expect!["UnresolvedRef"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attr() {
|
||||
check("{}.$0a", expect!["AttrField"]);
|
||||
check("{} ? $0a", expect!["AttrField"]);
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ pub(crate) fn to_semantic_type_and_modifiers(tag: HlTag) -> (TokenTypeIdx, Token
|
||||
mods.insert(TokenModIdx::Unresolved);
|
||||
TokenTypeIdx::Variable
|
||||
}
|
||||
HlTag::AttrField => TokenTypeIdx::Property,
|
||||
HlTag::Builtin(kind) => {
|
||||
mods.insert(TokenModIdx::DefaultLibrary);
|
||||
match kind {
|
||||
|
Loading…
Reference in New Issue
Block a user