diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 26 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 93 | ||||
-rw-r--r-- | crates/ra_cli/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_db/src/cancelation.rs | 49 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 21 | ||||
-rw-r--r-- | crates/test_utils/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/tools/Cargo.toml | 2 |
12 files changed, 144 insertions, 71 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index 2aee4ea16..a421a3e0b 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -10,7 +10,7 @@ description = "Generic LSP server scaffold." | |||
10 | [dependencies] | 10 | [dependencies] |
11 | languageserver-types = "0.53.1" | 11 | languageserver-types = "0.53.1" |
12 | log = "0.4.3" | 12 | log = "0.4.3" |
13 | failure = "0.1.2" | 13 | failure = "0.1.4" |
14 | serde_json = "1.0.24" | 14 | serde_json = "1.0.34" |
15 | serde = { version = "1.0.83", features = ["derive"] } | 15 | serde = { version = "1.0.83", features = ["derive"] } |
16 | crossbeam-channel = "0.3.5" | 16 | crossbeam-channel = "0.3.5" |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index bff2e00c9..5ed374c79 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -288,7 +288,11 @@ impl AnalysisImpl { | |||
288 | Some(it) => it, | 288 | Some(it) => it, |
289 | }; | 289 | }; |
290 | 290 | ||
291 | let mut ret = vec![(position.file_id, binding.syntax().range())]; | 291 | let mut ret = binding |
292 | .name() | ||
293 | .into_iter() | ||
294 | .map(|name| (position.file_id, name.syntax().range())) | ||
295 | .collect::<Vec<_>>(); | ||
292 | ret.extend( | 296 | ret.extend( |
293 | descr | 297 | descr |
294 | .scopes(&*self.db) | 298 | .scopes(&*self.db) |
@@ -505,7 +509,25 @@ impl AnalysisImpl { | |||
505 | let infer = function.infer(&*self.db)?; | 509 | let infer = function.infer(&*self.db)?; |
506 | Ok(infer.type_of_node(node).map(|t| t.to_string())) | 510 | Ok(infer.type_of_node(node).map(|t| t.to_string())) |
507 | } | 511 | } |
508 | 512 | pub fn rename( | |
513 | &self, | ||
514 | position: FilePosition, | ||
515 | new_name: &str, | ||
516 | ) -> Cancelable<Vec<SourceFileEdit>> { | ||
517 | let res = self | ||
518 | .find_all_refs(position)? | ||
519 | .iter() | ||
520 | .map(|(file_id, text_range)| SourceFileEdit { | ||
521 | file_id: *file_id, | ||
522 | edit: { | ||
523 | let mut builder = ra_text_edit::TextEditBuilder::new(); | ||
524 | builder.replace(*text_range, new_name.into()); | ||
525 | builder.finish() | ||
526 | }, | ||
527 | }) | ||
528 | .collect::<Vec<_>>(); | ||
529 | Ok(res) | ||
530 | } | ||
509 | fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 531 | fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> { |
510 | let name = name_ref.text(); | 532 | let name = name_ref.text(); |
511 | let mut query = Query::new(name.to_string()); | 533 | let mut query = Query::new(name.to_string()); |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9f5e9f358..e56168510 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -367,6 +367,13 @@ impl Analysis { | |||
367 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | 367 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
368 | self.imp.type_of(frange) | 368 | self.imp.type_of(frange) |
369 | } | 369 | } |
370 | pub fn rename( | ||
371 | &self, | ||
372 | position: FilePosition, | ||
373 | new_name: &str, | ||
374 | ) -> Cancelable<Vec<SourceFileEdit>> { | ||
375 | self.imp.rename(position, new_name) | ||
376 | } | ||
370 | } | 377 | } |
371 | 378 | ||
372 | pub struct LibraryData { | 379 | pub struct LibraryData { |
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 210fa2a13..a314fbc40 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_syntax::TextRange; | 1 | use ra_syntax::TextRange; |
2 | use test_utils::assert_eq_dbg; | 2 | use test_utils::{assert_eq_dbg, assert_eq_text}; |
3 | 3 | ||
4 | use ra_analysis::{ | 4 | use ra_analysis::{ |
5 | mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis}, | 5 | mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis}, |
@@ -453,3 +453,94 @@ fn test_find_all_refs_for_fn_param() { | |||
453 | let refs = get_all_refs(code); | 453 | let refs = get_all_refs(code); |
454 | assert_eq!(refs.len(), 2); | 454 | assert_eq!(refs.len(), 2); |
455 | } | 455 | } |
456 | #[test] | ||
457 | fn test_rename_for_local() { | ||
458 | test_rename( | ||
459 | r#" | ||
460 | fn main() { | ||
461 | let mut i = 1; | ||
462 | let j = 1; | ||
463 | i = i<|> + j; | ||
464 | |||
465 | { | ||
466 | i = 0; | ||
467 | } | ||
468 | |||
469 | i = 5; | ||
470 | }"#, | ||
471 | "k", | ||
472 | r#" | ||
473 | fn main() { | ||
474 | let mut k = 1; | ||
475 | let j = 1; | ||
476 | k = k + j; | ||
477 | |||
478 | { | ||
479 | k = 0; | ||
480 | } | ||
481 | |||
482 | k = 5; | ||
483 | }"#, | ||
484 | ); | ||
485 | } | ||
486 | |||
487 | #[test] | ||
488 | fn test_rename_for_param_inside() { | ||
489 | test_rename( | ||
490 | r#" | ||
491 | fn foo(i : u32) -> u32 { | ||
492 | i<|> | ||
493 | }"#, | ||
494 | "j", | ||
495 | r#" | ||
496 | fn foo(j : u32) -> u32 { | ||
497 | j | ||
498 | }"#, | ||
499 | ); | ||
500 | } | ||
501 | |||
502 | #[test] | ||
503 | fn test_rename_refs_for_fn_param() { | ||
504 | test_rename( | ||
505 | r#" | ||
506 | fn foo(i<|> : u32) -> u32 { | ||
507 | i | ||
508 | }"#, | ||
509 | "new_name", | ||
510 | r#" | ||
511 | fn foo(new_name : u32) -> u32 { | ||
512 | new_name | ||
513 | }"#, | ||
514 | ); | ||
515 | } | ||
516 | |||
517 | #[test] | ||
518 | fn test_rename_for_mut_param() { | ||
519 | test_rename( | ||
520 | r#" | ||
521 | fn foo(mut i<|> : u32) -> u32 { | ||
522 | i | ||
523 | }"#, | ||
524 | "new_name", | ||
525 | r#" | ||
526 | fn foo(mut new_name : u32) -> u32 { | ||
527 | new_name | ||
528 | }"#, | ||
529 | ); | ||
530 | } | ||
531 | fn test_rename(text: &str, new_name: &str, expected: &str) { | ||
532 | let (analysis, position) = single_file_with_position(text); | ||
533 | let edits = analysis.rename(position, new_name).unwrap(); | ||
534 | let mut text_edit_bulder = ra_text_edit::TextEditBuilder::new(); | ||
535 | let mut file_id: Option<FileId> = None; | ||
536 | for edit in edits { | ||
537 | file_id = Some(edit.file_id); | ||
538 | for atom in edit.edit.as_atoms() { | ||
539 | text_edit_bulder.replace(atom.delete, atom.insert.clone()); | ||
540 | } | ||
541 | } | ||
542 | let result = text_edit_bulder | ||
543 | .finish() | ||
544 | .apply(&*analysis.file_text(file_id.unwrap())); | ||
545 | assert_eq_text!(expected, &*result); | ||
546 | } | ||
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index 0b8d6f3dd..83f1d91e0 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml | |||
@@ -7,7 +7,7 @@ publish = false | |||
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | clap = "2.32.0" | 9 | clap = "2.32.0" |
10 | failure = "0.1.1" | 10 | failure = "0.1.4" |
11 | join_to_string = "0.1.1" | 11 | join_to_string = "0.1.1" |
12 | ra_syntax = { path = "../ra_syntax" } | 12 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_editor = { path = "../ra_editor" } | 13 | ra_editor = { path = "../ra_editor" } |
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index 75bcf2b39..ecc56d953 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -5,7 +5,6 @@ version = "0.1.0" | |||
5 | authors = ["Aleksey Kladov <[email protected]>"] | 5 | authors = ["Aleksey Kladov <[email protected]>"] |
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | backtrace = "0.3.1" | ||
9 | relative-path = "0.4.0" | 8 | relative-path = "0.4.0" |
10 | salsa = "0.9.0" | 9 | salsa = "0.9.0" |
11 | rustc-hash = "1.0" | 10 | rustc-hash = "1.0" |
diff --git a/crates/ra_db/src/cancelation.rs b/crates/ra_db/src/cancelation.rs index 73444b015..56ce27bff 100644 --- a/crates/ra_db/src/cancelation.rs +++ b/crates/ra_db/src/cancelation.rs | |||
@@ -15,29 +15,17 @@ | |||
15 | //! any background processing (this bit is handled by salsa, see | 15 | //! any background processing (this bit is handled by salsa, see |
16 | //! `BaseDatabase::check_canceled` method). | 16 | //! `BaseDatabase::check_canceled` method). |
17 | 17 | ||
18 | use std::{ | ||
19 | cmp, | ||
20 | hash::{Hash, Hasher}, | ||
21 | sync::Arc, | ||
22 | }; | ||
23 | |||
24 | use backtrace::Backtrace; | ||
25 | use parking_lot::Mutex; | ||
26 | |||
27 | /// An "error" signifing that the operation was canceled. | 18 | /// An "error" signifing that the operation was canceled. |
28 | #[derive(Clone)] | 19 | #[derive(Clone, PartialEq, Eq, Hash)] |
29 | pub struct Canceled { | 20 | pub struct Canceled { |
30 | backtrace: Arc<Mutex<Backtrace>>, | 21 | _private: (), |
31 | } | 22 | } |
32 | 23 | ||
33 | pub type Cancelable<T> = Result<T, Canceled>; | 24 | pub type Cancelable<T> = Result<T, Canceled>; |
34 | 25 | ||
35 | impl Canceled { | 26 | impl Canceled { |
36 | pub(crate) fn new() -> Canceled { | 27 | pub(crate) fn new() -> Canceled { |
37 | let bt = Backtrace::new_unresolved(); | 28 | Canceled { _private: () } |
38 | Canceled { | ||
39 | backtrace: Arc::new(Mutex::new(bt)), | ||
40 | } | ||
41 | } | 29 | } |
42 | } | 30 | } |
43 | 31 | ||
@@ -49,37 +37,8 @@ impl std::fmt::Display for Canceled { | |||
49 | 37 | ||
50 | impl std::fmt::Debug for Canceled { | 38 | impl std::fmt::Debug for Canceled { |
51 | fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 39 | fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
52 | let mut bt = self.backtrace.lock(); | 40 | write!(fmt, "Canceled") |
53 | let bt: &mut Backtrace = &mut *bt; | ||
54 | bt.resolve(); | ||
55 | write!(fmt, "canceled at:\n{:?}", bt) | ||
56 | } | 41 | } |
57 | } | 42 | } |
58 | 43 | ||
59 | impl std::error::Error for Canceled {} | 44 | impl std::error::Error for Canceled {} |
60 | |||
61 | impl PartialEq for Canceled { | ||
62 | fn eq(&self, _: &Canceled) -> bool { | ||
63 | true | ||
64 | } | ||
65 | } | ||
66 | |||
67 | impl Eq for Canceled {} | ||
68 | |||
69 | impl Hash for Canceled { | ||
70 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
71 | ().hash(hasher) | ||
72 | } | ||
73 | } | ||
74 | |||
75 | impl cmp::Ord for Canceled { | ||
76 | fn cmp(&self, _: &Canceled) -> cmp::Ordering { | ||
77 | cmp::Ordering::Equal | ||
78 | } | ||
79 | } | ||
80 | |||
81 | impl cmp::PartialOrd for Canceled { | ||
82 | fn partial_cmp(&self, other: &Canceled) -> Option<cmp::Ordering> { | ||
83 | Some(self.cmp(other)) | ||
84 | } | ||
85 | } | ||
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 22a26b844..8bd4caa53 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -8,9 +8,9 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
8 | rayon = "1.0.2" | 8 | rayon = "1.0.2" |
9 | threadpool = "1.7.1" | 9 | threadpool = "1.7.1" |
10 | relative-path = "0.4.0" | 10 | relative-path = "0.4.0" |
11 | failure = "0.1.2" | 11 | failure = "0.1.4" |
12 | failure_derive = "0.1.2" | 12 | failure_derive = "0.1.4" |
13 | serde_json = "1.0.24" | 13 | serde_json = "1.0.34" |
14 | serde = "1.0.83" | 14 | serde = "1.0.83" |
15 | drop_bomb = "0.1.0" | 15 | drop_bomb = "0.1.0" |
16 | crossbeam-channel = "0.3.5" | 16 | crossbeam-channel = "0.3.5" |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 46b48830d..06dd373c0 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -433,7 +433,7 @@ impl<'a> PoolDispatcher<'a> { | |||
433 | RawResponse::err( | 433 | RawResponse::err( |
434 | id, | 434 | id, |
435 | ErrorCode::ContentModified as i32, | 435 | ErrorCode::ContentModified as i32, |
436 | format!("content modified: {:?}", e), | 436 | "content modified".to_string(), |
437 | ) | 437 | ) |
438 | } else { | 438 | } else { |
439 | RawResponse::err( | 439 | RawResponse::err( |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 228eb7ce5..012f74270 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -556,24 +556,19 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option< | |||
556 | .into()); | 556 | .into()); |
557 | } | 557 | } |
558 | 558 | ||
559 | let refs = world | 559 | let renames = world |
560 | .analysis() | 560 | .analysis() |
561 | .find_all_refs(FilePosition { file_id, offset })?; | 561 | .rename(FilePosition { file_id, offset }, &*params.new_name)?; |
562 | if refs.is_empty() { | 562 | if renames.is_empty() { |
563 | return Ok(None); | 563 | return Ok(None); |
564 | } | 564 | } |
565 | 565 | ||
566 | let mut changes = HashMap::new(); | 566 | let mut changes = HashMap::new(); |
567 | for r in refs { | 567 | for edit in renames { |
568 | if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { | 568 | changes |
569 | changes | 569 | .entry(file_id.try_conv_with(&world)?) |
570 | .entry(loc.uri) | 570 | .or_insert_with(Vec::new) |
571 | .or_insert_with(Vec::new) | 571 | .extend(edit.edit.conv_with(&line_index)); |
572 | .push(TextEdit { | ||
573 | range: loc.range, | ||
574 | new_text: params.new_name.clone(), | ||
575 | }); | ||
576 | } | ||
577 | } | 572 | } |
578 | 573 | ||
579 | Ok(Some(WorkspaceEdit { | 574 | Ok(Some(WorkspaceEdit { |
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 02727993e..963491128 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml | |||
@@ -8,4 +8,4 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
8 | difference = "2.0.0" | 8 | difference = "2.0.0" |
9 | itertools = "0.8.0" | 9 | itertools = "0.8.0" |
10 | text_unit = "0.1.2" | 10 | text_unit = "0.1.2" |
11 | serde_json = "1.0.24" | 11 | serde_json = "1.0.34" |
diff --git a/crates/tools/Cargo.toml b/crates/tools/Cargo.toml index 4795b1387..9d6707a59 100644 --- a/crates/tools/Cargo.toml +++ b/crates/tools/Cargo.toml | |||
@@ -10,4 +10,4 @@ teraron = "0.0.1" | |||
10 | walkdir = "2.1.3" | 10 | walkdir = "2.1.3" |
11 | itertools = "0.8.0" | 11 | itertools = "0.8.0" |
12 | clap = "2.32.0" | 12 | clap = "2.32.0" |
13 | failure = "0.1.1" | 13 | failure = "0.1.4" |