remove old macro support

This commit is contained in:
Aleksey Kladov 2019-03-16 19:40:41 +03:00
parent ee3cf6172b
commit 6955e392f8
8 changed files with 94 additions and 260 deletions

View file

@ -1,55 +1,13 @@
use ra_db::SourceDatabase;
use ra_syntax::{
SyntaxNode, AstNode, SourceFile,
ast, algo::find_covering_node,
};
use ra_syntax::AstNode;
use crate::{
TextRange, FileRange,
db::RootDatabase,
};
// FIXME: restore macro support
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
let source_file = db.parse(frange.file_id);
if let Some(range) = extend_selection_in_macro(db, &source_file, frange) {
return range;
}
ra_ide_api_light::extend_selection(source_file.syntax(), frange.range).unwrap_or(frange.range)
}
fn extend_selection_in_macro(
_db: &RootDatabase,
source_file: &SourceFile,
frange: FileRange,
) -> Option<TextRange> {
let macro_call = find_macro_call(source_file.syntax(), frange.range)?;
let (off, exp) = hir::MacroDef::ast_expand(macro_call)?;
let dst_range = exp.map_range_forward(frange.range - off)?;
let dst_range = ra_ide_api_light::extend_selection(&exp.syntax(), dst_range)?;
let src_range = exp.map_range_back(dst_range)? + off;
Some(src_range)
}
fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCall> {
find_covering_node(node, range).ancestors().find_map(ast::MacroCall::cast)
}
#[cfg(test)]
mod tests {
use ra_syntax::TextRange;
use crate::mock_analysis::single_file_with_range;
#[test]
fn extend_selection_inside_macros() {
let (analysis, frange) = single_file_with_range(
"
fn main() {
vec![foo(|x| <|>x<|>)];
}
",
);
let r = analysis.extend_selection(frange).unwrap();
assert_eq!(r, TextRange::from_to(50.into(), 55.into()));
}
}

View file

@ -1,4 +1,4 @@
use ra_syntax::{ast, AstNode,};
use ra_syntax::AstNode;
use ra_db::SourceDatabase;
use crate::{
@ -8,37 +8,5 @@ use crate::{
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
let source_file = db.parse(file_id);
let mut res = ra_ide_api_light::highlight(source_file.syntax());
for macro_call in source_file.syntax().descendants().filter_map(ast::MacroCall::cast) {
if let Some((off, exp)) = hir::MacroDef::ast_expand(macro_call) {
let mapped_ranges =
ra_ide_api_light::highlight(&exp.syntax()).into_iter().filter_map(|r| {
let mapped_range = exp.map_range_back(r.range)?;
let res = HighlightedRange { range: mapped_range + off, tag: r.tag };
Some(res)
});
res.extend(mapped_ranges);
}
}
res
}
#[cfg(test)]
mod tests {
use crate::mock_analysis::single_file;
use insta::assert_debug_snapshot_matches;
#[test]
fn highlights_code_inside_macros() {
let (analysis, file_id) = single_file(
"
fn main() {
vec![{ let x = 92; x}];
}
",
);
let highlights = analysis.highlight(file_id).unwrap();
assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
}
ra_ide_api_light::highlight(source_file.syntax())
}