diff options
77 files changed, 800 insertions, 450 deletions
diff --git a/Cargo.lock b/Cargo.lock index fe09e4afe..5c7bcb17b 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -42,15 +42,14 @@ version = "0.0.0" | |||
42 | 42 | ||
43 | [[package]] | 43 | [[package]] |
44 | name = "arrayvec" | 44 | name = "arrayvec" |
45 | version = "0.5.1" | 45 | version = "0.5.2" |
46 | source = "registry+https://github.com/rust-lang/crates.io-index" | 46 | source = "registry+https://github.com/rust-lang/crates.io-index" |
47 | checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" | 47 | checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" |
48 | 48 | ||
49 | [[package]] | 49 | [[package]] |
50 | name = "assists" | 50 | name = "assists" |
51 | version = "0.0.0" | 51 | version = "0.0.0" |
52 | dependencies = [ | 52 | dependencies = [ |
53 | "base_db", | ||
54 | "either", | 53 | "either", |
55 | "hir", | 54 | "hir", |
56 | "ide_db", | 55 | "ide_db", |
@@ -128,26 +127,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
128 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" | 127 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" |
129 | 128 | ||
130 | [[package]] | 129 | [[package]] |
131 | name = "call_info" | ||
132 | version = "0.0.0" | ||
133 | dependencies = [ | ||
134 | "base_db", | ||
135 | "either", | ||
136 | "expect-test", | ||
137 | "hir", | ||
138 | "ide_db", | ||
139 | "stdx", | ||
140 | "syntax", | ||
141 | "test_utils", | ||
142 | ] | ||
143 | |||
144 | [[package]] | ||
145 | name = "cargo_metadata" | 130 | name = "cargo_metadata" |
146 | version = "0.12.0" | 131 | version = "0.12.0" |
147 | source = "registry+https://github.com/rust-lang/crates.io-index" | 132 | source = "registry+https://github.com/rust-lang/crates.io-index" |
148 | checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345" | 133 | checksum = "d5a5f7b42f606b7f23674f6f4d877628350682bc40687d3fae65679a58d55345" |
149 | dependencies = [ | 134 | dependencies = [ |
150 | "semver", | 135 | "semver 0.11.0", |
151 | "serde", | 136 | "serde", |
152 | "serde_json", | 137 | "serde_json", |
153 | ] | 138 | ] |
@@ -183,9 +168,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | |||
183 | 168 | ||
184 | [[package]] | 169 | [[package]] |
185 | name = "chalk-derive" | 170 | name = "chalk-derive" |
186 | version = "0.33.0" | 171 | version = "0.34.0" |
187 | source = "registry+https://github.com/rust-lang/crates.io-index" | 172 | source = "registry+https://github.com/rust-lang/crates.io-index" |
188 | checksum = "569014cab9084a6b826fe2507cc6d08f7897ba144fb1bc74e71b593dc8a0b952" | 173 | checksum = "0e9f986750ecb4df889d0a95d4586bd921889497b33908cc75bb80eadb4c600a" |
189 | dependencies = [ | 174 | dependencies = [ |
190 | "proc-macro2", | 175 | "proc-macro2", |
191 | "quote", | 176 | "quote", |
@@ -195,9 +180,9 @@ dependencies = [ | |||
195 | 180 | ||
196 | [[package]] | 181 | [[package]] |
197 | name = "chalk-ir" | 182 | name = "chalk-ir" |
198 | version = "0.33.0" | 183 | version = "0.34.0" |
199 | source = "registry+https://github.com/rust-lang/crates.io-index" | 184 | source = "registry+https://github.com/rust-lang/crates.io-index" |
200 | checksum = "8d9eab2a6590b696419f89c9ca3616fe8e8266ef676e6a6da8818c94963c9541" | 185 | checksum = "5c352c4649f1408bb3de5d86a248fda78d3d9cd1cbbd9502e7eca1be1e7ac368" |
201 | dependencies = [ | 186 | dependencies = [ |
202 | "chalk-derive", | 187 | "chalk-derive", |
203 | "lazy_static", | 188 | "lazy_static", |
@@ -205,9 +190,9 @@ dependencies = [ | |||
205 | 190 | ||
206 | [[package]] | 191 | [[package]] |
207 | name = "chalk-recursive" | 192 | name = "chalk-recursive" |
208 | version = "0.33.0" | 193 | version = "0.34.0" |
209 | source = "registry+https://github.com/rust-lang/crates.io-index" | 194 | source = "registry+https://github.com/rust-lang/crates.io-index" |
210 | checksum = "4a4671bcc70aa2d7e12ff4fe03f91d0c3c9ce387de915915e57fdf0c91dc5abd" | 195 | checksum = "7294bb2ac5446fcb83ec9524b9113f59a8913f174a9c1dea6db60532f17a1579" |
211 | dependencies = [ | 196 | dependencies = [ |
212 | "chalk-derive", | 197 | "chalk-derive", |
213 | "chalk-ir", | 198 | "chalk-ir", |
@@ -218,9 +203,9 @@ dependencies = [ | |||
218 | 203 | ||
219 | [[package]] | 204 | [[package]] |
220 | name = "chalk-solve" | 205 | name = "chalk-solve" |
221 | version = "0.33.0" | 206 | version = "0.34.0" |
222 | source = "registry+https://github.com/rust-lang/crates.io-index" | 207 | source = "registry+https://github.com/rust-lang/crates.io-index" |
223 | checksum = "45f75cc603f2fd302576c8b2976437f334e159e26d0afbb108a565b96c52184e" | 208 | checksum = "ffbca06963ed6f3d22faed840847a685f02feefa3825c0b94f9b791d03a0ac6f" |
224 | dependencies = [ | 209 | dependencies = [ |
225 | "chalk-derive", | 210 | "chalk-derive", |
226 | "chalk-ir", | 211 | "chalk-ir", |
@@ -268,9 +253,7 @@ dependencies = [ | |||
268 | name = "completion" | 253 | name = "completion" |
269 | version = "0.0.0" | 254 | version = "0.0.0" |
270 | dependencies = [ | 255 | dependencies = [ |
271 | "assists", | ||
272 | "base_db", | 256 | "base_db", |
273 | "call_info", | ||
274 | "expect-test", | 257 | "expect-test", |
275 | "hir", | 258 | "hir", |
276 | "ide_db", | 259 | "ide_db", |
@@ -292,11 +275,11 @@ checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" | |||
292 | 275 | ||
293 | [[package]] | 276 | [[package]] |
294 | name = "crc32fast" | 277 | name = "crc32fast" |
295 | version = "1.2.0" | 278 | version = "1.2.1" |
296 | source = "registry+https://github.com/rust-lang/crates.io-index" | 279 | source = "registry+https://github.com/rust-lang/crates.io-index" |
297 | checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" | 280 | checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" |
298 | dependencies = [ | 281 | dependencies = [ |
299 | "cfg-if 0.1.10", | 282 | "cfg-if 1.0.0", |
300 | ] | 283 | ] |
301 | 284 | ||
302 | [[package]] | 285 | [[package]] |
@@ -321,26 +304,25 @@ dependencies = [ | |||
321 | 304 | ||
322 | [[package]] | 305 | [[package]] |
323 | name = "crossbeam-deque" | 306 | name = "crossbeam-deque" |
324 | version = "0.7.3" | 307 | version = "0.8.0" |
325 | source = "registry+https://github.com/rust-lang/crates.io-index" | 308 | source = "registry+https://github.com/rust-lang/crates.io-index" |
326 | checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" | 309 | checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" |
327 | dependencies = [ | 310 | dependencies = [ |
311 | "cfg-if 1.0.0", | ||
328 | "crossbeam-epoch", | 312 | "crossbeam-epoch", |
329 | "crossbeam-utils 0.7.2", | 313 | "crossbeam-utils 0.8.0", |
330 | "maybe-uninit", | ||
331 | ] | 314 | ] |
332 | 315 | ||
333 | [[package]] | 316 | [[package]] |
334 | name = "crossbeam-epoch" | 317 | name = "crossbeam-epoch" |
335 | version = "0.8.2" | 318 | version = "0.9.0" |
336 | source = "registry+https://github.com/rust-lang/crates.io-index" | 319 | source = "registry+https://github.com/rust-lang/crates.io-index" |
337 | checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" | 320 | checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" |
338 | dependencies = [ | 321 | dependencies = [ |
339 | "autocfg", | 322 | "cfg-if 1.0.0", |
340 | "cfg-if 0.1.10", | 323 | "const_fn", |
341 | "crossbeam-utils 0.7.2", | 324 | "crossbeam-utils 0.8.0", |
342 | "lazy_static", | 325 | "lazy_static", |
343 | "maybe-uninit", | ||
344 | "memoffset", | 326 | "memoffset", |
345 | "scopeguard", | 327 | "scopeguard", |
346 | ] | 328 | ] |
@@ -498,6 +480,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
498 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | 480 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" |
499 | 481 | ||
500 | [[package]] | 482 | [[package]] |
483 | name = "generator" | ||
484 | version = "0.6.23" | ||
485 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
486 | checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc" | ||
487 | dependencies = [ | ||
488 | "cc", | ||
489 | "libc", | ||
490 | "log", | ||
491 | "rustc_version", | ||
492 | "winapi 0.3.9", | ||
493 | ] | ||
494 | |||
495 | [[package]] | ||
501 | name = "gimli" | 496 | name = "gimli" |
502 | version = "0.22.0" | 497 | version = "0.22.0" |
503 | source = "registry+https://github.com/rust-lang/crates.io-index" | 498 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -643,8 +638,6 @@ name = "ide" | |||
643 | version = "0.0.0" | 638 | version = "0.0.0" |
644 | dependencies = [ | 639 | dependencies = [ |
645 | "assists", | 640 | "assists", |
646 | "base_db", | ||
647 | "call_info", | ||
648 | "cfg", | 641 | "cfg", |
649 | "completion", | 642 | "completion", |
650 | "either", | 643 | "either", |
@@ -673,6 +666,7 @@ version = "0.0.0" | |||
673 | dependencies = [ | 666 | dependencies = [ |
674 | "base_db", | 667 | "base_db", |
675 | "either", | 668 | "either", |
669 | "expect-test", | ||
676 | "fst", | 670 | "fst", |
677 | "hir", | 671 | "hir", |
678 | "log", | 672 | "log", |
@@ -796,11 +790,11 @@ checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" | |||
796 | 790 | ||
797 | [[package]] | 791 | [[package]] |
798 | name = "libloading" | 792 | name = "libloading" |
799 | version = "0.6.4" | 793 | version = "0.6.5" |
800 | source = "registry+https://github.com/rust-lang/crates.io-index" | 794 | source = "registry+https://github.com/rust-lang/crates.io-index" |
801 | checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" | 795 | checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" |
802 | dependencies = [ | 796 | dependencies = [ |
803 | "cfg-if 0.1.10", | 797 | "cfg-if 1.0.0", |
804 | "winapi 0.3.9", | 798 | "winapi 0.3.9", |
805 | ] | 799 | ] |
806 | 800 | ||
@@ -832,6 +826,19 @@ dependencies = [ | |||
832 | ] | 826 | ] |
833 | 827 | ||
834 | [[package]] | 828 | [[package]] |
829 | name = "loom" | ||
830 | version = "0.3.6" | ||
831 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
832 | checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" | ||
833 | dependencies = [ | ||
834 | "cfg-if 0.1.10", | ||
835 | "generator", | ||
836 | "scoped-tls", | ||
837 | "serde", | ||
838 | "serde_json", | ||
839 | ] | ||
840 | |||
841 | [[package]] | ||
835 | name = "lsp-server" | 842 | name = "lsp-server" |
836 | version = "0.4.1" | 843 | version = "0.4.1" |
837 | source = "registry+https://github.com/rust-lang/crates.io-index" | 844 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1260,9 +1267,9 @@ dependencies = [ | |||
1260 | 1267 | ||
1261 | [[package]] | 1268 | [[package]] |
1262 | name = "rayon" | 1269 | name = "rayon" |
1263 | version = "1.4.1" | 1270 | version = "1.5.0" |
1264 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1271 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1265 | checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" | 1272 | checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" |
1266 | dependencies = [ | 1273 | dependencies = [ |
1267 | "autocfg", | 1274 | "autocfg", |
1268 | "crossbeam-deque", | 1275 | "crossbeam-deque", |
@@ -1272,13 +1279,13 @@ dependencies = [ | |||
1272 | 1279 | ||
1273 | [[package]] | 1280 | [[package]] |
1274 | name = "rayon-core" | 1281 | name = "rayon-core" |
1275 | version = "1.8.1" | 1282 | version = "1.9.0" |
1276 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1283 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1277 | checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" | 1284 | checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" |
1278 | dependencies = [ | 1285 | dependencies = [ |
1279 | "crossbeam-channel 0.4.4", | 1286 | "crossbeam-channel 0.5.0", |
1280 | "crossbeam-deque", | 1287 | "crossbeam-deque", |
1281 | "crossbeam-utils 0.7.2", | 1288 | "crossbeam-utils 0.8.0", |
1282 | "lazy_static", | 1289 | "lazy_static", |
1283 | "num_cpus", | 1290 | "num_cpus", |
1284 | ] | 1291 | ] |
@@ -1331,7 +1338,6 @@ name = "rust-analyzer" | |||
1331 | version = "0.0.0" | 1338 | version = "0.0.0" |
1332 | dependencies = [ | 1339 | dependencies = [ |
1333 | "anyhow", | 1340 | "anyhow", |
1334 | "base_db", | ||
1335 | "cfg", | 1341 | "cfg", |
1336 | "crossbeam-channel 0.5.0", | 1342 | "crossbeam-channel 0.5.0", |
1337 | "env_logger", | 1343 | "env_logger", |
@@ -1366,6 +1372,9 @@ dependencies = [ | |||
1366 | "text_edit", | 1372 | "text_edit", |
1367 | "threadpool", | 1373 | "threadpool", |
1368 | "toolchain", | 1374 | "toolchain", |
1375 | "tracing", | ||
1376 | "tracing-subscriber", | ||
1377 | "tracing-tree", | ||
1369 | "tt", | 1378 | "tt", |
1370 | "vfs", | 1379 | "vfs", |
1371 | "vfs-notify", | 1380 | "vfs-notify", |
@@ -1374,18 +1383,18 @@ dependencies = [ | |||
1374 | 1383 | ||
1375 | [[package]] | 1384 | [[package]] |
1376 | name = "rustc-ap-rustc_lexer" | 1385 | name = "rustc-ap-rustc_lexer" |
1377 | version = "683.0.0" | 1386 | version = "685.0.0" |
1378 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1387 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1379 | checksum = "c0c9a47e24d4b7d74ec583d8813803b36985ee082fe7debe55f257df92d5fe50" | 1388 | checksum = "4d6465438127d20bf9d0f5148f806c029934a74c9bce1103a42d47e81d3fe89a" |
1380 | dependencies = [ | 1389 | dependencies = [ |
1381 | "unicode-xid", | 1390 | "unicode-xid", |
1382 | ] | 1391 | ] |
1383 | 1392 | ||
1384 | [[package]] | 1393 | [[package]] |
1385 | name = "rustc-demangle" | 1394 | name = "rustc-demangle" |
1386 | version = "0.1.17" | 1395 | version = "0.1.18" |
1387 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1396 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1388 | checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" | 1397 | checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" |
1389 | 1398 | ||
1390 | [[package]] | 1399 | [[package]] |
1391 | name = "rustc-hash" | 1400 | name = "rustc-hash" |
@@ -1394,6 +1403,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1394 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" | 1403 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" |
1395 | 1404 | ||
1396 | [[package]] | 1405 | [[package]] |
1406 | name = "rustc_version" | ||
1407 | version = "0.2.3" | ||
1408 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1409 | checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" | ||
1410 | dependencies = [ | ||
1411 | "semver 0.9.0", | ||
1412 | ] | ||
1413 | |||
1414 | [[package]] | ||
1397 | name = "ryu" | 1415 | name = "ryu" |
1398 | version = "1.0.5" | 1416 | version = "1.0.5" |
1399 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1417 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1460,9 +1478,9 @@ dependencies = [ | |||
1460 | 1478 | ||
1461 | [[package]] | 1479 | [[package]] |
1462 | name = "scroll_derive" | 1480 | name = "scroll_derive" |
1463 | version = "0.10.3" | 1481 | version = "0.10.4" |
1464 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1482 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1465 | checksum = "6dfde5d1531034db129e95c76ac857e2baecea3443579d493d02224950b0fb6d" | 1483 | checksum = "b12bd20b94c7cdfda8c7ba9b92ad0d9a56e3fa018c25fca83b51aa664c9b4c0d" |
1466 | dependencies = [ | 1484 | dependencies = [ |
1467 | "proc-macro2", | 1485 | "proc-macro2", |
1468 | "quote", | 1486 | "quote", |
@@ -1471,16 +1489,31 @@ dependencies = [ | |||
1471 | 1489 | ||
1472 | [[package]] | 1490 | [[package]] |
1473 | name = "semver" | 1491 | name = "semver" |
1492 | version = "0.9.0" | ||
1493 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1494 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" | ||
1495 | dependencies = [ | ||
1496 | "semver-parser 0.7.0", | ||
1497 | ] | ||
1498 | |||
1499 | [[package]] | ||
1500 | name = "semver" | ||
1474 | version = "0.11.0" | 1501 | version = "0.11.0" |
1475 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1502 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1476 | checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" | 1503 | checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" |
1477 | dependencies = [ | 1504 | dependencies = [ |
1478 | "semver-parser", | 1505 | "semver-parser 0.10.1", |
1479 | "serde", | 1506 | "serde", |
1480 | ] | 1507 | ] |
1481 | 1508 | ||
1482 | [[package]] | 1509 | [[package]] |
1483 | name = "semver-parser" | 1510 | name = "semver-parser" |
1511 | version = "0.7.0" | ||
1512 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1513 | checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" | ||
1514 | |||
1515 | [[package]] | ||
1516 | name = "semver-parser" | ||
1484 | version = "0.10.1" | 1517 | version = "0.10.1" |
1485 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1518 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1486 | checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" | 1519 | checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" |
@@ -1532,11 +1565,12 @@ dependencies = [ | |||
1532 | 1565 | ||
1533 | [[package]] | 1566 | [[package]] |
1534 | name = "sharded-slab" | 1567 | name = "sharded-slab" |
1535 | version = "0.0.9" | 1568 | version = "0.1.0" |
1536 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1569 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1537 | checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" | 1570 | checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" |
1538 | dependencies = [ | 1571 | dependencies = [ |
1539 | "lazy_static", | 1572 | "lazy_static", |
1573 | "loom", | ||
1540 | ] | 1574 | ] |
1541 | 1575 | ||
1542 | [[package]] | 1576 | [[package]] |
@@ -1564,7 +1598,6 @@ dependencies = [ | |||
1564 | name = "ssr" | 1598 | name = "ssr" |
1565 | version = "0.0.0" | 1599 | version = "0.0.0" |
1566 | dependencies = [ | 1600 | dependencies = [ |
1567 | "base_db", | ||
1568 | "expect-test", | 1601 | "expect-test", |
1569 | "hir", | 1602 | "hir", |
1570 | "ide_db", | 1603 | "ide_db", |
@@ -1581,9 +1614,9 @@ version = "0.0.0" | |||
1581 | 1614 | ||
1582 | [[package]] | 1615 | [[package]] |
1583 | name = "syn" | 1616 | name = "syn" |
1584 | version = "1.0.45" | 1617 | version = "1.0.46" |
1585 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1618 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1586 | checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556" | 1619 | checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942" |
1587 | dependencies = [ | 1620 | dependencies = [ |
1588 | "proc-macro2", | 1621 | "proc-macro2", |
1589 | "quote", | 1622 | "quote", |
@@ -1760,9 +1793,9 @@ dependencies = [ | |||
1760 | 1793 | ||
1761 | [[package]] | 1794 | [[package]] |
1762 | name = "tracing-subscriber" | 1795 | name = "tracing-subscriber" |
1763 | version = "0.2.13" | 1796 | version = "0.2.14" |
1764 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1797 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1765 | checksum = "4ef0a5e15477aa303afbfac3a44cba9b6430fdaad52423b1e6c0dbbe28c3eedd" | 1798 | checksum = "2810660b9d5b18895d140caba6401765749a6a162e5d0736cfc44ea50db9d79d" |
1766 | dependencies = [ | 1799 | dependencies = [ |
1767 | "ansi_term", | 1800 | "ansi_term", |
1768 | "chrono", | 1801 | "chrono", |
diff --git a/crates/assists/Cargo.toml b/crates/assists/Cargo.toml index 264125651..108f656e9 100644 --- a/crates/assists/Cargo.toml +++ b/crates/assists/Cargo.toml | |||
@@ -18,7 +18,6 @@ stdx = { path = "../stdx", version = "0.0.0" } | |||
18 | syntax = { path = "../syntax", version = "0.0.0" } | 18 | syntax = { path = "../syntax", version = "0.0.0" } |
19 | text_edit = { path = "../text_edit", version = "0.0.0" } | 19 | text_edit = { path = "../text_edit", version = "0.0.0" } |
20 | profile = { path = "../profile", version = "0.0.0" } | 20 | profile = { path = "../profile", version = "0.0.0" } |
21 | base_db = { path = "../base_db", version = "0.0.0" } | ||
22 | ide_db = { path = "../ide_db", version = "0.0.0" } | 21 | ide_db = { path = "../ide_db", version = "0.0.0" } |
23 | hir = { path = "../hir", version = "0.0.0" } | 22 | hir = { path = "../hir", version = "0.0.0" } |
24 | test_utils = { path = "../test_utils", version = "0.0.0" } | 23 | test_utils = { path = "../test_utils", version = "0.0.0" } |
diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index bf520069e..d11fee196 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs | |||
@@ -3,8 +3,8 @@ | |||
3 | use std::mem; | 3 | use std::mem; |
4 | 4 | ||
5 | use algo::find_covering_element; | 5 | use algo::find_covering_element; |
6 | use base_db::{FileId, FileRange}; | ||
7 | use hir::Semantics; | 6 | use hir::Semantics; |
7 | use ide_db::base_db::{FileId, FileRange}; | ||
8 | use ide_db::{ | 8 | use ide_db::{ |
9 | label::Label, | 9 | label::Label, |
10 | source_change::{SourceChange, SourceFileEdit}, | 10 | source_change::{SourceChange, SourceFileEdit}, |
diff --git a/crates/assists/src/handlers/add_missing_impl_members.rs b/crates/assists/src/handlers/add_missing_impl_members.rs index 4c400f287..b82fb30ad 100644 --- a/crates/assists/src/handlers/add_missing_impl_members.rs +++ b/crates/assists/src/handlers/add_missing_impl_members.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use hir::HasSource; | 1 | use hir::HasSource; |
2 | use ide_db::traits::{get_missing_assoc_items, resolve_target_trait}; | ||
2 | use syntax::{ | 3 | use syntax::{ |
3 | ast::{ | 4 | ast::{ |
4 | self, | 5 | self, |
@@ -11,7 +12,7 @@ use syntax::{ | |||
11 | use crate::{ | 12 | use crate::{ |
12 | assist_context::{AssistContext, Assists}, | 13 | assist_context::{AssistContext, Assists}, |
13 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, | 14 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, |
14 | utils::{get_missing_assoc_items, render_snippet, resolve_target_trait, Cursor}, | 15 | utils::{render_snippet, Cursor}, |
15 | AssistId, AssistKind, | 16 | AssistId, AssistKind, |
16 | }; | 17 | }; |
17 | 18 | ||
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 7f4f80b23..48433feb9 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use base_db::FileId; | ||
2 | use hir::{EnumVariant, Module, ModuleDef, Name}; | 1 | use hir::{EnumVariant, Module, ModuleDef, Name}; |
2 | use ide_db::base_db::FileId; | ||
3 | use ide_db::{defs::Definition, search::Reference, RootDatabase}; | 3 | use ide_db::{defs::Definition, search::Reference, RootDatabase}; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | use rustc_hash::FxHashSet; | 5 | use rustc_hash::FxHashSet; |
diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index 66f74150c..c86720787 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use base_db::FileId; | ||
2 | use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; | 1 | use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; |
2 | use ide_db::base_db::FileId; | ||
3 | use syntax::{ | 3 | use syntax::{ |
4 | ast::{self, VisibilityOwner}, | 4 | ast::{self, VisibilityOwner}, |
5 | AstNode, TextRange, TextSize, | 5 | AstNode, TextRange, TextSize, |
diff --git a/crates/assists/src/handlers/generate_function.rs b/crates/assists/src/handlers/generate_function.rs index d23f4293b..758188a42 100644 --- a/crates/assists/src/handlers/generate_function.rs +++ b/crates/assists/src/handlers/generate_function.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use base_db::FileId; | ||
2 | use hir::HirDisplay; | 1 | use hir::HirDisplay; |
2 | use ide_db::base_db::FileId; | ||
3 | use rustc_hash::{FxHashMap, FxHashSet}; | 3 | use rustc_hash::{FxHashMap, FxHashSet}; |
4 | use syntax::{ | 4 | use syntax::{ |
5 | ast::{ | 5 | ast::{ |
diff --git a/crates/assists/src/handlers/remove_dbg.rs b/crates/assists/src/handlers/remove_dbg.rs index e10616779..9731344b8 100644 --- a/crates/assists/src/handlers/remove_dbg.rs +++ b/crates/assists/src/handlers/remove_dbg.rs | |||
@@ -93,8 +93,9 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) - | |||
93 | if macro_contents.len() < 2 { | 93 | if macro_contents.len() < 2 { |
94 | return false; | 94 | return false; |
95 | } | 95 | } |
96 | let mut macro_contents = macro_contents.into_iter().peekable(); | ||
96 | let mut unpaired_brackets_in_contents = Vec::new(); | 97 | let mut unpaired_brackets_in_contents = Vec::new(); |
97 | for element in macro_contents { | 98 | while let Some(element) = macro_contents.next() { |
98 | match element.kind() { | 99 | match element.kind() { |
99 | T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element), | 100 | T!['('] | T!['['] | T!['{'] => unpaired_brackets_in_contents.push(element), |
100 | T![')'] => { | 101 | T![')'] => { |
@@ -118,8 +119,14 @@ fn needs_parentheses_around_macro_contents(macro_contents: Vec<SyntaxElement>) - | |||
118 | symbol_kind => { | 119 | symbol_kind => { |
119 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); | 120 | let symbol_not_in_bracket = unpaired_brackets_in_contents.is_empty(); |
120 | if symbol_not_in_bracket | 121 | if symbol_not_in_bracket |
121 | && symbol_kind != SyntaxKind::COLON | 122 | && symbol_kind != SyntaxKind::COLON // paths |
122 | && symbol_kind.is_punct() | 123 | && (symbol_kind != SyntaxKind::DOT // field/method access |
124 | || macro_contents // range expressions consist of two SyntaxKind::Dot in macro invocations | ||
125 | .peek() | ||
126 | .map(|element| element.kind() == SyntaxKind::DOT) | ||
127 | .unwrap_or(false)) | ||
128 | && symbol_kind != SyntaxKind::QUESTION // try operator | ||
129 | && (symbol_kind.is_punct() || symbol_kind == SyntaxKind::AS_KW) | ||
123 | { | 130 | { |
124 | return true; | 131 | return true; |
125 | } | 132 | } |
@@ -243,6 +250,25 @@ fn main() { | |||
243 | } | 250 | } |
244 | 251 | ||
245 | #[test] | 252 | #[test] |
253 | fn test_remove_dbg_method_chaining() { | ||
254 | check_assist( | ||
255 | remove_dbg, | ||
256 | r#"let res = <|>dbg!(foo().bar()).baz();"#, | ||
257 | r#"let res = foo().bar().baz();"#, | ||
258 | ); | ||
259 | check_assist( | ||
260 | remove_dbg, | ||
261 | r#"let res = <|>dbg!(foo.bar()).baz();"#, | ||
262 | r#"let res = foo.bar().baz();"#, | ||
263 | ); | ||
264 | } | ||
265 | |||
266 | #[test] | ||
267 | fn test_remove_dbg_field_chaining() { | ||
268 | check_assist(remove_dbg, r#"let res = <|>dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#); | ||
269 | } | ||
270 | |||
271 | #[test] | ||
246 | fn test_remove_dbg_from_inside_fn() { | 272 | fn test_remove_dbg_from_inside_fn() { |
247 | check_assist_target( | 273 | check_assist_target( |
248 | remove_dbg, | 274 | remove_dbg, |
@@ -280,4 +306,59 @@ fn main() { | |||
280 | }"#, | 306 | }"#, |
281 | ); | 307 | ); |
282 | } | 308 | } |
309 | |||
310 | #[test] | ||
311 | fn test_remove_dbg_try_expr() { | ||
312 | check_assist( | ||
313 | remove_dbg, | ||
314 | r#"let res = <|>dbg!(result?).foo();"#, | ||
315 | r#"let res = result?.foo();"#, | ||
316 | ); | ||
317 | } | ||
318 | |||
319 | #[test] | ||
320 | fn test_remove_dbg_await_expr() { | ||
321 | check_assist( | ||
322 | remove_dbg, | ||
323 | r#"let res = <|>dbg!(fut.await).foo();"#, | ||
324 | r#"let res = fut.await.foo();"#, | ||
325 | ); | ||
326 | } | ||
327 | |||
328 | #[test] | ||
329 | fn test_remove_dbg_as_cast() { | ||
330 | check_assist( | ||
331 | remove_dbg, | ||
332 | r#"let res = <|>dbg!(3 as usize).foo();"#, | ||
333 | r#"let res = (3 as usize).foo();"#, | ||
334 | ); | ||
335 | } | ||
336 | |||
337 | #[test] | ||
338 | fn test_remove_dbg_index_expr() { | ||
339 | check_assist( | ||
340 | remove_dbg, | ||
341 | r#"let res = <|>dbg!(array[3]).foo();"#, | ||
342 | r#"let res = array[3].foo();"#, | ||
343 | ); | ||
344 | check_assist( | ||
345 | remove_dbg, | ||
346 | r#"let res = <|>dbg!(tuple.3).foo();"#, | ||
347 | r#"let res = tuple.3.foo();"#, | ||
348 | ); | ||
349 | } | ||
350 | |||
351 | #[test] | ||
352 | fn test_remove_dbg_range_expr() { | ||
353 | check_assist( | ||
354 | remove_dbg, | ||
355 | r#"let res = <|>dbg!(foo..bar).foo();"#, | ||
356 | r#"let res = (foo..bar).foo();"#, | ||
357 | ); | ||
358 | check_assist( | ||
359 | remove_dbg, | ||
360 | r#"let res = <|>dbg!(foo..=bar).foo();"#, | ||
361 | r#"let res = (foo..=bar).foo();"#, | ||
362 | ); | ||
363 | } | ||
283 | } | 364 | } |
diff --git a/crates/assists/src/handlers/replace_if_let_with_match.rs b/crates/assists/src/handlers/replace_if_let_with_match.rs index 79097621e..9a49c48c1 100644 --- a/crates/assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -7,10 +7,8 @@ use syntax::{ | |||
7 | AstNode, | 7 | AstNode, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, Assists}; |
11 | utils::{unwrap_trivial_block, TryEnum}, | 11 | use ide_db::ty_filter::TryEnum; |
12 | AssistContext, AssistId, AssistKind, Assists, | ||
13 | }; | ||
14 | 12 | ||
15 | // Assist: replace_if_let_with_match | 13 | // Assist: replace_if_let_with_match |
16 | // | 14 | // |
diff --git a/crates/assists/src/handlers/replace_let_with_if_let.rs b/crates/assists/src/handlers/replace_let_with_if_let.rs index ed6d0c29b..a5bcbda24 100644 --- a/crates/assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/assists/src/handlers/replace_let_with_if_let.rs | |||
@@ -9,7 +9,8 @@ use syntax::{ | |||
9 | AstNode, T, | 9 | AstNode, T, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{utils::TryEnum, AssistContext, AssistId, AssistKind, Assists}; | 12 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
13 | use ide_db::ty_filter::TryEnum; | ||
13 | 14 | ||
14 | // Assist: replace_let_with_if_let | 15 | // Assist: replace_let_with_if_let |
15 | // | 16 | // |
diff --git a/crates/assists/src/handlers/replace_unwrap_with_match.rs b/crates/assists/src/handlers/replace_unwrap_with_match.rs index 4043c219c..f547066f0 100644 --- a/crates/assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/assists/src/handlers/replace_unwrap_with_match.rs | |||
@@ -10,9 +10,10 @@ use syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | utils::{render_snippet, Cursor, TryEnum}, | 13 | utils::{render_snippet, Cursor}, |
14 | AssistContext, AssistId, AssistKind, Assists, | 14 | AssistContext, AssistId, AssistKind, Assists, |
15 | }; | 15 | }; |
16 | use ide_db::ty_filter::TryEnum; | ||
16 | 17 | ||
17 | // Assist: replace_unwrap_with_match | 18 | // Assist: replace_unwrap_with_match |
18 | // | 19 | // |
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index 8a664f654..70a651e10 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs | |||
@@ -17,8 +17,8 @@ mod tests; | |||
17 | pub mod utils; | 17 | pub mod utils; |
18 | pub mod ast_transform; | 18 | pub mod ast_transform; |
19 | 19 | ||
20 | use base_db::FileRange; | ||
21 | use hir::Semantics; | 20 | use hir::Semantics; |
21 | use ide_db::base_db::FileRange; | ||
22 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; | 22 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; |
23 | use syntax::TextRange; | 23 | use syntax::TextRange; |
24 | 24 | ||
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs index 2b687decf..849d85e76 100644 --- a/crates/assists/src/tests.rs +++ b/crates/assists/src/tests.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | mod generated; | 1 | mod generated; |
2 | 2 | ||
3 | use base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | ||
4 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use ide_db::base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | ||
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use syntax::TextRange; | 6 | use syntax::TextRange; |
7 | use test_utils::{assert_eq_text, extract_offset, extract_range}; | 7 | use test_utils::{assert_eq_text, extract_offset, extract_range}; |
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 1a6b48b45..56f925ee6 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -2,14 +2,13 @@ | |||
2 | pub(crate) mod insert_use; | 2 | pub(crate) mod insert_use; |
3 | pub(crate) mod import_assets; | 3 | pub(crate) mod import_assets; |
4 | 4 | ||
5 | use std::{iter, ops}; | 5 | use std::ops; |
6 | 6 | ||
7 | use hir::{Adt, Crate, Enum, Module, ScopeDef, Semantics, Trait, Type}; | 7 | use hir::{Crate, Enum, Module, ScopeDef, Semantics, Trait}; |
8 | use ide_db::RootDatabase; | 8 | use ide_db::RootDatabase; |
9 | use itertools::Itertools; | 9 | use itertools::Itertools; |
10 | use rustc_hash::FxHashSet; | ||
11 | use syntax::{ | 10 | use syntax::{ |
12 | ast::{self, make, ArgListOwner, NameOwner}, | 11 | ast::{self, make, ArgListOwner}, |
13 | AstNode, Direction, | 12 | AstNode, Direction, |
14 | SyntaxKind::*, | 13 | SyntaxKind::*, |
15 | SyntaxNode, TextSize, T, | 14 | SyntaxNode, TextSize, T, |
@@ -115,72 +114,6 @@ pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor | |||
115 | } | 114 | } |
116 | } | 115 | } |
117 | 116 | ||
118 | pub fn get_missing_assoc_items( | ||
119 | sema: &Semantics<RootDatabase>, | ||
120 | impl_def: &ast::Impl, | ||
121 | ) -> Vec<hir::AssocItem> { | ||
122 | // Names must be unique between constants and functions. However, type aliases | ||
123 | // may share the same name as a function or constant. | ||
124 | let mut impl_fns_consts = FxHashSet::default(); | ||
125 | let mut impl_type = FxHashSet::default(); | ||
126 | |||
127 | if let Some(item_list) = impl_def.assoc_item_list() { | ||
128 | for item in item_list.assoc_items() { | ||
129 | match item { | ||
130 | ast::AssocItem::Fn(f) => { | ||
131 | if let Some(n) = f.name() { | ||
132 | impl_fns_consts.insert(n.syntax().to_string()); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | ast::AssocItem::TypeAlias(t) => { | ||
137 | if let Some(n) = t.name() { | ||
138 | impl_type.insert(n.syntax().to_string()); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | ast::AssocItem::Const(c) => { | ||
143 | if let Some(n) = c.name() { | ||
144 | impl_fns_consts.insert(n.syntax().to_string()); | ||
145 | } | ||
146 | } | ||
147 | ast::AssocItem::MacroCall(_) => (), | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | resolve_target_trait(sema, impl_def).map_or(vec![], |target_trait| { | ||
153 | target_trait | ||
154 | .items(sema.db) | ||
155 | .iter() | ||
156 | .filter(|i| match i { | ||
157 | hir::AssocItem::Function(f) => { | ||
158 | !impl_fns_consts.contains(&f.name(sema.db).to_string()) | ||
159 | } | ||
160 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(sema.db).to_string()), | ||
161 | hir::AssocItem::Const(c) => c | ||
162 | .name(sema.db) | ||
163 | .map(|n| !impl_fns_consts.contains(&n.to_string())) | ||
164 | .unwrap_or_default(), | ||
165 | }) | ||
166 | .cloned() | ||
167 | .collect() | ||
168 | }) | ||
169 | } | ||
170 | |||
171 | pub(crate) fn resolve_target_trait( | ||
172 | sema: &Semantics<RootDatabase>, | ||
173 | impl_def: &ast::Impl, | ||
174 | ) -> Option<hir::Trait> { | ||
175 | let ast_path = | ||
176 | impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?; | ||
177 | |||
178 | match sema.resolve_path(&ast_path) { | ||
179 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), | ||
180 | _ => None, | ||
181 | } | ||
182 | } | ||
183 | |||
184 | pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize { | 117 | pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize { |
185 | node.children_with_tokens() | 118 | node.children_with_tokens() |
186 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) | 119 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) |
@@ -223,54 +156,6 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> { | |||
223 | } | 156 | } |
224 | } | 157 | } |
225 | 158 | ||
226 | #[derive(Clone, Copy)] | ||
227 | pub enum TryEnum { | ||
228 | Result, | ||
229 | Option, | ||
230 | } | ||
231 | |||
232 | impl TryEnum { | ||
233 | const ALL: [TryEnum; 2] = [TryEnum::Option, TryEnum::Result]; | ||
234 | |||
235 | pub fn from_ty(sema: &Semantics<RootDatabase>, ty: &Type) -> Option<TryEnum> { | ||
236 | let enum_ = match ty.as_adt() { | ||
237 | Some(Adt::Enum(it)) => it, | ||
238 | _ => return None, | ||
239 | }; | ||
240 | TryEnum::ALL.iter().find_map(|&var| { | ||
241 | if &enum_.name(sema.db).to_string() == var.type_name() { | ||
242 | return Some(var); | ||
243 | } | ||
244 | None | ||
245 | }) | ||
246 | } | ||
247 | |||
248 | pub(crate) fn happy_case(self) -> &'static str { | ||
249 | match self { | ||
250 | TryEnum::Result => "Ok", | ||
251 | TryEnum::Option => "Some", | ||
252 | } | ||
253 | } | ||
254 | |||
255 | pub(crate) fn sad_pattern(self) -> ast::Pat { | ||
256 | match self { | ||
257 | TryEnum::Result => make::tuple_struct_pat( | ||
258 | make::path_unqualified(make::path_segment(make::name_ref("Err"))), | ||
259 | iter::once(make::wildcard_pat().into()), | ||
260 | ) | ||
261 | .into(), | ||
262 | TryEnum::Option => make::ident_pat(make::name("None")).into(), | ||
263 | } | ||
264 | } | ||
265 | |||
266 | fn type_name(self) -> &'static str { | ||
267 | match self { | ||
268 | TryEnum::Result => "Result", | ||
269 | TryEnum::Option => "Option", | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | |||
274 | /// Helps with finding well-know things inside the standard library. This is | 159 | /// Helps with finding well-know things inside the standard library. This is |
275 | /// somewhat similar to the known paths infra inside hir, but it different; We | 160 | /// somewhat similar to the known paths infra inside hir, but it different; We |
276 | /// want to make sure that IDE specific paths don't become interesting inside | 161 | /// want to make sure that IDE specific paths don't become interesting inside |
diff --git a/crates/call_info/Cargo.toml b/crates/call_info/Cargo.toml deleted file mode 100644 index 98c0bd6db..000000000 --- a/crates/call_info/Cargo.toml +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | [package] | ||
2 | name = "call_info" | ||
3 | version = "0.0.0" | ||
4 | description = "TBD" | ||
5 | license = "MIT OR Apache-2.0" | ||
6 | authors = ["rust-analyzer developers"] | ||
7 | edition = "2018" | ||
8 | |||
9 | [lib] | ||
10 | doctest = false | ||
11 | |||
12 | [dependencies] | ||
13 | either = "1.5.3" | ||
14 | |||
15 | stdx = { path = "../stdx", version = "0.0.0" } | ||
16 | syntax = { path = "../syntax", version = "0.0.0" } | ||
17 | base_db = { path = "../base_db", version = "0.0.0" } | ||
18 | ide_db = { path = "../ide_db", version = "0.0.0" } | ||
19 | test_utils = { path = "../test_utils", version = "0.0.0" } | ||
20 | |||
21 | # call_info crate should depend only on the top-level `hir` package. if you need | ||
22 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | ||
23 | hir = { path = "../hir", version = "0.0.0" } | ||
24 | |||
25 | [dev-dependencies] | ||
26 | expect-test = "1.0" | ||
diff --git a/crates/completion/Cargo.toml b/crates/completion/Cargo.toml index 25192456a..b79ee33f7 100644 --- a/crates/completion/Cargo.toml +++ b/crates/completion/Cargo.toml | |||
@@ -21,8 +21,6 @@ base_db = { path = "../base_db", version = "0.0.0" } | |||
21 | ide_db = { path = "../ide_db", version = "0.0.0" } | 21 | ide_db = { path = "../ide_db", version = "0.0.0" } |
22 | profile = { path = "../profile", version = "0.0.0" } | 22 | profile = { path = "../profile", version = "0.0.0" } |
23 | test_utils = { path = "../test_utils", version = "0.0.0" } | 23 | test_utils = { path = "../test_utils", version = "0.0.0" } |
24 | assists = { path = "../assists", version = "0.0.0" } | ||
25 | call_info = { path = "../call_info", version = "0.0.0" } | ||
26 | 24 | ||
27 | # completions crate should depend only on the top-level `hir` package. if you need | 25 | # completions crate should depend only on the top-level `hir` package. if you need |
28 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 26 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
diff --git a/crates/completion/src/complete_mod.rs b/crates/completion/src/complete_mod.rs index 35a57aba3..385911afa 100644 --- a/crates/completion/src/complete_mod.rs +++ b/crates/completion/src/complete_mod.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Completes mod declarations. | 1 | //! Completes mod declarations. |
2 | 2 | ||
3 | use base_db::{SourceDatabaseExt, VfsPath}; | ||
4 | use hir::{Module, ModuleSource}; | 3 | use hir::{Module, ModuleSource}; |
4 | use ide_db::base_db::{SourceDatabaseExt, VfsPath}; | ||
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use rustc_hash::FxHashSet; | 6 | use rustc_hash::FxHashSet; |
7 | 7 | ||
diff --git a/crates/completion/src/complete_postfix.rs b/crates/completion/src/complete_postfix.rs index 700573cf2..2622f12ab 100644 --- a/crates/completion/src/complete_postfix.rs +++ b/crates/completion/src/complete_postfix.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | mod format_like; | 3 | mod format_like; |
4 | 4 | ||
5 | use assists::utils::TryEnum; | 5 | use ide_db::ty_filter::TryEnum; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | ast::{self, AstNode, AstToken}, | 7 | ast::{self, AstNode, AstToken}, |
8 | TextRange, TextSize, | 8 | TextRange, TextSize, |
diff --git a/crates/completion/src/complete_trait_impl.rs b/crates/completion/src/complete_trait_impl.rs index c06af99e2..a14be9c73 100644 --- a/crates/completion/src/complete_trait_impl.rs +++ b/crates/completion/src/complete_trait_impl.rs | |||
@@ -31,8 +31,8 @@ | |||
31 | //! } | 31 | //! } |
32 | //! ``` | 32 | //! ``` |
33 | 33 | ||
34 | use assists::utils::get_missing_assoc_items; | ||
35 | use hir::{self, HasAttrs, HasSource}; | 34 | use hir::{self, HasAttrs, HasSource}; |
35 | use ide_db::traits::get_missing_assoc_items; | ||
36 | use syntax::{ | 36 | use syntax::{ |
37 | ast::{self, edit, Impl}, | 37 | ast::{self, edit, Impl}, |
38 | display::function_declaration, | 38 | display::function_declaration, |
diff --git a/crates/completion/src/completion_context.rs b/crates/completion/src/completion_context.rs index e4f86d0e0..dca304a8f 100644 --- a/crates/completion/src/completion_context.rs +++ b/crates/completion/src/completion_context.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | //! See `CompletionContext` structure. | 1 | //! See `CompletionContext` structure. |
2 | 2 | ||
3 | use base_db::{FilePosition, SourceDatabase}; | ||
4 | use call_info::ActiveParameter; | ||
5 | use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type}; | 3 | use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type}; |
6 | use ide_db::RootDatabase; | 4 | use ide_db::base_db::{FilePosition, SourceDatabase}; |
5 | use ide_db::{call_info::ActiveParameter, RootDatabase}; | ||
7 | use syntax::{ | 6 | use syntax::{ |
8 | algo::{find_covering_element, find_node_at_offset}, | 7 | algo::{find_covering_element, find_node_at_offset}, |
9 | ast, match_ast, AstNode, NodeOrToken, | 8 | ast, match_ast, AstNode, NodeOrToken, |
diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 0a60ea7f2..b72fd249d 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs | |||
@@ -23,7 +23,7 @@ mod complete_macro_in_item_position; | |||
23 | mod complete_trait_impl; | 23 | mod complete_trait_impl; |
24 | mod complete_mod; | 24 | mod complete_mod; |
25 | 25 | ||
26 | use base_db::FilePosition; | 26 | use ide_db::base_db::FilePosition; |
27 | use ide_db::RootDatabase; | 27 | use ide_db::RootDatabase; |
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index f2cf2561f..b02556797 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Runs completion for testing purposes. | 1 | //! Runs completion for testing purposes. |
2 | 2 | ||
3 | use base_db::{fixture::ChangeFixture, FileLoader, FilePosition}; | ||
4 | use hir::Semantics; | 3 | use hir::Semantics; |
4 | use ide_db::base_db::{fixture::ChangeFixture, FileLoader, FilePosition}; | ||
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use itertools::Itertools; | 6 | use itertools::Itertools; |
7 | use stdx::{format_to, trim_indent}; | 7 | use stdx::{format_to, trim_indent}; |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index e9c62c6aa..367a1b98d 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -17,9 +17,9 @@ ena = "0.14.0" | |||
17 | log = "0.4.8" | 17 | log = "0.4.8" |
18 | rustc-hash = "1.1.0" | 18 | rustc-hash = "1.1.0" |
19 | scoped-tls = "1" | 19 | scoped-tls = "1" |
20 | chalk-solve = "0.33" | 20 | chalk-solve = { version = "0.34", default-features = false } |
21 | chalk-ir = "0.33" | 21 | chalk-ir = "0.34" |
22 | chalk-recursive = "0.33" | 22 | chalk-recursive = "0.34" |
23 | 23 | ||
24 | stdx = { path = "../stdx", version = "0.0.0" } | 24 | stdx = { path = "../stdx", version = "0.0.0" } |
25 | hir_def = { path = "../hir_def", version = "0.0.0" } | 25 | hir_def = { path = "../hir_def", version = "0.0.0" } |
diff --git a/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs index 324d60765..b0144a289 100644 --- a/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs +++ b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs | |||
@@ -1,156 +1,145 @@ | |||
1 | //! Functions for string case manipulation, such as detecting the identifier case, | 1 | //! Functions for string case manipulation, such as detecting the identifier case, |
2 | //! and converting it into appropriate form. | 2 | //! and converting it into appropriate form. |
3 | 3 | ||
4 | #[derive(Debug)] | 4 | // Code that was taken from rustc was taken at commit 89fdb30, |
5 | enum DetectedCase { | 5 | // from file /compiler/rustc_lint/src/nonstandard_style.rs |
6 | LowerCamelCase, | ||
7 | UpperCamelCase, | ||
8 | LowerSnakeCase, | ||
9 | UpperSnakeCase, | ||
10 | Unknown, | ||
11 | } | ||
12 | |||
13 | fn detect_case(ident: &str) -> DetectedCase { | ||
14 | let trimmed_ident = ident.trim_matches('_'); | ||
15 | let first_lowercase = trimmed_ident.starts_with(|chr: char| chr.is_ascii_lowercase()); | ||
16 | let mut has_lowercase = first_lowercase; | ||
17 | let mut has_uppercase = false; | ||
18 | let mut has_underscore = false; | ||
19 | |||
20 | for chr in trimmed_ident.chars() { | ||
21 | if chr == '_' { | ||
22 | has_underscore = true; | ||
23 | } else if chr.is_ascii_uppercase() { | ||
24 | has_uppercase = true; | ||
25 | } else if chr.is_ascii_lowercase() { | ||
26 | has_lowercase = true; | ||
27 | } | ||
28 | } | ||
29 | |||
30 | if has_uppercase { | ||
31 | if !has_lowercase { | ||
32 | if has_underscore { | ||
33 | DetectedCase::UpperSnakeCase | ||
34 | } else { | ||
35 | // It has uppercase only and no underscores. Ex: "AABB" | ||
36 | // This is a camel cased acronym. | ||
37 | DetectedCase::UpperCamelCase | ||
38 | } | ||
39 | } else if !has_underscore { | ||
40 | if first_lowercase { | ||
41 | DetectedCase::LowerCamelCase | ||
42 | } else { | ||
43 | DetectedCase::UpperCamelCase | ||
44 | } | ||
45 | } else { | ||
46 | // It has uppercase, it has lowercase, it has underscore. | ||
47 | // No assumptions here | ||
48 | DetectedCase::Unknown | ||
49 | } | ||
50 | } else { | ||
51 | DetectedCase::LowerSnakeCase | ||
52 | } | ||
53 | } | ||
54 | 6 | ||
55 | /// Converts an identifier to an UpperCamelCase form. | 7 | /// Converts an identifier to an UpperCamelCase form. |
56 | /// Returns `None` if the string is already is UpperCamelCase. | 8 | /// Returns `None` if the string is already is UpperCamelCase. |
57 | pub fn to_camel_case(ident: &str) -> Option<String> { | 9 | pub fn to_camel_case(ident: &str) -> Option<String> { |
58 | let detected_case = detect_case(ident); | 10 | if is_camel_case(ident) { |
59 | 11 | return None; | |
60 | match detected_case { | ||
61 | DetectedCase::UpperCamelCase => return None, | ||
62 | DetectedCase::LowerCamelCase => { | ||
63 | let mut first_capitalized = false; | ||
64 | let output = ident | ||
65 | .chars() | ||
66 | .map(|chr| { | ||
67 | if !first_capitalized && chr.is_ascii_lowercase() { | ||
68 | first_capitalized = true; | ||
69 | chr.to_ascii_uppercase() | ||
70 | } else { | ||
71 | chr | ||
72 | } | ||
73 | }) | ||
74 | .collect(); | ||
75 | return Some(output); | ||
76 | } | ||
77 | _ => {} | ||
78 | } | 12 | } |
79 | 13 | ||
80 | let mut output = String::with_capacity(ident.len()); | 14 | // Taken from rustc. |
81 | 15 | let ret = ident | |
82 | let mut capital_added = false; | 16 | .trim_matches('_') |
83 | for chr in ident.chars() { | 17 | .split('_') |
84 | if chr.is_alphabetic() { | 18 | .filter(|component| !component.is_empty()) |
85 | if !capital_added { | 19 | .map(|component| { |
86 | output.push(chr.to_ascii_uppercase()); | 20 | let mut camel_cased_component = String::new(); |
87 | capital_added = true; | 21 | |
88 | } else { | 22 | let mut new_word = true; |
89 | output.push(chr.to_ascii_lowercase()); | 23 | let mut prev_is_lower_case = true; |
24 | |||
25 | for c in component.chars() { | ||
26 | // Preserve the case if an uppercase letter follows a lowercase letter, so that | ||
27 | // `camelCase` is converted to `CamelCase`. | ||
28 | if prev_is_lower_case && c.is_uppercase() { | ||
29 | new_word = true; | ||
30 | } | ||
31 | |||
32 | if new_word { | ||
33 | camel_cased_component.push_str(&c.to_uppercase().to_string()); | ||
34 | } else { | ||
35 | camel_cased_component.push_str(&c.to_lowercase().to_string()); | ||
36 | } | ||
37 | |||
38 | prev_is_lower_case = c.is_lowercase(); | ||
39 | new_word = false; | ||
90 | } | 40 | } |
91 | } else if chr == '_' { | ||
92 | // Skip this character and make the next one capital. | ||
93 | capital_added = false; | ||
94 | } else { | ||
95 | // Put the characted as-is. | ||
96 | output.push(chr); | ||
97 | } | ||
98 | } | ||
99 | 41 | ||
100 | if output == ident { | 42 | camel_cased_component |
101 | // While we didn't detect the correct case at the beginning, there | 43 | }) |
102 | // may be special cases: e.g. `A` is both valid CamelCase and UPPER_SNAKE_CASE. | 44 | .fold((String::new(), None), |(acc, prev): (String, Option<String>), next| { |
103 | None | 45 | // separate two components with an underscore if their boundary cannot |
104 | } else { | 46 | // be distinguished using a uppercase/lowercase case distinction |
105 | Some(output) | 47 | let join = if let Some(prev) = prev { |
106 | } | 48 | let l = prev.chars().last().unwrap(); |
49 | let f = next.chars().next().unwrap(); | ||
50 | !char_has_case(l) && !char_has_case(f) | ||
51 | } else { | ||
52 | false | ||
53 | }; | ||
54 | (acc + if join { "_" } else { "" } + &next, Some(next)) | ||
55 | }) | ||
56 | .0; | ||
57 | Some(ret) | ||
107 | } | 58 | } |
108 | 59 | ||
109 | /// Converts an identifier to a lower_snake_case form. | 60 | /// Converts an identifier to a lower_snake_case form. |
110 | /// Returns `None` if the string is already in lower_snake_case. | 61 | /// Returns `None` if the string is already in lower_snake_case. |
111 | pub fn to_lower_snake_case(ident: &str) -> Option<String> { | 62 | pub fn to_lower_snake_case(ident: &str) -> Option<String> { |
112 | // First, assume that it's UPPER_SNAKE_CASE. | 63 | if is_lower_snake_case(ident) { |
113 | match detect_case(ident) { | 64 | return None; |
114 | DetectedCase::LowerSnakeCase => return None, | 65 | } else if is_upper_snake_case(ident) { |
115 | DetectedCase::UpperSnakeCase => { | 66 | return Some(ident.to_lowercase()); |
116 | return Some(ident.chars().map(|chr| chr.to_ascii_lowercase()).collect()) | ||
117 | } | ||
118 | _ => {} | ||
119 | } | 67 | } |
120 | 68 | ||
121 | // Otherwise, assume that it's CamelCase. | 69 | Some(stdx::to_lower_snake_case(ident)) |
122 | let lower_snake_case = stdx::to_lower_snake_case(ident); | ||
123 | |||
124 | if lower_snake_case == ident { | ||
125 | // While we didn't detect the correct case at the beginning, there | ||
126 | // may be special cases: e.g. `a` is both valid camelCase and snake_case. | ||
127 | None | ||
128 | } else { | ||
129 | Some(lower_snake_case) | ||
130 | } | ||
131 | } | 70 | } |
132 | 71 | ||
133 | /// Converts an identifier to an UPPER_SNAKE_CASE form. | 72 | /// Converts an identifier to an UPPER_SNAKE_CASE form. |
134 | /// Returns `None` if the string is already is UPPER_SNAKE_CASE. | 73 | /// Returns `None` if the string is already is UPPER_SNAKE_CASE. |
135 | pub fn to_upper_snake_case(ident: &str) -> Option<String> { | 74 | pub fn to_upper_snake_case(ident: &str) -> Option<String> { |
136 | match detect_case(ident) { | 75 | if is_upper_snake_case(ident) { |
137 | DetectedCase::UpperSnakeCase => return None, | 76 | return None; |
138 | DetectedCase::LowerSnakeCase => { | 77 | } else if is_lower_snake_case(ident) { |
139 | return Some(ident.chars().map(|chr| chr.to_ascii_uppercase()).collect()) | 78 | return Some(ident.to_uppercase()); |
140 | } | 79 | } |
141 | _ => {} | 80 | |
81 | Some(stdx::to_upper_snake_case(ident)) | ||
82 | } | ||
83 | |||
84 | // Taken from rustc. | ||
85 | // Modified by replacing the use of unstable feature `array_windows`. | ||
86 | fn is_camel_case(name: &str) -> bool { | ||
87 | let name = name.trim_matches('_'); | ||
88 | if name.is_empty() { | ||
89 | return true; | ||
142 | } | 90 | } |
143 | 91 | ||
144 | // Normalize the string from whatever form it's in currently, and then just make it uppercase. | 92 | let mut fst = None; |
145 | let upper_snake_case = stdx::to_upper_snake_case(ident); | 93 | // start with a non-lowercase letter rather than non-uppercase |
94 | // ones (some scripts don't have a concept of upper/lowercase) | ||
95 | !name.chars().next().unwrap().is_lowercase() | ||
96 | && !name.contains("__") | ||
97 | && !name.chars().any(|snd| { | ||
98 | let ret = match (fst, snd) { | ||
99 | (None, _) => false, | ||
100 | (Some(fst), snd) => { | ||
101 | char_has_case(fst) && snd == '_' || char_has_case(snd) && fst == '_' | ||
102 | } | ||
103 | }; | ||
104 | fst = Some(snd); | ||
105 | |||
106 | ret | ||
107 | }) | ||
108 | } | ||
109 | |||
110 | fn is_lower_snake_case(ident: &str) -> bool { | ||
111 | is_snake_case(ident, char::is_uppercase) | ||
112 | } | ||
146 | 113 | ||
147 | if upper_snake_case == ident { | 114 | fn is_upper_snake_case(ident: &str) -> bool { |
148 | // While we didn't detect the correct case at the beginning, there | 115 | is_snake_case(ident, char::is_lowercase) |
149 | // may be special cases: e.g. `A` is both valid CamelCase and UPPER_SNAKE_CASE. | 116 | } |
150 | None | 117 | |
151 | } else { | 118 | // Taken from rustc. |
152 | Some(upper_snake_case) | 119 | // Modified to allow checking for both upper and lower snake case. |
120 | fn is_snake_case<F: Fn(char) -> bool>(ident: &str, wrong_case: F) -> bool { | ||
121 | if ident.is_empty() { | ||
122 | return true; | ||
153 | } | 123 | } |
124 | let ident = ident.trim_matches('_'); | ||
125 | |||
126 | let mut allow_underscore = true; | ||
127 | ident.chars().all(|c| { | ||
128 | allow_underscore = match c { | ||
129 | '_' if !allow_underscore => return false, | ||
130 | '_' => false, | ||
131 | // It would be more obvious to check for the correct case, | ||
132 | // but some characters do not have a case. | ||
133 | c if !wrong_case(c) => true, | ||
134 | _ => return false, | ||
135 | }; | ||
136 | true | ||
137 | }) | ||
138 | } | ||
139 | |||
140 | // Taken from rustc. | ||
141 | fn char_has_case(c: char) -> bool { | ||
142 | c.is_lowercase() || c.is_uppercase() | ||
154 | } | 143 | } |
155 | 144 | ||
156 | #[cfg(test)] | 145 | #[cfg(test)] |
@@ -173,6 +162,7 @@ mod tests { | |||
173 | check(to_lower_snake_case, "CamelCase", expect![["camel_case"]]); | 162 | check(to_lower_snake_case, "CamelCase", expect![["camel_case"]]); |
174 | check(to_lower_snake_case, "lowerCamelCase", expect![["lower_camel_case"]]); | 163 | check(to_lower_snake_case, "lowerCamelCase", expect![["lower_camel_case"]]); |
175 | check(to_lower_snake_case, "a", expect![[""]]); | 164 | check(to_lower_snake_case, "a", expect![[""]]); |
165 | check(to_lower_snake_case, "abc", expect![[""]]); | ||
176 | } | 166 | } |
177 | 167 | ||
178 | #[test] | 168 | #[test] |
@@ -187,6 +177,11 @@ mod tests { | |||
187 | check(to_camel_case, "name", expect![["Name"]]); | 177 | check(to_camel_case, "name", expect![["Name"]]); |
188 | check(to_camel_case, "A", expect![[""]]); | 178 | check(to_camel_case, "A", expect![[""]]); |
189 | check(to_camel_case, "AABB", expect![[""]]); | 179 | check(to_camel_case, "AABB", expect![[""]]); |
180 | // Taken from rustc: /compiler/rustc_lint/src/nonstandard_style/tests.rs | ||
181 | check(to_camel_case, "X86_64", expect![[""]]); | ||
182 | check(to_camel_case, "x86__64", expect![["X86_64"]]); | ||
183 | check(to_camel_case, "Abc_123", expect![["Abc123"]]); | ||
184 | check(to_camel_case, "A1_b2_c3", expect![["A1B2C3"]]); | ||
190 | } | 185 | } |
191 | 186 | ||
192 | #[test] | 187 | #[test] |
@@ -197,5 +192,7 @@ mod tests { | |||
197 | check(to_upper_snake_case, "CamelCase", expect![["CAMEL_CASE"]]); | 192 | check(to_upper_snake_case, "CamelCase", expect![["CAMEL_CASE"]]); |
198 | check(to_upper_snake_case, "lowerCamelCase", expect![["LOWER_CAMEL_CASE"]]); | 193 | check(to_upper_snake_case, "lowerCamelCase", expect![["LOWER_CAMEL_CASE"]]); |
199 | check(to_upper_snake_case, "A", expect![[""]]); | 194 | check(to_upper_snake_case, "A", expect![[""]]); |
195 | check(to_upper_snake_case, "ABC", expect![[""]]); | ||
196 | check(to_upper_snake_case, "X86_64", expect![[""]]); | ||
200 | } | 197 | } |
201 | } | 198 | } |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index be3301313..dd7affcec 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -4,8 +4,8 @@ | |||
4 | //! conversions. | 4 | //! conversions. |
5 | 5 | ||
6 | use chalk_ir::{ | 6 | use chalk_ir::{ |
7 | cast::Cast, fold::shift::Shift, interner::HasInterner, PlaceholderIndex, Scalar, TypeName, | 7 | cast::Cast, fold::shift::Shift, interner::HasInterner, LifetimeData, PlaceholderIndex, Scalar, |
8 | UniverseIndex, | 8 | TypeName, UniverseIndex, |
9 | }; | 9 | }; |
10 | use chalk_solve::rust_ir; | 10 | use chalk_solve::rust_ir; |
11 | 11 | ||
@@ -76,7 +76,7 @@ impl ToChalk for Ty { | |||
76 | ); | 76 | ); |
77 | let bounded_ty = chalk_ir::DynTy { | 77 | let bounded_ty = chalk_ir::DynTy { |
78 | bounds: make_binders(where_clauses, 1), | 78 | bounds: make_binders(where_clauses, 1), |
79 | lifetime: FAKE_PLACEHOLDER.to_lifetime(&Interner), | 79 | lifetime: LifetimeData::Static.intern(&Interner), |
80 | }; | 80 | }; |
81 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) | 81 | chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) |
82 | } | 82 | } |
@@ -161,9 +161,6 @@ impl ToChalk for Ty { | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | const FAKE_PLACEHOLDER: PlaceholderIndex = | ||
165 | PlaceholderIndex { ui: UniverseIndex::ROOT, idx: usize::MAX }; | ||
166 | |||
167 | /// We currently don't model lifetimes, but Chalk does. So, we have to insert a | 164 | /// We currently don't model lifetimes, but Chalk does. So, we have to insert a |
168 | /// fake lifetime here, because Chalks built-in logic may expect it to be there. | 165 | /// fake lifetime here, because Chalks built-in logic may expect it to be there. |
169 | fn ref_to_chalk( | 166 | fn ref_to_chalk( |
@@ -172,7 +169,7 @@ fn ref_to_chalk( | |||
172 | subst: Substs, | 169 | subst: Substs, |
173 | ) -> chalk_ir::Ty<Interner> { | 170 | ) -> chalk_ir::Ty<Interner> { |
174 | let arg = subst[0].clone().to_chalk(db); | 171 | let arg = subst[0].clone().to_chalk(db); |
175 | let lifetime = FAKE_PLACEHOLDER.to_lifetime(&Interner); | 172 | let lifetime = LifetimeData::Static.intern(&Interner); |
176 | chalk_ir::ApplicationTy { | 173 | chalk_ir::ApplicationTy { |
177 | name: TypeName::Ref(mutability.to_chalk(db)), | 174 | name: TypeName::Ref(mutability.to_chalk(db)), |
178 | substitution: chalk_ir::Substitution::from_iter( | 175 | substitution: chalk_ir::Substitution::from_iter( |
@@ -205,7 +202,11 @@ fn array_to_chalk(db: &dyn HirDatabase, subst: Substs) -> chalk_ir::Ty<Interner> | |||
205 | substitution: chalk_ir::Substitution::empty(&Interner), | 202 | substitution: chalk_ir::Substitution::empty(&Interner), |
206 | } | 203 | } |
207 | .intern(&Interner); | 204 | .intern(&Interner); |
208 | let const_ = FAKE_PLACEHOLDER.to_const(&Interner, usize_ty); | 205 | let const_ = chalk_ir::ConstData { |
206 | ty: usize_ty, | ||
207 | value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: () }), | ||
208 | } | ||
209 | .intern(&Interner); | ||
209 | chalk_ir::ApplicationTy { | 210 | chalk_ir::ApplicationTy { |
210 | name: TypeName::Array, | 211 | name: TypeName::Array, |
211 | substitution: chalk_ir::Substitution::from_iter( | 212 | substitution: chalk_ir::Substitution::from_iter( |
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 76b52fa04..4d483580d 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml | |||
@@ -23,14 +23,12 @@ url = "2.1.1" | |||
23 | stdx = { path = "../stdx", version = "0.0.0" } | 23 | stdx = { path = "../stdx", version = "0.0.0" } |
24 | syntax = { path = "../syntax", version = "0.0.0" } | 24 | syntax = { path = "../syntax", version = "0.0.0" } |
25 | text_edit = { path = "../text_edit", version = "0.0.0" } | 25 | text_edit = { path = "../text_edit", version = "0.0.0" } |
26 | base_db = { path = "../base_db", version = "0.0.0" } | ||
27 | ide_db = { path = "../ide_db", version = "0.0.0" } | 26 | ide_db = { path = "../ide_db", version = "0.0.0" } |
28 | cfg = { path = "../cfg", version = "0.0.0" } | 27 | cfg = { path = "../cfg", version = "0.0.0" } |
29 | profile = { path = "../profile", version = "0.0.0" } | 28 | profile = { path = "../profile", version = "0.0.0" } |
30 | test_utils = { path = "../test_utils", version = "0.0.0" } | 29 | test_utils = { path = "../test_utils", version = "0.0.0" } |
31 | assists = { path = "../assists", version = "0.0.0" } | 30 | assists = { path = "../assists", version = "0.0.0" } |
32 | ssr = { path = "../ssr", version = "0.0.0" } | 31 | ssr = { path = "../ssr", version = "0.0.0" } |
33 | call_info = { path = "../call_info", version = "0.0.0" } | ||
34 | completion = { path = "../completion", version = "0.0.0" } | 32 | completion = { path = "../completion", version = "0.0.0" } |
35 | 33 | ||
36 | # ide should depend only on the top-level `hir` package. if you need | 34 | # ide should depend only on the top-level `hir` package. if you need |
diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 9d6433fe0..8ad50a2ee 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs | |||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | use indexmap::IndexMap; | 3 | use indexmap::IndexMap; |
4 | 4 | ||
5 | use call_info::FnCallNode; | ||
6 | use hir::Semantics; | 5 | use hir::Semantics; |
6 | use ide_db::call_info::FnCallNode; | ||
7 | use ide_db::RootDatabase; | 7 | use ide_db::RootDatabase; |
8 | use syntax::{ast, match_ast, AstNode, TextRange}; | 8 | use syntax::{ast, match_ast, AstNode, TextRange}; |
9 | 9 | ||
@@ -137,7 +137,7 @@ impl CallLocations { | |||
137 | 137 | ||
138 | #[cfg(test)] | 138 | #[cfg(test)] |
139 | mod tests { | 139 | mod tests { |
140 | use base_db::FilePosition; | 140 | use ide_db::base_db::FilePosition; |
141 | 141 | ||
142 | use crate::fixture; | 142 | use crate::fixture; |
143 | 143 | ||
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 232074c3d..d0ee58858 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -9,11 +9,11 @@ mod field_shorthand; | |||
9 | 9 | ||
10 | use std::cell::RefCell; | 10 | use std::cell::RefCell; |
11 | 11 | ||
12 | use base_db::SourceDatabase; | ||
13 | use hir::{ | 12 | use hir::{ |
14 | diagnostics::{Diagnostic as _, DiagnosticSinkBuilder}, | 13 | diagnostics::{Diagnostic as _, DiagnosticSinkBuilder}, |
15 | Semantics, | 14 | Semantics, |
16 | }; | 15 | }; |
16 | use ide_db::base_db::SourceDatabase; | ||
17 | use ide_db::RootDatabase; | 17 | use ide_db::RootDatabase; |
18 | use itertools::Itertools; | 18 | use itertools::Itertools; |
19 | use rustc_hash::FxHashSet; | 19 | use rustc_hash::FxHashSet; |
diff --git a/crates/ide/src/diagnostics/field_shorthand.rs b/crates/ide/src/diagnostics/field_shorthand.rs index 54e9fce9e..f41bcd619 100644 --- a/crates/ide/src/diagnostics/field_shorthand.rs +++ b/crates/ide/src/diagnostics/field_shorthand.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both | 1 | //! Suggests shortening `Foo { field: field }` to `Foo { field }` in both |
2 | //! expressions and patterns. | 2 | //! expressions and patterns. |
3 | 3 | ||
4 | use base_db::FileId; | 4 | use ide_db::base_db::FileId; |
5 | use ide_db::source_change::SourceFileEdit; | 5 | use ide_db::source_change::SourceFileEdit; |
6 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; | 6 | use syntax::{ast, match_ast, AstNode, SyntaxNode}; |
7 | use text_edit::TextEdit; | 7 | use text_edit::TextEdit; |
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 0c75e50b0..0c950003e 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! Provides a way to attach fixes to the diagnostics. | 1 | //! Provides a way to attach fixes to the diagnostics. |
2 | //! The same module also has all curret custom fixes for the diagnostics implemented. | 2 | //! The same module also has all curret custom fixes for the diagnostics implemented. |
3 | use base_db::FileId; | ||
4 | use hir::{ | 3 | use hir::{ |
5 | db::AstDatabase, | 4 | db::AstDatabase, |
6 | diagnostics::{ | 5 | diagnostics::{ |
@@ -9,6 +8,7 @@ use hir::{ | |||
9 | }, | 8 | }, |
10 | HasSource, HirDisplay, Semantics, VariantDef, | 9 | HasSource, HirDisplay, Semantics, VariantDef, |
11 | }; | 10 | }; |
11 | use ide_db::base_db::FileId; | ||
12 | use ide_db::{ | 12 | use ide_db::{ |
13 | source_change::{FileSystemEdit, SourceFileEdit}, | 13 | source_change::{FileSystemEdit, SourceFileEdit}, |
14 | RootDatabase, | 14 | RootDatabase, |
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index cf9d617dc..0c429a262 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use base_db::{FileId, SourceDatabase}; | ||
4 | use either::Either; | 3 | use either::Either; |
5 | use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; | 4 | use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource}; |
5 | use ide_db::base_db::{FileId, SourceDatabase}; | ||
6 | use ide_db::{defs::Definition, RootDatabase}; | 6 | use ide_db::{defs::Definition, RootDatabase}; |
7 | use syntax::{ | 7 | use syntax::{ |
8 | ast::{self, DocCommentsOwner, NameOwner}, | 8 | ast::{self, DocCommentsOwner, NameOwner}, |
diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs index ed06689f0..eb57f9224 100644 --- a/crates/ide/src/fixture.rs +++ b/crates/ide/src/fixture.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | //! Utilities for creating `Analysis` instances for tests. | 1 | //! Utilities for creating `Analysis` instances for tests. |
2 | use base_db::fixture::ChangeFixture; | 2 | use ide_db::base_db::fixture::ChangeFixture; |
3 | use test_utils::{extract_annotations, RangeOrOffset}; | 3 | use test_utils::{extract_annotations, RangeOrOffset}; |
4 | 4 | ||
5 | use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; | 5 | use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; |
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index a87e31019..15792f947 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs | |||
@@ -100,7 +100,7 @@ pub(crate) fn reference_definition( | |||
100 | 100 | ||
101 | #[cfg(test)] | 101 | #[cfg(test)] |
102 | mod tests { | 102 | mod tests { |
103 | use base_db::FileRange; | 103 | use ide_db::base_db::FileRange; |
104 | use syntax::{TextRange, TextSize}; | 104 | use syntax::{TextRange, TextSize}; |
105 | 105 | ||
106 | use crate::fixture; | 106 | use crate::fixture; |
diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 6c586bbd1..529004878 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs | |||
@@ -74,7 +74,7 @@ fn impls_for_trait( | |||
74 | 74 | ||
75 | #[cfg(test)] | 75 | #[cfg(test)] |
76 | mod tests { | 76 | mod tests { |
77 | use base_db::FileRange; | 77 | use ide_db::base_db::FileRange; |
78 | 78 | ||
79 | use crate::fixture; | 79 | use crate::fixture; |
80 | 80 | ||
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index 6d0df04dd..aba6bf5dc 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs | |||
@@ -54,7 +54,7 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | |||
54 | 54 | ||
55 | #[cfg(test)] | 55 | #[cfg(test)] |
56 | mod tests { | 56 | mod tests { |
57 | use base_db::FileRange; | 57 | use ide_db::base_db::FileRange; |
58 | 58 | ||
59 | use crate::fixture; | 59 | use crate::fixture; |
60 | 60 | ||
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 0332c7be0..832192881 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use base_db::SourceDatabase; | ||
2 | use hir::{ | 1 | use hir::{ |
3 | Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, | 2 | Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, |
4 | Module, ModuleDef, ModuleSource, Semantics, | 3 | Module, ModuleDef, ModuleSource, Semantics, |
5 | }; | 4 | }; |
5 | use ide_db::base_db::SourceDatabase; | ||
6 | use ide_db::{ | 6 | use ide_db::{ |
7 | defs::{Definition, NameClass, NameRefClass}, | 7 | defs::{Definition, NameClass, NameRefClass}, |
8 | RootDatabase, | 8 | RootDatabase, |
@@ -385,8 +385,8 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> { | |||
385 | 385 | ||
386 | #[cfg(test)] | 386 | #[cfg(test)] |
387 | mod tests { | 387 | mod tests { |
388 | use base_db::FileLoader; | ||
389 | use expect_test::{expect, Expect}; | 388 | use expect_test::{expect, Expect}; |
389 | use ide_db::base_db::FileLoader; | ||
390 | 390 | ||
391 | use crate::fixture; | 391 | use crate::fixture; |
392 | 392 | ||
@@ -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"#] | ||
645 | pub fn foo<|>(_: &Path) {} | ||
646 | |||
647 | fn 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/src/lib.rs b/crates/ide/src/lib.rs index cecfae4c7..4bc733b70 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -48,11 +48,11 @@ mod doc_links; | |||
48 | 48 | ||
49 | use std::sync::Arc; | 49 | use std::sync::Arc; |
50 | 50 | ||
51 | use base_db::{ | 51 | use cfg::CfgOptions; |
52 | use ide_db::base_db::{ | ||
52 | salsa::{self, ParallelDatabase}, | 53 | salsa::{self, ParallelDatabase}, |
53 | CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, | 54 | CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, |
54 | }; | 55 | }; |
55 | use cfg::CfgOptions; | ||
56 | use ide_db::{ | 56 | use ide_db::{ |
57 | symbol_index::{self, FileSymbol}, | 57 | symbol_index::{self, FileSymbol}, |
58 | LineIndexDatabase, | 58 | LineIndexDatabase, |
@@ -80,19 +80,19 @@ pub use crate::{ | |||
80 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, | 80 | Highlight, HighlightModifier, HighlightModifiers, HighlightTag, HighlightedRange, |
81 | }, | 81 | }, |
82 | }; | 82 | }; |
83 | pub use call_info::CallInfo; | ||
84 | pub use completion::{ | 83 | pub use completion::{ |
85 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 84 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
86 | }; | 85 | }; |
86 | pub use ide_db::call_info::CallInfo; | ||
87 | 87 | ||
88 | pub use assists::{ | 88 | pub use assists::{ |
89 | utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, | 89 | utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, |
90 | }; | 90 | }; |
91 | pub use base_db::{ | 91 | pub use hir::{Documentation, Semantics}; |
92 | pub use ide_db::base_db::{ | ||
92 | Canceled, Change, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, | 93 | Canceled, Change, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, |
93 | SourceRootId, | 94 | SourceRootId, |
94 | }; | 95 | }; |
95 | pub use hir::{Documentation, Semantics}; | ||
96 | pub use ide_db::{ | 96 | pub use ide_db::{ |
97 | label::Label, | 97 | label::Label, |
98 | line_index::{LineCol, LineIndex}, | 98 | line_index::{LineCol, LineIndex}, |
@@ -396,7 +396,7 @@ impl Analysis { | |||
396 | 396 | ||
397 | /// Computes parameter information for the given call expression. | 397 | /// Computes parameter information for the given call expression. |
398 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 398 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
399 | self.with_db(|db| call_info::call_info(db, position)) | 399 | self.with_db(|db| ide_db::call_info::call_info(db, position)) |
400 | } | 400 | } |
401 | 401 | ||
402 | /// Computes call hierarchy candidates for the given file position. | 402 | /// Computes call hierarchy candidates for the given file position. |
diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index ef94acfec..6cc3b2991 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use base_db::{CrateId, FileId, FilePosition}; | ||
2 | use hir::Semantics; | 1 | use hir::Semantics; |
2 | use ide_db::base_db::{CrateId, FileId, FilePosition}; | ||
3 | use ide_db::RootDatabase; | 3 | use ide_db::RootDatabase; |
4 | use syntax::{ | 4 | use syntax::{ |
5 | algo::find_node_at_offset, | 5 | algo::find_node_at_offset, |
diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs index 6944dbcd2..ea0acfaa0 100644 --- a/crates/ide/src/prime_caches.rs +++ b/crates/ide/src/prime_caches.rs | |||
@@ -3,8 +3,8 @@ | |||
3 | //! request takes longer to compute. This modules implemented prepopulating of | 3 | //! request takes longer to compute. This modules implemented prepopulating of |
4 | //! various caches, it's not really advanced at the moment. | 4 | //! various caches, it's not really advanced at the moment. |
5 | 5 | ||
6 | use base_db::SourceDatabase; | ||
7 | use hir::db::DefDatabase; | 6 | use hir::db::DefDatabase; |
7 | use ide_db::base_db::SourceDatabase; | ||
8 | 8 | ||
9 | use crate::RootDatabase; | 9 | use crate::RootDatabase; |
10 | 10 | ||
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 67ec257a8..a517081d5 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs | |||
@@ -191,8 +191,8 @@ fn get_struct_def_name_for_struct_literal_search( | |||
191 | 191 | ||
192 | #[cfg(test)] | 192 | #[cfg(test)] |
193 | mod tests { | 193 | mod tests { |
194 | use base_db::FileId; | ||
195 | use expect_test::{expect, Expect}; | 194 | use expect_test::{expect, Expect}; |
195 | use ide_db::base_db::FileId; | ||
196 | use stdx::format_to; | 196 | use stdx::format_to; |
197 | 197 | ||
198 | use crate::{fixture, SearchScope}; | 198 | use crate::{fixture, SearchScope}; |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 35aafc49d..26ac2371a 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use base_db::SourceDatabaseExt; | ||
4 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; | 3 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; |
4 | use ide_db::base_db::SourceDatabaseExt; | ||
5 | use ide_db::{ | 5 | use ide_db::{ |
6 | defs::{Definition, NameClass, NameRefClass}, | 6 | defs::{Definition, NameClass, NameRefClass}, |
7 | RootDatabase, | 7 | RootDatabase, |
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index 0af84daa0..8e91c99d7 100644 --- a/crates/ide/src/status.rs +++ b/crates/ide/src/status.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | use std::{fmt, iter::FromIterator, sync::Arc}; | 1 | use std::{fmt, iter::FromIterator, sync::Arc}; |
2 | 2 | ||
3 | use base_db::{ | 3 | use hir::MacroFile; |
4 | use ide_db::base_db::{ | ||
4 | salsa::debug::{DebugQueryTable, TableEntry}, | 5 | salsa::debug::{DebugQueryTable, TableEntry}, |
5 | CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId, | 6 | CrateId, FileId, FileTextQuery, SourceDatabase, SourceRootId, |
6 | }; | 7 | }; |
7 | use hir::MacroFile; | ||
8 | use ide_db::{ | 8 | use ide_db::{ |
9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, | 9 | symbol_index::{LibrarySymbolsQuery, SymbolIndex}, |
10 | RootDatabase, | 10 | RootDatabase, |
@@ -16,7 +16,7 @@ use stdx::format_to; | |||
16 | use syntax::{ast, Parse, SyntaxNode}; | 16 | use syntax::{ast, Parse, SyntaxNode}; |
17 | 17 | ||
18 | fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | 18 | fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { |
19 | base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() | 19 | ide_db::base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>() |
20 | } | 20 | } |
21 | fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { | 21 | fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { |
22 | hir::db::ParseMacroQuery.in_db(db).entries::<SyntaxTreeStats>() | 22 | hir::db::ParseMacroQuery.in_db(db).entries::<SyntaxTreeStats>() |
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 750848467..9f864179e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -579,7 +579,14 @@ fn highlight_element( | |||
579 | } | 579 | } |
580 | } | 580 | } |
581 | T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | 581 | T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { |
582 | HighlightTag::NumericLiteral.into() | 582 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; |
583 | |||
584 | let expr = prefix_expr.expr()?; | ||
585 | match expr { | ||
586 | ast::Expr::Literal(_) => HighlightTag::NumericLiteral, | ||
587 | _ => HighlightTag::Operator, | ||
588 | } | ||
589 | .into() | ||
583 | } | 590 | } |
584 | _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | 591 | _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { |
585 | HighlightTag::Operator.into() | 592 | HighlightTag::Operator.into() |
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 57e2d2923..abcc5cccc 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Renders a bit of code as HTML. | 1 | //! Renders a bit of code as HTML. |
2 | 2 | ||
3 | use base_db::SourceDatabase; | 3 | use ide_db::base_db::SourceDatabase; |
4 | use oorandom::Rand32; | 4 | use oorandom::Rand32; |
5 | use stdx::format_to; | 5 | use stdx::format_to; |
6 | use syntax::{AstNode, TextRange, TextSize}; | 6 | use syntax::{AstNode, TextRange, TextSize}; |
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index acd91b26c..59a74bc02 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs | |||
@@ -3,8 +3,8 @@ | |||
3 | use std::{collections::BTreeMap, convert::TryFrom}; | 3 | use std::{collections::BTreeMap, convert::TryFrom}; |
4 | 4 | ||
5 | use ast::{HasQuotes, HasStringValue}; | 5 | use ast::{HasQuotes, HasStringValue}; |
6 | use call_info::ActiveParameter; | ||
7 | use hir::Semantics; | 6 | use hir::Semantics; |
7 | use ide_db::call_info::ActiveParameter; | ||
8 | use itertools::Itertools; | 8 | use itertools::Itertools; |
9 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 9 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
10 | 10 | ||
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0cb84866d..c6b4f5a00 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -176,6 +176,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
176 | 176 | ||
177 | <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span> | 177 | <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span> |
178 | <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span> | 178 | <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span> |
179 | |||
180 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="punctuation">;</span> | ||
181 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="operator">-</span><span class="variable">baz</span><span class="punctuation">;</span> | ||
179 | <span class="punctuation">}</span> | 182 | <span class="punctuation">}</span> |
180 | 183 | ||
181 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> | 184 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index da20c300e..dd43f9dd9 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -150,6 +150,9 @@ fn main() { | |||
150 | 150 | ||
151 | let a = |x| x; | 151 | let a = |x| x; |
152 | let bar = Foo::baz; | 152 | let bar = Foo::baz; |
153 | |||
154 | let baz = -42; | ||
155 | let baz = -baz; | ||
153 | } | 156 | } |
154 | 157 | ||
155 | enum Option<T> { | 158 | enum Option<T> { |
diff --git a/crates/ide/src/syntax_tree.rs b/crates/ide/src/syntax_tree.rs index 0eed2dbd7..7941610d6 100644 --- a/crates/ide/src/syntax_tree.rs +++ b/crates/ide/src/syntax_tree.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use base_db::{FileId, SourceDatabase}; | 1 | use ide_db::base_db::{FileId, SourceDatabase}; |
2 | use ide_db::RootDatabase; | 2 | use ide_db::RootDatabase; |
3 | use syntax::{ | 3 | use syntax::{ |
4 | algo, AstNode, NodeOrToken, SourceFile, | 4 | algo, AstNode, NodeOrToken, SourceFile, |
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index 94b91f049..43458a3a2 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | mod on_enter; | 16 | mod on_enter; |
17 | 17 | ||
18 | use base_db::{FilePosition, SourceDatabase}; | 18 | use ide_db::base_db::{FilePosition, SourceDatabase}; |
19 | use ide_db::{source_change::SourceFileEdit, RootDatabase}; | 19 | use ide_db::{source_change::SourceFileEdit, RootDatabase}; |
20 | use syntax::{ | 20 | use syntax::{ |
21 | algo::find_node_at_offset, | 21 | algo::find_node_at_offset, |
diff --git a/crates/ide/src/typing/on_enter.rs b/crates/ide/src/typing/on_enter.rs index 98adef1d6..f4ea30352 100644 --- a/crates/ide/src/typing/on_enter.rs +++ b/crates/ide/src/typing/on_enter.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Handles the `Enter` key press. At the momently, this only continues | 1 | //! Handles the `Enter` key press. At the momently, this only continues |
2 | //! comments, but should handle indent some time in the future as well. | 2 | //! comments, but should handle indent some time in the future as well. |
3 | 3 | ||
4 | use base_db::{FilePosition, SourceDatabase}; | 4 | use ide_db::base_db::{FilePosition, SourceDatabase}; |
5 | use ide_db::RootDatabase; | 5 | use ide_db::RootDatabase; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | ast::{self, AstToken}, | 7 | ast::{self, AstToken}, |
diff --git a/crates/ide_db/Cargo.toml b/crates/ide_db/Cargo.toml index 320fb15e5..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] |
16 | log = "0.4.8" | 16 | log = "0.4.8" |
17 | rayon = "1.3.0" | 17 | rayon = "1.5.0" |
18 | fst = { version = "0.4", default-features = false } | 18 | fst = { version = "0.4", default-features = false } |
19 | rustc-hash = "1.1.0" | 19 | rustc-hash = "1.1.0" |
20 | once_cell = "1.3.1" | 20 | once_cell = "1.3.1" |
@@ -29,3 +29,6 @@ test_utils = { path = "../test_utils", version = "0.0.0" } | |||
29 | # ide should depend only on the top-level `hir` package. if you need | 29 | # ide should depend only on the top-level `hir` package. if you need |
30 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | 30 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. |
31 | hir = { path = "../hir", version = "0.0.0" } | 31 | hir = { path = "../hir", version = "0.0.0" } |
32 | |||
33 | [dev-dependencies] | ||
34 | expect-test = "1.0" | ||
diff --git a/crates/call_info/src/lib.rs b/crates/ide_db/src/call_info.rs index c45406c25..83a602b9a 100644 --- a/crates/call_info/src/lib.rs +++ b/crates/ide_db/src/call_info.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | use base_db::FilePosition; | 2 | use base_db::FilePosition; |
3 | use either::Either; | 3 | use either::Either; |
4 | use hir::{HasAttrs, HirDisplay, Semantics, Type}; | 4 | use hir::{HasAttrs, HirDisplay, Semantics, Type}; |
5 | use ide_db::RootDatabase; | ||
6 | use stdx::format_to; | 5 | use stdx::format_to; |
7 | use syntax::{ | 6 | use syntax::{ |
8 | ast::{self, ArgListOwner}, | 7 | ast::{self, ArgListOwner}, |
@@ -10,6 +9,8 @@ use syntax::{ | |||
10 | }; | 9 | }; |
11 | use test_utils::mark; | 10 | use test_utils::mark; |
12 | 11 | ||
12 | use crate::RootDatabase; | ||
13 | |||
13 | /// Contains information about a call site. Specifically the | 14 | /// Contains information about a call site. Specifically the |
14 | /// `FunctionSignature`and current parameter. | 15 | /// `FunctionSignature`and current parameter. |
15 | #[derive(Debug)] | 16 | #[derive(Debug)] |
@@ -228,9 +229,9 @@ impl FnCallNode { | |||
228 | 229 | ||
229 | #[cfg(test)] | 230 | #[cfg(test)] |
230 | mod tests { | 231 | mod tests { |
232 | use crate::RootDatabase; | ||
231 | use base_db::{fixture::ChangeFixture, FilePosition}; | 233 | use base_db::{fixture::ChangeFixture, FilePosition}; |
232 | use expect_test::{expect, Expect}; | 234 | use expect_test::{expect, Expect}; |
233 | use ide_db::RootDatabase; | ||
234 | use test_utils::{mark, RangeOrOffset}; | 235 | use test_utils::{mark, RangeOrOffset}; |
235 | 236 | ||
236 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | 237 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. |
@@ -249,7 +250,7 @@ mod tests { | |||
249 | 250 | ||
250 | fn check(ra_fixture: &str, expect: Expect) { | 251 | fn check(ra_fixture: &str, expect: Expect) { |
251 | let (db, position) = position(ra_fixture); | 252 | let (db, position) = position(ra_fixture); |
252 | let call_info = crate::call_info(&db, position); | 253 | let call_info = crate::call_info::call_info(&db, position); |
253 | let actual = match call_info { | 254 | let actual = match call_info { |
254 | Some(call_info) => { | 255 | Some(call_info) => { |
255 | let docs = match &call_info.doc { | 256 | let docs = match &call_info.doc { |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 7eff247c7..38ebdbf79 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -10,6 +10,9 @@ pub mod defs; | |||
10 | pub mod search; | 10 | pub mod search; |
11 | pub mod imports_locator; | 11 | pub mod imports_locator; |
12 | pub mod source_change; | 12 | pub mod source_change; |
13 | pub mod ty_filter; | ||
14 | pub mod traits; | ||
15 | pub mod call_info; | ||
13 | 16 | ||
14 | use std::{fmt, sync::Arc}; | 17 | use std::{fmt, sync::Arc}; |
15 | 18 | ||
@@ -23,6 +26,9 @@ use rustc_hash::FxHashSet; | |||
23 | 26 | ||
24 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; | 27 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; |
25 | 28 | ||
29 | /// `base_db` is normally also needed in places where `ide_db` is used, so this re-export is for convenience. | ||
30 | pub use base_db; | ||
31 | |||
26 | #[salsa::database( | 32 | #[salsa::database( |
27 | base_db::SourceDatabaseStorage, | 33 | base_db::SourceDatabaseStorage, |
28 | base_db::SourceDatabaseExtStorage, | 34 | base_db::SourceDatabaseExtStorage, |
diff --git a/crates/ide_db/src/traits.rs b/crates/ide_db/src/traits.rs new file mode 100644 index 000000000..f57b6dd91 --- /dev/null +++ b/crates/ide_db/src/traits.rs | |||
@@ -0,0 +1,227 @@ | |||
1 | //! Functionality for obtaining data related to traits from the DB. | ||
2 | |||
3 | use crate::RootDatabase; | ||
4 | use hir::Semantics; | ||
5 | use rustc_hash::FxHashSet; | ||
6 | use syntax::{ | ||
7 | ast::{self, NameOwner}, | ||
8 | AstNode, | ||
9 | }; | ||
10 | |||
11 | /// Given the `impl` block, attempts to find the trait this `impl` corresponds to. | ||
12 | pub fn resolve_target_trait( | ||
13 | sema: &Semantics<RootDatabase>, | ||
14 | impl_def: &ast::Impl, | ||
15 | ) -> Option<hir::Trait> { | ||
16 | let ast_path = | ||
17 | impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?; | ||
18 | |||
19 | match sema.resolve_path(&ast_path) { | ||
20 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), | ||
21 | _ => None, | ||
22 | } | ||
23 | } | ||
24 | |||
25 | /// Given the `impl` block, returns the list of associated items (e.g. functions or types) that are | ||
26 | /// missing in this `impl` block. | ||
27 | pub fn get_missing_assoc_items( | ||
28 | sema: &Semantics<RootDatabase>, | ||
29 | impl_def: &ast::Impl, | ||
30 | ) -> Vec<hir::AssocItem> { | ||
31 | // Names must be unique between constants and functions. However, type aliases | ||
32 | // may share the same name as a function or constant. | ||
33 | let mut impl_fns_consts = FxHashSet::default(); | ||
34 | let mut impl_type = FxHashSet::default(); | ||
35 | |||
36 | if let Some(item_list) = impl_def.assoc_item_list() { | ||
37 | for item in item_list.assoc_items() { | ||
38 | match item { | ||
39 | ast::AssocItem::Fn(f) => { | ||
40 | if let Some(n) = f.name() { | ||
41 | impl_fns_consts.insert(n.syntax().to_string()); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | ast::AssocItem::TypeAlias(t) => { | ||
46 | if let Some(n) = t.name() { | ||
47 | impl_type.insert(n.syntax().to_string()); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | ast::AssocItem::Const(c) => { | ||
52 | if let Some(n) = c.name() { | ||
53 | impl_fns_consts.insert(n.syntax().to_string()); | ||
54 | } | ||
55 | } | ||
56 | ast::AssocItem::MacroCall(_) => (), | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | resolve_target_trait(sema, impl_def).map_or(vec![], |target_trait| { | ||
62 | target_trait | ||
63 | .items(sema.db) | ||
64 | .iter() | ||
65 | .filter(|i| match i { | ||
66 | hir::AssocItem::Function(f) => { | ||
67 | !impl_fns_consts.contains(&f.name(sema.db).to_string()) | ||
68 | } | ||
69 | hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(sema.db).to_string()), | ||
70 | hir::AssocItem::Const(c) => c | ||
71 | .name(sema.db) | ||
72 | .map(|n| !impl_fns_consts.contains(&n.to_string())) | ||
73 | .unwrap_or_default(), | ||
74 | }) | ||
75 | .cloned() | ||
76 | .collect() | ||
77 | }) | ||
78 | } | ||
79 | |||
80 | #[cfg(test)] | ||
81 | mod tests { | ||
82 | use crate::RootDatabase; | ||
83 | use base_db::{fixture::ChangeFixture, FilePosition}; | ||
84 | use expect_test::{expect, Expect}; | ||
85 | use hir::Semantics; | ||
86 | use syntax::ast::{self, AstNode}; | ||
87 | use test_utils::RangeOrOffset; | ||
88 | |||
89 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | ||
90 | pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) { | ||
91 | let change_fixture = ChangeFixture::parse(ra_fixture); | ||
92 | let mut database = RootDatabase::default(); | ||
93 | database.apply_change(change_fixture.change); | ||
94 | let (file_id, range_or_offset) = | ||
95 | change_fixture.file_position.expect("expected a marker (<|>)"); | ||
96 | let offset = match range_or_offset { | ||
97 | RangeOrOffset::Range(_) => panic!(), | ||
98 | RangeOrOffset::Offset(it) => it, | ||
99 | }; | ||
100 | (database, FilePosition { file_id, offset }) | ||
101 | } | ||
102 | |||
103 | fn check_trait(ra_fixture: &str, expect: Expect) { | ||
104 | let (db, position) = position(ra_fixture); | ||
105 | let sema = Semantics::new(&db); | ||
106 | let file = sema.parse(position.file_id); | ||
107 | let impl_block: ast::Impl = | ||
108 | sema.find_node_at_offset_with_descend(file.syntax(), position.offset).unwrap(); | ||
109 | let trait_ = crate::traits::resolve_target_trait(&sema, &impl_block); | ||
110 | let actual = match trait_ { | ||
111 | Some(trait_) => trait_.name(&db).to_string(), | ||
112 | None => String::new(), | ||
113 | }; | ||
114 | expect.assert_eq(&actual); | ||
115 | } | ||
116 | |||
117 | fn check_missing_assoc(ra_fixture: &str, expect: Expect) { | ||
118 | let (db, position) = position(ra_fixture); | ||
119 | let sema = Semantics::new(&db); | ||
120 | let file = sema.parse(position.file_id); | ||
121 | let impl_block: ast::Impl = | ||
122 | sema.find_node_at_offset_with_descend(file.syntax(), position.offset).unwrap(); | ||
123 | let items = crate::traits::get_missing_assoc_items(&sema, &impl_block); | ||
124 | let actual = items | ||
125 | .into_iter() | ||
126 | .map(|item| item.name(&db).unwrap().to_string()) | ||
127 | .collect::<Vec<_>>() | ||
128 | .join("\n"); | ||
129 | expect.assert_eq(&actual); | ||
130 | } | ||
131 | |||
132 | #[test] | ||
133 | fn resolve_trait() { | ||
134 | check_trait( | ||
135 | r#" | ||
136 | pub trait Foo { | ||
137 | fn bar(); | ||
138 | } | ||
139 | impl Foo for u8 { | ||
140 | <|> | ||
141 | } | ||
142 | "#, | ||
143 | expect![["Foo"]], | ||
144 | ); | ||
145 | check_trait( | ||
146 | r#" | ||
147 | pub trait Foo { | ||
148 | fn bar(); | ||
149 | } | ||
150 | impl Foo for u8 { | ||
151 | fn bar() { | ||
152 | fn baz() { | ||
153 | <|> | ||
154 | } | ||
155 | baz(); | ||
156 | } | ||
157 | } | ||
158 | "#, | ||
159 | expect![["Foo"]], | ||
160 | ); | ||
161 | check_trait( | ||
162 | r#" | ||
163 | pub trait Foo { | ||
164 | fn bar(); | ||
165 | } | ||
166 | pub struct Bar; | ||
167 | impl Bar { | ||
168 | <|> | ||
169 | } | ||
170 | "#, | ||
171 | expect![[""]], | ||
172 | ); | ||
173 | } | ||
174 | |||
175 | #[test] | ||
176 | fn missing_assoc_items() { | ||
177 | check_missing_assoc( | ||
178 | r#" | ||
179 | pub trait Foo { | ||
180 | const FOO: u8; | ||
181 | fn bar(); | ||
182 | } | ||
183 | impl Foo for u8 { | ||
184 | <|> | ||
185 | }"#, | ||
186 | expect![[r#" | ||
187 | FOO | ||
188 | bar"#]], | ||
189 | ); | ||
190 | |||
191 | check_missing_assoc( | ||
192 | r#" | ||
193 | pub trait Foo { | ||
194 | const FOO: u8; | ||
195 | fn bar(); | ||
196 | } | ||
197 | impl Foo for u8 { | ||
198 | const FOO: u8 = 10; | ||
199 | <|> | ||
200 | }"#, | ||
201 | expect![[r#" | ||
202 | bar"#]], | ||
203 | ); | ||
204 | |||
205 | check_missing_assoc( | ||
206 | r#" | ||
207 | pub trait Foo { | ||
208 | const FOO: u8; | ||
209 | fn bar(); | ||
210 | } | ||
211 | impl Foo for u8 { | ||
212 | const FOO: u8 = 10; | ||
213 | fn bar() {<|>} | ||
214 | }"#, | ||
215 | expect![[r#""#]], | ||
216 | ); | ||
217 | |||
218 | check_missing_assoc( | ||
219 | r#" | ||
220 | pub struct Foo; | ||
221 | impl Foo { | ||
222 | fn bar() {<|>} | ||
223 | }"#, | ||
224 | expect![[r#""#]], | ||
225 | ); | ||
226 | } | ||
227 | } | ||
diff --git a/crates/ide_db/src/ty_filter.rs b/crates/ide_db/src/ty_filter.rs new file mode 100644 index 000000000..63a945282 --- /dev/null +++ b/crates/ide_db/src/ty_filter.rs | |||
@@ -0,0 +1,58 @@ | |||
1 | //! This module contains structures for filtering the expected types. | ||
2 | //! Use case for structures in this module is, for example, situation when you need to process | ||
3 | //! only certain `Enum`s. | ||
4 | |||
5 | use crate::RootDatabase; | ||
6 | use hir::{Adt, Semantics, Type}; | ||
7 | use std::iter; | ||
8 | use syntax::ast::{self, make}; | ||
9 | |||
10 | /// Enum types that implement `std::ops::Try` trait. | ||
11 | #[derive(Clone, Copy)] | ||
12 | pub enum TryEnum { | ||
13 | Result, | ||
14 | Option, | ||
15 | } | ||
16 | |||
17 | impl TryEnum { | ||
18 | const ALL: [TryEnum; 2] = [TryEnum::Option, TryEnum::Result]; | ||
19 | |||
20 | /// Returns `Some(..)` if the provided type is an enum that implements `std::ops::Try`. | ||
21 | pub fn from_ty(sema: &Semantics<RootDatabase>, ty: &Type) -> Option<TryEnum> { | ||
22 | let enum_ = match ty.as_adt() { | ||
23 | Some(Adt::Enum(it)) => it, | ||
24 | _ => return None, | ||
25 | }; | ||
26 | TryEnum::ALL.iter().find_map(|&var| { | ||
27 | if &enum_.name(sema.db).to_string() == var.type_name() { | ||
28 | return Some(var); | ||
29 | } | ||
30 | None | ||
31 | }) | ||
32 | } | ||
33 | |||
34 | pub fn happy_case(self) -> &'static str { | ||
35 | match self { | ||
36 | TryEnum::Result => "Ok", | ||
37 | TryEnum::Option => "Some", | ||
38 | } | ||
39 | } | ||
40 | |||
41 | pub fn sad_pattern(self) -> ast::Pat { | ||
42 | match self { | ||
43 | TryEnum::Result => make::tuple_struct_pat( | ||
44 | make::path_unqualified(make::path_segment(make::name_ref("Err"))), | ||
45 | iter::once(make::wildcard_pat().into()), | ||
46 | ) | ||
47 | .into(), | ||
48 | TryEnum::Option => make::ident_pat(make::name("None")).into(), | ||
49 | } | ||
50 | } | ||
51 | |||
52 | fn type_name(self) -> &'static str { | ||
53 | match self { | ||
54 | TryEnum::Result => "Result", | ||
55 | TryEnum::Option => "Option", | ||
56 | } | ||
57 | } | ||
58 | } | ||
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 66cf06e1a..975b24aaf 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -29,9 +29,12 @@ rustc-hash = "1.1.0" | |||
29 | serde = { version = "1.0.106", features = ["derive"] } | 29 | serde = { version = "1.0.106", features = ["derive"] } |
30 | serde_json = "1.0.48" | 30 | serde_json = "1.0.48" |
31 | threadpool = "1.7.1" | 31 | threadpool = "1.7.1" |
32 | rayon = "1.3.1" | 32 | rayon = "1.5" |
33 | mimalloc = { version = "0.1.19", default-features = false, optional = true } | 33 | mimalloc = { version = "0.1.19", default-features = false, optional = true } |
34 | lsp-server = "0.4.0" | 34 | lsp-server = "0.4.0" |
35 | tracing = "0.1" | ||
36 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } | ||
37 | tracing-tree = { version = "0.1.4" } | ||
35 | 38 | ||
36 | stdx = { path = "../stdx", version = "0.0.0" } | 39 | stdx = { path = "../stdx", version = "0.0.0" } |
37 | flycheck = { path = "../flycheck", version = "0.0.0" } | 40 | flycheck = { path = "../flycheck", version = "0.0.0" } |
@@ -46,7 +49,6 @@ cfg = { path = "../cfg", version = "0.0.0" } | |||
46 | toolchain = { path = "../toolchain", version = "0.0.0" } | 49 | toolchain = { path = "../toolchain", version = "0.0.0" } |
47 | 50 | ||
48 | # This should only be used in CLI | 51 | # This should only be used in CLI |
49 | base_db = { path = "../base_db", version = "0.0.0" } | ||
50 | ide_db = { path = "../ide_db", version = "0.0.0" } | 52 | ide_db = { path = "../ide_db", version = "0.0.0" } |
51 | ssr = { path = "../ssr", version = "0.0.0" } | 53 | ssr = { path = "../ssr", version = "0.0.0" } |
52 | hir = { path = "../hir", version = "0.0.0" } | 54 | hir = { path = "../hir", version = "0.0.0" } |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 97b246a32..4175e569e 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -68,10 +68,32 @@ fn setup_logging(log_file: Option<PathBuf>) -> Result<()> { | |||
68 | let filter = env::var("RA_LOG").ok(); | 68 | let filter = env::var("RA_LOG").ok(); |
69 | logger::Logger::new(log_file, filter.as_deref()).install(); | 69 | logger::Logger::new(log_file, filter.as_deref()).install(); |
70 | 70 | ||
71 | tracing_setup::setup_tracing()?; | ||
72 | |||
71 | profile::init(); | 73 | profile::init(); |
72 | Ok(()) | 74 | Ok(()) |
73 | } | 75 | } |
74 | 76 | ||
77 | mod tracing_setup { | ||
78 | use tracing::subscriber; | ||
79 | use tracing_subscriber::layer::SubscriberExt; | ||
80 | use tracing_subscriber::EnvFilter; | ||
81 | use tracing_subscriber::Registry; | ||
82 | use tracing_tree::HierarchicalLayer; | ||
83 | |||
84 | pub fn setup_tracing() -> super::Result<()> { | ||
85 | let filter = EnvFilter::from_env("CHALK_DEBUG"); | ||
86 | let layer = HierarchicalLayer::default() | ||
87 | .with_indent_lines(true) | ||
88 | .with_ansi(false) | ||
89 | .with_indent_amount(2) | ||
90 | .with_writer(std::io::stderr); | ||
91 | let subscriber = Registry::default().with(filter).with(layer); | ||
92 | subscriber::set_global_default(subscriber)?; | ||
93 | Ok(()) | ||
94 | } | ||
95 | } | ||
96 | |||
75 | fn run_server() -> Result<()> { | 97 | fn run_server() -> Result<()> { |
76 | log::info!("server will start"); | 98 | log::info!("server will start"); |
77 | 99 | ||
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index d1c095ba5..8e33986d5 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -3,13 +3,13 @@ | |||
3 | use std::{env, path::PathBuf, str::FromStr, sync::Arc, time::Instant}; | 3 | use std::{env, path::PathBuf, str::FromStr, sync::Arc, time::Instant}; |
4 | 4 | ||
5 | use anyhow::{bail, format_err, Result}; | 5 | use anyhow::{bail, format_err, Result}; |
6 | use base_db::{ | ||
7 | salsa::{Database, Durability}, | ||
8 | FileId, | ||
9 | }; | ||
10 | use ide::{ | 6 | use ide::{ |
11 | Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineCol, | 7 | Analysis, AnalysisHost, Change, CompletionConfig, DiagnosticsConfig, FilePosition, LineCol, |
12 | }; | 8 | }; |
9 | use ide_db::base_db::{ | ||
10 | salsa::{Database, Durability}, | ||
11 | FileId, | ||
12 | }; | ||
13 | use vfs::AbsPathBuf; | 13 | use vfs::AbsPathBuf; |
14 | 14 | ||
15 | use crate::{ | 15 | use crate::{ |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index fb2b2b000..98ef0cd68 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -6,16 +6,16 @@ use std::{ | |||
6 | time::{SystemTime, UNIX_EPOCH}, | 6 | time::{SystemTime, UNIX_EPOCH}, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use base_db::{ | ||
10 | salsa::{self, ParallelDatabase}, | ||
11 | SourceDatabaseExt, | ||
12 | }; | ||
13 | use hir::{ | 9 | use hir::{ |
14 | db::{AstDatabase, DefDatabase, HirDatabase}, | 10 | db::{AstDatabase, DefDatabase, HirDatabase}, |
15 | original_range, AssocItem, Crate, HasSource, HirDisplay, ModuleDef, | 11 | original_range, AssocItem, Crate, HasSource, HirDisplay, ModuleDef, |
16 | }; | 12 | }; |
17 | use hir_def::FunctionId; | 13 | use hir_def::FunctionId; |
18 | use hir_ty::{Ty, TypeWalk}; | 14 | use hir_ty::{Ty, TypeWalk}; |
15 | use ide_db::base_db::{ | ||
16 | salsa::{self, ParallelDatabase}, | ||
17 | SourceDatabaseExt, | ||
18 | }; | ||
19 | use itertools::Itertools; | 19 | use itertools::Itertools; |
20 | use oorandom::Rand32; | 20 | use oorandom::Rand32; |
21 | use rayon::prelude::*; | 21 | use rayon::prelude::*; |
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index a89993a2b..368f627ac 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -6,9 +6,9 @@ use std::path::Path; | |||
6 | use anyhow::anyhow; | 6 | use anyhow::anyhow; |
7 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
8 | 8 | ||
9 | use base_db::SourceDatabaseExt; | ||
10 | use hir::Crate; | 9 | use hir::Crate; |
11 | use ide::{DiagnosticsConfig, Severity}; | 10 | use ide::{DiagnosticsConfig, Severity}; |
11 | use ide_db::base_db::SourceDatabaseExt; | ||
12 | 12 | ||
13 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use crate::cli::{load_cargo::load_cargo, Result}; |
14 | 14 | ||
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 7ae1c9055..ab1e2ab92 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -3,9 +3,9 @@ | |||
3 | use std::{path::Path, sync::Arc}; | 3 | use std::{path::Path, sync::Arc}; |
4 | 4 | ||
5 | use anyhow::Result; | 5 | use anyhow::Result; |
6 | use base_db::CrateGraph; | ||
7 | use crossbeam_channel::{unbounded, Receiver}; | 6 | use crossbeam_channel::{unbounded, Receiver}; |
8 | use ide::{AnalysisHost, Change}; | 7 | use ide::{AnalysisHost, Change}; |
8 | use ide_db::base_db::CrateGraph; | ||
9 | use project_model::{CargoConfig, ProcMacroClient, ProjectManifest, ProjectWorkspace}; | 9 | use project_model::{CargoConfig, ProcMacroClient, ProjectManifest, ProjectWorkspace}; |
10 | use vfs::{loader::Handle, AbsPath, AbsPathBuf}; | 10 | use vfs::{loader::Handle, AbsPath, AbsPathBuf}; |
11 | 11 | ||
diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs index c11e10943..a06631dac 100644 --- a/crates/rust-analyzer/src/cli/ssr.rs +++ b/crates/rust-analyzer/src/cli/ssr.rs | |||
@@ -4,7 +4,7 @@ use crate::cli::{load_cargo::load_cargo, Result}; | |||
4 | use ssr::{MatchFinder, SsrPattern, SsrRule}; | 4 | use ssr::{MatchFinder, SsrPattern, SsrRule}; |
5 | 5 | ||
6 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | 6 | pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { |
7 | use base_db::SourceDatabaseExt; | 7 | use ide_db::base_db::SourceDatabaseExt; |
8 | let (host, vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 8 | let (host, vfs) = load_cargo(&std::env::current_dir()?, true, true)?; |
9 | let db = host.raw_database(); | 9 | let db = host.raw_database(); |
10 | let mut match_finder = MatchFinder::at_first_file(db)?; | 10 | let mut match_finder = MatchFinder::at_first_file(db)?; |
@@ -26,7 +26,7 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { | |||
26 | /// `debug_snippet`. This is intended for debugging and probably isn't in it's current form useful | 26 | /// `debug_snippet`. This is intended for debugging and probably isn't in it's current form useful |
27 | /// for much else. | 27 | /// for much else. |
28 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { | 28 | pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<String>) -> Result<()> { |
29 | use base_db::SourceDatabaseExt; | 29 | use ide_db::base_db::SourceDatabaseExt; |
30 | use ide_db::symbol_index::SymbolsDatabase; | 30 | use ide_db::symbol_index::SymbolsDatabase; |
31 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, true, true)?; | 31 | let (host, _vfs) = load_cargo(&std::env::current_dir()?, true, true)?; |
32 | let db = host.raw_database(); | 32 | let db = host.raw_database(); |
diff --git a/crates/rust-analyzer/src/from_proto.rs b/crates/rust-analyzer/src/from_proto.rs index 5b9f52993..aa6b808d6 100644 --- a/crates/rust-analyzer/src/from_proto.rs +++ b/crates/rust-analyzer/src/from_proto.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | //! Conversion lsp_types types to rust-analyzer specific ones. | 1 | //! Conversion lsp_types types to rust-analyzer specific ones. |
2 | use std::convert::TryFrom; | 2 | use std::convert::TryFrom; |
3 | 3 | ||
4 | use base_db::{FileId, FilePosition, FileRange}; | ||
5 | use ide::{AssistKind, LineCol, LineIndex}; | 4 | use ide::{AssistKind, LineCol, LineIndex}; |
5 | use ide_db::base_db::{FileId, FilePosition, FileRange}; | ||
6 | use syntax::{TextRange, TextSize}; | 6 | use syntax::{TextRange, TextSize}; |
7 | use vfs::AbsPathBuf; | 7 | use vfs::AbsPathBuf; |
8 | 8 | ||
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index dafab6a6a..673a2eebc 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -5,10 +5,10 @@ | |||
5 | 5 | ||
6 | use std::{sync::Arc, time::Instant}; | 6 | use std::{sync::Arc, time::Instant}; |
7 | 7 | ||
8 | use base_db::{CrateId, VfsPath}; | ||
9 | use crossbeam_channel::{unbounded, Receiver, Sender}; | 8 | use crossbeam_channel::{unbounded, Receiver, Sender}; |
10 | use flycheck::FlycheckHandle; | 9 | use flycheck::FlycheckHandle; |
11 | use ide::{Analysis, AnalysisHost, Change, FileId}; | 10 | use ide::{Analysis, AnalysisHost, Change, FileId}; |
11 | use ide_db::base_db::{CrateId, VfsPath}; | ||
12 | use lsp_types::{SemanticTokens, Url}; | 12 | use lsp_types::{SemanticTokens, Url}; |
13 | use parking_lot::{Mutex, RwLock}; | 13 | use parking_lot::{Mutex, RwLock}; |
14 | use project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; | 14 | use project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; |
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs index bd888f634..1d271a9d8 100644 --- a/crates/rust-analyzer/src/lsp_utils.rs +++ b/crates/rust-analyzer/src/lsp_utils.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | //! Utilities for LSP-related boilerplate code. | 1 | //! Utilities for LSP-related boilerplate code. |
2 | use std::{error::Error, ops::Range}; | 2 | use std::{error::Error, ops::Range}; |
3 | 3 | ||
4 | use base_db::Canceled; | ||
5 | use ide::LineIndex; | 4 | use ide::LineIndex; |
5 | use ide_db::base_db::Canceled; | ||
6 | use lsp_server::Notification; | 6 | use lsp_server::Notification; |
7 | 7 | ||
8 | use crate::{from_proto, global_state::GlobalState}; | 8 | use crate::{from_proto, global_state::GlobalState}; |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index fb18f9014..ed5292733 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -5,10 +5,10 @@ use std::{ | |||
5 | time::{Duration, Instant}, | 5 | time::{Duration, Instant}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use base_db::VfsPath; | ||
9 | use crossbeam_channel::{select, Receiver}; | 8 | use crossbeam_channel::{select, Receiver}; |
10 | use ide::PrimeCachesProgress; | 9 | use ide::PrimeCachesProgress; |
11 | use ide::{Canceled, FileId}; | 10 | use ide::{Canceled, FileId}; |
11 | use ide_db::base_db::VfsPath; | ||
12 | use lsp_server::{Connection, Notification, Request, Response}; | 12 | use lsp_server::{Connection, Notification, Request, Response}; |
13 | use lsp_types::notification::Notification as _; | 13 | use lsp_types::notification::Notification as _; |
14 | use project_model::ProjectWorkspace; | 14 | use project_model::ProjectWorkspace; |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index f7215f129..0eabd51bd 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | //! Project loading & configuration updates | 1 | //! Project loading & configuration updates |
2 | use std::{mem, sync::Arc}; | 2 | use std::{mem, sync::Arc}; |
3 | 3 | ||
4 | use base_db::{CrateGraph, SourceRoot, VfsPath}; | ||
5 | use flycheck::{FlycheckConfig, FlycheckHandle}; | 4 | use flycheck::{FlycheckConfig, FlycheckHandle}; |
6 | use ide::Change; | 5 | use ide::Change; |
6 | use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath}; | ||
7 | use project_model::{ProcMacroClient, ProjectWorkspace}; | 7 | use project_model::{ProcMacroClient, ProjectWorkspace}; |
8 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; | 8 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; |
9 | 9 | ||
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 0d34970bc..24a658fc6 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -4,13 +4,13 @@ use std::{ | |||
4 | sync::atomic::{AtomicU32, Ordering}, | 4 | sync::atomic::{AtomicU32, Ordering}, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use base_db::{FileId, FileRange}; | ||
8 | use ide::{ | 7 | use ide::{ |
9 | Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, | 8 | Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, |
10 | FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, HighlightedRange, | 9 | FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, HighlightedRange, |
11 | Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, | 10 | Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, |
12 | ReferenceAccess, ResolvedAssist, Runnable, Severity, SourceChange, SourceFileEdit, TextEdit, | 11 | ReferenceAccess, ResolvedAssist, Runnable, Severity, SourceChange, SourceFileEdit, TextEdit, |
13 | }; | 12 | }; |
13 | use ide_db::base_db::{FileId, FileRange}; | ||
14 | use itertools::Itertools; | 14 | use itertools::Itertools; |
15 | use syntax::{SyntaxKind, TextRange, TextSize}; | 15 | use syntax::{SyntaxKind, TextRange, TextSize}; |
16 | 16 | ||
@@ -809,7 +809,7 @@ mod tests { | |||
809 | let completions: Vec<(String, Option<String>)> = analysis | 809 | let completions: Vec<(String, Option<String>)> = analysis |
810 | .completions( | 810 | .completions( |
811 | &ide::CompletionConfig::default(), | 811 | &ide::CompletionConfig::default(), |
812 | base_db::FilePosition { file_id, offset }, | 812 | ide_db::base_db::FilePosition { file_id, offset }, |
813 | ) | 813 | ) |
814 | .unwrap() | 814 | .unwrap() |
815 | .unwrap() | 815 | .unwrap() |
diff --git a/crates/ssr/Cargo.toml b/crates/ssr/Cargo.toml index 408140014..98ed25fb6 100644 --- a/crates/ssr/Cargo.toml +++ b/crates/ssr/Cargo.toml | |||
@@ -16,7 +16,6 @@ itertools = "0.9.0" | |||
16 | 16 | ||
17 | text_edit = { path = "../text_edit", version = "0.0.0" } | 17 | text_edit = { path = "../text_edit", version = "0.0.0" } |
18 | syntax = { path = "../syntax", version = "0.0.0" } | 18 | syntax = { path = "../syntax", version = "0.0.0" } |
19 | base_db = { path = "../base_db", version = "0.0.0" } | ||
20 | ide_db = { path = "../ide_db", version = "0.0.0" } | 19 | ide_db = { path = "../ide_db", version = "0.0.0" } |
21 | hir = { path = "../hir", version = "0.0.0" } | 20 | hir = { path = "../hir", version = "0.0.0" } |
22 | test_utils = { path = "../test_utils", version = "0.0.0" } | 21 | test_utils = { path = "../test_utils", version = "0.0.0" } |
diff --git a/crates/ssr/src/lib.rs b/crates/ssr/src/lib.rs index ba669fd56..747ce495d 100644 --- a/crates/ssr/src/lib.rs +++ b/crates/ssr/src/lib.rs | |||
@@ -73,8 +73,8 @@ use crate::errors::bail; | |||
73 | pub use crate::errors::SsrError; | 73 | pub use crate::errors::SsrError; |
74 | pub use crate::matching::Match; | 74 | pub use crate::matching::Match; |
75 | use crate::matching::MatchFailureReason; | 75 | use crate::matching::MatchFailureReason; |
76 | use base_db::{FileId, FilePosition, FileRange}; | ||
77 | use hir::Semantics; | 76 | use hir::Semantics; |
77 | use ide_db::base_db::{FileId, FilePosition, FileRange}; | ||
78 | use ide_db::source_change::SourceFileEdit; | 78 | use ide_db::source_change::SourceFileEdit; |
79 | use resolving::ResolvedRule; | 79 | use resolving::ResolvedRule; |
80 | use rustc_hash::FxHashMap; | 80 | use rustc_hash::FxHashMap; |
@@ -126,7 +126,7 @@ impl<'db> MatchFinder<'db> { | |||
126 | 126 | ||
127 | /// Constructs an instance using the start of the first file in `db` as the lookup context. | 127 | /// Constructs an instance using the start of the first file in `db` as the lookup context. |
128 | pub fn at_first_file(db: &'db ide_db::RootDatabase) -> Result<MatchFinder<'db>, SsrError> { | 128 | pub fn at_first_file(db: &'db ide_db::RootDatabase) -> Result<MatchFinder<'db>, SsrError> { |
129 | use base_db::SourceDatabaseExt; | 129 | use ide_db::base_db::SourceDatabaseExt; |
130 | use ide_db::symbol_index::SymbolsDatabase; | 130 | use ide_db::symbol_index::SymbolsDatabase; |
131 | if let Some(first_file_id) = db | 131 | if let Some(first_file_id) = db |
132 | .local_roots() | 132 | .local_roots() |
@@ -160,7 +160,7 @@ impl<'db> MatchFinder<'db> { | |||
160 | 160 | ||
161 | /// Finds matches for all added rules and returns edits for all found matches. | 161 | /// Finds matches for all added rules and returns edits for all found matches. |
162 | pub fn edits(&self) -> Vec<SourceFileEdit> { | 162 | pub fn edits(&self) -> Vec<SourceFileEdit> { |
163 | use base_db::SourceDatabaseExt; | 163 | use ide_db::base_db::SourceDatabaseExt; |
164 | let mut matches_by_file = FxHashMap::default(); | 164 | let mut matches_by_file = FxHashMap::default(); |
165 | for m in self.matches().matches { | 165 | for m in self.matches().matches { |
166 | matches_by_file | 166 | matches_by_file |
@@ -205,7 +205,7 @@ impl<'db> MatchFinder<'db> { | |||
205 | /// them, while recording reasons why they don't match. This API is useful for command | 205 | /// them, while recording reasons why they don't match. This API is useful for command |
206 | /// line-based debugging where providing a range is difficult. | 206 | /// line-based debugging where providing a range is difficult. |
207 | pub fn debug_where_text_equal(&self, file_id: FileId, snippet: &str) -> Vec<MatchDebugInfo> { | 207 | pub fn debug_where_text_equal(&self, file_id: FileId, snippet: &str) -> Vec<MatchDebugInfo> { |
208 | use base_db::SourceDatabaseExt; | 208 | use ide_db::base_db::SourceDatabaseExt; |
209 | let file = self.sema.parse(file_id); | 209 | let file = self.sema.parse(file_id); |
210 | let mut res = Vec::new(); | 210 | let mut res = Vec::new(); |
211 | let file_text = self.sema.db.file_text(file_id); | 211 | let file_text = self.sema.db.file_text(file_id); |
diff --git a/crates/ssr/src/matching.rs b/crates/ssr/src/matching.rs index 948862a77..99b187311 100644 --- a/crates/ssr/src/matching.rs +++ b/crates/ssr/src/matching.rs | |||
@@ -6,8 +6,8 @@ use crate::{ | |||
6 | resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo}, | 6 | resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo}, |
7 | SsrMatches, | 7 | SsrMatches, |
8 | }; | 8 | }; |
9 | use base_db::FileRange; | ||
10 | use hir::Semantics; | 9 | use hir::Semantics; |
10 | use ide_db::base_db::FileRange; | ||
11 | use rustc_hash::FxHashMap; | 11 | use rustc_hash::FxHashMap; |
12 | use std::{cell::Cell, iter::Peekable}; | 12 | use std::{cell::Cell, iter::Peekable}; |
13 | use syntax::ast::{AstNode, AstToken}; | 13 | use syntax::ast::{AstNode, AstToken}; |
diff --git a/crates/ssr/src/resolving.rs b/crates/ssr/src/resolving.rs index 347cc4aad..f5ceb5729 100644 --- a/crates/ssr/src/resolving.rs +++ b/crates/ssr/src/resolving.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use crate::errors::error; | 3 | use crate::errors::error; |
4 | use crate::{parsing, SsrError}; | 4 | use crate::{parsing, SsrError}; |
5 | use base_db::FilePosition; | 5 | use ide_db::base_db::FilePosition; |
6 | use parsing::Placeholder; | 6 | use parsing::Placeholder; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | use syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; | 8 | use syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; |
diff --git a/crates/ssr/src/search.rs b/crates/ssr/src/search.rs index a595fd269..44b5db029 100644 --- a/crates/ssr/src/search.rs +++ b/crates/ssr/src/search.rs | |||
@@ -5,7 +5,7 @@ use crate::{ | |||
5 | resolving::{ResolvedPath, ResolvedPattern, ResolvedRule}, | 5 | resolving::{ResolvedPath, ResolvedPattern, ResolvedRule}, |
6 | Match, MatchFinder, | 6 | Match, MatchFinder, |
7 | }; | 7 | }; |
8 | use base_db::{FileId, FileRange}; | 8 | use ide_db::base_db::{FileId, FileRange}; |
9 | use ide_db::{ | 9 | use ide_db::{ |
10 | defs::Definition, | 10 | defs::Definition, |
11 | search::{Reference, SearchScope}, | 11 | search::{Reference, SearchScope}, |
@@ -145,7 +145,7 @@ impl<'db> MatchFinder<'db> { | |||
145 | fn search_files_do(&self, mut callback: impl FnMut(FileId)) { | 145 | fn search_files_do(&self, mut callback: impl FnMut(FileId)) { |
146 | if self.restrict_ranges.is_empty() { | 146 | if self.restrict_ranges.is_empty() { |
147 | // Unrestricted search. | 147 | // Unrestricted search. |
148 | use base_db::SourceDatabaseExt; | 148 | use ide_db::base_db::SourceDatabaseExt; |
149 | use ide_db::symbol_index::SymbolsDatabase; | 149 | use ide_db::symbol_index::SymbolsDatabase; |
150 | for &root in self.sema.db.local_roots().iter() { | 150 | for &root in self.sema.db.local_roots().iter() { |
151 | let sr = self.sema.db.source_root(root); | 151 | let sr = self.sema.db.source_root(root); |
diff --git a/crates/ssr/src/tests.rs b/crates/ssr/src/tests.rs index 20231a9bc..63131f6ca 100644 --- a/crates/ssr/src/tests.rs +++ b/crates/ssr/src/tests.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use crate::{MatchFinder, SsrRule}; | 1 | use crate::{MatchFinder, SsrRule}; |
2 | use base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt}; | ||
3 | use expect_test::{expect, Expect}; | 2 | use expect_test::{expect, Expect}; |
3 | use ide_db::base_db::{salsa::Durability, FileId, FilePosition, FileRange, SourceDatabaseExt}; | ||
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
5 | use std::sync::Arc; | 5 | use std::sync::Arc; |
6 | use test_utils::{mark, RangeOrOffset}; | 6 | use test_utils::{mark, RangeOrOffset}; |
@@ -62,7 +62,7 @@ fn parser_undefined_placeholder_in_replacement() { | |||
62 | /// `code` may optionally contain a cursor marker `<|>`. If it doesn't, then the position will be | 62 | /// `code` may optionally contain a cursor marker `<|>`. If it doesn't, then the position will be |
63 | /// the start of the file. If there's a second cursor marker, then we'll return a single range. | 63 | /// the start of the file. If there's a second cursor marker, then we'll return a single range. |
64 | pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec<FileRange>) { | 64 | pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Vec<FileRange>) { |
65 | use base_db::fixture::WithFixture; | 65 | use ide_db::base_db::fixture::WithFixture; |
66 | use ide_db::symbol_index::SymbolsDatabase; | 66 | use ide_db::symbol_index::SymbolsDatabase; |
67 | let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) { | 67 | let (mut db, file_id, range_or_offset) = if code.contains(test_utils::CURSOR_MARKER) { |
68 | ide_db::RootDatabase::with_range_or_offset(code) | 68 | ide_db::RootDatabase::with_range_or_offset(code) |
@@ -83,7 +83,7 @@ pub(crate) fn single_file(code: &str) -> (ide_db::RootDatabase, FilePosition, Ve | |||
83 | } | 83 | } |
84 | } | 84 | } |
85 | let mut local_roots = FxHashSet::default(); | 85 | let mut local_roots = FxHashSet::default(); |
86 | local_roots.insert(base_db::fixture::WORKSPACE); | 86 | local_roots.insert(ide_db::base_db::fixture::WORKSPACE); |
87 | db.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); | 87 | db.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); |
88 | (db, position, selections) | 88 | (db, position, selections) |
89 | } | 89 | } |
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] |
14 | itertools = "0.9.0" | 14 | itertools = "0.9.0" |
15 | rowan = "0.10.0" | 15 | rowan = "0.10.0" |
16 | rustc_lexer = { version = "683.0.0", package = "rustc-ap-rustc_lexer" } | 16 | rustc_lexer = { version = "685.0.0", package = "rustc-ap-rustc_lexer" } |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
19 | once_cell = "1.3.1" | 19 | once_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; | |||
7 | use parser::SyntaxKind; | 7 | use parser::SyntaxKind; |
8 | 8 | ||
9 | use crate::{ | 9 | use 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/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json index 450116df2..1b8cc713a 100644 --- a/editors/code/rust.tmGrammar.json +++ b/editors/code/rust.tmGrammar.json | |||
@@ -641,10 +641,28 @@ | |||
641 | }, | 641 | }, |
642 | { | 642 | { |
643 | "comment": "less than, greater than (special case)", | 643 | "comment": "less than, greater than (special case)", |
644 | "match": "(^|\\s)(?<!=)([<>])\\s", | 644 | "match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))", |
645 | "captures": { | 645 | "captures": { |
646 | "1": { | ||
647 | "name": "punctuation.brackets.round.rust" | ||
648 | }, | ||
646 | "2": { | 649 | "2": { |
650 | "name": "punctuation.brackets.square.rust" | ||
651 | }, | ||
652 | "3": { | ||
653 | "name": "punctuation.brackets.curly.rust" | ||
654 | }, | ||
655 | "4": { | ||
647 | "name": "keyword.operator.comparison.rust" | 656 | "name": "keyword.operator.comparison.rust" |
657 | }, | ||
658 | "5": { | ||
659 | "name": "punctuation.brackets.round.rust" | ||
660 | }, | ||
661 | "6": { | ||
662 | "name": "punctuation.brackets.square.rust" | ||
663 | }, | ||
664 | "7": { | ||
665 | "name": "punctuation.brackets.curly.rust" | ||
648 | } | 666 | } |
649 | } | 667 | } |
650 | }, | 668 | }, |