diff options
-rw-r--r-- | Cargo.lock | 8 | ||||
-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/main_loop/handlers.rs | 35 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 6 |
5 files changed, 22 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock index e0599edb3..eea206f99 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -541,7 +541,7 @@ dependencies = [ | |||
541 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | 541 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", |
542 | "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", | 542 | "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", |
543 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 543 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
544 | "lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", | 544 | "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)", |
545 | "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)", | 545 | "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)", |
546 | "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", | 546 | "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", |
547 | ] | 547 | ] |
@@ -775,7 +775,7 @@ dependencies = [ | |||
775 | [[package]] | 775 | [[package]] |
776 | name = "lsp-types" | 776 | name = "lsp-types" |
777 | version = "0.58.1" | 777 | version = "0.58.1" |
778 | source = "registry+https://github.com/rust-lang/crates.io-index" | 778 | source = "git+https://github.com/kjeremy/languageserver-types?branch=flatten#f3f793173bb1461602dabf83d324b638b3e6ec61" |
779 | dependencies = [ | 779 | dependencies = [ |
780 | "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 780 | "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
781 | "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", | 781 | "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1200,7 +1200,7 @@ dependencies = [ | |||
1200 | "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1200 | "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1201 | "gen_lsp_server 0.2.0", | 1201 | "gen_lsp_server 0.2.0", |
1202 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | 1202 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1203 | "lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1203 | "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)", |
1204 | "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1204 | "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1205 | "ra_arena 0.1.0", | 1205 | "ra_arena 0.1.0", |
1206 | "ra_ide_api 0.1.0", | 1206 | "ra_ide_api 0.1.0", |
@@ -2201,7 +2201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2201 | "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" | 2201 | "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" |
2202 | "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" | 2202 | "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" |
2203 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" | 2203 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" |
2204 | "checksum lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "42c7edac51b6739544453fd33c7ae5e910d1ec4f2d9904cf1990f8f6581e26f5" | 2204 | "checksum lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)" = "<none>" |
2205 | "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" | 2205 | "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" |
2206 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" | 2206 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" |
2207 | "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" | 2207 | "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" |
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index bf57df81f..46b02a459 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.58.0" | 11 | lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten" } |
12 | log = "0.4.3" | 12 | log = "0.4.3" |
13 | serde_json = "1.0.34" | 13 | serde_json = "1.0.34" |
14 | serde = { version = "1.0.83", features = ["derive"] } | 14 | serde = { version = "1.0.83", features = ["derive"] } |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 2c4b3789e..9c9dda01f 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -13,7 +13,7 @@ crossbeam-channel = "0.3.5" | |||
13 | flexi_logger = "0.13.0" | 13 | flexi_logger = "0.13.0" |
14 | log = "0.4.3" | 14 | log = "0.4.3" |
15 | url_serde = "0.2.0" | 15 | url_serde = "0.2.0" |
16 | lsp-types = { version = "0.58.0", features = ["proposed"] } | 16 | lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten", features = ["proposed"] } |
17 | rustc-hash = "1.0" | 17 | rustc-hash = "1.0" |
18 | parking_lot = "0.8.0" | 18 | parking_lot = "0.8.0" |
19 | 19 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a8d6f7c23..6b407cb0c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -153,14 +153,12 @@ pub fn handle_on_type_formatting( | |||
153 | params: req::DocumentOnTypeFormattingParams, | 153 | params: req::DocumentOnTypeFormattingParams, |
154 | ) -> Result<Option<Vec<TextEdit>>> { | 154 | ) -> Result<Option<Vec<TextEdit>>> { |
155 | let _p = profile("handle_on_type_formatting"); | 155 | let _p = profile("handle_on_type_formatting"); |
156 | let file_id = params.text_document.try_conv_with(&world)?; | 156 | let mut position = params.text_document_position.try_conv_with(&world)?; |
157 | let line_index = world.analysis().file_line_index(file_id); | 157 | let line_index = world.analysis().file_line_index(position.file_id); |
158 | let position = FilePosition { | 158 | |
159 | file_id, | 159 | // in `ra_ide_api`, the `on_type` invariant is that |
160 | /// in `ra_ide_api`, the `on_type` invariant is that | 160 | // `text.char_at(position) == typed_char`. |
161 | /// `text.char_at(position) == typed_char`. | 161 | position.offset = position.offset - TextUnit::of_char('.'); |
162 | offset: params.position.conv_with(&line_index) - TextUnit::of_char('.'), | ||
163 | }; | ||
164 | 162 | ||
165 | let edit = match params.ch.as_str() { | 163 | let edit = match params.ch.as_str() { |
166 | "=" => world.analysis().on_eq_typed(position), | 164 | "=" => world.analysis().on_eq_typed(position), |
@@ -407,12 +405,7 @@ pub fn handle_completion( | |||
407 | params: req::CompletionParams, | 405 | params: req::CompletionParams, |
408 | ) -> Result<Option<req::CompletionResponse>> { | 406 | ) -> Result<Option<req::CompletionResponse>> { |
409 | let _p = profile("handle_completion"); | 407 | let _p = profile("handle_completion"); |
410 | let position = { | 408 | let position = params.text_document_position.try_conv_with(&world)?; |
411 | let file_id = params.text_document.try_conv_with(&world)?; | ||
412 | let line_index = world.analysis().file_line_index(file_id); | ||
413 | let offset = params.position.conv_with(&line_index); | ||
414 | FilePosition { file_id, offset } | ||
415 | }; | ||
416 | let completion_triggered_after_single_colon = { | 409 | let completion_triggered_after_single_colon = { |
417 | let mut res = false; | 410 | let mut res = false; |
418 | if let Some(ctx) = params.context { | 411 | if let Some(ctx) = params.context { |
@@ -543,9 +536,7 @@ pub fn handle_prepare_rename( | |||
543 | } | 536 | } |
544 | 537 | ||
545 | pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> { | 538 | pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> { |
546 | let file_id = params.text_document.try_conv_with(&world)?; | 539 | let position = params.text_document_position.try_conv_with(&world)?; |
547 | let line_index = world.analysis().file_line_index(file_id); | ||
548 | let offset = params.position.conv_with(&line_index); | ||
549 | 540 | ||
550 | if params.new_name.is_empty() { | 541 | if params.new_name.is_empty() { |
551 | return Err(LspError::new( | 542 | return Err(LspError::new( |
@@ -555,8 +546,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio | |||
555 | .into()); | 546 | .into()); |
556 | } | 547 | } |
557 | 548 | ||
558 | let optional_change = | 549 | let optional_change = world.analysis().rename(position, &*params.new_name)?; |
559 | world.analysis().rename(FilePosition { file_id, offset }, &*params.new_name)?; | ||
560 | let change = match optional_change { | 550 | let change = match optional_change { |
561 | None => return Ok(None), | 551 | None => return Ok(None), |
562 | Some(it) => it, | 552 | Some(it) => it, |
@@ -571,11 +561,10 @@ pub fn handle_references( | |||
571 | world: WorldSnapshot, | 561 | world: WorldSnapshot, |
572 | params: req::ReferenceParams, | 562 | params: req::ReferenceParams, |
573 | ) -> Result<Option<Vec<Location>>> { | 563 | ) -> Result<Option<Vec<Location>>> { |
574 | let file_id = params.text_document.try_conv_with(&world)?; | 564 | let position = params.text_document_position.try_conv_with(&world)?; |
575 | let line_index = world.analysis().file_line_index(file_id); | 565 | let line_index = world.analysis().file_line_index(position.file_id); |
576 | let offset = params.position.conv_with(&line_index); | ||
577 | 566 | ||
578 | let refs = match world.analysis().find_all_refs(FilePosition { file_id, offset })? { | 567 | let refs = match world.analysis().find_all_refs(position)? { |
579 | None => return Ok(None), | 568 | None => return Ok(None), |
580 | Some(refs) => refs, | 569 | Some(refs) => refs, |
581 | }; | 570 | }; |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index d271b02fc..451be32a8 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -37,9 +37,11 @@ use std::collections::Spam; | |||
37 | eprintln!("loading took {:?}", project_start.elapsed()); | 37 | eprintln!("loading took {:?}", project_start.elapsed()); |
38 | let completion_start = Instant::now(); | 38 | let completion_start = Instant::now(); |
39 | let res = server.send_request::<Completion>(CompletionParams { | 39 | let res = server.send_request::<Completion>(CompletionParams { |
40 | text_document: server.doc_id("src/lib.rs"), | 40 | text_document_position: TextDocumentPositionParams::new( |
41 | server.doc_id("src/lib.rs"), | ||
42 | Position::new(0, 23), | ||
43 | ), | ||
41 | context: None, | 44 | context: None, |
42 | position: Position::new(0, 23), | ||
43 | }); | 45 | }); |
44 | assert!(format!("{}", res).contains("HashMap")); | 46 | assert!(format!("{}", res).contains("HashMap")); |
45 | eprintln!("completion took {:?}", completion_start.elapsed()); | 47 | eprintln!("completion took {:?}", completion_start.elapsed()); |