diff options
author | Aleksey Kladov <[email protected]> | 2019-04-21 10:13:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-21 10:13:48 +0100 |
commit | fa12ed2b8f3466af88644e59127cd169549f8899 (patch) | |
tree | 8837e4192d6121115a5a9b94044d33bd683184b2 | |
parent | 31b7697cf6f4ebb4ebc35b055e6b4ad9a28e28e9 (diff) |
switch to official extend selection API
-rw-r--r-- | Cargo.lock | 28 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 47 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 22 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands/extend_selection.ts | 34 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 4 | ||||
-rw-r--r-- | editors/code/src/server.ts | 1 |
13 files changed, 89 insertions, 63 deletions
diff --git a/Cargo.lock b/Cargo.lock index 81dd812f4..723c1ac5f 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -270,7 +270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
270 | dependencies = [ | 270 | dependencies = [ |
271 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 271 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
272 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 272 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
273 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 273 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
274 | ] | 274 | ] |
275 | 275 | ||
276 | [[package]] | 276 | [[package]] |
@@ -343,7 +343,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
343 | dependencies = [ | 343 | dependencies = [ |
344 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 344 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
345 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 345 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
346 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 346 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
347 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", | 347 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", |
348 | ] | 348 | ] |
349 | 349 | ||
@@ -430,7 +430,7 @@ dependencies = [ | |||
430 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | 430 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", |
431 | "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 431 | "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", |
432 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 432 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
433 | "lsp-types 0.56.0 (registry+https://github.com/rust-lang/crates.io-index)", | 433 | "lsp-types 0.57.0 (git+https://github.com/matklad/lsp-types?branch=selection-range)", |
434 | "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", | 434 | "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", |
435 | "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", | 435 | "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", |
436 | ] | 436 | ] |
@@ -634,8 +634,8 @@ dependencies = [ | |||
634 | 634 | ||
635 | [[package]] | 635 | [[package]] |
636 | name = "lsp-types" | 636 | name = "lsp-types" |
637 | version = "0.56.0" | 637 | version = "0.57.0" |
638 | source = "registry+https://github.com/rust-lang/crates.io-index" | 638 | source = "git+https://github.com/matklad/lsp-types?branch=selection-range#6e37d45bcf411c18c22ab29ec155946ff001339e" |
639 | dependencies = [ | 639 | dependencies = [ |
640 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", | 640 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", |
641 | "num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", | 641 | "num-derive 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -747,7 +747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
747 | dependencies = [ | 747 | dependencies = [ |
748 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 748 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
749 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 749 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
750 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 750 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
751 | ] | 751 | ] |
752 | 752 | ||
753 | [[package]] | 753 | [[package]] |
@@ -844,7 +844,7 @@ dependencies = [ | |||
844 | "pest_meta 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | 844 | "pest_meta 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", |
845 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 845 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
846 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 846 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
847 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 847 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
848 | ] | 848 | ] |
849 | 849 | ||
850 | [[package]] | 850 | [[package]] |
@@ -1027,7 +1027,7 @@ dependencies = [ | |||
1027 | "flexi_logger 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", | 1027 | "flexi_logger 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", |
1028 | "gen_lsp_server 0.1.0", | 1028 | "gen_lsp_server 0.1.0", |
1029 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1029 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1030 | "lsp-types 0.56.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1030 | "lsp-types 0.57.0 (git+https://github.com/matklad/lsp-types?branch=selection-range)", |
1031 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1031 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1032 | "ra_arena 0.1.0", | 1032 | "ra_arena 0.1.0", |
1033 | "ra_ide_api 0.1.0", | 1033 | "ra_ide_api 0.1.0", |
@@ -1378,7 +1378,7 @@ dependencies = [ | |||
1378 | "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1378 | "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1379 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 1379 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
1380 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 1380 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
1381 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 1381 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
1382 | ] | 1382 | ] |
1383 | 1383 | ||
1384 | [[package]] | 1384 | [[package]] |
@@ -1423,7 +1423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1423 | dependencies = [ | 1423 | dependencies = [ |
1424 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 1424 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
1425 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 1425 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
1426 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 1426 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
1427 | ] | 1427 | ] |
1428 | 1428 | ||
1429 | [[package]] | 1429 | [[package]] |
@@ -1501,7 +1501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1501 | 1501 | ||
1502 | [[package]] | 1502 | [[package]] |
1503 | name = "syn" | 1503 | name = "syn" |
1504 | version = "0.15.31" | 1504 | version = "0.15.32" |
1505 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1505 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1506 | dependencies = [ | 1506 | dependencies = [ |
1507 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 1507 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1516,7 +1516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1516 | dependencies = [ | 1516 | dependencies = [ |
1517 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", | 1517 | "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", |
1518 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", | 1518 | "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", |
1519 | "syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)", | 1519 | "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", |
1520 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1520 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1521 | ] | 1521 | ] |
1522 | 1522 | ||
@@ -1937,7 +1937,7 @@ dependencies = [ | |||
1937 | "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" | 1937 | "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" |
1938 | "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" | 1938 | "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" |
1939 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" | 1939 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" |
1940 | "checksum lsp-types 0.56.0 (registry+https://github.com/rust-lang/crates.io-index)" = "31954f2cf354421e6f99a48fdcfd5c3113c675a0db311960ffdac0b8d45cf09c" | 1940 | "checksum lsp-types 0.57.0 (git+https://github.com/matklad/lsp-types?branch=selection-range)" = "<none>" |
1941 | "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" | 1941 | "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" |
1942 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" | 1942 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" |
1943 | "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" | 1943 | "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" |
@@ -2010,7 +2010,7 @@ dependencies = [ | |||
2010 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" | 2010 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" |
2011 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" | 2011 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" |
2012 | "checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" | 2012 | "checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" |
2013 | "checksum syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d2b4cfac95805274c6afdb12d8f770fa2d27c045953e7b630a81801953699a9a" | 2013 | "checksum syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)" = "846620ec526c1599c070eff393bfeeeb88a93afa2513fc3b49f1fea84cf7b0ed" |
2014 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" | 2014 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" |
2015 | "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" | 2015 | "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" |
2016 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" | 2016 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" |
diff --git a/Cargo.toml b/Cargo.toml index c5155e899..0e474a184 100644 --- a/Cargo.toml +++ b/Cargo.toml | |||
@@ -6,3 +6,4 @@ incremental = true | |||
6 | debug = true | 6 | debug = true |
7 | 7 | ||
8 | [patch.'crates-io'] | 8 | [patch.'crates-io'] |
9 | lsp-types = { git = "https://github.com/matklad/lsp-types", branch = "selection-range" } | ||
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index 9e0d819d0..34343e2f2 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" | |||
8 | description = "Generic LSP server scaffold." | 8 | description = "Generic LSP server scaffold." |
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | lsp-types = "0.56.0" | 11 | lsp-types = "0.57.0" |
12 | log = "0.4.3" | 12 | log = "0.4.3" |
13 | failure = "0.1.4" | 13 | failure = "0.1.4" |
14 | serde_json = "1.0.34" | 14 | serde_json = "1.0.34" |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index bc181e4eb..c855d6f68 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -15,7 +15,7 @@ crossbeam-channel = "0.3.5" | |||
15 | flexi_logger = "0.11.0" | 15 | flexi_logger = "0.11.0" |
16 | log = "0.4.3" | 16 | log = "0.4.3" |
17 | url_serde = "0.2.0" | 17 | url_serde = "0.2.0" |
18 | lsp-types = "0.56.0" | 18 | lsp-types = "0.57.0" |
19 | rustc-hash = "1.0" | 19 | rustc-hash = "1.0" |
20 | parking_lot = "0.7.0" | 20 | parking_lot = "0.7.0" |
21 | 21 | ||
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index 2af2b89fe..f6d2b75e7 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -2,7 +2,7 @@ use lsp_types::{ | |||
2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, | 2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, |
3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, | 3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, |
4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, | 4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, |
5 | TextDocumentSyncOptions, ImplementationProviderCapability, | 5 | TextDocumentSyncOptions, ImplementationProviderCapability, GenericCapability, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | pub fn server_capabilities() -> ServerCapabilities { | 8 | pub fn server_capabilities() -> ServerCapabilities { |
@@ -37,6 +37,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
37 | first_trigger_character: "=".to_string(), | 37 | first_trigger_character: "=".to_string(), |
38 | more_trigger_character: Some(vec![".".to_string()]), | 38 | more_trigger_character: Some(vec![".".to_string()]), |
39 | }), | 39 | }), |
40 | selection_range_provider: Some(GenericCapability::default()), | ||
40 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), | 41 | folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), |
41 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { | 42 | rename_provider: Some(RenameProviderCapability::Options(RenameOptions { |
42 | prepare_provider: Some(true), | 43 | prepare_provider: Some(true), |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 07ac4917a..dc1f8f3f7 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -297,6 +297,7 @@ fn on_request( | |||
297 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? | 297 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? |
298 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? | 298 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? |
299 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? | 299 | .on::<req::ExtendSelection>(handlers::handle_extend_selection)? |
300 | .on::<req::SelectionRangeRequest>(handlers::handle_selection_range)? | ||
300 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? | 301 | .on::<req::FindMatchingBrace>(handlers::handle_find_matching_brace)? |
301 | .on::<req::JoinLines>(handlers::handle_join_lines)? | 302 | .on::<req::JoinLines>(handlers::handle_join_lines)? |
302 | .on::<req::OnEnter>(handlers::handle_on_enter)? | 303 | .on::<req::OnEnter>(handlers::handle_on_enter)? |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index eb8a53545..530081494 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -11,7 +11,7 @@ use ra_ide_api::{ | |||
11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, | 11 | FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, |
12 | AssistId, | 12 | AssistId, |
13 | }; | 13 | }; |
14 | use ra_syntax::{AstNode, SyntaxKind, TextUnit}; | 14 | use ra_syntax::{AstNode, SyntaxKind, TextUnit, TextRange}; |
15 | use ra_prof::profile; | 15 | use ra_prof::profile; |
16 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
17 | use serde::{Serialize, Deserialize}; | 17 | use serde::{Serialize, Deserialize}; |
@@ -39,10 +39,15 @@ pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> | |||
39 | Ok(res) | 39 | Ok(res) |
40 | } | 40 | } |
41 | 41 | ||
42 | // FIXME: drop this API | ||
42 | pub fn handle_extend_selection( | 43 | pub fn handle_extend_selection( |
43 | world: ServerWorld, | 44 | world: ServerWorld, |
44 | params: req::ExtendSelectionParams, | 45 | params: req::ExtendSelectionParams, |
45 | ) -> Result<req::ExtendSelectionResult> { | 46 | ) -> Result<req::ExtendSelectionResult> { |
47 | log::error!( | ||
48 | "extend selection is deprecated and will be removed soon, | ||
49 | use the new selection range API in LSP", | ||
50 | ); | ||
46 | let file_id = params.text_document.try_conv_with(&world)?; | 51 | let file_id = params.text_document.try_conv_with(&world)?; |
47 | let line_index = world.analysis().file_line_index(file_id); | 52 | let line_index = world.analysis().file_line_index(file_id); |
48 | let selections = params | 53 | let selections = params |
@@ -55,6 +60,46 @@ pub fn handle_extend_selection( | |||
55 | Ok(req::ExtendSelectionResult { selections }) | 60 | Ok(req::ExtendSelectionResult { selections }) |
56 | } | 61 | } |
57 | 62 | ||
63 | pub fn handle_selection_range( | ||
64 | world: ServerWorld, | ||
65 | params: req::SelectionRangeParams, | ||
66 | ) -> Result<Vec<req::SelectionRange>> { | ||
67 | let file_id = params.text_document.try_conv_with(&world)?; | ||
68 | let line_index = world.analysis().file_line_index(file_id); | ||
69 | params | ||
70 | .positions | ||
71 | .into_iter() | ||
72 | .map_conv_with(&line_index) | ||
73 | .map(|position| { | ||
74 | let mut ranges = Vec::new(); | ||
75 | { | ||
76 | let mut range = TextRange::from_to(position, position); | ||
77 | loop { | ||
78 | ranges.push(range); | ||
79 | let frange = FileRange { file_id, range }; | ||
80 | let next = world.analysis().extend_selection(frange)?; | ||
81 | if next == range { | ||
82 | break; | ||
83 | } else { | ||
84 | range = next | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | let mut range = req::SelectionRange { | ||
89 | range: ranges.last().unwrap().conv_with(&line_index), | ||
90 | parent: None, | ||
91 | }; | ||
92 | for r in ranges.iter().rev().skip(1) { | ||
93 | range = req::SelectionRange { | ||
94 | range: r.conv_with(&line_index), | ||
95 | parent: Some(Box::new(range)), | ||
96 | } | ||
97 | } | ||
98 | Ok(range) | ||
99 | }) | ||
100 | .collect() | ||
101 | } | ||
102 | |||
58 | pub fn handle_find_matching_brace( | 103 | pub fn handle_find_matching_brace( |
59 | world: ServerWorld, | 104 | world: ServerWorld, |
60 | params: req::FindMatchingBraceParams, | 105 | params: req::FindMatchingBraceParams, |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 4f35ab9b5..6090eb7b9 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -64,6 +64,28 @@ pub struct ExtendSelectionResult { | |||
64 | pub selections: Vec<Range>, | 64 | pub selections: Vec<Range>, |
65 | } | 65 | } |
66 | 66 | ||
67 | pub enum SelectionRangeRequest {} | ||
68 | |||
69 | impl Request for SelectionRangeRequest { | ||
70 | type Params = SelectionRangeParams; | ||
71 | type Result = Vec<SelectionRange>; | ||
72 | const METHOD: &'static str = "textDocument/selectionRange"; | ||
73 | } | ||
74 | |||
75 | #[derive(Deserialize, Debug)] | ||
76 | #[serde(rename_all = "camelCase")] | ||
77 | pub struct SelectionRangeParams { | ||
78 | pub text_document: TextDocumentIdentifier, | ||
79 | pub positions: Vec<Position>, | ||
80 | } | ||
81 | |||
82 | #[derive(Serialize, Debug)] | ||
83 | #[serde(rename_all = "camelCase")] | ||
84 | pub struct SelectionRange { | ||
85 | pub range: Range, | ||
86 | pub parent: Option<Box<SelectionRange>>, | ||
87 | } | ||
88 | |||
67 | pub enum FindMatchingBrace {} | 89 | pub enum FindMatchingBrace {} |
68 | 90 | ||
69 | impl Request for FindMatchingBrace { | 91 | impl Request for FindMatchingBrace { |
diff --git a/editors/code/package.json b/editors/code/package.json index 8f195c996..015b912b3 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -81,11 +81,6 @@ | |||
81 | "category": "Rust Analyzer" | 81 | "category": "Rust Analyzer" |
82 | }, | 82 | }, |
83 | { | 83 | { |
84 | "command": "rust-analyzer.extendSelection", | ||
85 | "title": "Extend selection", | ||
86 | "category": "Rust Analyzer" | ||
87 | }, | ||
88 | { | ||
89 | "command": "rust-analyzer.matchingBrace", | 84 | "command": "rust-analyzer.matchingBrace", |
90 | "title": "Find matching brace", | 85 | "title": "Find matching brace", |
91 | "category": "Rust Analyzer" | 86 | "category": "Rust Analyzer" |
diff --git a/editors/code/src/commands/extend_selection.ts b/editors/code/src/commands/extend_selection.ts deleted file mode 100644 index 6f4187d15..000000000 --- a/editors/code/src/commands/extend_selection.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; | ||
4 | import { Server } from '../server'; | ||
5 | |||
6 | interface ExtendSelectionParams { | ||
7 | textDocument: TextDocumentIdentifier; | ||
8 | selections: Range[]; | ||
9 | } | ||
10 | |||
11 | interface ExtendSelectionResult { | ||
12 | selections: Range[]; | ||
13 | } | ||
14 | |||
15 | export async function handle() { | ||
16 | const editor = vscode.window.activeTextEditor; | ||
17 | if (editor == null || editor.document.languageId !== 'rust') { | ||
18 | return; | ||
19 | } | ||
20 | const request: ExtendSelectionParams = { | ||
21 | selections: editor.selections.map(s => | ||
22 | Server.client.code2ProtocolConverter.asRange(s) | ||
23 | ), | ||
24 | textDocument: { uri: editor.document.uri.toString() } | ||
25 | }; | ||
26 | const response = await Server.client.sendRequest<ExtendSelectionResult>( | ||
27 | 'rust-analyzer/extendSelection', | ||
28 | request | ||
29 | ); | ||
30 | editor.selections = response.selections.map((range: Range) => { | ||
31 | const r = Server.client.protocol2CodeConverter.asRange(range); | ||
32 | return new vscode.Selection(r.start, r.end); | ||
33 | }); | ||
34 | } | ||
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index f36c4b040..194658497 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as analyzerStatus from './analyzer_status'; | 1 | import * as analyzerStatus from './analyzer_status'; |
2 | import * as applySourceChange from './apply_source_change'; | 2 | import * as applySourceChange from './apply_source_change'; |
3 | import * as extendSelection from './extend_selection'; | ||
4 | import * as joinLines from './join_lines'; | 3 | import * as joinLines from './join_lines'; |
5 | import * as matchingBrace from './matching_brace'; | 4 | import * as matchingBrace from './matching_brace'; |
6 | import * as onEnter from './on_enter'; | 5 | import * as onEnter from './on_enter'; |
@@ -11,7 +10,6 @@ import * as syntaxTree from './syntaxTree'; | |||
11 | export { | 10 | export { |
12 | analyzerStatus, | 11 | analyzerStatus, |
13 | applySourceChange, | 12 | applySourceChange, |
14 | extendSelection, | ||
15 | joinLines, | 13 | joinLines, |
16 | matchingBrace, | 14 | matchingBrace, |
17 | parentModule, | 15 | parentModule, |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 48dd2a614..c8c3004a7 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -58,10 +58,6 @@ export function activate(context: vscode.ExtensionContext) { | |||
58 | Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null) | 58 | Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null) |
59 | ); | 59 | ); |
60 | registerCommand( | 60 | registerCommand( |
61 | 'rust-analyzer.extendSelection', | ||
62 | commands.extendSelection.handle | ||
63 | ); | ||
64 | registerCommand( | ||
65 | 'rust-analyzer.matchingBrace', | 61 | 'rust-analyzer.matchingBrace', |
66 | commands.matchingBrace.handle | 62 | commands.matchingBrace.handle |
67 | ); | 63 | ); |
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 5e9a19340..81c2b3fff 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts | |||
@@ -74,6 +74,7 @@ export class Server { | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | }; | 76 | }; |
77 | Server.client.registerProposedFeatures(); | ||
77 | Server.client.onReady().then(() => { | 78 | Server.client.onReady().then(() => { |
78 | for (const [type, handler] of notificationHandlers) { | 79 | for (const [type, handler] of notificationHandlers) { |
79 | Server.client.onNotification(type, handler); | 80 | Server.client.onNotification(type, handler); |