mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Option begone part 2
This commit is contained in:
parent
96a774261f
commit
a2a3fecae3
31 changed files with 113 additions and 152 deletions
|
@ -140,7 +140,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||
self.imp.parse(file_id)
|
||||
}
|
||||
|
||||
pub fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||
pub fn parse_or_expand(&self, file_id: HirFileId) -> SyntaxNode {
|
||||
self.imp.parse_or_expand(file_id)
|
||||
}
|
||||
|
||||
|
@ -518,23 +518,23 @@ impl<'db> SemanticsImpl<'db> {
|
|||
tree
|
||||
}
|
||||
|
||||
fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||
let node = self.db.parse_or_expand(file_id)?;
|
||||
fn parse_or_expand(&self, file_id: HirFileId) -> SyntaxNode {
|
||||
let node = self.db.parse_or_expand(file_id);
|
||||
self.cache(node.clone(), file_id);
|
||||
Some(node)
|
||||
node
|
||||
}
|
||||
|
||||
fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
|
||||
let sa = self.analyze_no_infer(macro_call.syntax())?;
|
||||
let file_id = sa.expand(self.db, InFile::new(sa.file_id, macro_call))?;
|
||||
let node = self.parse_or_expand(file_id)?;
|
||||
let node = self.parse_or_expand(file_id);
|
||||
Some(node)
|
||||
}
|
||||
|
||||
fn expand_attr_macro(&self, item: &ast::Item) -> Option<SyntaxNode> {
|
||||
let src = self.wrap_node_infile(item.clone());
|
||||
let macro_call_id = self.with_ctx(|ctx| ctx.item_to_macro_call(src))?;
|
||||
self.parse_or_expand(macro_call_id.as_file())
|
||||
Some(self.parse_or_expand(macro_call_id.as_file()))
|
||||
}
|
||||
|
||||
fn expand_derive_as_pseudo_attr_macro(&self, attr: &ast::Attr) -> Option<SyntaxNode> {
|
||||
|
@ -543,7 +543,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
let call_id = self.with_ctx(|ctx| {
|
||||
ctx.attr_to_derive_macro_call(src.with_value(&adt), src).map(|(_, it, _)| it)
|
||||
})?;
|
||||
self.parse_or_expand(call_id.as_file())
|
||||
Some(self.parse_or_expand(call_id.as_file()))
|
||||
}
|
||||
|
||||
fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<Option<Macro>>> {
|
||||
|
@ -566,7 +566,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
.into_iter()
|
||||
.flat_map(|call| {
|
||||
let file_id = call?.as_file();
|
||||
let node = self.db.parse_or_expand(file_id)?;
|
||||
let node = self.db.parse_or_expand(file_id);
|
||||
self.cache(node.clone(), file_id);
|
||||
Some(node)
|
||||
})
|
||||
|
@ -990,7 +990,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
}
|
||||
|
||||
fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
|
||||
let root = self.parse_or_expand(src.file_id).unwrap();
|
||||
let root = self.parse_or_expand(src.file_id);
|
||||
let node = src.map(|it| it.to_node(&root));
|
||||
node.as_ref().original_file_range(self.db.upcast())
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ impl SourceAnalyzer {
|
|||
expr: InFile<ast::MacroCall>,
|
||||
) -> Option<InFile<ast::Expr>> {
|
||||
let macro_file = self.body_source_map()?.node_macro_file(expr.as_ref())?;
|
||||
let expanded = db.parse_or_expand(macro_file)?;
|
||||
let expanded = db.parse_or_expand(macro_file);
|
||||
let res = if let Some(stmts) = ast::MacroStmts::cast(expanded.clone()) {
|
||||
match stmts.expr()? {
|
||||
ast::Expr::MacroExpr(mac) => {
|
||||
|
|
|
@ -32,18 +32,18 @@ pub struct DeclarationLocation {
|
|||
}
|
||||
|
||||
impl DeclarationLocation {
|
||||
pub fn syntax<DB: HirDatabase>(&self, sema: &Semantics<'_, DB>) -> Option<SyntaxNode> {
|
||||
let root = sema.parse_or_expand(self.hir_file_id)?;
|
||||
Some(self.ptr.to_node(&root))
|
||||
pub fn syntax<DB: HirDatabase>(&self, sema: &Semantics<'_, DB>) -> SyntaxNode {
|
||||
let root = sema.parse_or_expand(self.hir_file_id);
|
||||
self.ptr.to_node(&root)
|
||||
}
|
||||
|
||||
pub fn original_range(&self, db: &dyn HirDatabase) -> Option<FileRange> {
|
||||
let node = resolve_node(db, self.hir_file_id, &self.ptr)?;
|
||||
Some(node.as_ref().original_file_range(db.upcast()))
|
||||
pub fn original_range(&self, db: &dyn HirDatabase) -> FileRange {
|
||||
let node = resolve_node(db, self.hir_file_id, &self.ptr);
|
||||
node.as_ref().original_file_range(db.upcast())
|
||||
}
|
||||
|
||||
pub fn original_name_range(&self, db: &dyn HirDatabase) -> Option<FileRange> {
|
||||
let node = resolve_node(db, self.hir_file_id, &self.name_ptr)?;
|
||||
let node = resolve_node(db, self.hir_file_id, &self.name_ptr);
|
||||
node.as_ref().original_file_range_opt(db.upcast())
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,10 @@ fn resolve_node(
|
|||
db: &dyn HirDatabase,
|
||||
file_id: HirFileId,
|
||||
ptr: &SyntaxNodePtr,
|
||||
) -> Option<InFile<SyntaxNode>> {
|
||||
let root = db.parse_or_expand(file_id)?;
|
||||
) -> InFile<SyntaxNode> {
|
||||
let root = db.parse_or_expand(file_id);
|
||||
let node = ptr.to_node(&root);
|
||||
Some(InFile::new(file_id, node))
|
||||
InFile::new(file_id, node)
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue