aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock71
-rw-r--r--crates/ra_arena/src/lib.rs2
-rw-r--r--crates/ra_batch/Cargo.toml1
-rw-r--r--crates/ra_batch/src/lib.rs26
-rw-r--r--crates/ra_batch/src/vfs_filter.rs54
-rw-r--r--crates/ra_cli/src/analysis_stats.rs6
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/src/config.rs (renamed from crates/ra_lsp_server/src/init.rs)15
-rw-r--r--crates/ra_lsp_server/src/conv.rs20
-rw-r--r--crates/ra_lsp_server/src/lib.rs6
-rw-r--r--crates/ra_lsp_server/src/main.rs4
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs20
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs21
-rw-r--r--crates/ra_lsp_server/src/markdown.rs17
-rw-r--r--crates/ra_lsp_server/src/vfs_filter.rs54
-rw-r--r--crates/ra_lsp_server/src/world.rs24
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs4
-rw-r--r--crates/ra_parser/src/parser.rs54
-rw-r--r--crates/ra_project_model/Cargo.toml1
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs57
-rw-r--r--crates/ra_project_model/src/sysroot.rs2
-rw-r--r--crates/ra_vfs_glob/Cargo.toml9
-rw-r--r--crates/ra_vfs_glob/src/lib.rs94
-rw-r--r--docs/user/README.md3
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts4
-rw-r--r--editors/code/src/server.ts3
28 files changed, 335 insertions, 245 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7dffcd0bc..365b77f41 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -118,6 +118,14 @@ dependencies = [
118] 118]
119 119
120[[package]] 120[[package]]
121name = "bstr"
122version = "0.2.6"
123source = "registry+https://github.com/rust-lang/crates.io-index"
124dependencies = [
125 "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
126]
127
128[[package]]
121name = "byte-tools" 129name = "byte-tools"
122version = "0.3.1" 130version = "0.3.1"
123source = "registry+https://github.com/rust-lang/crates.io-index" 131source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -468,7 +476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
468 476
469[[package]] 477[[package]]
470name = "flexi_logger" 478name = "flexi_logger"
471version = "0.14.0" 479version = "0.14.1"
472source = "registry+https://github.com/rust-lang/crates.io-index" 480source = "registry+https://github.com/rust-lang/crates.io-index"
473dependencies = [ 481dependencies = [
474 "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", 482 "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -479,6 +487,11 @@ dependencies = [
479] 487]
480 488
481[[package]] 489[[package]]
490name = "fnv"
491version = "1.0.6"
492source = "registry+https://github.com/rust-lang/crates.io-index"
493
494[[package]]
482name = "format-buf" 495name = "format-buf"
483version = "1.0.0" 496version = "1.0.0"
484source = "registry+https://github.com/rust-lang/crates.io-index" 497source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -537,7 +550,7 @@ name = "gen_lsp_server"
537version = "0.2.0" 550version = "0.2.0"
538dependencies = [ 551dependencies = [
539 "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 552 "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
540 "flexi_logger 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 553 "flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
541 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 554 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
542 "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)", 555 "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
543 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", 556 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -554,7 +567,7 @@ dependencies = [
554 567
555[[package]] 568[[package]]
556name = "getrandom" 569name = "getrandom"
557version = "0.1.7" 570version = "0.1.8"
558source = "registry+https://github.com/rust-lang/crates.io-index" 571source = "registry+https://github.com/rust-lang/crates.io-index"
559dependencies = [ 572dependencies = [
560 "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 573 "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -572,6 +585,18 @@ version = "0.3.0"
572source = "registry+https://github.com/rust-lang/crates.io-index" 585source = "registry+https://github.com/rust-lang/crates.io-index"
573 586
574[[package]] 587[[package]]
588name = "globset"
589version = "0.4.4"
590source = "registry+https://github.com/rust-lang/crates.io-index"
591dependencies = [
592 "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
593 "bstr 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
594 "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
595 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
596 "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
597]
598
599[[package]]
575name = "heck" 600name = "heck"
576version = "0.3.1" 601version = "0.3.1"
577source = "registry+https://github.com/rust-lang/crates.io-index" 602source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1145,6 +1170,7 @@ dependencies = [
1145 "ra_ide_api 0.1.0", 1170 "ra_ide_api 0.1.0",
1146 "ra_project_model 0.1.0", 1171 "ra_project_model 0.1.0",
1147 "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 1172 "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
1173 "ra_vfs_glob 0.1.0",
1148 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1174 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1149] 1175]
1150 1176
@@ -1153,7 +1179,7 @@ name = "ra_cli"
1153version = "0.1.0" 1179version = "0.1.0"
1154dependencies = [ 1180dependencies = [
1155 "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", 1181 "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
1156 "flexi_logger 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 1182 "flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
1157 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 1183 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
1158 "ra_batch 0.1.0", 1184 "ra_batch 0.1.0",
1159 "ra_db 0.1.0", 1185 "ra_db 0.1.0",
@@ -1239,7 +1265,7 @@ name = "ra_lsp_server"
1239version = "0.1.0" 1265version = "0.1.0"
1240dependencies = [ 1266dependencies = [
1241 "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 1267 "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
1242 "flexi_logger 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 1268 "flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
1243 "gen_lsp_server 0.2.0", 1269 "gen_lsp_server 0.2.0",
1244 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 1270 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
1245 "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)", 1271 "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1250,6 +1276,7 @@ dependencies = [
1250 "ra_syntax 0.1.0", 1276 "ra_syntax 0.1.0",
1251 "ra_text_edit 0.1.0", 1277 "ra_text_edit 0.1.0",
1252 "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 1278 "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
1279 "ra_vfs_glob 0.1.0",
1253 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1280 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1254 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1281 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1255 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", 1282 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1301,7 +1328,6 @@ dependencies = [
1301 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 1328 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
1302 "ra_arena 0.1.0", 1329 "ra_arena 0.1.0",
1303 "ra_db 0.1.0", 1330 "ra_db 0.1.0",
1304 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1305 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 1331 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1306 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", 1332 "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
1307 "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", 1333 "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1370,6 +1396,14 @@ dependencies = [
1370] 1396]
1371 1397
1372[[package]] 1398[[package]]
1399name = "ra_vfs_glob"
1400version = "0.1.0"
1401dependencies = [
1402 "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
1403 "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
1404]
1405
1406[[package]]
1373name = "rand" 1407name = "rand"
1374version = "0.6.5" 1408version = "0.6.5"
1375source = "registry+https://github.com/rust-lang/crates.io-index" 1409source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1377,7 +1411,7 @@ dependencies = [
1377 "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 1411 "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1378 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", 1412 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
1379 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1413 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1380 "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1414 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1381 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 1415 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1382 "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1416 "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1383 "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 1417 "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1392,7 +1426,7 @@ name = "rand"
1392version = "0.7.0" 1426version = "0.7.0"
1393source = "registry+https://github.com/rust-lang/crates.io-index" 1427source = "registry+https://github.com/rust-lang/crates.io-index"
1394dependencies = [ 1428dependencies = [
1395 "getrandom 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 1429 "getrandom 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1396 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", 1430 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
1397 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 1431 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
1398 "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 1432 "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1423,12 +1457,12 @@ name = "rand_core"
1423version = "0.3.1" 1457version = "0.3.1"
1424source = "registry+https://github.com/rust-lang/crates.io-index" 1458source = "registry+https://github.com/rust-lang/crates.io-index"
1425dependencies = [ 1459dependencies = [
1426 "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1460 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1427] 1461]
1428 1462
1429[[package]] 1463[[package]]
1430name = "rand_core" 1464name = "rand_core"
1431version = "0.4.0" 1465version = "0.4.2"
1432source = "registry+https://github.com/rust-lang/crates.io-index" 1466source = "registry+https://github.com/rust-lang/crates.io-index"
1433 1467
1434[[package]] 1468[[package]]
@@ -1436,7 +1470,7 @@ name = "rand_core"
1436version = "0.5.0" 1470version = "0.5.0"
1437source = "registry+https://github.com/rust-lang/crates.io-index" 1471source = "registry+https://github.com/rust-lang/crates.io-index"
1438dependencies = [ 1472dependencies = [
1439 "getrandom 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 1473 "getrandom 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
1440] 1474]
1441 1475
1442[[package]] 1476[[package]]
@@ -1469,7 +1503,7 @@ version = "0.1.4"
1469source = "registry+https://github.com/rust-lang/crates.io-index" 1503source = "registry+https://github.com/rust-lang/crates.io-index"
1470dependencies = [ 1504dependencies = [
1471 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", 1505 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
1472 "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1506 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1473 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 1507 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
1474] 1508]
1475 1509
@@ -1481,7 +1515,7 @@ dependencies = [
1481 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 1515 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
1482 "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1516 "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1483 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", 1517 "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
1484 "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1518 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1485 "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1519 "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1486 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 1520 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
1487] 1521]
@@ -1492,7 +1526,7 @@ version = "0.1.2"
1492source = "registry+https://github.com/rust-lang/crates.io-index" 1526source = "registry+https://github.com/rust-lang/crates.io-index"
1493dependencies = [ 1527dependencies = [
1494 "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 1528 "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1495 "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1529 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1496] 1530]
1497 1531
1498[[package]] 1532[[package]]
@@ -2116,6 +2150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2116"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" 2150"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
2117"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" 2151"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
2118"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" 2152"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09"
2153"checksum bstr 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e0a692f1c740e7e821ca71a22cf99b9b2322dfa94d10f71443befb1797b3946a"
2119"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" 2154"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
2120"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 2155"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
2121"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" 2156"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
@@ -2157,7 +2192,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2157"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" 2192"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
2158"checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" 2193"checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d"
2159"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" 2194"checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
2160"checksum flexi_logger 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c33205472cdf9f0626ff7c058d4b9cbef51673ceaf1169e54d4be49133cbab2" 2195"checksum flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2be2727ae1f60711d1991788605245e70cc500bd1d92edb909af160634e1a869"
2196"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
2161"checksum format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7aea5a5909a74969507051a3b17adc84737e31a5f910559892aedce026f4d53" 2197"checksum format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7aea5a5909a74969507051a3b17adc84737e31a5f910559892aedce026f4d53"
2162"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" 2198"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
2163"checksum fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" 2199"checksum fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
@@ -2167,9 +2203,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2167"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" 2203"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
2168"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 2204"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
2169"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" 2205"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
2170"checksum getrandom 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8e190892c840661957ba9f32dacfb3eb405e657f9f9f60485605f0bb37d6f8" 2206"checksum getrandom 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "34f33de6f0ae7c9cb5e574502a562e2b512799e32abb801cd1e79ad952b62b49"
2171"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" 2207"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
2172"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 2208"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
2209"checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2"
2173"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 2210"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
2174"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" 2211"checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
2175"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" 2212"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
@@ -2239,7 +2276,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2239"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" 2276"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
2240"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" 2277"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
2241"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 2278"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
2242"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" 2279"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
2243"checksum rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca" 2280"checksum rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca"
2244"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" 2281"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
2245"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 2282"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs
index 3b7cb77b1..3ec8d3b60 100644
--- a/crates/ra_arena/src/lib.rs
+++ b/crates/ra_arena/src/lib.rs
@@ -79,7 +79,7 @@ impl<ID: ArenaId, T> Arena<ID, T> {
79 self.data.push(value); 79 self.data.push(value);
80 ID::from_raw(id) 80 ID::from_raw(id)
81 } 81 }
82 pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> { 82 pub fn iter(&self) -> impl Iterator<Item = (ID, &T)> + ExactSizeIterator {
83 self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value)) 83 self.data.iter().enumerate().map(|(idx, value)| (ID::from_raw(RawId(idx as u32)), value))
84 } 84 }
85} 85}
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml
index 0ee94c445..8e23826a4 100644
--- a/crates/ra_batch/Cargo.toml
+++ b/crates/ra_batch/Cargo.toml
@@ -9,6 +9,7 @@ log = "0.4.5"
9rustc-hash = "1.0" 9rustc-hash = "1.0"
10 10
11ra_vfs = "0.2.0" 11ra_vfs = "0.2.0"
12ra_vfs_glob = { path = "../ra_vfs_glob" }
12ra_db = { path = "../ra_db" } 13ra_db = { path = "../ra_db" }
13ra_ide_api = { path = "../ra_ide_api" } 14ra_ide_api = { path = "../ra_ide_api" }
14ra_hir = { path = "../ra_hir" } 15ra_hir = { path = "../ra_hir" }
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs
index c25737aaa..0db751465 100644
--- a/crates/ra_batch/src/lib.rs
+++ b/crates/ra_batch/src/lib.rs
@@ -1,14 +1,12 @@
1mod vfs_filter;
2
3use std::{collections::HashSet, error::Error, path::Path}; 1use std::{collections::HashSet, error::Error, path::Path};
4 2
5use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
6 4
7use ra_db::{CrateGraph, FileId, SourceRootId}; 5use ra_db::{CrateGraph, FileId, SourceRootId};
8use ra_ide_api::{AnalysisChange, AnalysisHost}; 6use ra_ide_api::{AnalysisChange, AnalysisHost};
9use ra_project_model::{ProjectRoot, ProjectWorkspace}; 7use ra_project_model::{PackageRoot, ProjectWorkspace};
10use ra_vfs::{Vfs, VfsChange}; 8use ra_vfs::{RootEntry, Vfs, VfsChange};
11use vfs_filter::IncludeRustFiles; 9use ra_vfs_glob::RustPackageFilterBuilder;
12 10
13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; 11type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
14 12
@@ -19,11 +17,23 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
19 SourceRootId(r.0) 17 SourceRootId(r.0)
20} 18}
21 19
22pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, ProjectRoot>)> { 20pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
23 let root = std::env::current_dir()?.join(root); 21 let root = std::env::current_dir()?.join(root);
24 let ws = ProjectWorkspace::discover(root.as_ref())?; 22 let ws = ProjectWorkspace::discover(root.as_ref())?;
25 let project_roots = ws.to_roots(); 23 let project_roots = ws.to_roots();
26 let (mut vfs, roots) = Vfs::new(IncludeRustFiles::from_roots(project_roots.clone()).collect()); 24 let (mut vfs, roots) = Vfs::new(
25 project_roots
26 .iter()
27 .map(|pkg_root| {
28 RootEntry::new(
29 pkg_root.path().clone(),
30 RustPackageFilterBuilder::default()
31 .set_member(pkg_root.is_member())
32 .into_vfs_filter(),
33 )
34 })
35 .collect(),
36 );
27 let crate_graph = ws.to_crate_graph(&mut |path: &Path| { 37 let crate_graph = ws.to_crate_graph(&mut |path: &Path| {
28 let vfs_file = vfs.load(path); 38 let vfs_file = vfs.load(path);
29 log::debug!("vfs file {:?} -> {:?}", path, vfs_file); 39 log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
@@ -48,7 +58,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
48} 58}
49 59
50pub fn load( 60pub fn load(
51 source_roots: &FxHashMap<SourceRootId, ProjectRoot>, 61 source_roots: &FxHashMap<SourceRootId, PackageRoot>,
52 crate_graph: CrateGraph, 62 crate_graph: CrateGraph,
53 vfs: &mut Vfs, 63 vfs: &mut Vfs,
54) -> AnalysisHost { 64) -> AnalysisHost {
diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs
deleted file mode 100644
index 2f0d8cb8b..000000000
--- a/crates/ra_batch/src/vfs_filter.rs
+++ /dev/null
@@ -1,54 +0,0 @@
1use ra_project_model::ProjectRoot;
2use ra_vfs::{Filter, RelativePath, RootEntry};
3use std::path::PathBuf;
4
5/// `IncludeRustFiles` is used to convert
6/// from `ProjectRoot` to `RootEntry` for VFS
7pub struct IncludeRustFiles {
8 root: ProjectRoot,
9}
10
11impl IncludeRustFiles {
12 pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry>
13 where
14 R: IntoIterator<Item = ProjectRoot>,
15 {
16 roots.into_iter().map(IncludeRustFiles::from_root)
17 }
18
19 pub fn from_root(root: ProjectRoot) -> RootEntry {
20 IncludeRustFiles::from(root).into()
21 }
22
23 #[allow(unused)]
24 pub fn external(path: PathBuf) -> RootEntry {
25 IncludeRustFiles::from_root(ProjectRoot::new(path, false))
26 }
27
28 pub fn member(path: PathBuf) -> RootEntry {
29 IncludeRustFiles::from_root(ProjectRoot::new(path, true))
30 }
31}
32
33impl Filter for IncludeRustFiles {
34 fn include_dir(&self, dir_path: &RelativePath) -> bool {
35 self.root.include_dir(dir_path)
36 }
37
38 fn include_file(&self, file_path: &RelativePath) -> bool {
39 self.root.include_file(file_path)
40 }
41}
42
43impl From<ProjectRoot> for IncludeRustFiles {
44 fn from(v: ProjectRoot) -> IncludeRustFiles {
45 IncludeRustFiles { root: v }
46 }
47}
48
49impl From<IncludeRustFiles> for RootEntry {
50 fn from(v: IncludeRustFiles) -> RootEntry {
51 let path = v.root.path().clone();
52 RootEntry::new(path, Box::new(v))
53 }
54}
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs
index 403aab352..7e7e6c073 100644
--- a/crates/ra_cli/src/analysis_stats.rs
+++ b/crates/ra_cli/src/analysis_stats.rs
@@ -52,6 +52,9 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
52 println!("Total modules found: {}", visited_modules.len()); 52 println!("Total modules found: {}", visited_modules.len());
53 println!("Total declarations: {}", num_decls); 53 println!("Total declarations: {}", num_decls);
54 println!("Total functions: {}", funcs.len()); 54 println!("Total functions: {}", funcs.len());
55 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
56
57 let inference_time = Instant::now();
55 let bar = indicatif::ProgressBar::with_draw_target( 58 let bar = indicatif::ProgressBar::with_draw_target(
56 funcs.len() as u64, 59 funcs.len() as u64,
57 indicatif::ProgressDrawTarget::stderr_nohz(), 60 indicatif::ProgressDrawTarget::stderr_nohz(),
@@ -112,7 +115,8 @@ pub fn run(verbose: bool, memory_usage: bool, path: &Path, only: Option<&str>) -
112 num_exprs_partially_unknown, 115 num_exprs_partially_unknown,
113 (num_exprs_partially_unknown * 100 / num_exprs) 116 (num_exprs_partially_unknown * 100 / num_exprs)
114 ); 117 );
115 println!("Analysis: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 118 println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage());
119 println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
116 120
117 if memory_usage { 121 if memory_usage {
118 drop(db); 122 drop(db);
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index cec360667..c282d6db8 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -25,6 +25,7 @@ ra_ide_api = { path = "../ra_ide_api" }
25gen_lsp_server = { path = "../gen_lsp_server" } 25gen_lsp_server = { path = "../gen_lsp_server" }
26ra_project_model = { path = "../ra_project_model" } 26ra_project_model = { path = "../ra_project_model" }
27ra_prof = { path = "../ra_prof" } 27ra_prof = { path = "../ra_prof" }
28ra_vfs_glob = { path = "../ra_vfs_glob" }
28 29
29[dev-dependencies] 30[dev-dependencies]
30tempfile = "3" 31tempfile = "3"
diff --git a/crates/ra_lsp_server/src/init.rs b/crates/ra_lsp_server/src/config.rs
index b894b449d..6dcdc695a 100644
--- a/crates/ra_lsp_server/src/init.rs
+++ b/crates/ra_lsp_server/src/config.rs
@@ -1,9 +1,9 @@
1use serde::{Deserialize, Deserializer}; 1use serde::{Deserialize, Deserializer};
2 2
3/// Client provided initialization options 3/// Client provided initialization options
4#[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)] 4#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
5#[serde(rename_all = "camelCase", default)] 5#[serde(rename_all = "camelCase", default)]
6pub struct InitializationOptions { 6pub struct ServerConfig {
7 /// Whether the client supports our custom highlighting publishing decorations. 7 /// Whether the client supports our custom highlighting publishing decorations.
8 /// This is different to the highlightingOn setting, which is whether the user 8 /// This is different to the highlightingOn setting, which is whether the user
9 /// wants our custom highlighting to be used. 9 /// wants our custom highlighting to be used.
@@ -18,14 +18,17 @@ pub struct InitializationOptions {
18 #[serde(deserialize_with = "nullable_bool_true")] 18 #[serde(deserialize_with = "nullable_bool_true")]
19 pub show_workspace_loaded: bool, 19 pub show_workspace_loaded: bool,
20 20
21 pub exclude_globs: Vec<String>,
22
21 pub lru_capacity: Option<usize>, 23 pub lru_capacity: Option<usize>,
22} 24}
23 25
24impl Default for InitializationOptions { 26impl Default for ServerConfig {
25 fn default() -> InitializationOptions { 27 fn default() -> ServerConfig {
26 InitializationOptions { 28 ServerConfig {
27 publish_decorations: false, 29 publish_decorations: false,
28 show_workspace_loaded: true, 30 show_workspace_loaded: true,
31 exclude_globs: Vec::new(),
29 lru_capacity: None, 32 lru_capacity: None,
30 } 33 }
31 } 34 }
@@ -56,7 +59,7 @@ mod test {
56 #[test] 59 #[test]
57 fn deserialize_init_options_defaults() { 60 fn deserialize_init_options_defaults() {
58 // check that null == default for both fields 61 // check that null == default for both fields
59 let default = InitializationOptions::default(); 62 let default = ServerConfig::default();
60 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap()); 63 assert_eq!(default, serde_json::from_str(r#"{}"#).unwrap());
61 assert_eq!( 64 assert_eq!(
62 default, 65 default,
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 59c5e1582..df8ea6e0d 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -1,13 +1,13 @@
1use lsp_types::{ 1use lsp_types::{
2 self, CreateFile, DocumentChangeOperation, DocumentChanges, Documentation, Location, 2 self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
3 LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, 3 Location, LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp,
4 TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url, 4 SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem,
5 VersionedTextDocumentIdentifier, WorkspaceEdit, 5 TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit,
6}; 6};
7use ra_ide_api::{ 7use ra_ide_api::{
8 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, 8 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
9 FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, 9 FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo,
10 SourceChange, SourceFileEdit, 10 Severity, SourceChange, SourceFileEdit,
11}; 11};
12use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 12use ra_syntax::{SyntaxKind, TextRange, TextUnit};
13use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -79,6 +79,16 @@ impl Conv for CompletionItemKind {
79 } 79 }
80} 80}
81 81
82impl Conv for Severity {
83 type Output = DiagnosticSeverity;
84 fn conv(self) -> DiagnosticSeverity {
85 match self {
86 Severity::Error => DiagnosticSeverity::Error,
87 Severity::WeakWarning => DiagnosticSeverity::Hint,
88 }
89 }
90}
91
82impl ConvWith for CompletionItem { 92impl ConvWith for CompletionItem {
83 type Ctx = LineIndex; 93 type Ctx = LineIndex;
84 type Output = ::lsp_types::CompletionItem; 94 type Output = ::lsp_types::CompletionItem;
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index 56a263aa5..795f86383 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -4,13 +4,11 @@ mod conv;
4mod main_loop; 4mod main_loop;
5mod markdown; 5mod markdown;
6mod project_model; 6mod project_model;
7mod vfs_filter;
8pub mod req; 7pub mod req;
9pub mod init; 8pub mod config;
10mod world; 9mod world;
11 10
12pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; 11pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
13pub use crate::{ 12pub use crate::{
14 caps::server_capabilities, init::InitializationOptions, main_loop::main_loop, 13 caps::server_capabilities, config::ServerConfig, main_loop::main_loop, main_loop::LspError,
15 main_loop::LspError,
16}; 14};
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index c1f8243be..1a2ab1bc2 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -2,7 +2,7 @@ use flexi_logger::{Duplicate, Logger};
2use gen_lsp_server::{run_server, stdio_transport}; 2use gen_lsp_server::{run_server, stdio_transport};
3use serde::Deserialize; 3use serde::Deserialize;
4 4
5use ra_lsp_server::{InitializationOptions, Result}; 5use ra_lsp_server::{Result, ServerConfig};
6use ra_prof; 6use ra_prof;
7 7
8fn main() -> Result<()> { 8fn main() -> Result<()> {
@@ -48,7 +48,7 @@ fn main_inner() -> Result<()> {
48 48
49 let opts = params 49 let opts = params
50 .initialization_options 50 .initialization_options
51 .and_then(|v| InitializationOptions::deserialize(v).ok()) 51 .and_then(|v| ServerConfig::deserialize(v).ok())
52 .unwrap_or_default(); 52 .unwrap_or_default();
53 53
54 ra_lsp_server::main_loop(workspace_roots, params.capabilities, opts, r, s) 54 ra_lsp_server::main_loop(workspace_roots, params.capabilities, opts, r, s)
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 8e830c8b8..9d540a87e 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -23,7 +23,7 @@ use crate::{
23 project_model::workspace_loader, 23 project_model::workspace_loader,
24 req, 24 req,
25 world::{Options, WorldSnapshot, WorldState}, 25 world::{Options, WorldSnapshot, WorldState},
26 InitializationOptions, Result, 26 Result, ServerConfig,
27}; 27};
28 28
29const THREADPOOL_SIZE: usize = 8; 29const THREADPOOL_SIZE: usize = 8;
@@ -52,10 +52,11 @@ impl Error for LspError {}
52pub fn main_loop( 52pub fn main_loop(
53 ws_roots: Vec<PathBuf>, 53 ws_roots: Vec<PathBuf>,
54 client_caps: ClientCapabilities, 54 client_caps: ClientCapabilities,
55 options: InitializationOptions, 55 config: ServerConfig,
56 msg_receiver: &Receiver<RawMessage>, 56 msg_receiver: &Receiver<RawMessage>,
57 msg_sender: &Sender<RawMessage>, 57 msg_sender: &Sender<RawMessage>,
58) -> Result<()> { 58) -> Result<()> {
59 log::debug!("server_config: {:?}", config);
59 // FIXME: support dynamic workspace loading. 60 // FIXME: support dynamic workspace loading.
60 let workspaces = { 61 let workspaces = {
61 let ws_worker = workspace_loader(); 62 let ws_worker = workspace_loader();
@@ -77,14 +78,19 @@ pub fn main_loop(
77 } 78 }
78 loaded_workspaces 79 loaded_workspaces
79 }; 80 };
80 81 let globs = config
82 .exclude_globs
83 .iter()
84 .map(|glob| ra_vfs_glob::Glob::new(glob))
85 .collect::<std::result::Result<Vec<_>, _>>()?;
81 let mut state = WorldState::new( 86 let mut state = WorldState::new(
82 ws_roots, 87 ws_roots,
83 workspaces, 88 workspaces,
84 options.lru_capacity, 89 config.lru_capacity,
90 &globs,
85 Options { 91 Options {
86 publish_decorations: options.publish_decorations, 92 publish_decorations: config.publish_decorations,
87 show_workspace_loaded: options.show_workspace_loaded, 93 show_workspace_loaded: config.show_workspace_loaded,
88 supports_location_link: client_caps 94 supports_location_link: client_caps
89 .text_document 95 .text_document
90 .and_then(|it| it.definition) 96 .and_then(|it| it.definition)
@@ -269,7 +275,7 @@ fn main_loop_inner(
269 && pending_libraries.is_empty() 275 && pending_libraries.is_empty()
270 && in_flight_libraries == 0 276 && in_flight_libraries == 0
271 { 277 {
272 let n_packages: usize = state.workspaces.iter().map(|it| it.count()).sum(); 278 let n_packages: usize = state.workspaces.iter().map(|it| it.n_packages()).sum();
273 if state.options.show_workspace_loaded { 279 if state.options.show_workspace_loaded {
274 let msg = format!("workspace loaded, {} rust packages", n_packages); 280 let msg = format!("workspace loaded, {} rust packages", n_packages);
275 show_message(req::MessageType::Info, msg, msg_sender); 281 show_message(req::MessageType::Info, msg, msg_sender);
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index a6dc1f964..686ee5d12 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -3,13 +3,13 @@ use std::{fmt::Write as _, io::Write as _};
3use gen_lsp_server::ErrorCode; 3use gen_lsp_server::ErrorCode;
4use lsp_types::{ 4use lsp_types::{
5 CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic, 5 CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic,
6 DiagnosticSeverity, DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, 6 DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind,
7 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, 7 FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position,
8 MarkupKind, Position, PrepareRenameResponse, Range, RenameParams, SymbolInformation, 8 PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier,
9 TextDocumentIdentifier, TextEdit, WorkspaceEdit, 9 TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, 12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind,
13}; 13};
14use ra_prof::profile; 14use ra_prof::profile;
15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -838,7 +838,7 @@ pub fn publish_diagnostics(
838 .into_iter() 838 .into_iter()
839 .map(|d| Diagnostic { 839 .map(|d| Diagnostic {
840 range: d.range.conv_with(&line_index), 840 range: d.range.conv_with(&line_index),
841 severity: Some(to_diagnostic_severity(d.severity)), 841 severity: Some(d.severity.conv()),
842 code: None, 842 code: None,
843 source: Some("rust-analyzer".to_string()), 843 source: Some("rust-analyzer".to_string()),
844 message: d.message, 844 message: d.message,
@@ -871,15 +871,6 @@ fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>>
871 Ok(res) 871 Ok(res)
872} 872}
873 873
874fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity {
875 use ra_ide_api::Severity::*;
876
877 match severity {
878 Error => DiagnosticSeverity::Error,
879 WeakWarning => DiagnosticSeverity::Hint,
880 }
881}
882
883pub fn handle_inlay_hints( 874pub fn handle_inlay_hints(
884 world: WorldSnapshot, 875 world: WorldSnapshot,
885 params: InlayHintsParams, 876 params: InlayHintsParams,
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs
index 947ef77cd..c1eb0236a 100644
--- a/crates/ra_lsp_server/src/markdown.rs
+++ b/crates/ra_lsp_server/src/markdown.rs
@@ -54,4 +54,21 @@ mod tests {
54 let comment = "this\nis\nultiline"; 54 let comment = "this\nis\nultiline";
55 assert_eq!(format_docs(comment), comment); 55 assert_eq!(format_docs(comment), comment);
56 } 56 }
57
58 #[test]
59 fn test_code_blocks_in_comments_marked_as_rust() {
60 let comment = r#"```rust
61fn main(){}
62```
63Some comment.
64```
65let a = 1;
66```"#;
67
68 assert_eq!(
69 format_docs(comment),
70 "```rust\nfn main(){}\n```\nSome comment.\n```rust\nlet a = 1;\n```"
71 );
72 }
73
57} 74}
diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs
deleted file mode 100644
index e16a57da5..000000000
--- a/crates/ra_lsp_server/src/vfs_filter.rs
+++ /dev/null
@@ -1,54 +0,0 @@
1use ra_project_model::ProjectRoot;
2use ra_vfs::{Filter, RelativePath, RootEntry};
3use std::path::PathBuf;
4
5/// `IncludeRustFiles` is used to convert
6/// from `ProjectRoot` to `RootEntry` for VFS
7pub struct IncludeRustFiles {
8 root: ProjectRoot,
9}
10
11impl IncludeRustFiles {
12 pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry>
13 where
14 R: IntoIterator<Item = ProjectRoot>,
15 {
16 roots.into_iter().map(IncludeRustFiles::from_root)
17 }
18
19 pub fn from_root(root: ProjectRoot) -> RootEntry {
20 IncludeRustFiles::from(root).into()
21 }
22
23 #[allow(unused)]
24 pub fn external(path: PathBuf) -> RootEntry {
25 IncludeRustFiles::from_root(ProjectRoot::new(path, false))
26 }
27
28 pub fn member(path: PathBuf) -> RootEntry {
29 IncludeRustFiles::from_root(ProjectRoot::new(path, true))
30 }
31}
32
33impl Filter for IncludeRustFiles {
34 fn include_dir(&self, dir_path: &RelativePath) -> bool {
35 self.root.include_dir(dir_path)
36 }
37
38 fn include_file(&self, file_path: &RelativePath) -> bool {
39 self.root.include_file(file_path)
40 }
41}
42
43impl std::convert::From<ProjectRoot> for IncludeRustFiles {
44 fn from(v: ProjectRoot) -> IncludeRustFiles {
45 IncludeRustFiles { root: v }
46 }
47}
48
49impl std::convert::From<IncludeRustFiles> for RootEntry {
50 fn from(v: IncludeRustFiles) -> RootEntry {
51 let path = v.root.path().clone();
52 RootEntry::new(path, Box::new(v))
53 }
54}
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index 1d7755910..9990ef62e 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -9,13 +9,13 @@ use parking_lot::RwLock;
9use ra_ide_api::{ 9use ra_ide_api::{
10 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, 10 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
11}; 11};
12use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; 12use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot};
13use ra_vfs_glob::{Glob, RustPackageFilterBuilder};
13use relative_path::RelativePathBuf; 14use relative_path::RelativePathBuf;
14 15
15use crate::{ 16use crate::{
16 main_loop::pending_requests::{CompletedRequest, LatestRequests}, 17 main_loop::pending_requests::{CompletedRequest, LatestRequests},
17 project_model::ProjectWorkspace, 18 project_model::ProjectWorkspace,
18 vfs_filter::IncludeRustFiles,
19 LspError, Result, 19 LspError, Result,
20}; 20};
21 21
@@ -56,14 +56,28 @@ impl WorldState {
56 folder_roots: Vec<PathBuf>, 56 folder_roots: Vec<PathBuf>,
57 workspaces: Vec<ProjectWorkspace>, 57 workspaces: Vec<ProjectWorkspace>,
58 lru_capacity: Option<usize>, 58 lru_capacity: Option<usize>,
59 exclude_globs: &[Glob],
59 options: Options, 60 options: Options,
60 ) -> WorldState { 61 ) -> WorldState {
61 let mut change = AnalysisChange::new(); 62 let mut change = AnalysisChange::new();
62 63
63 let mut roots = Vec::new(); 64 let mut roots = Vec::new();
64 roots.extend(folder_roots.iter().cloned().map(IncludeRustFiles::member)); 65 roots.extend(folder_roots.iter().map(|path| {
66 let mut filter = RustPackageFilterBuilder::default().set_member(true);
67 for glob in exclude_globs.iter() {
68 filter = filter.exclude(glob.clone());
69 }
70 RootEntry::new(path.clone(), filter.into_vfs_filter())
71 }));
65 for ws in workspaces.iter() { 72 for ws in workspaces.iter() {
66 roots.extend(IncludeRustFiles::from_roots(ws.to_roots())); 73 roots.extend(ws.to_roots().into_iter().map(|pkg_root| {
74 let mut filter =
75 RustPackageFilterBuilder::default().set_member(pkg_root.is_member());
76 for glob in exclude_globs.iter() {
77 filter = filter.exclude(glob.clone());
78 }
79 RootEntry::new(pkg_root.path().clone(), filter.into_vfs_filter())
80 }));
67 } 81 }
68 82
69 let (mut vfs, vfs_roots) = Vfs::new(roots); 83 let (mut vfs, vfs_roots) = Vfs::new(roots);
@@ -211,7 +225,7 @@ impl WorldSnapshot {
211 } else { 225 } else {
212 res.push_str("workspaces:\n"); 226 res.push_str("workspaces:\n");
213 for w in self.workspaces.iter() { 227 for w in self.workspaces.iter() {
214 res += &format!("{} packages loaded\n", w.count()); 228 res += &format!("{} packages loaded\n", w.n_packages());
215 } 229 }
216 } 230 }
217 res.push_str("\nanalysis:\n"); 231 res.push_str("\nanalysis:\n");
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 5dddbbe17..ba8ee8b06 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -22,7 +22,7 @@ use tempfile::TempDir;
22use test_utils::{find_mismatch, parse_fixture}; 22use test_utils::{find_mismatch, parse_fixture};
23use thread_worker::Worker; 23use thread_worker::Worker;
24 24
25use ra_lsp_server::{main_loop, req, InitializationOptions}; 25use ra_lsp_server::{main_loop, req, ServerConfig};
26 26
27pub struct Project<'a> { 27pub struct Project<'a> {
28 fixture: &'a str, 28 fixture: &'a str,
@@ -107,7 +107,7 @@ impl Server {
107 window: None, 107 window: None,
108 experimental: None, 108 experimental: None,
109 }, 109 },
110 InitializationOptions::default(), 110 ServerConfig::default(),
111 &msg_receiver, 111 &msg_receiver,
112 &msg_sender, 112 &msg_sender,
113 ) 113 )
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs
index 159ed50df..393586561 100644
--- a/crates/ra_parser/src/parser.rs
+++ b/crates/ra_parser/src/parser.rs
@@ -6,7 +6,7 @@ use crate::{
6 event::Event, 6 event::Event,
7 ParseError, 7 ParseError,
8 SyntaxKind::{self, EOF, ERROR, TOMBSTONE}, 8 SyntaxKind::{self, EOF, ERROR, TOMBSTONE},
9 TokenSet, TokenSource, T, 9 Token, TokenSet, TokenSource, T,
10}; 10};
11 11
12/// `Parser` struct provides the low-level API for 12/// `Parser` struct provides the low-level API for
@@ -87,8 +87,9 @@ impl<'t> Parser<'t> {
87 let mut i = 0; 87 let mut i = 0;
88 88
89 loop { 89 loop {
90 let mut kind = self.token_source.lookahead_nth(i).kind; 90 let token = self.token_source.lookahead_nth(i);
91 if let Some((composited, step)) = self.is_composite(kind, i) { 91 let mut kind = token.kind;
92 if let Some((composited, step)) = self.is_composite(token, i) {
92 kind = composited; 93 kind = composited;
93 i += step; 94 i += step;
94 } else { 95 } else {
@@ -250,32 +251,47 @@ impl<'t> Parser<'t> {
250 } 251 }
251 252
252 /// helper function for check if it is composite. 253 /// helper function for check if it is composite.
253 fn is_composite(&self, kind: SyntaxKind, n: usize) -> Option<(SyntaxKind, usize)> { 254 fn is_composite(&self, first: Token, n: usize) -> Option<(SyntaxKind, usize)> {
254 // We assume the dollars will not occuried between 255 // We assume the dollars will not occuried between
255 // mult-byte tokens 256 // mult-byte tokens
256 257
257 let first = self.token_source.lookahead_nth(n); 258 let jn1 = first.is_jointed_to_next;
259 if !jn1 && first.kind != T![-] {
260 return None;
261 }
262
258 let second = self.token_source.lookahead_nth(n + 1); 263 let second = self.token_source.lookahead_nth(n + 1);
264 if first.kind == T![-] && second.kind == T![>] {
265 return Some((T![->], 2));
266 }
267 if !jn1 {
268 return None;
269 }
270
271 match (first.kind, second.kind) {
272 (T![:], T![:]) => return Some((T![::], 2)),
273 (T![=], T![=]) => return Some((T![==], 2)),
274 (T![=], T![>]) => return Some((T![=>], 2)),
275 (T![!], T![=]) => return Some((T![!=], 2)),
276 _ => {}
277 }
278
279 if first.kind != T![.] || second.kind != T![.] {
280 return None;
281 }
282
259 let third = self.token_source.lookahead_nth(n + 2); 283 let third = self.token_source.lookahead_nth(n + 2);
260 284
261 let jn1 = first.is_jointed_to_next;
262 let la2 = second.kind;
263 let jn2 = second.is_jointed_to_next; 285 let jn2 = second.is_jointed_to_next;
264 let la3 = third.kind; 286 let la3 = third.kind;
265 287
266 match kind { 288 if jn2 && la3 == T![.] {
267 T![.] if jn1 && la2 == T![.] && jn2 && la3 == T![.] => Some((T![...], 3)), 289 return Some((T![...], 3));
268 T![.] if jn1 && la2 == T![.] && la3 == T![=] => Some((T![..=], 3)), 290 }
269 T![.] if jn1 && la2 == T![.] => Some((T![..], 2)), 291 if la3 == T![=] {
270 292 return Some((T![..=], 3));
271 T![:] if jn1 && la2 == T![:] => Some((T![::], 2)),
272 T![=] if jn1 && la2 == T![=] => Some((T![==], 2)),
273 T![=] if jn1 && la2 == T![>] => Some((T![=>], 2)),
274
275 T![!] if jn1 && la2 == T![=] => Some((T![!=], 2)),
276 T![-] if la2 == T![>] => Some((T![->], 2)),
277 _ => None,
278 } 293 }
294 return Some((T![..], 2));
279 } 295 }
280 296
281 fn eat_dollars(&mut self) { 297 fn eat_dollars(&mut self) {
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml
index 3545d23c9..4fd6c75ef 100644
--- a/crates/ra_project_model/Cargo.toml
+++ b/crates/ra_project_model/Cargo.toml
@@ -7,7 +7,6 @@ authors = ["rust-analyzer developers"]
7[dependencies] 7[dependencies]
8log = "0.4.5" 8log = "0.4.5"
9rustc-hash = "1.0" 9rustc-hash = "1.0"
10relative-path = "0.4.0"
11 10
12cargo_metadata = "0.8.0" 11cargo_metadata = "0.8.0"
13 12
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 2b06e9e37..712d8818f 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -167,7 +167,7 @@ impl CargoWorkspace {
167 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root }) 167 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root })
168 } 168 }
169 169
170 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a { 170 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + ExactSizeIterator + 'a {
171 self.packages.iter().map(|(id, _pkg)| id) 171 self.packages.iter().map(|(id, _pkg)| id)
172 } 172 }
173 173
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 08e5c1c32..55b94b911 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -9,14 +9,10 @@ use std::{
9 path::{Path, PathBuf}, 9 path::{Path, PathBuf},
10}; 10};
11 11
12use rustc_hash::FxHashMap;
13
14use ra_db::{CrateGraph, Edition, FileId}; 12use ra_db::{CrateGraph, Edition, FileId};
15 13use rustc_hash::FxHashMap;
16use serde_json::from_reader; 14use serde_json::from_reader;
17 15
18use relative_path::RelativePath;
19
20pub use crate::{ 16pub use crate::{
21 cargo_workspace::{CargoWorkspace, Package, Target, TargetKind}, 17 cargo_workspace::{CargoWorkspace, Package, Target, TargetKind},
22 json_project::JsonProject, 18 json_project::JsonProject,
@@ -34,20 +30,20 @@ pub enum ProjectWorkspace {
34 Json { project: JsonProject }, 30 Json { project: JsonProject },
35} 31}
36 32
37/// `ProjectRoot` describes a workspace root folder. 33/// `PackageRoot` describes a package root folder.
38/// Which may be an external dependency, or a member of 34/// Which may be an external dependency, or a member of
39/// the current workspace. 35/// the current workspace.
40#[derive(Clone)] 36#[derive(Clone)]
41pub struct ProjectRoot { 37pub struct PackageRoot {
42 /// Path to the root folder 38 /// Path to the root folder
43 path: PathBuf, 39 path: PathBuf,
44 /// Is a member of the current workspace 40 /// Is a member of the current workspace
45 is_member: bool, 41 is_member: bool,
46} 42}
47 43
48impl ProjectRoot { 44impl PackageRoot {
49 pub fn new(path: PathBuf, is_member: bool) -> ProjectRoot { 45 pub fn new(path: PathBuf, is_member: bool) -> PackageRoot {
50 ProjectRoot { path, is_member } 46 PackageRoot { path, is_member }
51 } 47 }
52 48
53 pub fn path(&self) -> &PathBuf { 49 pub fn path(&self) -> &PathBuf {
@@ -57,28 +53,6 @@ impl ProjectRoot {
57 pub fn is_member(&self) -> bool { 53 pub fn is_member(&self) -> bool {
58 self.is_member 54 self.is_member
59 } 55 }
60
61 pub fn include_dir(&self, dir_path: &RelativePath) -> bool {
62 const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"];
63 const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"];
64
65 let is_ignored = if self.is_member {
66 dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str()))
67 } else {
68 dir_path.components().any(|c| {
69 let path = c.as_str();
70 COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path)
71 })
72 };
73
74 let hidden = dir_path.components().any(|c| c.as_str().starts_with('.'));
75
76 !is_ignored && !hidden
77 }
78
79 pub fn include_file(&self, file_path: &RelativePath) -> bool {
80 file_path.extension() == Some("rs")
81 }
82} 56}
83 57
84impl ProjectWorkspace { 58impl ProjectWorkspace {
@@ -99,38 +73,39 @@ impl ProjectWorkspace {
99 } 73 }
100 } 74 }
101 75
102 /// Returns the roots for the current ProjectWorkspace 76 /// Returns the roots for the current `ProjectWorkspace`
103 /// The return type contains the path and whether or not 77 /// The return type contains the path and whether or not
104 /// the root is a member of the current workspace 78 /// the root is a member of the current workspace
105 pub fn to_roots(&self) -> Vec<ProjectRoot> { 79 pub fn to_roots(&self) -> Vec<PackageRoot> {
106 match self { 80 match self {
107 ProjectWorkspace::Json { project } => { 81 ProjectWorkspace::Json { project } => {
108 let mut roots = Vec::with_capacity(project.roots.len()); 82 let mut roots = Vec::with_capacity(project.roots.len());
109 for root in &project.roots { 83 for root in &project.roots {
110 roots.push(ProjectRoot::new(root.path.clone(), true)); 84 roots.push(PackageRoot::new(root.path.clone(), true));
111 } 85 }
112 roots 86 roots
113 } 87 }
114 ProjectWorkspace::Cargo { cargo, sysroot } => { 88 ProjectWorkspace::Cargo { cargo, sysroot } => {
115 let mut roots = 89 let mut roots = Vec::with_capacity(cargo.packages().len() + sysroot.crates().len());
116 Vec::with_capacity(cargo.packages().count() + sysroot.crates().count());
117 for pkg in cargo.packages() { 90 for pkg in cargo.packages() {
118 let root = pkg.root(&cargo).to_path_buf(); 91 let root = pkg.root(&cargo).to_path_buf();
119 let member = pkg.is_member(&cargo); 92 let member = pkg.is_member(&cargo);
120 roots.push(ProjectRoot::new(root, member)); 93 roots.push(PackageRoot::new(root, member));
121 } 94 }
122 for krate in sysroot.crates() { 95 for krate in sysroot.crates() {
123 roots.push(ProjectRoot::new(krate.root_dir(&sysroot).to_path_buf(), false)) 96 roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false))
124 } 97 }
125 roots 98 roots
126 } 99 }
127 } 100 }
128 } 101 }
129 102
130 pub fn count(&self) -> usize { 103 pub fn n_packages(&self) -> usize {
131 match self { 104 match self {
132 ProjectWorkspace::Json { project } => project.crates.len(), 105 ProjectWorkspace::Json { project } => project.crates.len(),
133 ProjectWorkspace::Cargo { cargo, .. } => cargo.packages().count(), 106 ProjectWorkspace::Cargo { cargo, sysroot } => {
107 cargo.packages().len() + sysroot.crates().len()
108 }
134 } 109 }
135 } 110 }
136 111
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs
index 4f6e880dd..3f34d51cc 100644
--- a/crates/ra_project_model/src/sysroot.rs
+++ b/crates/ra_project_model/src/sysroot.rs
@@ -28,7 +28,7 @@ impl Sysroot {
28 self.by_name("std") 28 self.by_name("std")
29 } 29 }
30 30
31 pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + 'a { 31 pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a {
32 self.crates.iter().map(|(id, _data)| id) 32 self.crates.iter().map(|(id, _data)| id)
33 } 33 }
34 34
diff --git a/crates/ra_vfs_glob/Cargo.toml b/crates/ra_vfs_glob/Cargo.toml
new file mode 100644
index 000000000..0390d7da1
--- /dev/null
+++ b/crates/ra_vfs_glob/Cargo.toml
@@ -0,0 +1,9 @@
1[package]
2edition = "2018"
3name = "ra_vfs_glob"
4version = "0.1.0"
5authors = ["rust-analyzer developers"]
6
7[dependencies]
8ra_vfs = "0.2.0"
9globset = "0.4.4"
diff --git a/crates/ra_vfs_glob/src/lib.rs b/crates/ra_vfs_glob/src/lib.rs
new file mode 100644
index 000000000..12401d75a
--- /dev/null
+++ b/crates/ra_vfs_glob/src/lib.rs
@@ -0,0 +1,94 @@
1//! `ra_vfs_glob` crate implements exclusion rules for vfs.
2//!
3//! By default, we include only `.rs` files, and skip some know offenders like
4//! `/target` or `/node_modules` altogether.
5//!
6//! It's also possible to add custom exclusion globs.
7
8use globset::{GlobSet, GlobSetBuilder};
9use ra_vfs::{Filter, RelativePath};
10
11pub use globset::{Glob, GlobBuilder};
12
13const ALWAYS_IGNORED: &[&str] = &["target/**", "**/node_modules/**", "**/.git/**"];
14const IGNORED_FOR_NON_MEMBERS: &[&str] = &["examples/**", "tests/**", "benches/**"];
15
16pub struct RustPackageFilterBuilder {
17 is_member: bool,
18 exclude: GlobSetBuilder,
19}
20
21impl Default for RustPackageFilterBuilder {
22 fn default() -> RustPackageFilterBuilder {
23 RustPackageFilterBuilder { is_member: false, exclude: GlobSetBuilder::new() }
24 }
25}
26
27impl RustPackageFilterBuilder {
28 pub fn set_member(mut self, is_member: bool) -> RustPackageFilterBuilder {
29 self.is_member = is_member;
30 self
31 }
32 pub fn exclude(mut self, glob: Glob) -> RustPackageFilterBuilder {
33 self.exclude.add(glob);
34 self
35 }
36 pub fn into_vfs_filter(self) -> Box<dyn Filter> {
37 let RustPackageFilterBuilder { is_member, mut exclude } = self;
38 for &glob in ALWAYS_IGNORED {
39 exclude.add(Glob::new(glob).unwrap());
40 }
41 if !is_member {
42 for &glob in IGNORED_FOR_NON_MEMBERS {
43 exclude.add(Glob::new(glob).unwrap());
44 }
45 }
46 Box::new(RustPackageFilter { exclude: exclude.build().unwrap() })
47 }
48}
49
50struct RustPackageFilter {
51 exclude: GlobSet,
52}
53
54impl Filter for RustPackageFilter {
55 fn include_dir(&self, dir_path: &RelativePath) -> bool {
56 !self.exclude.is_match(dir_path.as_str())
57 }
58
59 fn include_file(&self, file_path: &RelativePath) -> bool {
60 file_path.extension() == Some("rs")
61 }
62}
63
64#[test]
65fn test_globs() {
66 let filter = RustPackageFilterBuilder::default().set_member(true).into_vfs_filter();
67
68 assert!(filter.include_dir(RelativePath::new("src/tests")));
69 assert!(filter.include_dir(RelativePath::new("src/target")));
70 assert!(filter.include_dir(RelativePath::new("tests")));
71 assert!(filter.include_dir(RelativePath::new("benches")));
72
73 assert!(!filter.include_dir(RelativePath::new("target")));
74 assert!(!filter.include_dir(RelativePath::new("src/foo/.git")));
75 assert!(!filter.include_dir(RelativePath::new("foo/node_modules")));
76
77 let filter = RustPackageFilterBuilder::default().set_member(false).into_vfs_filter();
78
79 assert!(filter.include_dir(RelativePath::new("src/tests")));
80 assert!(filter.include_dir(RelativePath::new("src/target")));
81
82 assert!(!filter.include_dir(RelativePath::new("target")));
83 assert!(!filter.include_dir(RelativePath::new("src/foo/.git")));
84 assert!(!filter.include_dir(RelativePath::new("foo/node_modules")));
85 assert!(!filter.include_dir(RelativePath::new("tests")));
86 assert!(!filter.include_dir(RelativePath::new("benches")));
87
88 let filter = RustPackageFilterBuilder::default()
89 .set_member(true)
90 .exclude(Glob::new("src/llvm-project/**").unwrap())
91 .into_vfs_filter();
92
93 assert!(!filter.include_dir(RelativePath::new("src/llvm-project/clang")));
94}
diff --git a/docs/user/README.md b/docs/user/README.md
index a5e17f604..7990d1d31 100644
--- a/docs/user/README.md
+++ b/docs/user/README.md
@@ -71,6 +71,9 @@ See https://github.com/microsoft/vscode/issues/72308[microsoft/vscode#72308] for
71* `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable 71* `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable
72* `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo 72* `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo
73 watch` for live error highlighting (note, this **does not** use rust-analyzer) 73 watch` for live error highlighting (note, this **does not** use rust-analyzer)
74* `rust-analyzer.excludeGlobs`: a list of glob-patterns for exclusion (see globset [docs](https://docs.rs/globset) for syntax).
75 Note: glob patterns are applied to all Cargo packages and a rooted at a package root.
76 This is not very intuitive and a limitation of a current implementation.
74* `rust-analyzer.cargo-watch.check-arguments`: cargo-watch check arguments. 77* `rust-analyzer.cargo-watch.check-arguments`: cargo-watch check arguments.
75 (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` ) 78 (e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` )
76* `rust-analyzer.trace.server`: enables internal logging 79* `rust-analyzer.trace.server`: enables internal logging
diff --git a/editors/code/package.json b/editors/code/package.json
index 808dc5dc1..48ab886bf 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -197,6 +197,11 @@
197 ], 197 ],
198 "description": "Whether to run `cargo watch` on startup" 198 "description": "Whether to run `cargo watch` on startup"
199 }, 199 },
200 "rust-analyzer.excludeGlobs": {
201 "type": "array",
202 "default": "[]",
203 "description": "Paths to exclude from analysis"
204 },
200 "rust-analyzer.cargo-watch.arguments": { 205 "rust-analyzer.cargo-watch.arguments": {
201 "type": "string", 206 "type": "string",
202 "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", 207 "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 4d58a1a93..4df6b50ef 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -22,6 +22,7 @@ export class Config {
22 public showWorkspaceLoadedNotification = true; 22 public showWorkspaceLoadedNotification = true;
23 public lruCapacity: null | number = null; 23 public lruCapacity: null | number = null;
24 public displayInlayHints = true; 24 public displayInlayHints = true;
25 public excludeGlobs = [];
25 public cargoWatchOptions: CargoWatchOptions = { 26 public cargoWatchOptions: CargoWatchOptions = {
26 enableOnStartup: 'ask', 27 enableOnStartup: 'ask',
27 trace: 'off', 28 trace: 'off',
@@ -128,5 +129,8 @@ export class Config {
128 if (config.has('displayInlayHints')) { 129 if (config.has('displayInlayHints')) {
129 this.displayInlayHints = config.get('displayInlayHints') as boolean; 130 this.displayInlayHints = config.get('displayInlayHints') as boolean;
130 } 131 }
132 if (config.has('excludeGlobs')) {
133 this.excludeGlobs = config.get('excludeGlobs') || [];
134 }
131 } 135 }
132} 136}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 7029142fd..2b4c25c28 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -36,7 +36,8 @@ export class Server {
36 publishDecorations: true, 36 publishDecorations: true,
37 showWorkspaceLoaded: 37 showWorkspaceLoaded:
38 Server.config.showWorkspaceLoadedNotification, 38 Server.config.showWorkspaceLoadedNotification,
39 lruCapacity: Server.config.lruCapacity 39 lruCapacity: Server.config.lruCapacity,
40 excludeGlobs: Server.config.excludeGlobs
40 }, 41 },
41 traceOutputChannel 42 traceOutputChannel
42 }; 43 };