remove hard-coded query-group macro

This commit is contained in:
Aleksey Kladov 2019-02-11 22:24:39 +03:00
parent a78142cc64
commit 0d060b073c
5 changed files with 4 additions and 67 deletions

View file

@ -11,7 +11,7 @@ use std::sync::Arc;
use ra_syntax::{
TextRange, TextUnit, SourceFile, AstNode, SyntaxNode, TreeArc, SyntaxNodePtr,
ast::{self, NameOwner},
ast,
};
use crate::{MacroCallId, PersistentHirDatabase};
@ -20,7 +20,6 @@ use crate::{MacroCallId, PersistentHirDatabase};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MacroDef {
Vec,
QueryGroup,
}
impl MacroDef {
@ -39,8 +38,6 @@ impl MacroDef {
let name_ref = path.segment()?.name_ref()?;
if name_ref.text() == "vec" {
MacroDef::Vec
} else if name_ref.text() == "query_group" {
MacroDef::QueryGroup
} else {
return None;
}
@ -56,7 +53,6 @@ impl MacroDef {
fn expand(self, input: MacroInput) -> Option<MacroExpansion> {
match self {
MacroDef::Vec => self.expand_vec(input),
MacroDef::QueryGroup => self.expand_query_group(input),
}
}
fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> {
@ -69,24 +65,6 @@ impl MacroDef {
let res = MacroExpansion { text, ranges_map, ptr };
Some(res)
}
fn expand_query_group(self, input: MacroInput) -> Option<MacroExpansion> {
let anchor = "trait ";
let pos = input.text.find(anchor)? + anchor.len();
let trait_name =
input.text[pos..].chars().take_while(|c| c.is_alphabetic()).collect::<String>();
if trait_name.is_empty() {
return None;
}
let src_range = TextRange::offset_len((pos as u32).into(), TextUnit::of_str(&trait_name));
let text = format!(r"trait {} {{ }}", trait_name);
let file = SourceFile::parse(&text);
let trait_def = file.syntax().descendants().find_map(ast::TraitDef::cast)?;
let name = trait_def.name()?;
let ptr = SyntaxNodePtr::new(trait_def.syntax());
let ranges_map = vec![(src_range, name.syntax().range())];
let res = MacroExpansion { text, ranges_map, ptr };
Some(res)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -109,7 +87,7 @@ pub struct MacroExpansion {
}
impl MacroExpansion {
// FIXME: does not really make sense, macro expansion is not neccessary a
// FIXME: does not really make sense, macro expansion is not necessary a
// whole file. See `MacroExpansion::ptr` as well.
pub(crate) fn file(&self) -> TreeArc<SourceFile> {
SourceFile::parse(&self.text)

View file

@ -326,6 +326,7 @@ fn name_res_works_for_broken_modules() {
}
#[test]
#[ignore]
fn item_map_contains_items_from_expansions() {
let (item_map, module_id) = item_map(
"

View file

@ -1,28 +0,0 @@
---
created: "2019-02-01T07:52:15.689836752+00:00"
creator: insta@0.5.3
expression: "&highlights"
source: crates/ra_ide_api/src/syntax_highlighting.rs
---
[
HighlightedRange {
range: [20; 32),
tag: "macro"
},
HighlightedRange {
range: [13; 18),
tag: "text"
},
HighlightedRange {
range: [51; 54),
tag: "keyword"
},
HighlightedRange {
range: [55; 60),
tag: "keyword"
},
HighlightedRange {
range: [61; 72),
tag: "function"
}
]

View file

@ -41,19 +41,4 @@ mod tests {
let highlights = analysis.highlight(file_id).unwrap();
assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
}
// FIXME: this test is not really necessary: artifact of the inital hacky
// macros implementation.
#[test]
fn highlight_query_group_macro() {
let (analysis, file_id) = single_file(
"
salsa::query_group! {
pub trait HirDatabase: SyntaxDatabase {}
}
",
);
let highlights = analysis.highlight(file_id).unwrap();
assert_debug_snapshot_matches!("highlight_query_group_macro", &highlights);
}
}

View file

@ -91,6 +91,7 @@ fn test_find_all_refs_for_fn_param() {
}
#[test]
#[ignore]
fn world_symbols_include_stuff_from_macros() {
let (analysis, _) = single_file(
"