about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-db
diff options
context:
space:
mode:
authorLaurențiu Nicola <lnicola@dend.ro>2022-10-18 09:12:49 +0300
committerLaurențiu Nicola <lnicola@dend.ro>2022-10-18 09:12:49 +0300
commitcb8fdff56da1b72ab942e41dc213059d83b58456 (patch)
tree621be08fef2c975ed0909cb980651134117b2359 /src/tools/rust-analyzer/crates/ide-db
parent98a5ac269cffada469753ad2416717e251863f9a (diff)
parent0531aab522f25d6aae30b2cc23a09f4b9257eedc (diff)
downloadrust-cb8fdff56da1b72ab942e41dc213059d83b58456.tar.gz
rust-cb8fdff56da1b72ab942e41dc213059d83b58456.zip
:arrow_up: rust-analyzer
Diffstat (limited to 'src/tools/rust-analyzer/crates/ide-db')
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs6
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs9
3 files changed, 12 insertions, 7 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
index 30272bc16f6..cf0bcd5c96b 100644
--- a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
@@ -15,9 +15,9 @@ tracing = "0.1.35"
 rayon = "1.5.3"
 fst = { version = "0.4.7", default-features = false }
 rustc-hash = "1.1.0"
-once_cell = "1.12.0"
+once_cell = "1.15.0"
 either = "1.7.0"
-itertools = "0.10.3"
+itertools = "0.10.5"
 arrayvec = "0.7.2"
 indexmap = "1.9.1"
 memchr = "2.5.0"
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
index f48a5700866..2d6927cee99 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
@@ -1,7 +1,8 @@
 //! Tools to work with format string literals for the `format_args!` family of macros.
+use crate::syntax_helpers::node_ext::macro_call_for_string_token;
 use syntax::{
     ast::{self, IsString},
-    AstNode, AstToken, TextRange, TextSize,
+    TextRange, TextSize,
 };
 
 pub fn is_format_string(string: &ast::String) -> bool {
@@ -14,8 +15,7 @@ pub fn is_format_string(string: &ast::String) -> bool {
     // This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
     // strings. It still fails for `concat!("{", "}")`, but that is rare.
     (|| {
-        let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
-        let name = macro_call.path()?.segment()?.name_ref()?;
+        let name = macro_call_for_string_token(string)?.path()?.segment()?.name_ref()?;
 
         if !matches!(
             name.text().as_str(),
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
index b890e2b58df..39710b8f13e 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
@@ -2,8 +2,8 @@
 use itertools::Itertools;
 use parser::T;
 use syntax::{
-    ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind},
-    AstNode, Preorder, RustLanguage, WalkEvent,
+    ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
+    AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
 };
 
 pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
@@ -457,3 +457,8 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Pat
         .collect();
     Some(paths)
 }
+
+pub fn macro_call_for_string_token(string: &ast::String) -> Option<MacroCall> {
+    let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
+    Some(macro_call)
+}