diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 46 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/runnables.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/symbol_index.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/src/syntax_highlighting.rs | 36 | ||||
-rw-r--r-- | crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap | 2 |
8 files changed, 20 insertions, 95 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 0c90ed5b5..26fde91bc 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -223,7 +223,7 @@ impl RootDatabase { | |||
223 | self.query(hir::db::FileItemsQuery).sweep(sweep); | 223 | self.query(hir::db::FileItemsQuery).sweep(sweep); |
224 | self.query(hir::db::FileItemQuery).sweep(sweep); | 224 | self.query(hir::db::FileItemQuery).sweep(sweep); |
225 | 225 | ||
226 | self.query(hir::db::LowerModuleWithSourceMapQuery).sweep(sweep); | 226 | self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); |
227 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); | 227 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); |
228 | } | 228 | } |
229 | } | 229 | } |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 71003104b..28c8f83ab 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! This modules takes care of rendering various defenitions as completion items. | 1 | //! This modules takes care of rendering various defenitions as completion items. |
2 | use join_to_string::join; | 2 | use join_to_string::join; |
3 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
4 | use hir::{Docs, PerNs, Resolution}; | 4 | use hir::{Docs, PerNs, Resolution, HirDisplay}; |
5 | use ra_syntax::ast::NameOwner; | 5 | use ra_syntax::ast::NameOwner; |
6 | 6 | ||
7 | use crate::completion::{ | 7 | use crate::completion::{ |
@@ -22,7 +22,7 @@ impl Completions { | |||
22 | field.name(ctx.db).to_string(), | 22 | field.name(ctx.db).to_string(), |
23 | ) | 23 | ) |
24 | .kind(CompletionItemKind::Field) | 24 | .kind(CompletionItemKind::Field) |
25 | .detail(field.ty(ctx.db).subst(substs).to_string()) | 25 | .detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string()) |
26 | .set_documentation(field.docs(ctx.db)) | 26 | .set_documentation(field.docs(ctx.db)) |
27 | .add_to(self); | 27 | .add_to(self); |
28 | } | 28 | } |
@@ -30,7 +30,7 @@ impl Completions { | |||
30 | pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { | 30 | pub(crate) fn add_pos_field(&mut self, ctx: &CompletionContext, field: usize, ty: &hir::Ty) { |
31 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string()) | 31 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), field.to_string()) |
32 | .kind(CompletionItemKind::Field) | 32 | .kind(CompletionItemKind::Field) |
33 | .detail(ty.to_string()) | 33 | .detail(ty.display(ctx.db).to_string()) |
34 | .add_to(self); | 34 | .add_to(self); |
35 | } | 35 | } |
36 | 36 | ||
@@ -154,7 +154,10 @@ impl Completions { | |||
154 | None => return, | 154 | None => return, |
155 | }; | 155 | }; |
156 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); | 156 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); |
157 | let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string(); | 157 | let detail = join(detail_types.map(|t| t.display(ctx.db).to_string())) |
158 | .separator(", ") | ||
159 | .surround_with("(", ")") | ||
160 | .to_string(); | ||
158 | 161 | ||
159 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | 162 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) |
160 | .kind(CompletionItemKind::EnumVariant) | 163 | .kind(CompletionItemKind::EnumVariant) |
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 4051728e1..d23290b74 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -1,55 +1,13 @@ | |||
1 | use ra_db::SourceDatabase; | 1 | use ra_db::SourceDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::AstNode; |
3 | SyntaxNode, AstNode, SourceFile, | ||
4 | ast, algo::find_covering_node, | ||
5 | }; | ||
6 | 3 | ||
7 | use crate::{ | 4 | use crate::{ |
8 | TextRange, FileRange, | 5 | TextRange, FileRange, |
9 | db::RootDatabase, | 6 | db::RootDatabase, |
10 | }; | 7 | }; |
11 | 8 | ||
9 | // FIXME: restore macro support | ||
12 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { | 10 | pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { |
13 | let source_file = db.parse(frange.file_id); | 11 | let source_file = db.parse(frange.file_id); |
14 | if let Some(range) = extend_selection_in_macro(db, &source_file, frange) { | ||
15 | return range; | ||
16 | } | ||
17 | ra_ide_api_light::extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range) | 12 | ra_ide_api_light::extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range) |
18 | } | 13 | } |
19 | |||
20 | fn extend_selection_in_macro( | ||
21 | _db: &RootDatabase, | ||
22 | source_file: &SourceFile, | ||
23 | frange: FileRange, | ||
24 | ) -> Option<TextRange> { | ||
25 | let macro_call = find_macro_call(source_file.syntax(), frange.range)?; | ||
26 | let (off, exp) = hir::MacroDef::ast_expand(macro_call)?; | ||
27 | let dst_range = exp.map_range_forward(frange.range - off)?; | ||
28 | let dst_range = ra_ide_api_light::extend_selection(&exp.syntax(), dst_range)?; | ||
29 | let src_range = exp.map_range_back(dst_range)? + off; | ||
30 | Some(src_range) | ||
31 | } | ||
32 | |||
33 | fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCall> { | ||
34 | find_covering_node(node, range).ancestors().find_map(ast::MacroCall::cast) | ||
35 | } | ||
36 | |||
37 | #[cfg(test)] | ||
38 | mod tests { | ||
39 | use ra_syntax::TextRange; | ||
40 | |||
41 | use crate::mock_analysis::single_file_with_range; | ||
42 | |||
43 | #[test] | ||
44 | fn extend_selection_inside_macros() { | ||
45 | let (analysis, frange) = single_file_with_range( | ||
46 | " | ||
47 | fn main() { | ||
48 | vec![foo(|x| <|>x<|>)]; | ||
49 | } | ||
50 | ", | ||
51 | ); | ||
52 | let r = analysis.extend_selection(frange).unwrap(); | ||
53 | assert_eq!(r, TextRange::from_to(50.into(), 55.into())); | ||
54 | } | ||
55 | } | ||
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 66a625c6c..f6a83dd93 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -3,6 +3,7 @@ use ra_syntax::{ | |||
3 | AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner}, | 3 | AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner}, |
4 | algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, | 4 | algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, |
5 | }; | 5 | }; |
6 | use hir::HirDisplay; | ||
6 | 7 | ||
7 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; | 8 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; |
8 | 9 | ||
@@ -134,9 +135,9 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { | |||
134 | let infer = function.infer(db); | 135 | let infer = function.infer(db); |
135 | let source_map = function.body_source_map(db); | 136 | let source_map = function.body_source_map(db); |
136 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) { | 137 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) { |
137 | Some(infer[expr].to_string()) | 138 | Some(infer[expr].display(db).to_string()) |
138 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) { | 139 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) { |
139 | Some(infer[pat].to_string()) | 140 | Some(infer[pat].display(db).to_string()) |
140 | } else { | 141 | } else { |
141 | None | 142 | None |
142 | } | 143 | } |
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index d64b5a4e0..2395930f0 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | TextRange, SyntaxNode, | 3 | TextRange, SyntaxNode, |
4 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, | 4 | ast::{self, AstNode, NameOwner, ModuleItemOwner, AttrsOwner}, |
5 | }; | 5 | }; |
6 | use ra_db::SourceDatabase; | 6 | use ra_db::SourceDatabase; |
7 | 7 | ||
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index 94fe1d6d7..23c743bef 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs | |||
@@ -30,7 +30,7 @@ use std::{ | |||
30 | use fst::{self, Streamer}; | 30 | use fst::{self, Streamer}; |
31 | use ra_syntax::{ | 31 | use ra_syntax::{ |
32 | SyntaxNode, SyntaxNodePtr, SourceFile, SmolStr, TreeArc, AstNode, | 32 | SyntaxNode, SyntaxNodePtr, SourceFile, SmolStr, TreeArc, AstNode, |
33 | algo::{visit::{visitor, Visitor}, find_covering_node}, | 33 | algo::{visit::{visitor, Visitor}}, |
34 | SyntaxKind::{self, *}, | 34 | SyntaxKind::{self, *}, |
35 | ast::{self, NameOwner}, | 35 | ast::{self, NameOwner}, |
36 | WalkEvent, | 36 | WalkEvent, |
@@ -66,14 +66,9 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> | |||
66 | db.check_canceled(); | 66 | db.check_canceled(); |
67 | let source_file = db.parse(file_id); | 67 | let source_file = db.parse(file_id); |
68 | 68 | ||
69 | let mut symbols = source_file_to_file_symbols(&source_file, file_id); | 69 | let symbols = source_file_to_file_symbols(&source_file, file_id); |
70 | 70 | ||
71 | for (name, text_range) in hir::source_binder::macro_symbols(db, file_id) { | 71 | // TODO: add macros here |
72 | let node = find_covering_node(source_file.syntax(), text_range); | ||
73 | let ptr = SyntaxNodePtr::new(node); | ||
74 | // TODO: Should we get container name for macro symbols? | ||
75 | symbols.push(FileSymbol { file_id, name, ptr, name_range: None, container_name: None }) | ||
76 | } | ||
77 | 72 | ||
78 | Arc::new(SymbolIndex::new(symbols)) | 73 | Arc::new(SymbolIndex::new(symbols)) |
79 | } | 74 | } |
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 345b6653d..fdd87bcff 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_syntax::{ast, AstNode,}; | 1 | use ra_syntax::AstNode; |
2 | use ra_db::SourceDatabase; | 2 | use ra_db::SourceDatabase; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
@@ -8,37 +8,5 @@ use crate::{ | |||
8 | 8 | ||
9 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { | 9 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { |
10 | let source_file = db.parse(file_id); | 10 | let source_file = db.parse(file_id); |
11 | let mut res = ra_ide_api_light::highlight(source_file.syntax()); | 11 | ra_ide_api_light::highlight(source_file.syntax()) |
12 | for macro_call in source_file.syntax().descendants().filter_map(ast::MacroCall::cast) { | ||
13 | if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) { | ||
14 | let mapped_ranges = | ||
15 | ra_ide_api_light::highlight(&exp.syntax()).into_iter().filter_map(|r| { | ||
16 | let mapped_range = exp.map_range_back(r.range)?; | ||
17 | let res = HighlightedRange { range: mapped_range + off, tag: r.tag }; | ||
18 | Some(res) | ||
19 | }); | ||
20 | res.extend(mapped_ranges); | ||
21 | } | ||
22 | } | ||
23 | res | ||
24 | } | ||
25 | |||
26 | #[cfg(test)] | ||
27 | mod tests { | ||
28 | use crate::mock_analysis::single_file; | ||
29 | |||
30 | use insta::assert_debug_snapshot_matches; | ||
31 | |||
32 | #[test] | ||
33 | fn highlights_code_inside_macros() { | ||
34 | let (analysis, file_id) = single_file( | ||
35 | " | ||
36 | fn main() { | ||
37 | vec![{ let x = 92; x}]; | ||
38 | } | ||
39 | ", | ||
40 | ); | ||
41 | let highlights = analysis.highlight(file_id).unwrap(); | ||
42 | assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights); | ||
43 | } | ||
44 | } | 12 | } |
diff --git a/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap index d258820af..5bb953892 100644 --- a/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap +++ b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap | |||
@@ -7,7 +7,7 @@ source: "crates\\ra_ide_api\\tests\\test\\main.rs" | |||
7 | [ | 7 | [ |
8 | Diagnostic { | 8 | Diagnostic { |
9 | message: "unresolved module", | 9 | message: "unresolved module", |
10 | range: [4; 7), | 10 | range: [0; 8), |
11 | fix: Some( | 11 | fix: Some( |
12 | SourceChange { | 12 | SourceChange { |
13 | label: "create module", | 13 | label: "create module", |