aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs3
-rw-r--r--crates/ide/src/diagnostics/fixes.rs33
-rw-r--r--crates/ide/src/display/navigation_target.rs37
-rw-r--r--crates/ide/src/file_structure.rs3
-rw-r--r--crates/ide/src/lib.rs2
-rw-r--r--crates/ide/src/references.rs16
-rw-r--r--crates/ide/src/runnables.rs4
-rw-r--r--crates/ide/src/syntax_highlighting.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs3
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs2
11 files changed, 69 insertions, 42 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index b35bc2bae..8607139ba 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -136,6 +136,9 @@ pub(crate) fn diagnostics(
136 .on::<hir::diagnostics::IncorrectCase, _>(|d| { 136 .on::<hir::diagnostics::IncorrectCase, _>(|d| {
137 res.borrow_mut().push(warning_with_fix(d, &sema)); 137 res.borrow_mut().push(warning_with_fix(d, &sema));
138 }) 138 })
139 .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| {
140 res.borrow_mut().push(warning_with_fix(d, &sema));
141 })
139 .on::<hir::diagnostics::InactiveCode, _>(|d| { 142 .on::<hir::diagnostics::InactiveCode, _>(|d| {
140 // If there's inactive code somewhere in a macro, don't propagate to the call-site. 143 // If there's inactive code somewhere in a macro, don't propagate to the call-site.
141 if d.display_source().file_id.expansion_info(db).is_some() { 144 if d.display_source().file_id.expansion_info(db).is_some() {
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs
index 579d5a308..cbfc66ab3 100644
--- a/crates/ide/src/diagnostics/fixes.rs
+++ b/crates/ide/src/diagnostics/fixes.rs
@@ -4,7 +4,7 @@ use hir::{
4 db::AstDatabase, 4 db::AstDatabase,
5 diagnostics::{ 5 diagnostics::{
6 Diagnostic, IncorrectCase, MissingFields, MissingOkOrSomeInTailExpr, NoSuchField, 6 Diagnostic, IncorrectCase, MissingFields, MissingOkOrSomeInTailExpr, NoSuchField,
7 RemoveThisSemicolon, UnresolvedModule, 7 RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap, UnresolvedModule,
8 }, 8 },
9 HasSource, HirDisplay, InFile, Semantics, VariantDef, 9 HasSource, HirDisplay, InFile, Semantics, VariantDef,
10}; 10};
@@ -15,8 +15,8 @@ use ide_db::{
15}; 15};
16use syntax::{ 16use syntax::{
17 algo, 17 algo,
18 ast::{self, edit::IndentLevel, make}, 18 ast::{self, edit::IndentLevel, make, ArgListOwner},
19 AstNode, 19 AstNode, TextRange,
20}; 20};
21use text_edit::TextEdit; 21use text_edit::TextEdit;
22 22
@@ -144,6 +144,33 @@ impl DiagnosticWithFix for IncorrectCase {
144 } 144 }
145} 145}
146 146
147impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap {
148 fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
149 let root = sema.db.parse_or_expand(self.file)?;
150 let next_expr = self.next_expr.to_node(&root);
151 let next_call = ast::MethodCallExpr::cast(next_expr.syntax().clone())?;
152
153 let filter_map_call = ast::MethodCallExpr::cast(next_call.receiver()?.syntax().clone())?;
154 let filter_map_name_range = filter_map_call.name_ref()?.ident_token()?.text_range();
155 let filter_map_args = filter_map_call.arg_list()?;
156
157 let range_to_replace =
158 TextRange::new(filter_map_name_range.start(), next_expr.syntax().text_range().end());
159 let replacement = format!("find_map{}", filter_map_args.syntax().text());
160 let trigger_range = next_expr.syntax().text_range();
161
162 let edit = TextEdit::replace(range_to_replace, replacement);
163
164 let source_change = SourceChange::from_text_edit(self.file.original_file(sema.db), edit);
165
166 Some(Fix::new(
167 "Replace filter_map(..).next() with find_map()",
168 source_change,
169 trigger_range,
170 ))
171 }
172}
173
147fn missing_record_expr_field_fix( 174fn missing_record_expr_field_fix(
148 sema: &Semantics<RootDatabase>, 175 sema: &Semantics<RootDatabase>,
149 usage_file_id: FileId, 176 usage_file_id: FileId,
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 9c568c90c..23d885218 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -7,6 +7,7 @@ use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, Mo
7use ide_db::{ 7use ide_db::{
8 base_db::{FileId, FileRange, SourceDatabase}, 8 base_db::{FileId, FileRange, SourceDatabase},
9 symbol_index::FileSymbolKind, 9 symbol_index::FileSymbolKind,
10 SymbolKind,
10}; 11};
11use ide_db::{defs::Definition, RootDatabase}; 12use ide_db::{defs::Definition, RootDatabase};
12use syntax::{ 13use syntax::{
@@ -18,30 +19,6 @@ use crate::FileSymbol;
18 19
19use super::short_label::ShortLabel; 20use super::short_label::ShortLabel;
20 21
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub enum SymbolKind {
23 Module,
24 Impl,
25 Field,
26 TypeParam,
27 ConstParam,
28 LifetimeParam,
29 ValueParam,
30 SelfParam,
31 Local,
32 Label,
33 Function,
34 Const,
35 Static,
36 Struct,
37 Enum,
38 Variant,
39 Union,
40 TypeAlias,
41 Trait,
42 Macro,
43}
44
45/// `NavigationTarget` represents and element in the editor's UI which you can 22/// `NavigationTarget` represents and element in the editor's UI which you can
46/// click on to navigate to a particular piece of code. 23/// click on to navigate to a particular piece of code.
47/// 24///
@@ -196,6 +173,7 @@ impl ToNav for FileSymbol {
196 FileSymbolKind::Const => SymbolKind::Const, 173 FileSymbolKind::Const => SymbolKind::Const,
197 FileSymbolKind::Static => SymbolKind::Static, 174 FileSymbolKind::Static => SymbolKind::Static,
198 FileSymbolKind::Macro => SymbolKind::Macro, 175 FileSymbolKind::Macro => SymbolKind::Macro,
176 FileSymbolKind::Union => SymbolKind::Union,
199 }), 177 }),
200 full_range: self.range, 178 full_range: self.range,
201 focus_range: self.name_range, 179 focus_range: self.name_range,
@@ -457,13 +435,16 @@ impl TryToNav for hir::TypeParam {
457 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 435 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
458 let src = self.source(db)?; 436 let src = self.source(db)?;
459 let full_range = match &src.value { 437 let full_range = match &src.value {
460 Either::Left(it) => it.syntax().text_range(), 438 Either::Left(it) => it
439 .name()
440 .map_or_else(|| it.syntax().text_range(), |name| name.syntax().text_range()),
461 Either::Right(it) => it.syntax().text_range(), 441 Either::Right(it) => it.syntax().text_range(),
462 }; 442 };
463 let focus_range = match &src.value { 443 let focus_range = match &src.value {
464 Either::Left(_) => None, 444 Either::Left(it) => it.name(),
465 Either::Right(it) => it.name().map(|it| it.syntax().text_range()), 445 Either::Right(it) => it.name(),
466 }; 446 }
447 .map(|it| it.syntax().text_range());
467 Some(NavigationTarget { 448 Some(NavigationTarget {
468 file_id: src.file_id.original_file(db), 449 file_id: src.file_id.original_file(db),
469 name: self.name(db).to_string().into(), 450 name: self.name(db).to_string().into(),
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs
index 32556dad3..26793bdb4 100644
--- a/crates/ide/src/file_structure.rs
+++ b/crates/ide/src/file_structure.rs
@@ -1,10 +1,9 @@
1use ide_db::SymbolKind;
1use syntax::{ 2use syntax::{
2 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, 3 ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
3 match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent, 4 match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent,
4}; 5};
5 6
6use crate::SymbolKind;
7
8#[derive(Debug, Clone)] 7#[derive(Debug, Clone)]
9pub struct StructureNode { 8pub struct StructureNode {
10 pub parent: Option<usize>, 9 pub parent: Option<usize>,
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 567b8117e..989e94a31 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -65,7 +65,7 @@ use crate::display::ToNav;
65pub use crate::{ 65pub use crate::{
66 call_hierarchy::CallItem, 66 call_hierarchy::CallItem,
67 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, 67 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
68 display::navigation_target::{NavigationTarget, SymbolKind}, 68 display::navigation_target::NavigationTarget,
69 expand_macro::ExpandedMacro, 69 expand_macro::ExpandedMacro,
70 file_structure::StructureNode, 70 file_structure::StructureNode,
71 folding_ranges::{Fold, FoldKind}, 71 folding_ranges::{Fold, FoldKind},
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 3a4f4d80b..40d9487eb 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -1098,4 +1098,20 @@ fn foo<const FOO$0: usize>() -> usize {
1098 "#]], 1098 "#]],
1099 ); 1099 );
1100 } 1100 }
1101
1102 #[test]
1103 fn test_find_self_ty_in_trait_def() {
1104 check(
1105 r#"
1106trait Foo {
1107 fn f() -> Self$0;
1108}
1109"#,
1110 expect![[r#"
1111 Self TypeParam FileId(0) 6..9 6..9 Other
1112
1113 FileId(0) 26..30 Other
1114 "#]],
1115 );
1116 }
1101} 1117}
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 975abf47f..33170906d 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -3,7 +3,7 @@ use std::fmt;
3use assists::utils::test_related_attribute; 3use assists::utils::test_related_attribute;
4use cfg::CfgExpr; 4use cfg::CfgExpr;
5use hir::{AsAssocItem, HasAttrs, HasSource, Semantics}; 5use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
6use ide_db::{defs::Definition, RootDatabase}; 6use ide_db::{defs::Definition, RootDatabase, SymbolKind};
7use itertools::Itertools; 7use itertools::Itertools;
8use syntax::{ 8use syntax::{
9 ast::{self, AstNode, AttrsOwner}, 9 ast::{self, AstNode, AttrsOwner},
@@ -13,7 +13,7 @@ use test_utils::mark;
13 13
14use crate::{ 14use crate::{
15 display::{ToNav, TryToNav}, 15 display::{ToNav, TryToNav},
16 FileId, NavigationTarget, SymbolKind, 16 FileId, NavigationTarget,
17}; 17};
18 18
19#[derive(Debug, Clone)] 19#[derive(Debug, Clone)]
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index f2d4da78d..a3d4e4f77 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -13,7 +13,7 @@ mod html;
13mod tests; 13mod tests;
14 14
15use hir::{Name, Semantics}; 15use hir::{Name, Semantics};
16use ide_db::RootDatabase; 16use ide_db::{RootDatabase, SymbolKind};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use syntax::{ 18use syntax::{
19 ast::{self, HasFormatSpecifier}, 19 ast::{self, HasFormatSpecifier},
@@ -27,7 +27,7 @@ use crate::{
27 format::highlight_format_string, highlights::Highlights, 27 format::highlight_format_string, highlights::Highlights,
28 macro_rules::MacroRulesHighlighter, tags::Highlight, 28 macro_rules::MacroRulesHighlighter, tags::Highlight,
29 }, 29 },
30 FileId, HlMod, HlTag, SymbolKind, 30 FileId, HlMod, HlTag,
31}; 31};
32 32
33pub(crate) use html::highlight_as_html; 33pub(crate) use html::highlight_as_html;
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs
index 8a9b5ca8c..8c67a0863 100644
--- a/crates/ide/src/syntax_highlighting/format.rs
+++ b/crates/ide/src/syntax_highlighting/format.rs
@@ -1,10 +1,11 @@
1//! Syntax highlighting for format macro strings. 1//! Syntax highlighting for format macro strings.
2use ide_db::SymbolKind;
2use syntax::{ 3use syntax::{
3 ast::{self, FormatSpecifier, HasFormatSpecifier}, 4 ast::{self, FormatSpecifier, HasFormatSpecifier},
4 AstNode, AstToken, TextRange, 5 AstNode, AstToken, TextRange,
5}; 6};
6 7
7use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag, SymbolKind}; 8use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag};
8 9
9pub(super) fn highlight_format_string( 10pub(super) fn highlight_format_string(
10 stack: &mut Highlights, 11 stack: &mut Highlights,
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 8625ef5df..24fcbb584 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -3,7 +3,7 @@
3use hir::{AsAssocItem, Semantics, VariantDef}; 3use hir::{AsAssocItem, Semantics, VariantDef};
4use ide_db::{ 4use ide_db::{
5 defs::{Definition, NameClass, NameRefClass}, 5 defs::{Definition, NameClass, NameRefClass},
6 RootDatabase, 6 RootDatabase, SymbolKind,
7}; 7};
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9use syntax::{ 9use syntax::{
@@ -12,7 +12,7 @@ use syntax::{
12 SyntaxNode, SyntaxToken, T, 12 SyntaxNode, SyntaxToken, T,
13}; 13};
14 14
15use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind}; 15use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag};
16 16
17pub(super) fn element( 17pub(super) fn element(
18 sema: &Semantics<RootDatabase>, 18 sema: &Semantics<RootDatabase>,
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs
index 8dd05ac52..3c02fdb11 100644
--- a/crates/ide/src/syntax_highlighting/tags.rs
+++ b/crates/ide/src/syntax_highlighting/tags.rs
@@ -3,7 +3,7 @@
3 3
4use std::{fmt, ops}; 4use std::{fmt, ops};
5 5
6use crate::SymbolKind; 6use ide_db::SymbolKind;
7 7
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9pub struct Highlight { 9pub struct Highlight {