aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock142
-rw-r--r--crates/assists/src/utils/insert_use.rs166
-rw-r--r--crates/hir_ty/Cargo.toml6
-rw-r--r--crates/ide/src/hover.rs27
-rw-r--r--crates/ide_db/Cargo.toml2
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/syntax/Cargo.toml2
-rw-r--r--crates/syntax/src/ast/node_ext.rs14
-rw-r--r--crates/test_utils/src/lib.rs6
9 files changed, 275 insertions, 92 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 769120fc2..efabcf2c5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -42,9 +42,9 @@ version = "0.0.0"
42 42
43[[package]] 43[[package]]
44name = "arrayvec" 44name = "arrayvec"
45version = "0.5.1" 45version = "0.5.2"
46source = "registry+https://github.com/rust-lang/crates.io-index" 46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" 47checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
48 48
49[[package]] 49[[package]]
50name = "assists" 50name = "assists"
@@ -132,7 +132,7 @@ version = "0.12.0"
132source = "registry+https://github.com/rust-lang/crates.io-index" 132source = "registry+https://github.com/rust-lang/crates.io-index"
133checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345" 133checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345"
134dependencies = [ 134dependencies = [
135 "semver", 135 "semver 0.11.0",
136 "serde", 136 "serde",
137 "serde_json", 137 "serde_json",
138] 138]
@@ -168,9 +168,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
168 168
169[[package]] 169[[package]]
170name = "chalk-derive" 170name = "chalk-derive"
171version = "0.33.0" 171version = "0.34.0"
172source = "registry+https://github.com/rust-lang/crates.io-index" 172source = "registry+https://github.com/rust-lang/crates.io-index"
173checksum = "569014cab9084a6b826fe2507cc6d08f7897ba144fb1bc74e71b593dc8a0b952" 173checksum = "0e9f986750ecb4df889d0a95d4586bd921889497b33908cc75bb80eadb4c600a"
174dependencies = [ 174dependencies = [
175 "proc-macro2", 175 "proc-macro2",
176 "quote", 176 "quote",
@@ -180,9 +180,9 @@ dependencies = [
180 180
181[[package]] 181[[package]]
182name = "chalk-ir" 182name = "chalk-ir"
183version = "0.33.0" 183version = "0.34.0"
184source = "registry+https://github.com/rust-lang/crates.io-index" 184source = "registry+https://github.com/rust-lang/crates.io-index"
185checksum = "8d9eab2a6590b696419f89c9ca3616fe8e8266ef676e6a6da8818c94963c9541" 185checksum = "5c352c4649f1408bb3de5d86a248fda78d3d9cd1cbbd9502e7eca1be1e7ac368"
186dependencies = [ 186dependencies = [
187 "chalk-derive", 187 "chalk-derive",
188 "lazy_static", 188 "lazy_static",
@@ -190,9 +190,9 @@ dependencies = [
190 190
191[[package]] 191[[package]]
192name = "chalk-recursive" 192name = "chalk-recursive"
193version = "0.33.0" 193version = "0.34.0"
194source = "registry+https://github.com/rust-lang/crates.io-index" 194source = "registry+https://github.com/rust-lang/crates.io-index"
195checksum = "4a4671bcc70aa2d7e12ff4fe03f91d0c3c9ce387de915915e57fdf0c91dc5abd" 195checksum = "7294bb2ac5446fcb83ec9524b9113f59a8913f174a9c1dea6db60532f17a1579"
196dependencies = [ 196dependencies = [
197 "chalk-derive", 197 "chalk-derive",
198 "chalk-ir", 198 "chalk-ir",
@@ -203,9 +203,9 @@ dependencies = [
203 203
204[[package]] 204[[package]]
205name = "chalk-solve" 205name = "chalk-solve"
206version = "0.33.0" 206version = "0.34.0"
207source = "registry+https://github.com/rust-lang/crates.io-index" 207source = "registry+https://github.com/rust-lang/crates.io-index"
208checksum = "45f75cc603f2fd302576c8b2976437f334e159e26d0afbb108a565b96c52184e" 208checksum = "ffbca06963ed6f3d22faed840847a685f02feefa3825c0b94f9b791d03a0ac6f"
209dependencies = [ 209dependencies = [
210 "chalk-derive", 210 "chalk-derive",
211 "chalk-ir", 211 "chalk-ir",
@@ -275,11 +275,11 @@ checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2"
275 275
276[[package]] 276[[package]]
277name = "crc32fast" 277name = "crc32fast"
278version = "1.2.0" 278version = "1.2.1"
279source = "registry+https://github.com/rust-lang/crates.io-index" 279source = "registry+https://github.com/rust-lang/crates.io-index"
280checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" 280checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
281dependencies = [ 281dependencies = [
282 "cfg-if 0.1.10", 282 "cfg-if 1.0.0",
283] 283]
284 284
285[[package]] 285[[package]]
@@ -304,26 +304,25 @@ dependencies = [
304 304
305[[package]] 305[[package]]
306name = "crossbeam-deque" 306name = "crossbeam-deque"
307version = "0.7.3" 307version = "0.8.0"
308source = "registry+https://github.com/rust-lang/crates.io-index" 308source = "registry+https://github.com/rust-lang/crates.io-index"
309checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" 309checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
310dependencies = [ 310dependencies = [
311 "cfg-if 1.0.0",
311 "crossbeam-epoch", 312 "crossbeam-epoch",
312 "crossbeam-utils 0.7.2", 313 "crossbeam-utils 0.8.0",
313 "maybe-uninit",
314] 314]
315 315
316[[package]] 316[[package]]
317name = "crossbeam-epoch" 317name = "crossbeam-epoch"
318version = "0.8.2" 318version = "0.9.0"
319source = "registry+https://github.com/rust-lang/crates.io-index" 319source = "registry+https://github.com/rust-lang/crates.io-index"
320checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" 320checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f"
321dependencies = [ 321dependencies = [
322 "autocfg", 322 "cfg-if 1.0.0",
323 "cfg-if 0.1.10", 323 "const_fn",
324 "crossbeam-utils 0.7.2", 324 "crossbeam-utils 0.8.0",
325 "lazy_static", 325 "lazy_static",
326 "maybe-uninit",
327 "memoffset", 326 "memoffset",
328 "scopeguard", 327 "scopeguard",
329] 328]
@@ -481,6 +480,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
481checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 480checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
482 481
483[[package]] 482[[package]]
483name = "generator"
484version = "0.6.23"
485source = "registry+https://github.com/rust-lang/crates.io-index"
486checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc"
487dependencies = [
488 "cc",
489 "libc",
490 "log",
491 "rustc_version",
492 "winapi 0.3.9",
493]
494
495[[package]]
484name = "gimli" 496name = "gimli"
485version = "0.22.0" 497version = "0.22.0"
486source = "registry+https://github.com/rust-lang/crates.io-index" 498source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -778,11 +790,11 @@ checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
778 790
779[[package]] 791[[package]]
780name = "libloading" 792name = "libloading"
781version = "0.6.4" 793version = "0.6.5"
782source = "registry+https://github.com/rust-lang/crates.io-index" 794source = "registry+https://github.com/rust-lang/crates.io-index"
783checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" 795checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0"
784dependencies = [ 796dependencies = [
785 "cfg-if 0.1.10", 797 "cfg-if 1.0.0",
786 "winapi 0.3.9", 798 "winapi 0.3.9",
787] 799]
788 800
@@ -814,6 +826,19 @@ dependencies = [
814] 826]
815 827
816[[package]] 828[[package]]
829name = "loom"
830version = "0.3.6"
831source = "registry+https://github.com/rust-lang/crates.io-index"
832checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed"
833dependencies = [
834 "cfg-if 0.1.10",
835 "generator",
836 "scoped-tls",
837 "serde",
838 "serde_json",
839]
840
841[[package]]
817name = "lsp-server" 842name = "lsp-server"
818version = "0.4.1" 843version = "0.4.1"
819source = "registry+https://github.com/rust-lang/crates.io-index" 844source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1242,9 +1267,9 @@ dependencies = [
1242 1267
1243[[package]] 1268[[package]]
1244name = "rayon" 1269name = "rayon"
1245version = "1.4.1" 1270version = "1.5.0"
1246source = "registry+https://github.com/rust-lang/crates.io-index" 1271source = "registry+https://github.com/rust-lang/crates.io-index"
1247checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" 1272checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
1248dependencies = [ 1273dependencies = [
1249 "autocfg", 1274 "autocfg",
1250 "crossbeam-deque", 1275 "crossbeam-deque",
@@ -1254,13 +1279,13 @@ dependencies = [
1254 1279
1255[[package]] 1280[[package]]
1256name = "rayon-core" 1281name = "rayon-core"
1257version = "1.8.1" 1282version = "1.9.0"
1258source = "registry+https://github.com/rust-lang/crates.io-index" 1283source = "registry+https://github.com/rust-lang/crates.io-index"
1259checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" 1284checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
1260dependencies = [ 1285dependencies = [
1261 "crossbeam-channel 0.4.4", 1286 "crossbeam-channel 0.5.0",
1262 "crossbeam-deque", 1287 "crossbeam-deque",
1263 "crossbeam-utils 0.7.2", 1288 "crossbeam-utils 0.8.0",
1264 "lazy_static", 1289 "lazy_static",
1265 "num_cpus", 1290 "num_cpus",
1266] 1291]
@@ -1355,18 +1380,18 @@ dependencies = [
1355 1380
1356[[package]] 1381[[package]]
1357name = "rustc-ap-rustc_lexer" 1382name = "rustc-ap-rustc_lexer"
1358version = "683.0.0" 1383version = "685.0.0"
1359source = "registry+https://github.com/rust-lang/crates.io-index" 1384source = "registry+https://github.com/rust-lang/crates.io-index"
1360checksum = "c0c9a47e24d4b7d74ec583d8813803b36985ee082fe7debe55f257df92d5fe50" 1385checksum = "4d6465438127d20bf9d0f5148f806c029934a74c9bce1103a42d47e81d3fe89a"
1361dependencies = [ 1386dependencies = [
1362 "unicode-xid", 1387 "unicode-xid",
1363] 1388]
1364 1389
1365[[package]] 1390[[package]]
1366name = "rustc-demangle" 1391name = "rustc-demangle"
1367version = "0.1.17" 1392version = "0.1.18"
1368source = "registry+https://github.com/rust-lang/crates.io-index" 1393source = "registry+https://github.com/rust-lang/crates.io-index"
1369checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" 1394checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
1370 1395
1371[[package]] 1396[[package]]
1372name = "rustc-hash" 1397name = "rustc-hash"
@@ -1375,6 +1400,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1375checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 1400checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
1376 1401
1377[[package]] 1402[[package]]
1403name = "rustc_version"
1404version = "0.2.3"
1405source = "registry+https://github.com/rust-lang/crates.io-index"
1406checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
1407dependencies = [
1408 "semver 0.9.0",
1409]
1410
1411[[package]]
1378name = "ryu" 1412name = "ryu"
1379version = "1.0.5" 1413version = "1.0.5"
1380source = "registry+https://github.com/rust-lang/crates.io-index" 1414source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1441,9 +1475,9 @@ dependencies = [
1441 1475
1442[[package]] 1476[[package]]
1443name = "scroll_derive" 1477name = "scroll_derive"
1444version = "0.10.3" 1478version = "0.10.4"
1445source = "registry+https://github.com/rust-lang/crates.io-index" 1479source = "registry+https://github.com/rust-lang/crates.io-index"
1446checksum = "6dfde5d1531034db129e95c76ac857e2baecea3443579d493d02224950b0fb6d" 1480checksum = "b12bd20b94c7cdfda8c7ba9b92ad0d9a56e3fa018c25fca83b51aa664c9b4c0d"
1447dependencies = [ 1481dependencies = [
1448 "proc-macro2", 1482 "proc-macro2",
1449 "quote", 1483 "quote",
@@ -1452,16 +1486,31 @@ dependencies = [
1452 1486
1453[[package]] 1487[[package]]
1454name = "semver" 1488name = "semver"
1489version = "0.9.0"
1490source = "registry+https://github.com/rust-lang/crates.io-index"
1491checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
1492dependencies = [
1493 "semver-parser 0.7.0",
1494]
1495
1496[[package]]
1497name = "semver"
1455version = "0.11.0" 1498version = "0.11.0"
1456source = "registry+https://github.com/rust-lang/crates.io-index" 1499source = "registry+https://github.com/rust-lang/crates.io-index"
1457checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" 1500checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
1458dependencies = [ 1501dependencies = [
1459 "semver-parser", 1502 "semver-parser 0.10.1",
1460 "serde", 1503 "serde",
1461] 1504]
1462 1505
1463[[package]] 1506[[package]]
1464name = "semver-parser" 1507name = "semver-parser"
1508version = "0.7.0"
1509source = "registry+https://github.com/rust-lang/crates.io-index"
1510checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
1511
1512[[package]]
1513name = "semver-parser"
1465version = "0.10.1" 1514version = "0.10.1"
1466source = "registry+https://github.com/rust-lang/crates.io-index" 1515source = "registry+https://github.com/rust-lang/crates.io-index"
1467checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" 1516checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
@@ -1513,11 +1562,12 @@ dependencies = [
1513 1562
1514[[package]] 1563[[package]]
1515name = "sharded-slab" 1564name = "sharded-slab"
1516version = "0.0.9" 1565version = "0.1.0"
1517source = "registry+https://github.com/rust-lang/crates.io-index" 1566source = "registry+https://github.com/rust-lang/crates.io-index"
1518checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" 1567checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127"
1519dependencies = [ 1568dependencies = [
1520 "lazy_static", 1569 "lazy_static",
1570 "loom",
1521] 1571]
1522 1572
1523[[package]] 1573[[package]]
@@ -1561,9 +1611,9 @@ version = "0.0.0"
1561 1611
1562[[package]] 1612[[package]]
1563name = "syn" 1613name = "syn"
1564version = "1.0.45" 1614version = "1.0.46"
1565source = "registry+https://github.com/rust-lang/crates.io-index" 1615source = "registry+https://github.com/rust-lang/crates.io-index"
1566checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556" 1616checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942"
1567dependencies = [ 1617dependencies = [
1568 "proc-macro2", 1618 "proc-macro2",
1569 "quote", 1619 "quote",
@@ -1740,9 +1790,9 @@ dependencies = [
1740 1790
1741[[package]] 1791[[package]]
1742name = "tracing-subscriber" 1792name = "tracing-subscriber"
1743version = "0.2.13" 1793version = "0.2.14"
1744source = "registry+https://github.com/rust-lang/crates.io-index" 1794source = "registry+https://github.com/rust-lang/crates.io-index"
1745checksum = "4ef0a5e15477aa303afbfac3a44cba9b6430fdaad52423b1e6c0dbbe28c3eedd" 1795checksum = "2810660b9d5b18895d140caba6401765749a6a162e5d0736cfc44ea50db9d79d"
1746dependencies = [ 1796dependencies = [
1747 "ansi_term", 1797 "ansi_term",
1748 "chrono", 1798 "chrono",
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs
index 409985b3b..033fbcedc 100644
--- a/crates/assists/src/utils/insert_use.rs
+++ b/crates/assists/src/utils/insert_use.rs
@@ -14,6 +14,7 @@ use syntax::{
14 }, 14 },
15 InsertPosition, SyntaxElement, SyntaxNode, 15 InsertPosition, SyntaxElement, SyntaxNode,
16}; 16};
17use test_utils::mark;
17 18
18#[derive(Debug)] 19#[derive(Debug)]
19pub enum ImportScope { 20pub enum ImportScope {
@@ -109,6 +110,12 @@ pub(crate) fn insert_use(
109 // so look for the place we have to insert to 110 // so look for the place we have to insert to
110 let (insert_position, add_blank) = find_insert_position(scope, path); 111 let (insert_position, add_blank) = find_insert_position(scope, path);
111 112
113 let indent = if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize {
114 Some(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into())
115 } else {
116 None
117 };
118
112 let to_insert: Vec<SyntaxElement> = { 119 let to_insert: Vec<SyntaxElement> = {
113 let mut buf = Vec::new(); 120 let mut buf = Vec::new();
114 121
@@ -120,9 +127,13 @@ pub(crate) fn insert_use(
120 _ => (), 127 _ => (),
121 } 128 }
122 129
123 if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize { 130 if add_blank.has_before() {
124 buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into()); 131 if let Some(indent) = indent.clone() {
132 mark::hit!(insert_use_indent_before);
133 buf.push(indent);
134 }
125 } 135 }
136
126 buf.push(use_item.syntax().clone().into()); 137 buf.push(use_item.syntax().clone().into());
127 138
128 match add_blank { 139 match add_blank {
@@ -133,6 +144,16 @@ pub(crate) fn insert_use(
133 _ => (), 144 _ => (),
134 } 145 }
135 146
147 // only add indentation *after* our stuff if there's another node directly after it
148 if add_blank.has_after() && matches!(insert_position, InsertPosition::Before(_)) {
149 if let Some(indent) = indent {
150 mark::hit!(insert_use_indent_after);
151 buf.push(indent);
152 }
153 } else if add_blank.has_after() && matches!(insert_position, InsertPosition::After(_)) {
154 mark::hit!(insert_use_no_indent_after);
155 }
156
136 buf 157 buf
137 }; 158 };
138 159
@@ -470,6 +491,15 @@ enum AddBlankLine {
470 AfterTwice, 491 AfterTwice,
471} 492}
472 493
494impl AddBlankLine {
495 fn has_before(&self) -> bool {
496 matches!(self, AddBlankLine::Before | AddBlankLine::BeforeTwice | AddBlankLine::Around)
497 }
498 fn has_after(&self) -> bool {
499 matches!(self, AddBlankLine::After | AddBlankLine::AfterTwice | AddBlankLine::Around)
500 }
501}
502
473fn find_insert_position( 503fn find_insert_position(
474 scope: &ImportScope, 504 scope: &ImportScope,
475 insert_path: ast::Path, 505 insert_path: ast::Path,
@@ -562,6 +592,21 @@ use std::bar::G;",
562 } 592 }
563 593
564 #[test] 594 #[test]
595 fn insert_start_indent() {
596 mark::check!(insert_use_indent_after);
597 check_none(
598 "std::bar::AA",
599 r"
600 use std::bar::B;
601 use std::bar::D;",
602 r"
603 use std::bar::AA;
604 use std::bar::B;
605 use std::bar::D;",
606 )
607 }
608
609 #[test]
565 fn insert_middle() { 610 fn insert_middle() {
566 check_none( 611 check_none(
567 "std::bar::EE", 612 "std::bar::EE",
@@ -580,6 +625,24 @@ use std::bar::G;",
580 } 625 }
581 626
582 #[test] 627 #[test]
628 fn insert_middle_indent() {
629 check_none(
630 "std::bar::EE",
631 r"
632 use std::bar::A;
633 use std::bar::D;
634 use std::bar::F;
635 use std::bar::G;",
636 r"
637 use std::bar::A;
638 use std::bar::D;
639 use std::bar::EE;
640 use std::bar::F;
641 use std::bar::G;",
642 )
643 }
644
645 #[test]
583 fn insert_end() { 646 fn insert_end() {
584 check_none( 647 check_none(
585 "std::bar::ZZ", 648 "std::bar::ZZ",
@@ -598,6 +661,25 @@ use std::bar::ZZ;",
598 } 661 }
599 662
600 #[test] 663 #[test]
664 fn insert_end_indent() {
665 mark::check!(insert_use_indent_before);
666 check_none(
667 "std::bar::ZZ",
668 r"
669 use std::bar::A;
670 use std::bar::D;
671 use std::bar::F;
672 use std::bar::G;",
673 r"
674 use std::bar::A;
675 use std::bar::D;
676 use std::bar::F;
677 use std::bar::G;
678 use std::bar::ZZ;",
679 )
680 }
681
682 #[test]
601 fn insert_middle_nested() { 683 fn insert_middle_nested() {
602 check_none( 684 check_none(
603 "std::bar::EE", 685 "std::bar::EE",
@@ -620,18 +702,18 @@ use std::bar::G;",
620 check_none( 702 check_none(
621 "foo::bar::GG", 703 "foo::bar::GG",
622 r" 704 r"
623use std::bar::A; 705 use std::bar::A;
624use std::bar::D; 706 use std::bar::D;
625 707
626use foo::bar::F; 708 use foo::bar::F;
627use foo::bar::H;", 709 use foo::bar::H;",
628 r" 710 r"
629use std::bar::A; 711 use std::bar::A;
630use std::bar::D; 712 use std::bar::D;
631 713
632use foo::bar::F; 714 use foo::bar::F;
633use foo::bar::GG; 715 use foo::bar::GG;
634use foo::bar::H;", 716 use foo::bar::H;",
635 ) 717 )
636 } 718 }
637 719
@@ -640,22 +722,22 @@ use foo::bar::H;",
640 check_none( 722 check_none(
641 "foo::bar::GG", 723 "foo::bar::GG",
642 r" 724 r"
643use foo::bar::A; 725 use foo::bar::A;
644use foo::bar::D; 726 use foo::bar::D;
645 727
646use std; 728 use std;
647 729
648use foo::bar::F; 730 use foo::bar::F;
649use foo::bar::H;", 731 use foo::bar::H;",
650 r" 732 r"
651use foo::bar::A; 733 use foo::bar::A;
652use foo::bar::D; 734 use foo::bar::D;
653use foo::bar::GG; 735 use foo::bar::GG;
654 736
655use std; 737 use std;
656 738
657use foo::bar::F; 739 use foo::bar::F;
658use foo::bar::H;", 740 use foo::bar::H;",
659 ) 741 )
660 } 742 }
661 743
@@ -664,13 +746,13 @@ use foo::bar::H;",
664 check_none( 746 check_none(
665 "std::fmt", 747 "std::fmt",
666 r" 748 r"
667use foo::bar::A; 749 use foo::bar::A;
668use foo::bar::D;", 750 use foo::bar::D;",
669 r" 751 r"
670use std::fmt; 752 use std::fmt;
671 753
672use foo::bar::A; 754 use foo::bar::A;
673use foo::bar::D;", 755 use foo::bar::D;",
674 ) 756 )
675 } 757 }
676 758
@@ -714,6 +796,20 @@ fn main() {}",
714 } 796 }
715 797
716 #[test] 798 #[test]
799 fn insert_empty_module() {
800 mark::check!(insert_use_no_indent_after);
801 check(
802 "foo::bar",
803 "mod x {}",
804 r"{
805 use foo::bar;
806}",
807 None,
808 true,
809 )
810 }
811
812 #[test]
717 fn insert_after_inner_attr() { 813 fn insert_after_inner_attr() {
718 check_full( 814 check_full(
719 "foo::bar", 815 "foo::bar",
@@ -991,11 +1087,13 @@ use foo::bar::baz::Qux;",
991 ra_fixture_before: &str, 1087 ra_fixture_before: &str,
992 ra_fixture_after: &str, 1088 ra_fixture_after: &str,
993 mb: Option<MergeBehaviour>, 1089 mb: Option<MergeBehaviour>,
1090 module: bool,
994 ) { 1091 ) {
995 let file = super::ImportScope::from( 1092 let mut syntax = ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone();
996 ast::SourceFile::parse(ra_fixture_before).tree().syntax().clone(), 1093 if module {
997 ) 1094 syntax = syntax.descendants().find_map(ast::Module::cast).unwrap().syntax().clone();
998 .unwrap(); 1095 }
1096 let file = super::ImportScope::from(syntax).unwrap();
999 let path = ast::SourceFile::parse(&format!("use {};", path)) 1097 let path = ast::SourceFile::parse(&format!("use {};", path))
1000 .tree() 1098 .tree()
1001 .syntax() 1099 .syntax()
@@ -1008,15 +1106,15 @@ use foo::bar::baz::Qux;",
1008 } 1106 }
1009 1107
1010 fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 1108 fn check_full(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1011 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Full)) 1109 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Full), false)
1012 } 1110 }
1013 1111
1014 fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 1112 fn check_last(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1015 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Last)) 1113 check(path, ra_fixture_before, ra_fixture_after, Some(MergeBehaviour::Last), false)
1016 } 1114 }
1017 1115
1018 fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 1116 fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1019 check(path, ra_fixture_before, ra_fixture_after, None) 1117 check(path, ra_fixture_before, ra_fixture_after, None, false)
1020 } 1118 }
1021 1119
1022 fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehaviour) { 1120 fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehaviour) {
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index e9c62c6aa..be7c812cb 100644
--- a/crates/hir_ty/Cargo.toml
+++ b/crates/hir_ty/Cargo.toml
@@ -17,9 +17,9 @@ ena = "0.14.0"
17log = "0.4.8" 17log = "0.4.8"
18rustc-hash = "1.1.0" 18rustc-hash = "1.1.0"
19scoped-tls = "1" 19scoped-tls = "1"
20chalk-solve = "0.33" 20chalk-solve = "0.34"
21chalk-ir = "0.33" 21chalk-ir = "0.34"
22chalk-recursive = "0.33" 22chalk-recursive = "0.34"
23 23
24stdx = { path = "../stdx", version = "0.0.0" } 24stdx = { path = "../stdx", version = "0.0.0" }
25hir_def = { path = "../hir_def", version = "0.0.0" } 25hir_def = { path = "../hir_def", version = "0.0.0" }
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 94d895c5e..832192881 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -638,6 +638,33 @@ fn main() { }
638 } 638 }
639 639
640 #[test] 640 #[test]
641 fn hover_shows_fn_doc_attr_raw_string() {
642 check(
643 r##"
644#[doc = r#"Raw string doc attr"#]
645pub fn foo<|>(_: &Path) {}
646
647fn main() { }
648"##,
649 expect![[r##"
650 *foo*
651
652 ```rust
653 test
654 ```
655
656 ```rust
657 pub fn foo(_: &Path)
658 ```
659
660 ---
661
662 Raw string doc attr
663 "##]],
664 );
665 }
666
667 #[test]
641 fn hover_shows_struct_field_info() { 668 fn hover_shows_struct_field_info() {
642 // Hovering over the field when instantiating 669 // Hovering over the field when instantiating
643 check( 670 check(
diff --git a/crates/ide_db/Cargo.toml b/crates/ide_db/Cargo.toml
index 3ff7a1a6a..72a9212f1 100644
--- a/crates/ide_db/Cargo.toml
+++ b/crates/ide_db/Cargo.toml
@@ -14,7 +14,7 @@ wasm = []
14 14
15[dependencies] 15[dependencies]
16log = "0.4.8" 16log = "0.4.8"
17rayon = "1.3.0" 17rayon = "1.5.0"
18fst = { version = "0.4", default-features = false } 18fst = { version = "0.4", default-features = false }
19rustc-hash = "1.1.0" 19rustc-hash = "1.1.0"
20once_cell = "1.3.1" 20once_cell = "1.3.1"
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index f8f97b1d3..2f0fa9726 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -29,7 +29,7 @@ rustc-hash = "1.1.0"
29serde = { version = "1.0.106", features = ["derive"] } 29serde = { version = "1.0.106", features = ["derive"] }
30serde_json = "1.0.48" 30serde_json = "1.0.48"
31threadpool = "1.7.1" 31threadpool = "1.7.1"
32rayon = "1.3.1" 32rayon = "1.5"
33mimalloc = { version = "0.1.19", default-features = false, optional = true } 33mimalloc = { version = "0.1.19", default-features = false, optional = true }
34lsp-server = "0.4.0" 34lsp-server = "0.4.0"
35 35
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index aa39ce554..e8de61868 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
13[dependencies] 13[dependencies]
14itertools = "0.9.0" 14itertools = "0.9.0"
15rowan = "0.10.0" 15rowan = "0.10.0"
16rustc_lexer = { version = "683.0.0", package = "rustc-ap-rustc_lexer" } 16rustc_lexer = { version = "685.0.0", package = "rustc-ap-rustc_lexer" }
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18arrayvec = "0.5.1" 18arrayvec = "0.5.1"
19once_cell = "1.3.1" 19once_cell = "1.3.1"
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 50c1c157d..c5cd1c504 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -7,7 +7,7 @@ use itertools::Itertools;
7use parser::SyntaxKind; 7use parser::SyntaxKind;
8 8
9use crate::{ 9use crate::{
10 ast::{self, support, AstNode, NameOwner, SyntaxNode}, 10 ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode},
11 SmolStr, SyntaxElement, SyntaxToken, T, 11 SmolStr, SyntaxElement, SyntaxToken, T,
12}; 12};
13 13
@@ -53,8 +53,16 @@ impl ast::Attr {
53 pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> { 53 pub fn as_simple_key_value(&self) -> Option<(SmolStr, SmolStr)> {
54 let lit = self.literal()?; 54 let lit = self.literal()?;
55 let key = self.simple_name()?; 55 let key = self.simple_name()?;
56 // FIXME: escape? raw string? 56 let value_token = lit.syntax().first_token()?;
57 let value = lit.syntax().first_token()?.text().trim_matches('"').into(); 57
58 let value: SmolStr = if let Some(s) = ast::String::cast(value_token.clone()) {
59 s.value()?.into()
60 } else if let Some(s) = ast::RawString::cast(value_token) {
61 s.value()?.into()
62 } else {
63 return None;
64 };
65
58 Some((key, value)) 66 Some((key, value))
59 } 67 }
60 68
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index ad586c882..a49be4602 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -43,12 +43,12 @@ macro_rules! assert_eq_text {
43 let right = $right; 43 let right = $right;
44 if left != right { 44 if left != right {
45 if left.trim() == right.trim() { 45 if left.trim() == right.trim() {
46 eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); 46 std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right);
47 } else { 47 } else {
48 let changeset = $crate::__Changeset::new(left, right, "\n"); 48 let changeset = $crate::__Changeset::new(left, right, "\n");
49 eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset); 49 std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset);
50 } 50 }
51 eprintln!($($tt)*); 51 std::eprintln!($($tt)*);
52 panic!("text differs"); 52 panic!("text differs");
53 } 53 }
54 }}; 54 }};