aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-16 16:40:41 +0000
committerAleksey Kladov <[email protected]>2019-03-17 09:53:22 +0000
commit6955e392f8c1cd49e769328b14e10b84ede26744 (patch)
tree5eeb4f7f65dd5dcf8bb5c1e3b4ffe5f353b5659d /crates/ra_ide_api
parentee3cf6172b29a1dc0973800b5a4f97afa5eefd90 (diff)
remove old macro support
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs46
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs36
2 files changed, 4 insertions, 78 deletions
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 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::AstNode;
3 SyntaxNode, AstNode, SourceFile,
4 ast, algo::find_covering_node,
5};
6 3
7use crate::{ 4use crate::{
8 TextRange, FileRange, 5 TextRange, FileRange,
9 db::RootDatabase, 6 db::RootDatabase,
10}; 7};
11 8
9// FIXME: restore macro support
12pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { 10pub(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
20fn 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
33fn 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)]
38mod 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/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 @@
1use ra_syntax::{ast, AstNode,}; 1use ra_syntax::AstNode;
2use ra_db::SourceDatabase; 2use ra_db::SourceDatabase;
3 3
4use crate::{ 4use crate::{
@@ -8,37 +8,5 @@ use crate::{
8 8
9pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 9pub(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)]
27mod 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}