diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2021-11-25 16:34:32 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2021-11-25 16:34:40 +0100 |
| commit | 4bf75c5d6e3311c9e09e02556a5080ac4e4a6b61 (patch) | |
| tree | 33fec6e6f4a584353d367b0383e9cedc30a38944 | |
| parent | 4ca6233bd2723c33152dcabd32f184d769d8339c (diff) | |
| download | rust-4bf75c5d6e3311c9e09e02556a5080ac4e4a6b61.tar.gz rust-4bf75c5d6e3311c9e09e02556a5080ac4e4a6b61.zip | |
fix: Prioritize tuple fields in highlight_related
| -rw-r--r-- | crates/ide/src/highlight_related.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 357b0d2455c..aac23be777f 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -10,7 +10,7 @@ use rustc_hash::FxHashSet; use syntax::{ ast::{self, HasLoopBody}, match_ast, AstNode, - SyntaxKind::IDENT, + SyntaxKind::{IDENT, INT_NUMBER}, SyntaxNode, SyntaxToken, TextRange, T, }; @@ -54,10 +54,9 @@ pub(crate) fn highlight_related( T![?] => 4, // prefer `?` when the cursor is sandwiched like in `await$0?` T![->] => 3, kind if kind.is_keyword() => 2, - IDENT => 1, + IDENT | INT_NUMBER => 1, _ => 0, })?; - match token.kind() { T![?] if config.exit_points && token.parent().and_then(ast::TryExpr::cast).is_some() => { highlight_exit_points(sema, token) @@ -347,6 +346,22 @@ mod tests { } #[test] + fn test_hl_tuple_fields() { + check( + r#" +struct Tuple(u32, u32); + +fn foo(t: Tuple) { + t.0$0; + // ^ read + t.0; + // ^ read +} +"#, + ); + } + + #[test] fn test_hl_module() { check( r#" |
