Repository: rust-analyzer/rust-analyzer
Pull request #1478 (2019-07-03 14:39:40)

Added resolve submodules with raw name
#1211


Patch:
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs
index ba17958eb9..06a2dbc760 100644
--- a/crates/ra_hir/src/name.rs
+++ b/crates/ra_hir/src/name.rs
@@ -98,13 +98,15 @@ pub(crate) trait AsName {
 
 impl AsName for ast::NameRef {
     fn as_name(&self) -> Name {
-        Name::new(self.text().clone())
+        let name = resolve_name(self.text());
+        Name::new(name)
     }
 }
 
 impl AsName for ast::Name {
     fn as_name(&self) -> Name {
-        Name::new(self.text().clone())
+        let name = resolve_name(self.text());
+        Name::new(name)
     }
 }
 
@@ -184,3 +186,12 @@ impl AsName for KnownName {
         Name::new(s.into())
     }
 }
+
+fn resolve_name(text: &SmolStr) -> SmolStr {
+    let raw_start = "r#";
+    if text.as_str().starts_with(raw_start) {
+        SmolStr::new(&text[raw_start.len()..])
+    } else {
+        text.clone()
+    }
+}
diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json
index b3666f30b3..6b3a12f91a 100644
--- a/editors/code/package-lock.json
+++ b/editors/code/package-lock.json
@@ -39,8 +39,7 @@
         "@types/seedrandom": {
             "version": "2.4.28",
             "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.28.tgz",
-            "integrity": "sha512-SMA+fUwULwK7sd/ZJicUztiPs8F1yCPwF3O23Z9uQ32ME5Ha0NmDK9+QTsYE4O2tHXChzXomSWWeIhCnoN1LqA==",
-            "dev": true
+            "integrity": "sha512-SMA+fUwULwK7sd/ZJicUztiPs8F1yCPwF3O23Z9uQ32ME5Ha0NmDK9+QTsYE4O2tHXChzXomSWWeIhCnoN1LqA=="
         },
         "agent-base": {
             "version": "4.2.1",
@@ -114,18 +113,6 @@
             "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
             "dev": true
         },
-        "azure-devops-node-api": {
-            "version": "7.2.0",
-            "resolved": "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-7.2.0.tgz",
-            "integrity": "sha512-pMfGJ6gAQ7LRKTHgiRF+8iaUUeGAI0c8puLaqHLc7B8AR7W6GJLozK9RFeUHFjEGybC9/EB3r67WPd7e46zQ8w==",
-            "dev": true,
-            "requires": {
-                "os": "0.1.1",
-                "tunnel": "0.0.4",
-                "typed-rest-client": "1.2.0",
-                "underscore": "1.8.3"
-            }
-        },
         "balanced-match": {
             "version": "1.0.0",
             "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -302,12 +289,6 @@
             "integrity": "sha1-OjYof1A05pnnV3kBBSwubJQlFjE=",
             "dev": true
         },
-        "didyoumean": {
-            "version": "1.2.1",
-            "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.1.tgz",
-            "integrity": "sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=",
-            "dev": true
-        },
         "diff": {
             "version": "3.5.0",
             "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
@@ -824,12 +805,6 @@
                 "wrappy": "1"
             }
         },
-        "os": {
-            "version": "0.1.1",
-            "resolved": "https://registry.npmjs.org/os/-/os-0.1.1.tgz",
-            "integrity": "sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M=",
-            "dev": true
-        },
         "os-homedir": {
             "version": "1.0.2",
             "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
@@ -912,6 +887,12 @@
             "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
             "dev": true
         },
+        "q": {
+            "version": "1.5.1",
+            "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
+            "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
+            "dev": true
+        },
         "qs": {
             "version": "6.5.2",
             "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
@@ -934,9 +915,9 @@
             }
         },
         "readable-stream": {
-            "version": "3.4.0",
-            "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
-            "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
+            "version": "3.3.0",
+            "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.3.0.tgz",
+            "integrity": "sha512-EsI+s3k3XsW+fU8fQACLN59ky34AZ14LoeVZpYwmZvldCFo0r0gnelwF2TcMjLor/BTL5aDJVBMkss0dthToPw==",
             "dev": true,
             "requires": {
                 "inherits": "^2.0.3",
@@ -1196,13 +1177,21 @@
             "dev": true
         },
         "typed-rest-client": {
-            "version": "1.2.0",
-            "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.2.0.tgz",
-            "integrity": "sha512-FrUshzZ1yxH8YwGR29PWWnfksLEILbWJydU7zfIRkyH7kAEzB62uMAl2WY6EyolWpLpVHeJGgQm45/MaruaHpw==",
+            "version": "0.9.0",
+            "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-0.9.0.tgz",
+            "integrity": "sha1-92jMDcP06VDwbgSCXDaz54NKofI=",
             "dev": true,
             "requires": {
                 "tunnel": "0.0.4",
                 "underscore": "1.8.3"
+            },
+            "dependencies": {
+                "underscore": {
+                    "version": "1.8.3",
+                    "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
+                    "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=",
+                    "dev": true
+                }
             }
         },
         "typescript": {
@@ -1218,9 +1207,9 @@
             "dev": true
         },
         "underscore": {
-            "version": "1.8.3",
-            "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
-            "integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=",
+            "version": "1.9.1",
+            "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz",
+            "integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==",
             "dev": true
         },
         "uri-js": {
@@ -1272,17 +1261,15 @@
             }
         },
         "vsce": {
-            "version": "1.64.0",
-            "resolved": "https://registry.npmjs.org/vsce/-/vsce-1.64.0.tgz",
-            "integrity": "sha512-t3R7QTe2nAXQZs2kD+nA8GjdlX8pAQlnzxaNTG2976i5cyQ8r+ZsMNa/f9PDt7bhjcQM+u/fL+LkNuw+hwoy2A==",
+            "version": "1.59.0",
+            "resolved": "https://registry.npmjs.org/vsce/-/vsce-1.59.0.tgz",
+            "integrity": "sha512-tkB97885k5ce25Brbe9AZTCAXAkBh7oa5EOzY0BCJQ51W/mfRaQuCluCd9gZpWdgiU4AbPvwxtoVKKsenlSt8w==",
             "dev": true,
             "requires": {
-                "azure-devops-node-api": "^7.2.0",
                 "chalk": "^2.4.2",
                 "cheerio": "^1.0.0-rc.1",
                 "commander": "^2.8.1",
                 "denodeify": "^1.2.1",
-                "didyoumean": "^1.2.1",
                 "glob": "^7.0.6",
                 "lodash": "^4.17.10",
                 "markdown-it": "^8.3.1",
@@ -1293,8 +1280,8 @@
                 "read": "^1.0.7",
                 "semver": "^5.1.0",
                 "tmp": "0.0.29",
-                "typed-rest-client": "1.2.0",
                 "url-join": "^1.1.0",
+                "vso-node-api": "6.1.2-preview",
                 "yauzl": "^2.3.1",
                 "yazl": "^2.2.2"
             }
@@ -1352,6 +1339,18 @@
                 "https-proxy-agent": "^2.2.1"
             }
         },
+        "vso-node-api": {
+            "version": "6.1.2-preview",
+            "resolved": "https://registry.npmjs.org/vso-node-api/-/vso-node-api-6.1.2-preview.tgz",
+            "integrity": "sha1-qrNUbfJFHs2JTgcbuZtd8Zxfp48=",
+            "dev": true,
+            "requires": {
+                "q": "^1.0.1",
+                "tunnel": "0.0.4",
+                "typed-rest-client": "^0.9.0",
+                "underscore": "^1.8.3"
+            }
+        },
         "wrappy": {
             "version": "1.0.2",
             "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
diff --git a/editors/code/package.json b/editors/code/package.json
index 052f0b3b3c..52972031d1 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -44,7 +44,7 @@
         "tslint": "^5.16.0",
         "tslint-config-prettier": "^1.18.0",
         "typescript": "^3.4.4",
-        "vsce": "^1.64.0",
+        "vsce": "^1.59.0",
         "vscode": "^1.1.33"
     },
     "activationEvents": [


Test patch:
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index adac814d91..07b533e290 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -338,6 +338,32 @@ fn module_resolution_works_for_non_standard_filenames() {
     "###);
 }
 
+#[test]
+fn module_resolution_works_for_raw_modules() {
+    let map = def_map_with_crate_graph(
+        "
+        //- /library.rs
+        mod r#async;
+        use self::r#async::Bar;
+
+        //- /async.rs
+        pub struct Bar;
+        ",
+        crate_graph! {
+            "library": ("/library.rs", []),
+        },
+    );
+
+    assert_snapshot_matches!(map, @r###"
+        ⋮crate
+        ⋮Bar: t v
+        ⋮async: t
+        ⋮
+        ⋮crate::async
+        ⋮Bar: t v
+    "###);
+}
+
 #[test]
 fn name_res_works_for_broken_modules() {
     covers!(name_res_works_for_broken_modules);