diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/hover.rs | 29 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 21 | ||||
-rw-r--r-- | crates/ide/src/runnables.rs | 35 |
3 files changed, 35 insertions, 50 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index f2ad95cb6..72c9c66fe 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -17,7 +17,7 @@ use crate::{ | |||
17 | doc_links::{remove_links, rewrite_links}, | 17 | doc_links::{remove_links, rewrite_links}, |
18 | markdown_remove::remove_markdown, | 18 | markdown_remove::remove_markdown, |
19 | markup::Markup, | 19 | markup::Markup, |
20 | runnables::runnable, | 20 | runnables::{runnable, runnable_fn}, |
21 | FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, | 21 | FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, |
22 | }; | 22 | }; |
23 | 23 | ||
@@ -31,19 +31,6 @@ pub struct HoverConfig { | |||
31 | pub markdown: bool, | 31 | pub markdown: bool, |
32 | } | 32 | } |
33 | 33 | ||
34 | impl Default for HoverConfig { | ||
35 | fn default() -> Self { | ||
36 | Self { | ||
37 | implementations: true, | ||
38 | run: true, | ||
39 | debug: true, | ||
40 | goto_type_def: true, | ||
41 | links_in_hover: true, | ||
42 | markdown: true, | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | impl HoverConfig { | 34 | impl HoverConfig { |
48 | pub const NO_ACTIONS: Self = Self { | 35 | pub const NO_ACTIONS: Self = Self { |
49 | implementations: false, | 36 | implementations: false, |
@@ -204,22 +191,20 @@ fn runnable_action( | |||
204 | match def { | 191 | match def { |
205 | Definition::ModuleDef(it) => match it { | 192 | Definition::ModuleDef(it) => match it { |
206 | ModuleDef::Module(it) => match it.definition_source(sema.db).value { | 193 | ModuleDef::Module(it) => match it.definition_source(sema.db).value { |
207 | ModuleSource::Module(it) => runnable(&sema, it.syntax().clone(), file_id) | 194 | ModuleSource::Module(it) => { |
208 | .map(|it| HoverAction::Runnable(it)), | 195 | runnable(&sema, it.syntax().clone()).map(|it| HoverAction::Runnable(it)) |
196 | } | ||
209 | _ => None, | 197 | _ => None, |
210 | }, | 198 | }, |
211 | ModuleDef::Function(it) => { | 199 | ModuleDef::Function(func) => { |
212 | #[allow(deprecated)] | 200 | let src = func.source(sema.db)?; |
213 | let src = it.source(sema.db)?; | ||
214 | if src.file_id != file_id.into() { | 201 | if src.file_id != file_id.into() { |
215 | mark::hit!(hover_macro_generated_struct_fn_doc_comment); | 202 | mark::hit!(hover_macro_generated_struct_fn_doc_comment); |
216 | mark::hit!(hover_macro_generated_struct_fn_doc_attr); | 203 | mark::hit!(hover_macro_generated_struct_fn_doc_attr); |
217 | |||
218 | return None; | 204 | return None; |
219 | } | 205 | } |
220 | 206 | ||
221 | runnable(&sema, src.value.syntax().clone(), file_id) | 207 | runnable_fn(&sema, func).map(HoverAction::Runnable) |
222 | .map(|it| HoverAction::Runnable(it)) | ||
223 | } | 208 | } |
224 | _ => None, | 209 | _ => None, |
225 | }, | 210 | }, |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 65df7979c..fe60abfc8 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -18,12 +18,6 @@ pub struct InlayHintsConfig { | |||
18 | pub max_length: Option<usize>, | 18 | pub max_length: Option<usize>, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl Default for InlayHintsConfig { | ||
22 | fn default() -> Self { | ||
23 | Self { type_hints: true, parameter_hints: true, chaining_hints: true, max_length: None } | ||
24 | } | ||
25 | } | ||
26 | |||
27 | #[derive(Clone, Debug, PartialEq, Eq)] | 21 | #[derive(Clone, Debug, PartialEq, Eq)] |
28 | pub enum InlayKind { | 22 | pub enum InlayKind { |
29 | TypeHint, | 23 | TypeHint, |
@@ -433,8 +427,15 @@ mod tests { | |||
433 | 427 | ||
434 | use crate::{fixture, inlay_hints::InlayHintsConfig}; | 428 | use crate::{fixture, inlay_hints::InlayHintsConfig}; |
435 | 429 | ||
430 | const TEST_CONFIG: InlayHintsConfig = InlayHintsConfig { | ||
431 | type_hints: true, | ||
432 | parameter_hints: true, | ||
433 | chaining_hints: true, | ||
434 | max_length: None, | ||
435 | }; | ||
436 | |||
436 | fn check(ra_fixture: &str) { | 437 | fn check(ra_fixture: &str) { |
437 | check_with_config(InlayHintsConfig::default(), ra_fixture); | 438 | check_with_config(TEST_CONFIG, ra_fixture); |
438 | } | 439 | } |
439 | 440 | ||
440 | fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { | 441 | fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { |
@@ -748,7 +749,7 @@ fn main() { | |||
748 | #[test] | 749 | #[test] |
749 | fn hint_truncation() { | 750 | fn hint_truncation() { |
750 | check_with_config( | 751 | check_with_config( |
751 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | 752 | InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, |
752 | r#" | 753 | r#" |
753 | struct Smol<T>(T); | 754 | struct Smol<T>(T); |
754 | 755 | ||
@@ -831,7 +832,7 @@ fn main() { | |||
831 | #[test] | 832 | #[test] |
832 | fn omitted_parameters_hints_heuristics() { | 833 | fn omitted_parameters_hints_heuristics() { |
833 | check_with_config( | 834 | check_with_config( |
834 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | 835 | InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, |
835 | r#" | 836 | r#" |
836 | fn map(f: i32) {} | 837 | fn map(f: i32) {} |
837 | fn filter(predicate: i32) {} | 838 | fn filter(predicate: i32) {} |
@@ -924,7 +925,7 @@ fn main() { | |||
924 | #[test] | 925 | #[test] |
925 | fn unit_structs_have_no_type_hints() { | 926 | fn unit_structs_have_no_type_hints() { |
926 | check_with_config( | 927 | check_with_config( |
927 | InlayHintsConfig { max_length: Some(8), ..Default::default() }, | 928 | InlayHintsConfig { max_length: Some(8), ..TEST_CONFIG }, |
928 | r#" | 929 | r#" |
929 | enum Result<T, E> { Ok(T), Err(E) } | 930 | enum Result<T, E> { Ok(T), Err(E) } |
930 | use Result::*; | 931 | use Result::*; |
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index c893afc7c..f4030f3ef 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs | |||
@@ -2,11 +2,11 @@ use std::fmt; | |||
2 | 2 | ||
3 | use assists::utils::test_related_attribute; | 3 | use assists::utils::test_related_attribute; |
4 | use cfg::CfgExpr; | 4 | use cfg::CfgExpr; |
5 | use hir::{AsAssocItem, HasAttrs, InFile, Semantics}; | 5 | use hir::{AsAssocItem, HasAttrs, HasSource, Semantics}; |
6 | use ide_db::RootDatabase; | 6 | use ide_db::RootDatabase; |
7 | use itertools::Itertools; | 7 | use itertools::Itertools; |
8 | use syntax::{ | 8 | use syntax::{ |
9 | ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, | 9 | ast::{self, AstNode, AttrsOwner, ModuleItemOwner}, |
10 | match_ast, SyntaxNode, | 10 | match_ast, SyntaxNode, |
11 | }; | 11 | }; |
12 | 12 | ||
@@ -96,17 +96,16 @@ impl Runnable { | |||
96 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { | 96 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { |
97 | let sema = Semantics::new(db); | 97 | let sema = Semantics::new(db); |
98 | let source_file = sema.parse(file_id); | 98 | let source_file = sema.parse(file_id); |
99 | source_file.syntax().descendants().filter_map(|i| runnable(&sema, i, file_id)).collect() | 99 | source_file.syntax().descendants().filter_map(|i| runnable(&sema, i)).collect() |
100 | } | 100 | } |
101 | 101 | ||
102 | pub(crate) fn runnable( | 102 | pub(crate) fn runnable(sema: &Semantics<RootDatabase>, item: SyntaxNode) -> Option<Runnable> { |
103 | sema: &Semantics<RootDatabase>, | ||
104 | item: SyntaxNode, | ||
105 | file_id: FileId, | ||
106 | ) -> Option<Runnable> { | ||
107 | let runnable_item = match_ast! { | 103 | let runnable_item = match_ast! { |
108 | match (item.clone()) { | 104 | match (item.clone()) { |
109 | ast::Fn(it) => runnable_fn(sema, it, file_id), | 105 | ast::Fn(func) => { |
106 | let def = sema.to_def(&func)?; | ||
107 | runnable_fn(sema, def) | ||
108 | }, | ||
110 | ast::Module(it) => runnable_mod(sema, it), | 109 | ast::Module(it) => runnable_mod(sema, it), |
111 | _ => None, | 110 | _ => None, |
112 | } | 111 | } |
@@ -114,23 +113,23 @@ pub(crate) fn runnable( | |||
114 | runnable_item.or_else(|| runnable_doctest(sema, item)) | 113 | runnable_item.or_else(|| runnable_doctest(sema, item)) |
115 | } | 114 | } |
116 | 115 | ||
117 | fn runnable_fn(sema: &Semantics<RootDatabase>, func: ast::Fn, file_id: FileId) -> Option<Runnable> { | 116 | pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> Option<Runnable> { |
118 | let def = sema.to_def(&func)?; | 117 | let func = def.source(sema.db)?; |
119 | let name_string = func.name()?.text().to_string(); | 118 | let name_string = def.name(sema.db).to_string(); |
120 | 119 | ||
121 | let kind = if name_string == "main" { | 120 | let kind = if name_string == "main" { |
122 | RunnableKind::Bin | 121 | RunnableKind::Bin |
123 | } else { | 122 | } else { |
124 | let canonical_path = sema.to_def(&func).and_then(|def| { | 123 | let canonical_path = { |
125 | let def: hir::ModuleDef = def.into(); | 124 | let def: hir::ModuleDef = def.into(); |
126 | def.canonical_path(sema.db) | 125 | def.canonical_path(sema.db) |
127 | }); | 126 | }; |
128 | let test_id = canonical_path.map(TestId::Path).unwrap_or(TestId::Name(name_string)); | 127 | let test_id = canonical_path.map(TestId::Path).unwrap_or(TestId::Name(name_string)); |
129 | 128 | ||
130 | if test_related_attribute(&func).is_some() { | 129 | if test_related_attribute(&func.value).is_some() { |
131 | let attr = TestAttr::from_fn(&func); | 130 | let attr = TestAttr::from_fn(&func.value); |
132 | RunnableKind::Test { test_id, attr } | 131 | RunnableKind::Test { test_id, attr } |
133 | } else if func.has_atom_attr("bench") { | 132 | } else if func.value.has_atom_attr("bench") { |
134 | RunnableKind::Bench { test_id } | 133 | RunnableKind::Bench { test_id } |
135 | } else { | 134 | } else { |
136 | return None; | 135 | return None; |
@@ -139,7 +138,7 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, func: ast::Fn, file_id: FileId) - | |||
139 | 138 | ||
140 | let nav = NavigationTarget::from_named( | 139 | let nav = NavigationTarget::from_named( |
141 | sema.db, | 140 | sema.db, |
142 | InFile::new(file_id.into(), &func), | 141 | func.as_ref().map(|it| it as &dyn ast::NameOwner), |
143 | SymbolKind::Function, | 142 | SymbolKind::Function, |
144 | ); | 143 | ); |
145 | let cfg = def.attrs(sema.db).cfg(); | 144 | let cfg = def.attrs(sema.db).cfg(); |