diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/extend_selection.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 25 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting.rs | 16 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/format.rs | 4 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injection.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/syntax_tree.rs | 6 |
7 files changed, 37 insertions, 22 deletions
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 02e17ba43..d275dd75b 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -157,7 +157,8 @@ fn missing_record_expr_field_fix( | |||
157 | return None; | 157 | return None; |
158 | } | 158 | } |
159 | let new_field = make::record_field( | 159 | let new_field = make::record_field( |
160 | record_expr_field.field_name()?, | 160 | None, |
161 | make::name(record_expr_field.field_name()?.text()), | ||
161 | make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?), | 162 | make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?), |
162 | ); | 163 | ); |
163 | 164 | ||
diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs index 3ee0af8ad..0971f7701 100644 --- a/crates/ide/src/extend_selection.rs +++ b/crates/ide/src/extend_selection.rs | |||
@@ -35,7 +35,7 @@ fn try_extend_selection( | |||
35 | ) -> Option<TextRange> { | 35 | ) -> Option<TextRange> { |
36 | let range = frange.range; | 36 | let range = frange.range; |
37 | 37 | ||
38 | let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; | 38 | let string_kinds = [COMMENT, STRING, BYTE_STRING]; |
39 | let list_kinds = [ | 39 | let list_kinds = [ |
40 | RECORD_PAT_FIELD_LIST, | 40 | RECORD_PAT_FIELD_LIST, |
41 | MATCH_ARM_LIST, | 41 | MATCH_ARM_LIST, |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index ac704ae21..6cfb22e13 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -162,7 +162,7 @@ fn get_param_name_hints( | |||
162 | .zip(args) | 162 | .zip(args) |
163 | .filter_map(|((param, _ty), arg)| { | 163 | .filter_map(|((param, _ty), arg)| { |
164 | let param_name = match param? { | 164 | let param_name = match param? { |
165 | Either::Left(self_param) => self_param.to_string(), | 165 | Either::Left(_) => "self".to_string(), |
166 | Either::Right(pat) => match pat { | 166 | Either::Right(pat) => match pat { |
167 | ast::Pat::IdentPat(it) => it.name()?.to_string(), | 167 | ast::Pat::IdentPat(it) => it.name()?.to_string(), |
168 | _ => return None, | 168 | _ => return None, |
@@ -809,7 +809,7 @@ fn main() { | |||
809 | t.method(123); | 809 | t.method(123); |
810 | //^^^ param | 810 | //^^^ param |
811 | Test::method(&t, 3456); | 811 | Test::method(&t, 3456); |
812 | //^^ &self ^^^^ param | 812 | //^^ self ^^^^ param |
813 | Test::from_syntax( | 813 | Test::from_syntax( |
814 | FileId {}, | 814 | FileId {}, |
815 | //^^^^^^^^^ file_id | 815 | //^^^^^^^^^ file_id |
@@ -1360,4 +1360,25 @@ fn main() { | |||
1360 | "#, | 1360 | "#, |
1361 | ); | 1361 | ); |
1362 | } | 1362 | } |
1363 | |||
1364 | #[test] | ||
1365 | fn self_param_hints() { | ||
1366 | check( | ||
1367 | r#" | ||
1368 | struct Foo; | ||
1369 | |||
1370 | impl Foo { | ||
1371 | fn foo(self: Self) {} | ||
1372 | fn bar(self: &Self) {} | ||
1373 | } | ||
1374 | |||
1375 | fn main() { | ||
1376 | Foo::foo(Foo); | ||
1377 | //^^^ self | ||
1378 | Foo::bar(&Foo); | ||
1379 | //^^^^ self | ||
1380 | } | ||
1381 | "#, | ||
1382 | ) | ||
1383 | } | ||
1363 | } | 1384 | } |
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index efcc8ecfe..05bafe9c8 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -179,10 +179,12 @@ pub(crate) fn highlight( | |||
179 | element.clone() | 179 | element.clone() |
180 | }; | 180 | }; |
181 | 181 | ||
182 | if let Some(token) = element.as_token().cloned().and_then(ast::RawString::cast) { | 182 | if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) { |
183 | let expanded = element_to_highlight.as_token().unwrap().clone(); | 183 | if token.is_raw() { |
184 | if injection::highlight_injection(&mut stack, &sema, token, expanded).is_some() { | 184 | let expanded = element_to_highlight.as_token().unwrap().clone(); |
185 | continue; | 185 | if injection::highlight_injection(&mut stack, &sema, token, expanded).is_some() { |
186 | continue; | ||
187 | } | ||
186 | } | 188 | } |
187 | } | 189 | } |
188 | 190 | ||
@@ -214,10 +216,6 @@ pub(crate) fn highlight( | |||
214 | } | 216 | } |
215 | stack.pop_and_inject(None); | 217 | stack.pop_and_inject(None); |
216 | } | 218 | } |
217 | } else if let Some(string) = | ||
218 | element_to_highlight.as_token().cloned().and_then(ast::RawString::cast) | ||
219 | { | ||
220 | format_string_highlighter.highlight_format_string(&mut stack, &string, range); | ||
221 | } | 219 | } |
222 | } | 220 | } |
223 | } | 221 | } |
@@ -532,7 +530,7 @@ fn highlight_element( | |||
532 | None => h.into(), | 530 | None => h.into(), |
533 | } | 531 | } |
534 | } | 532 | } |
535 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), | 533 | STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), |
536 | ATTR => HighlightTag::Attribute.into(), | 534 | ATTR => HighlightTag::Attribute.into(), |
537 | INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), | 535 | INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), |
538 | BYTE => HighlightTag::ByteLiteral.into(), | 536 | BYTE => HighlightTag::ByteLiteral.into(), |
diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index 71bde24f0..42f27df5d 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs | |||
@@ -29,9 +29,7 @@ impl FormatStringHighlighter { | |||
29 | .children_with_tokens() | 29 | .children_with_tokens() |
30 | .filter(|t| t.kind() != SyntaxKind::WHITESPACE) | 30 | .filter(|t| t.kind() != SyntaxKind::WHITESPACE) |
31 | .nth(1) | 31 | .nth(1) |
32 | .filter(|e| { | 32 | .filter(|e| ast::String::can_cast(e.kind())) |
33 | ast::String::can_cast(e.kind()) || ast::RawString::can_cast(e.kind()) | ||
34 | }) | ||
35 | } | 33 | } |
36 | _ => {} | 34 | _ => {} |
37 | } | 35 | } |
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index 59a74bc02..e97d1be1a 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | use std::{collections::BTreeMap, convert::TryFrom}; | 3 | use std::{collections::BTreeMap, convert::TryFrom}; |
4 | 4 | ||
5 | use ast::{HasQuotes, HasStringValue}; | ||
6 | use hir::Semantics; | 5 | use hir::Semantics; |
7 | use ide_db::call_info::ActiveParameter; | 6 | use ide_db::call_info::ActiveParameter; |
8 | use itertools::Itertools; | 7 | use itertools::Itertools; |
@@ -15,7 +14,7 @@ use super::HighlightedRangeStack; | |||
15 | pub(super) fn highlight_injection( | 14 | pub(super) fn highlight_injection( |
16 | acc: &mut HighlightedRangeStack, | 15 | acc: &mut HighlightedRangeStack, |
17 | sema: &Semantics<RootDatabase>, | 16 | sema: &Semantics<RootDatabase>, |
18 | literal: ast::RawString, | 17 | literal: ast::String, |
19 | expanded: SyntaxToken, | 18 | expanded: SyntaxToken, |
20 | ) -> Option<()> { | 19 | ) -> Option<()> { |
21 | let active_parameter = ActiveParameter::at_token(&sema, expanded)?; | 20 | let active_parameter = ActiveParameter::at_token(&sema, expanded)?; |
diff --git a/crates/ide/src/syntax_tree.rs b/crates/ide/src/syntax_tree.rs index 7941610d6..6dd05c05d 100644 --- a/crates/ide/src/syntax_tree.rs +++ b/crates/ide/src/syntax_tree.rs | |||
@@ -1,9 +1,7 @@ | |||
1 | use ide_db::base_db::{FileId, SourceDatabase}; | 1 | use ide_db::base_db::{FileId, SourceDatabase}; |
2 | use ide_db::RootDatabase; | 2 | use ide_db::RootDatabase; |
3 | use syntax::{ | 3 | use syntax::{ |
4 | algo, AstNode, NodeOrToken, SourceFile, | 4 | algo, AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize, |
5 | SyntaxKind::{RAW_STRING, STRING}, | ||
6 | SyntaxToken, TextRange, TextSize, | ||
7 | }; | 5 | }; |
8 | 6 | ||
9 | // Feature: Show Syntax Tree | 7 | // Feature: Show Syntax Tree |
@@ -46,7 +44,7 @@ fn syntax_tree_for_string(token: &SyntaxToken, text_range: TextRange) -> Option< | |||
46 | // we'll attempt parsing it as rust syntax | 44 | // we'll attempt parsing it as rust syntax |
47 | // to provide the syntax tree of the contents of the string | 45 | // to provide the syntax tree of the contents of the string |
48 | match token.kind() { | 46 | match token.kind() { |
49 | STRING | RAW_STRING => syntax_tree_for_token(token, text_range), | 47 | STRING => syntax_tree_for_token(token, text_range), |
50 | _ => None, | 48 | _ => None, |
51 | } | 49 | } |
52 | } | 50 | } |