From f78de3bb95acb996102a74b5b12d33054ba6d4c4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 18 Apr 2020 19:26:35 +0800 Subject: Ignore proc-macro in completion --- crates/ra_ide/src/completion/presentation.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 55f75b15a..2189cef65 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -156,6 +156,12 @@ impl Completions { name: Option, macro_: hir::MacroDef, ) { + // FIXME: Currently proc-macro do not have ast-node, + // such that it does not have source + if macro_.is_proc_macro() { + return; + } + let name = match name { Some(it) => it, None => return, -- cgit v1.2.3 From ca61356b01c8f0919443b3ccd5e543e06694466a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Apr 2020 20:59:22 +0200 Subject: Add semantic tag for unresolved references This is a quick way to implement unresolved reference diagnostics. For example, adding to VS Code config "editor.tokenColorCustomizationsExperimental": { "unresolvedReference": "#FF0000" }, will highlight all unresolved refs in red. --- crates/ra_ide/src/snapshots/highlighting.html | 6 ++--- .../ra_ide/src/snapshots/rainbow_highlighting.html | 6 ++--- crates/ra_ide/src/syntax_highlighting.rs | 29 +++++++++++----------- crates/ra_ide/src/syntax_highlighting/tags.rs | 2 ++ 4 files changed, 23 insertions(+), 20 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index 214dcbb62..ccb1fc751 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -50,12 +50,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd fn main() { println!("Hello, {}!", 92); - let mut vec = Vec::new(); + let mut vec = Vec::new(); if true { let x = 92; - vec.push(Foo { x, y: 1 }); + vec.push(Foo { x, y: 1 }); } - unsafe { vec.set_len(0); } + unsafe { vec.set_len(0); } let mut x = 42; let y = &mut x; diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index dddbfc0dd..3df82c45f 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -28,11 +28,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
fn main() {
     let hello = "hello";
-    let x = hello.to_string();
-    let y = hello.to_string();
+    let x = hello.to_string();
+    let y = hello.to_string();
 
     let x = "other color please!";
-    let y = x.to_string();
+    let y = x.to_string();
 }
 
 fn bar() {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 7b15b82bd..93d502875 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -239,20 +239,21 @@ fn highlight_element(
         NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None,
         NAME_REF => {
             let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
-            let name_kind = classify_name_ref(sema, &name_ref)?;
-
-            match name_kind {
-                NameRefClass::Definition(def) => {
-                    if let Definition::Local(local) = &def {
-                        if let Some(name) = local.name(db) {
-                            let shadow_count =
-                                bindings_shadow_count.entry(name.clone()).or_default();
-                            binding_hash = Some(calc_binding_hash(&name, *shadow_count))
-                        }
-                    };
-                    highlight_name(db, def)
-                }
-                NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
+            match classify_name_ref(sema, &name_ref) {
+                Some(name_kind) => match name_kind {
+                    NameRefClass::Definition(def) => {
+                        if let Definition::Local(local) = &def {
+                            if let Some(name) = local.name(db) {
+                                let shadow_count =
+                                    bindings_shadow_count.entry(name.clone()).or_default();
+                                binding_hash = Some(calc_binding_hash(&name, *shadow_count))
+                            }
+                        };
+                        highlight_name(db, def)
+                    }
+                    NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
+                },
+                None => HighlightTag::UnresolvedReference.into(),
             }
         }
 
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index e8b138e1a..f2c421654 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -38,6 +38,7 @@ pub enum HighlightTag {
     TypeParam,
     Union,
     Local,
+    UnresolvedReference,
 }
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -79,6 +80,7 @@ impl HighlightTag {
             HighlightTag::TypeParam => "type_param",
             HighlightTag::Union => "union",
             HighlightTag::Local => "variable",
+            HighlightTag::UnresolvedReference => "unresolved_reference",
         }
     }
 }
-- 
cgit v1.2.3


From fa2ea8f494d8434da705dc0e0f047f3bd7503af9 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov 
Date: Sat, 18 Apr 2020 22:05:06 +0200
Subject: Fix goto definition for record patterns

---
 crates/ra_ide/src/goto_definition.rs | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 8aed94d16..9998ca5a3 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -62,10 +62,9 @@ pub(crate) enum ReferenceResult {
 
 impl ReferenceResult {
     fn to_vec(self) -> Vec {
-        use self::ReferenceResult::*;
         match self {
-            Exact(target) => vec![target],
-            Approximate(vec) => vec,
+            ReferenceResult::Exact(target) => vec![target],
+            ReferenceResult::Approximate(vec) => vec,
         }
     }
 }
@@ -74,8 +73,6 @@ pub(crate) fn reference_definition(
     sema: &Semantics,
     name_ref: &ast::NameRef,
 ) -> ReferenceResult {
-    use self::ReferenceResult::*;
-
     let name_kind = classify_name_ref(sema, name_ref);
     if let Some(def) = name_kind {
         let def = def.definition();
@@ -91,7 +88,7 @@ pub(crate) fn reference_definition(
         .into_iter()
         .map(|s| s.to_nav(sema.db))
         .collect();
-    Approximate(navs)
+    ReferenceResult::Approximate(navs)
 }
 
 #[cfg(test)]
@@ -398,6 +395,25 @@ mod tests {
         );
     }
 
+    #[test]
+    fn goto_def_for_record_pat_fields() {
+        covers!(ra_ide_db::goto_def_for_record_field_pats);
+        check_goto(
+            r"
+            //- /lib.rs
+            struct Foo {
+                spam: u32,
+            }
+
+            fn bar(foo: Foo) -> Foo {
+                let Foo { spam<|>: _, } = foo
+            }
+            ",
+            "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)",
+            "spam: u32|spam",
+        );
+    }
+
     #[test]
     fn goto_def_for_record_fields_macros() {
         check_goto(
-- 
cgit v1.2.3


From d7f3d858add197f91969c69b1d4a14dbcb801f03 Mon Sep 17 00:00:00 2001
From: Jeremy Kolb 
Date: Sun, 19 Apr 2020 15:15:49 -0400
Subject: Some clippy fixes

---
 crates/ra_ide/src/extend_selection.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index f5a063351..753d2ef6a 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -96,7 +96,7 @@ fn try_extend_selection(
         return Some(node.text_range());
     }
 
-    let node = shallowest_node(&node.into());
+    let node = shallowest_node(&node);
 
     if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
         if let Some(range) = extend_list_item(&node) {
-- 
cgit v1.2.3