aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock80
-rw-r--r--crates/gen_lsp_server/Cargo.toml2
-rw-r--r--crates/ra_analysis/src/lib.rs5
-rw-r--r--crates/ra_editor/src/folding_ranges.rs142
-rw-r--r--crates/ra_editor/src/lib.rs2
-rw-r--r--crates/ra_lsp_server/Cargo.toml2
-rw-r--r--crates/ra_lsp_server/src/caps.rs6
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs44
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs1
9 files changed, 236 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e51fd4a7a..815c97483 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,7 +3,7 @@ name = "aho-corasick"
3version = "0.6.8" 3version = "0.6.8"
4source = "registry+https://github.com/rust-lang/crates.io-index" 4source = "registry+https://github.com/rust-lang/crates.io-index"
5dependencies = [ 5dependencies = [
6 "memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 6 "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
7] 7]
8 8
9[[package]] 9[[package]]
@@ -11,7 +11,7 @@ name = "ansi_term"
11version = "0.11.0" 11version = "0.11.0"
12source = "registry+https://github.com/rust-lang/crates.io-index" 12source = "registry+https://github.com/rust-lang/crates.io-index"
13dependencies = [ 13dependencies = [
14 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 14 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
15] 15]
16 16
17[[package]] 17[[package]]
@@ -29,7 +29,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29dependencies = [ 29dependencies = [
30 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 30 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
31 "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 31 "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
32 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 32 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
33] 33]
34 34
35[[package]] 35[[package]]
@@ -41,7 +41,7 @@ dependencies = [
41 "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 41 "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
42 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 42 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
43 "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 43 "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
44 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 44 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
45] 45]
46 46
47[[package]] 47[[package]]
@@ -81,7 +81,7 @@ dependencies = [
81 "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 81 "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
82 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 82 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
83 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 83 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
84 "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", 84 "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
85] 85]
86 86
87[[package]] 87[[package]]
@@ -128,7 +128,7 @@ dependencies = [
128 128
129[[package]] 129[[package]]
130name = "crossbeam-channel" 130name = "crossbeam-channel"
131version = "0.2.5" 131version = "0.2.6"
132source = "registry+https://github.com/rust-lang/crates.io-index" 132source = "registry+https://github.com/rust-lang/crates.io-index"
133dependencies = [ 133dependencies = [
134 "crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 134 "crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -273,13 +273,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
273name = "gen_lsp_server" 273name = "gen_lsp_server"
274version = "0.1.0" 274version = "0.1.0"
275dependencies = [ 275dependencies = [
276 "crossbeam-channel 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 276 "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
277 "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 277 "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
278 "languageserver-types 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)", 278 "languageserver-types 0.51.0 (registry+https://github.com/rust-lang/crates.io-index)",
279 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", 279 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
280 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 280 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
281 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 281 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
282 "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", 282 "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
283] 283]
284 284
285[[package]] 285[[package]]
@@ -339,7 +339,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
339 339
340[[package]] 340[[package]]
341name = "languageserver-types" 341name = "languageserver-types"
342version = "0.50.0" 342version = "0.51.0"
343source = "registry+https://github.com/rust-lang/crates.io-index" 343source = "registry+https://github.com/rust-lang/crates.io-index"
344dependencies = [ 344dependencies = [
345 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 345 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -347,7 +347,7 @@ dependencies = [
347 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 347 "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
348 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 348 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
349 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 349 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
350 "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", 350 "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
351 "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 351 "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
352 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 352 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
353] 353]
@@ -389,10 +389,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
389 389
390[[package]] 390[[package]]
391name = "memchr" 391name = "memchr"
392version = "2.0.2" 392version = "2.1.0"
393source = "registry+https://github.com/rust-lang/crates.io-index" 393source = "registry+https://github.com/rust-lang/crates.io-index"
394dependencies = [ 394dependencies = [
395 "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
395 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 396 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
397 "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
396] 398]
397 399
398[[package]] 400[[package]]
@@ -401,7 +403,7 @@ version = "0.6.2"
401source = "registry+https://github.com/rust-lang/crates.io-index" 403source = "registry+https://github.com/rust-lang/crates.io-index"
402dependencies = [ 404dependencies = [
403 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 405 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
404 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 406 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
405] 407]
406 408
407[[package]] 409[[package]]
@@ -448,7 +450,7 @@ dependencies = [
448 450
449[[package]] 451[[package]]
450name = "once_cell" 452name = "once_cell"
451version = "0.1.5" 453version = "0.1.6"
452source = "registry+https://github.com/rust-lang/crates.io-index" 454source = "registry+https://github.com/rust-lang/crates.io-index"
453dependencies = [ 455dependencies = [
454 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 456 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -480,7 +482,7 @@ dependencies = [
480 "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", 482 "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
481 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 483 "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
482 "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 484 "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
483 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 485 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
484] 486]
485 487
486[[package]] 488[[package]]
@@ -528,11 +530,11 @@ dependencies = [
528name = "ra_analysis" 530name = "ra_analysis"
529version = "0.1.0" 531version = "0.1.0"
530dependencies = [ 532dependencies = [
531 "crossbeam-channel 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 533 "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
532 "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 534 "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
533 "im 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 535 "im 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
534 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", 536 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
535 "once_cell 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 537 "once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
536 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", 538 "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
537 "ra_editor 0.1.0", 539 "ra_editor 0.1.0",
538 "ra_syntax 0.1.0", 540 "ra_syntax 0.1.0",
@@ -570,13 +572,13 @@ name = "ra_lsp_server"
570version = "0.1.0" 572version = "0.1.0"
571dependencies = [ 573dependencies = [
572 "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 574 "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
573 "crossbeam-channel 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 575 "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
574 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 576 "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
575 "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 577 "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
576 "flexi_logger 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", 578 "flexi_logger 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
577 "gen_lsp_server 0.1.0", 579 "gen_lsp_server 0.1.0",
578 "im 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 580 "im 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
579 "languageserver-types 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)", 581 "languageserver-types 0.51.0 (registry+https://github.com/rust-lang/crates.io-index)",
580 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", 582 "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
581 "ra_analysis 0.1.0", 583 "ra_analysis 0.1.0",
582 "ra_editor 0.1.0", 584 "ra_editor 0.1.0",
@@ -585,7 +587,7 @@ dependencies = [
585 "relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 587 "relative-path 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
586 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 588 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
587 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 589 "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
588 "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", 590 "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
589 "smol_str 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 591 "smol_str 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
590 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 592 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
591 "text_unit 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 593 "text_unit 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -614,7 +616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
614dependencies = [ 616dependencies = [
615 "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 617 "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
616 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 618 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
617 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 619 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
618] 620]
619 621
620[[package]] 622[[package]]
@@ -626,7 +628,7 @@ dependencies = [
626 "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 628 "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
627 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 629 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
628 "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 630 "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
629 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 631 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
630] 632]
631 633
632[[package]] 634[[package]]
@@ -674,7 +676,7 @@ version = "1.0.5"
674source = "registry+https://github.com/rust-lang/crates.io-index" 676source = "registry+https://github.com/rust-lang/crates.io-index"
675dependencies = [ 677dependencies = [
676 "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", 678 "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
677 "memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 679 "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
678 "regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 680 "regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
679 "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 681 "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
680 "utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 682 "utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -698,7 +700,7 @@ name = "remove_dir_all"
698version = "0.5.1" 700version = "0.5.1"
699source = "registry+https://github.com/rust-lang/crates.io-index" 701source = "registry+https://github.com/rust-lang/crates.io-index"
700dependencies = [ 702dependencies = [
701 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 703 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
702] 704]
703 705
704[[package]] 706[[package]]
@@ -784,12 +786,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
784dependencies = [ 786dependencies = [
785 "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", 787 "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
786 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", 788 "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
787 "syn 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)", 789 "syn 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
788] 790]
789 791
790[[package]] 792[[package]]
791name = "serde_json" 793name = "serde_json"
792version = "1.0.27" 794version = "1.0.28"
793source = "registry+https://github.com/rust-lang/crates.io-index" 795source = "registry+https://github.com/rust-lang/crates.io-index"
794dependencies = [ 796dependencies = [
795 "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 797 "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -858,7 +860,7 @@ dependencies = [
858 860
859[[package]] 861[[package]]
860name = "syn" 862name = "syn"
861version = "0.15.4" 863version = "0.15.5"
862source = "registry+https://github.com/rust-lang/crates.io-index" 864source = "registry+https://github.com/rust-lang/crates.io-index"
863dependencies = [ 865dependencies = [
864 "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", 866 "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -908,7 +910,7 @@ dependencies = [
908 "pest_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 910 "pest_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
909 "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 911 "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
910 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", 912 "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
911 "serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", 913 "serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
912 "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 914 "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
913 "unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 915 "unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
914 "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 916 "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -964,7 +966,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
964dependencies = [ 966dependencies = [
965 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", 967 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
966 "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", 968 "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
967 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 969 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
968] 970]
969 971
970[[package]] 972[[package]]
@@ -1120,13 +1122,13 @@ version = "2.2.5"
1120source = "registry+https://github.com/rust-lang/crates.io-index" 1122source = "registry+https://github.com/rust-lang/crates.io-index"
1121dependencies = [ 1123dependencies = [
1122 "same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 1124 "same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
1123 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 1125 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
1124 "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1126 "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1125] 1127]
1126 1128
1127[[package]] 1129[[package]]
1128name = "winapi" 1130name = "winapi"
1129version = "0.3.5" 1131version = "0.3.6"
1130source = "registry+https://github.com/rust-lang/crates.io-index" 1132source = "registry+https://github.com/rust-lang/crates.io-index"
1131dependencies = [ 1133dependencies = [
1132 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1134 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1143,7 +1145,7 @@ name = "winapi-util"
1143version = "0.1.1" 1145version = "0.1.1"
1144source = "registry+https://github.com/rust-lang/crates.io-index" 1146source = "registry+https://github.com/rust-lang/crates.io-index"
1145dependencies = [ 1147dependencies = [
1146 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 1148 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
1147] 1149]
1148 1150
1149[[package]] 1151[[package]]
@@ -1167,7 +1169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1167"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" 1169"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
1168"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" 1170"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
1169"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 1171"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
1170"checksum crossbeam-channel 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a5716fadb87a5633db34c5e83ee6e036e6edc229f8a6bfb7c7c84ed340ba95df" 1172"checksum crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b85741761b7f160bc5e7e0c14986ef685b7f8bf9b7ad081c60c604bb4649827"
1171"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" 1173"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
1172"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" 1174"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150"
1173"checksum crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c90f1474584f38e270b5b613e898c8c328aa4f3dea85e0a27ac2e642f009416" 1175"checksum crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c90f1474584f38e270b5b613e898c8c328aa4f3dea85e0a27ac2e642f009416"
@@ -1192,13 +1194,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1192"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" 1194"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450"
1193"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" 1195"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
1194"checksum join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7bddc885f3fd69dd4b5d747c2efe6dd2c36d795ea9938281ed50910e32c95e31" 1196"checksum join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7bddc885f3fd69dd4b5d747c2efe6dd2c36d795ea9938281ed50910e32c95e31"
1195"checksum languageserver-types 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6866bed90d044147c6d71d3e4d31339e356164ab7b76b9fd13ccb1211528e166" 1197"checksum languageserver-types 0.51.0 (registry+https://github.com/rust-lang/crates.io-index)" = "caecadd973c43c93f5ce96fa457da310113d867af28808a8ed74023e9887a39e"
1196"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" 1198"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
1197"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" 1199"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
1198"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54" 1200"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54"
1199"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" 1201"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
1200"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 1202"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
1201"checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d" 1203"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
1202"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff" 1204"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
1203"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" 1205"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
1204"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" 1206"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
@@ -1206,7 +1208,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1206"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" 1208"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
1207"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 1209"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
1208"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" 1210"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
1209"checksum once_cell 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cecf059b719a56d137b66fadaee0781c08b1f61c040c36f5c6851d6769bab0af" 1211"checksum once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d7ce3535d54560c937c1652ba4a0da66bfc63e0f8e07bed127483afb6e5ee925"
1210"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" 1212"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
1211"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" 1213"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5"
1212"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" 1214"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
@@ -1238,7 +1240,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1238"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 1240"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
1239"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" 1241"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
1240"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe" 1242"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe"
1241"checksum serde_json 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "59790990c5115d16027f00913e2e66de23a51f70422e549d2ad68c8c5f268f1c" 1243"checksum serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d30ec34ac923489285d24688c7a9c0898d16edff27fc1f1bd854edeff6ca3b7f"
1242"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" 1244"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
1243"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d" 1245"checksum smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"
1244"checksum smol_str 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "248055d41f4c53f8ee7048e8a578a5190d0cca306630718091e4d481735e44b9" 1246"checksum smol_str 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "248055d41f4c53f8ee7048e8a578a5190d0cca306630718091e4d481735e44b9"
@@ -1247,7 +1249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1247"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" 1249"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
1248"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" 1250"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
1249"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" 1251"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
1250"checksum syn 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9056ebe7f2d6a38bc63171816fd1d3430da5a43896de21676dc5c0a4b8274a11" 1252"checksum syn 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5522da8e493dbd7703e88ec5518546ed45c30efa2699f291a7bd0a08fb0a6ab6"
1251"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" 1253"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
1252"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" 1254"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
1253"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" 1255"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
@@ -1279,7 +1281,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1279"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" 1281"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
1280"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" 1282"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
1281"checksum walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "af464bc7be7b785c7ac72e266a6b67c4c9070155606f51655a650a6686204e35" 1283"checksum walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "af464bc7be7b785c7ac72e266a6b67c4c9070155606f51655a650a6686204e35"
1282"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" 1284"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
1283"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1285"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1284"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab" 1286"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
1285"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1287"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml
index 4eb508fc0..6580ba6e4 100644
--- a/crates/gen_lsp_server/Cargo.toml
+++ b/crates/gen_lsp_server/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"] 4authors = ["Aleksey Kladov <[email protected]>"]
5 5
6[dependencies] 6[dependencies]
7languageserver-types = "0.50.0" 7languageserver-types = "0.51.0"
8log = "0.4.3" 8log = "0.4.3"
9 9
10failure = "0.1.2" 10failure = "0.1.2"
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 4da55ab26..b4c7db476 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -34,6 +34,7 @@ use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
34pub use ra_editor::{ 34pub use ra_editor::{
35 StructureNode, LineIndex, FileSymbol, 35 StructureNode, LineIndex, FileSymbol,
36 Runnable, RunnableKind, HighlightedRange, CompletionItem, 36 Runnable, RunnableKind, HighlightedRange, CompletionItem,
37 Fold, FoldKind
37}; 38};
38pub use job::{JobToken, JobHandle}; 39pub use job::{JobToken, JobHandle};
39 40
@@ -224,6 +225,10 @@ impl Analysis {
224 pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { 225 pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
225 self.imp.diagnostics(file_id) 226 self.imp.diagnostics(file_id)
226 } 227 }
228 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
229 let file = self.imp.file_syntax(file_id);
230 ra_editor::folding_ranges(&file)
231 }
227} 232}
228 233
229#[derive(Debug)] 234#[derive(Debug)]
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
new file mode 100644
index 000000000..817da28d1
--- /dev/null
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -0,0 +1,142 @@
1use std::collections::HashSet;
2
3use ra_syntax::{
4 File, TextRange, SyntaxNodeRef,
5 SyntaxKind,
6 algo::{walk, Direction, siblings},
7};
8
9#[derive(Debug, PartialEq, Eq)]
10pub enum FoldKind {
11 Comment,
12 Imports,
13}
14
15#[derive(Debug)]
16pub struct Fold {
17 pub range: TextRange,
18 pub kind: FoldKind,
19}
20
21pub fn folding_ranges(file: &File) -> Vec<Fold> {
22 let syntax = file.syntax();
23
24 let mut res = vec![];
25 let mut visited = HashSet::new();
26
27 for node in walk::preorder(syntax) {
28 if visited.contains(&node) {
29 continue;
30 }
31
32 let range_and_kind = match node.kind() {
33 SyntaxKind::COMMENT => (
34 contiguous_range_for(SyntaxKind::COMMENT, node, &mut visited),
35 Some(FoldKind::Comment),
36 ),
37 SyntaxKind::USE_ITEM => (
38 contiguous_range_for(SyntaxKind::USE_ITEM, node, &mut visited),
39 Some(FoldKind::Imports),
40 ),
41 _ => (None, None),
42 };
43
44 match range_and_kind {
45 (Some(range), Some(kind)) => {
46 res.push(Fold {
47 range: range,
48 kind: kind
49 });
50 }
51 _ => {}
52 }
53 }
54
55 res
56}
57
58fn contiguous_range_for<'a>(
59 kind: SyntaxKind,
60 node: SyntaxNodeRef<'a>,
61 visited: &mut HashSet<SyntaxNodeRef<'a>>,
62) -> Option<TextRange> {
63 visited.insert(node);
64
65 let left = node;
66 let mut right = node;
67 for node in siblings(node, Direction::Forward) {
68 visited.insert(node);
69 match node.kind() {
70 SyntaxKind::WHITESPACE if !node.leaf_text().unwrap().as_str().contains("\n\n") => (),
71 k => {
72 if k == kind {
73 right = node
74 } else {
75 break;
76 }
77 }
78 }
79 }
80 if left != right {
81 Some(TextRange::from_to(
82 left.range().start(),
83 right.range().end(),
84 ))
85 } else {
86 None
87 }
88}
89
90#[cfg(test)]
91mod tests {
92 use super::*;
93
94 #[test]
95 fn test_fold_comments() {
96 let text = r#"
97// Hello
98// this is a multiline
99// comment
100//
101
102// But this is not
103
104fn main() {
105 // We should
106 // also
107 // fold
108 // this one.
109}"#;
110
111 let file = File::parse(&text);
112 let folds = folding_ranges(&file);
113 assert_eq!(folds.len(), 2);
114 assert_eq!(folds[0].range.start(), 1.into());
115 assert_eq!(folds[0].range.end(), 46.into());
116 assert_eq!(folds[0].kind, FoldKind::Comment);
117
118 assert_eq!(folds[1].range.start(), 84.into());
119 assert_eq!(folds[1].range.end(), 137.into());
120 assert_eq!(folds[1].kind, FoldKind::Comment);
121 }
122
123 #[test]
124 fn test_fold_imports() {
125 let text = r#"
126use std::str;
127use std::vec;
128use std::io as iop;
129
130fn main() {
131}"#;
132
133 let file = File::parse(&text);
134 let folds = folding_ranges(&file);
135 assert_eq!(folds.len(), 1);
136 assert_eq!(folds[0].range.start(), 1.into());
137 assert_eq!(folds[0].range.end(), 48.into());
138 assert_eq!(folds[0].kind, FoldKind::Imports);
139 }
140
141
142} \ No newline at end of file
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index 78ed34c7c..de929d73a 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -10,6 +10,7 @@ mod extend_selection;
10mod symbols; 10mod symbols;
11mod line_index; 11mod line_index;
12mod edit; 12mod edit;
13mod folding_ranges;
13mod code_actions; 14mod code_actions;
14mod typing; 15mod typing;
15mod completion; 16mod completion;
@@ -36,6 +37,7 @@ pub use self::{
36 }, 37 },
37 typing::{join_lines, on_eq_typed}, 38 typing::{join_lines, on_eq_typed},
38 completion::{scope_completion, CompletionItem}, 39 completion::{scope_completion, CompletionItem},
40 folding_ranges::{Fold, FoldKind, folding_ranges}
39}; 41};
40 42
41#[derive(Debug)] 43#[derive(Debug)]
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index b851f70e1..32463e499 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -15,7 +15,7 @@ crossbeam-channel = "0.2.4"
15flexi_logger = "0.9.1" 15flexi_logger = "0.9.1"
16log = "0.4.3" 16log = "0.4.3"
17url_serde = "0.2.0" 17url_serde = "0.2.0"
18languageserver-types = "0.50.0" 18languageserver-types = "0.51.0"
19walkdir = "2.2.0" 19walkdir = "2.2.0"
20im = "12.0.0" 20im = "12.0.0"
21cargo_metadata = "0.6.0" 21cargo_metadata = "0.6.0"
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 7456aea8a..3c628f29c 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -1,5 +1,7 @@
1use languageserver_types::{ 1use languageserver_types::{
2 ServerCapabilities, 2 ServerCapabilities,
3 CodeActionProviderCapability,
4 FoldingRangeProviderCapability,
3 TextDocumentSyncCapability, 5 TextDocumentSyncCapability,
4 TextDocumentSyncOptions, 6 TextDocumentSyncOptions,
5 TextDocumentSyncKind, 7 TextDocumentSyncKind,
@@ -32,7 +34,7 @@ pub fn server_capabilities() -> ServerCapabilities {
32 document_highlight_provider: None, 34 document_highlight_provider: None,
33 document_symbol_provider: Some(true), 35 document_symbol_provider: Some(true),
34 workspace_symbol_provider: Some(true), 36 workspace_symbol_provider: Some(true),
35 code_action_provider: Some(true), 37 code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
36 code_lens_provider: None, 38 code_lens_provider: None,
37 document_formatting_provider: None, 39 document_formatting_provider: None,
38 document_range_formatting_provider: None, 40 document_range_formatting_provider: None,
@@ -40,10 +42,12 @@ pub fn server_capabilities() -> ServerCapabilities {
40 first_trigger_character: "=".to_string(), 42 first_trigger_character: "=".to_string(),
41 more_trigger_character: None, 43 more_trigger_character: None,
42 }), 44 }),
45 folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)),
43 rename_provider: None, 46 rename_provider: None,
44 color_provider: None, 47 color_provider: None,
45 execute_command_provider: Some(ExecuteCommandOptions { 48 execute_command_provider: Some(ExecuteCommandOptions {
46 commands: vec!["apply_code_action".to_string()], 49 commands: vec!["apply_code_action".to_string()],
47 }), 50 }),
51 workspace: None,
48 } 52 }
49} 53}
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index b2ebc9cdc..51061543c 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,15 +1,16 @@
1use std::collections::HashMap; 1use std::collections::{HashMap};
2 2
3use languageserver_types::{ 3use languageserver_types::{
4 Diagnostic, DiagnosticSeverity, DocumentSymbol, 4 Diagnostic, DiagnosticSeverity, DocumentSymbol,
5 Command, TextDocumentIdentifier, 5 CodeActionResponse, Command, TextDocumentIdentifier,
6 SymbolInformation, Position, Location, TextEdit, 6 SymbolInformation, Position, Location, TextEdit,
7 CompletionItem, InsertTextFormat, CompletionItemKind, 7 CompletionItem, InsertTextFormat, CompletionItemKind,
8 FoldingRange, FoldingRangeParams, FoldingRangeKind
8}; 9};
9use serde_json::to_value; 10use serde_json::to_value;
10use ra_analysis::{Query, FileId, RunnableKind, JobToken}; 11use ra_analysis::{Query, FileId, RunnableKind, JobToken, FoldKind};
11use ra_syntax::{ 12use ra_syntax::{
12 text_utils::contains_offset_nonstrict, 13 text_utils::contains_offset_nonstrict
13}; 14};
14 15
15use ::{ 16use ::{
@@ -177,6 +178,7 @@ pub fn handle_workspace_symbol(
177 world, &line_index 178 world, &line_index
178 )?, 179 )?,
179 container_name: None, 180 container_name: None,
181 deprecated: None,
180 }; 182 };
181 res.push(info); 183 res.push(info);
182 }; 184 };
@@ -365,11 +367,41 @@ pub fn handle_completion(
365 Ok(Some(req::CompletionResponse::Array(items))) 367 Ok(Some(req::CompletionResponse::Array(items)))
366} 368}
367 369
370pub fn handle_folding_range(
371 world: ServerWorld,
372 params: FoldingRangeParams,
373 _token: JobToken,
374) -> Result<Option<Vec<FoldingRange>>> {
375 let file_id = params.text_document.try_conv_with(&world)?;
376 let line_index = world.analysis().file_line_index(file_id);
377
378 let res = Some(world.analysis()
379 .folding_ranges(file_id)
380 .into_iter()
381 .map(|fold| {
382 let kind = match fold.kind {
383 FoldKind::Comment => FoldingRangeKind::Comment,
384 FoldKind::Imports => FoldingRangeKind::Imports
385 };
386 let range = fold.range.conv_with(&line_index);
387 FoldingRange {
388 start_line: range.start.line,
389 start_character: Some(range.start.character),
390 end_line: range.end.line,
391 end_character: Some(range.start.character),
392 kind: Some(kind)
393 }
394 })
395 .collect());
396
397 Ok(res)
398}
399
368pub fn handle_code_action( 400pub fn handle_code_action(
369 world: ServerWorld, 401 world: ServerWorld,
370 params: req::CodeActionParams, 402 params: req::CodeActionParams,
371 _token: JobToken, 403 _token: JobToken,
372) -> Result<Option<Vec<Command>>> { 404) -> Result<Option<CodeActionResponse>> {
373 let file_id = params.text_document.try_conv_with(&world)?; 405 let file_id = params.text_document.try_conv_with(&world)?;
374 let line_index = world.analysis().file_line_index(file_id); 406 let line_index = world.analysis().file_line_index(file_id);
375 let range = params.range.conv_with(&line_index); 407 let range = params.range.conv_with(&line_index);
@@ -392,7 +424,7 @@ pub fn handle_code_action(
392 res.push(cmd); 424 res.push(cmd);
393 } 425 }
394 426
395 Ok(Some(res)) 427 Ok(Some(CodeActionResponse::Commands(res)))
396} 428}
397 429
398pub fn publish_diagnostics( 430pub fn publish_diagnostics(
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index 2b2279e97..abc58b70e 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -253,6 +253,7 @@ fn on_request(
253 .on::<req::DecorationsRequest>(handlers::handle_decorations)? 253 .on::<req::DecorationsRequest>(handlers::handle_decorations)?
254 .on::<req::Completion>(handlers::handle_completion)? 254 .on::<req::Completion>(handlers::handle_completion)?
255 .on::<req::CodeActionRequest>(handlers::handle_code_action)? 255 .on::<req::CodeActionRequest>(handlers::handle_code_action)?
256 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
256 .finish(); 257 .finish();
257 match req { 258 match req {
258 Ok((id, handle)) => { 259 Ok((id, handle)) => {