mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
internal: Report macro definition errors on the definition
This commit is contained in:
parent
0bb9a17312
commit
a5558cdfe5
10 changed files with 115 additions and 14 deletions
|
@ -99,6 +99,8 @@ pub trait ExpandDatabase: SourceDatabase {
|
|||
/// file or a macro expansion.
|
||||
#[salsa::transparent]
|
||||
fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>;
|
||||
#[salsa::transparent]
|
||||
fn parse_or_expand_with_err(&self, file_id: HirFileId) -> Option<Parse<SyntaxNode>>;
|
||||
/// Implementation for the macro case.
|
||||
fn parse_macro_expansion(
|
||||
&self,
|
||||
|
@ -252,13 +254,23 @@ fn parse_or_expand(db: &dyn ExpandDatabase, file_id: HirFileId) -> Option<Syntax
|
|||
match file_id.repr() {
|
||||
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
||||
HirFileIdRepr::MacroFile(macro_file) => {
|
||||
// FIXME: Note how we convert from `Parse` to `SyntaxNode` here,
|
||||
// forgetting about parse errors.
|
||||
db.parse_macro_expansion(macro_file).value.map(|(it, _)| it.syntax_node())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_or_expand_with_err(
|
||||
db: &dyn ExpandDatabase,
|
||||
file_id: HirFileId,
|
||||
) -> Option<Parse<SyntaxNode>> {
|
||||
match file_id.repr() {
|
||||
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).to_syntax()),
|
||||
HirFileIdRepr::MacroFile(macro_file) => {
|
||||
db.parse_macro_expansion(macro_file).value.map(|(parse, _)| parse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_macro_expansion(
|
||||
db: &dyn ExpandDatabase,
|
||||
macro_file: MacroFile,
|
||||
|
|
|
@ -187,7 +187,10 @@ fn lazy_expand(
|
|||
);
|
||||
|
||||
let err = db.macro_expand_error(id);
|
||||
let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node));
|
||||
let value =
|
||||
db.parse_or_expand_with_err(id.as_file()).map(|node| InFile::new(id.as_file(), node));
|
||||
// FIXME: report parse errors
|
||||
let value = value.map(|it| it.map(|it| it.syntax_node()));
|
||||
|
||||
ExpandResult { value, err }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue