diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_ide/src/lib.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 142 |
1 files changed, 37 insertions, 105 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index ecac5134e..0fede0d87 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -17,30 +17,33 @@ macro_rules! eprintln { | |||
17 | 17 | ||
18 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
19 | 19 | ||
20 | mod markup; | ||
20 | mod prime_caches; | 21 | mod prime_caches; |
21 | mod status; | 22 | mod display; |
23 | |||
24 | mod call_hierarchy; | ||
25 | mod call_info; | ||
22 | mod completion; | 26 | mod completion; |
23 | mod runnables; | 27 | mod diagnostics; |
28 | mod expand_macro; | ||
29 | mod extend_selection; | ||
30 | mod file_structure; | ||
31 | mod folding_ranges; | ||
24 | mod goto_definition; | 32 | mod goto_definition; |
25 | mod goto_type_definition; | ||
26 | mod goto_implementation; | 33 | mod goto_implementation; |
27 | mod extend_selection; | 34 | mod goto_type_definition; |
28 | mod hover; | 35 | mod hover; |
29 | mod call_hierarchy; | 36 | mod inlay_hints; |
30 | mod call_info; | 37 | mod join_lines; |
31 | mod syntax_highlighting; | 38 | mod matching_brace; |
32 | mod parent_module; | 39 | mod parent_module; |
33 | mod references; | 40 | mod references; |
34 | mod diagnostics; | 41 | mod runnables; |
42 | mod ssr; | ||
43 | mod status; | ||
44 | mod syntax_highlighting; | ||
35 | mod syntax_tree; | 45 | mod syntax_tree; |
36 | mod folding_ranges; | ||
37 | mod join_lines; | ||
38 | mod typing; | 46 | mod typing; |
39 | mod matching_brace; | ||
40 | mod display; | ||
41 | mod inlay_hints; | ||
42 | mod expand_macro; | ||
43 | mod ssr; | ||
44 | 47 | ||
45 | use std::sync::Arc; | 48 | use std::sync::Arc; |
46 | 49 | ||
@@ -59,15 +62,18 @@ use crate::display::ToNav; | |||
59 | 62 | ||
60 | pub use crate::{ | 63 | pub use crate::{ |
61 | call_hierarchy::CallItem, | 64 | call_hierarchy::CallItem, |
65 | call_info::CallInfo, | ||
62 | completion::{ | 66 | completion::{ |
63 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 67 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
64 | }, | 68 | }, |
65 | diagnostics::Severity, | 69 | diagnostics::Severity, |
66 | display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, | 70 | display::NavigationTarget, |
67 | expand_macro::ExpandedMacro, | 71 | expand_macro::ExpandedMacro, |
72 | file_structure::StructureNode, | ||
68 | folding_ranges::{Fold, FoldKind}, | 73 | folding_ranges::{Fold, FoldKind}, |
69 | hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, | 74 | hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, |
70 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, | 75 | inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, |
76 | markup::Markup, | ||
71 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, | 77 | references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, |
72 | runnables::{Runnable, RunnableKind, TestId}, | 78 | runnables::{Runnable, RunnableKind, TestId}, |
73 | syntax_highlighting::{ | 79 | syntax_highlighting::{ |
@@ -75,8 +81,8 @@ pub use crate::{ | |||
75 | }, | 81 | }, |
76 | }; | 82 | }; |
77 | 83 | ||
78 | pub use hir::Documentation; | 84 | pub use hir::{Documentation, Semantics}; |
79 | pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; | 85 | pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; |
80 | pub use ra_db::{ | 86 | pub use ra_db::{ |
81 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, | 87 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, |
82 | SourceRootId, | 88 | SourceRootId, |
@@ -129,14 +135,6 @@ impl<T> RangeInfo<T> { | |||
129 | } | 135 | } |
130 | } | 136 | } |
131 | 137 | ||
132 | /// Contains information about a call site. Specifically the | ||
133 | /// `FunctionSignature`and current parameter. | ||
134 | #[derive(Debug)] | ||
135 | pub struct CallInfo { | ||
136 | pub signature: FunctionSignature, | ||
137 | pub active_parameter: Option<usize>, | ||
138 | } | ||
139 | |||
140 | /// `AnalysisHost` stores the current state of the world. | 138 | /// `AnalysisHost` stores the current state of the world. |
141 | #[derive(Debug)] | 139 | #[derive(Debug)] |
142 | pub struct AnalysisHost { | 140 | pub struct AnalysisHost { |
@@ -328,7 +326,7 @@ impl Analysis { | |||
328 | /// Returns a tree representation of symbols in the file. Useful to draw a | 326 | /// Returns a tree representation of symbols in the file. Useful to draw a |
329 | /// file outline. | 327 | /// file outline. |
330 | pub fn file_structure(&self, file_id: FileId) -> Cancelable<Vec<StructureNode>> { | 328 | pub fn file_structure(&self, file_id: FileId) -> Cancelable<Vec<StructureNode>> { |
331 | self.with_db(|db| file_structure(&db.parse(file_id).tree())) | 329 | self.with_db(|db| file_structure::file_structure(&db.parse(file_id).tree())) |
332 | } | 330 | } |
333 | 331 | ||
334 | /// Returns a list of the places in the file where type hints can be displayed. | 332 | /// Returns a list of the places in the file where type hints can be displayed. |
@@ -385,7 +383,9 @@ impl Analysis { | |||
385 | position: FilePosition, | 383 | position: FilePosition, |
386 | search_scope: Option<SearchScope>, | 384 | search_scope: Option<SearchScope>, |
387 | ) -> Cancelable<Option<ReferenceSearchResult>> { | 385 | ) -> Cancelable<Option<ReferenceSearchResult>> { |
388 | self.with_db(|db| references::find_all_refs(db, position, search_scope).map(|it| it.info)) | 386 | self.with_db(|db| { |
387 | references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info) | ||
388 | }) | ||
389 | } | 389 | } |
390 | 390 | ||
391 | /// Returns a short text describing element at position. | 391 | /// Returns a short text describing element at position. |
@@ -487,8 +487,12 @@ impl Analysis { | |||
487 | } | 487 | } |
488 | 488 | ||
489 | /// Computes the set of diagnostics for the given file. | 489 | /// Computes the set of diagnostics for the given file. |
490 | pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { | 490 | pub fn diagnostics( |
491 | self.with_db(|db| diagnostics::diagnostics(db, file_id)) | 491 | &self, |
492 | file_id: FileId, | ||
493 | enable_experimental: bool, | ||
494 | ) -> Cancelable<Vec<Diagnostic>> { | ||
495 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | ||
492 | } | 496 | } |
493 | 497 | ||
494 | /// Returns the edit required to rename reference at the position to the new | 498 | /// Returns the edit required to rename reference at the position to the new |
@@ -505,9 +509,11 @@ impl Analysis { | |||
505 | &self, | 509 | &self, |
506 | query: &str, | 510 | query: &str, |
507 | parse_only: bool, | 511 | parse_only: bool, |
512 | position: FilePosition, | ||
513 | selections: Vec<FileRange>, | ||
508 | ) -> Cancelable<Result<SourceChange, SsrError>> { | 514 | ) -> Cancelable<Result<SourceChange, SsrError>> { |
509 | self.with_db(|db| { | 515 | self.with_db(|db| { |
510 | let edits = ssr::parse_search_replace(query, parse_only, db)?; | 516 | let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?; |
511 | Ok(SourceChange::from(edits)) | 517 | Ok(SourceChange::from(edits)) |
512 | }) | 518 | }) |
513 | } | 519 | } |
@@ -526,77 +532,3 @@ fn analysis_is_send() { | |||
526 | fn is_send<T: Send>() {} | 532 | fn is_send<T: Send>() {} |
527 | is_send::<Analysis>(); | 533 | is_send::<Analysis>(); |
528 | } | 534 | } |
529 | |||
530 | #[cfg(test)] | ||
531 | mod tests { | ||
532 | use crate::{display::NavigationTarget, mock_analysis::single_file, Query}; | ||
533 | use ra_syntax::{ | ||
534 | SmolStr, | ||
535 | SyntaxKind::{FN_DEF, STRUCT_DEF}, | ||
536 | }; | ||
537 | |||
538 | #[test] | ||
539 | fn test_world_symbols_with_no_container() { | ||
540 | let code = r#" | ||
541 | enum FooInner { } | ||
542 | "#; | ||
543 | |||
544 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
545 | |||
546 | let s = symbols.pop().unwrap(); | ||
547 | |||
548 | assert_eq!(s.name(), "FooInner"); | ||
549 | assert!(s.container_name().is_none()); | ||
550 | } | ||
551 | |||
552 | #[test] | ||
553 | fn test_world_symbols_include_container_name() { | ||
554 | let code = r#" | ||
555 | fn foo() { | ||
556 | enum FooInner { } | ||
557 | } | ||
558 | "#; | ||
559 | |||
560 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
561 | |||
562 | let s = symbols.pop().unwrap(); | ||
563 | |||
564 | assert_eq!(s.name(), "FooInner"); | ||
565 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
566 | |||
567 | let code = r#" | ||
568 | mod foo { | ||
569 | struct FooInner; | ||
570 | } | ||
571 | "#; | ||
572 | |||
573 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
574 | |||
575 | let s = symbols.pop().unwrap(); | ||
576 | |||
577 | assert_eq!(s.name(), "FooInner"); | ||
578 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
579 | } | ||
580 | |||
581 | #[test] | ||
582 | fn test_world_symbols_are_case_sensitive() { | ||
583 | let code = r#" | ||
584 | fn foo() {} | ||
585 | |||
586 | struct Foo; | ||
587 | "#; | ||
588 | |||
589 | let symbols = get_symbols_matching(code, "Foo"); | ||
590 | |||
591 | let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind()); | ||
592 | let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind()); | ||
593 | |||
594 | assert_eq!(fn_match, Some(FN_DEF)); | ||
595 | assert_eq!(struct_match, Some(STRUCT_DEF)); | ||
596 | } | ||
597 | |||
598 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
599 | let (analysis, _) = single_file(text); | ||
600 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
601 | } | ||
602 | } | ||