mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
rename to source_map
This commit is contained in:
parent
f4c5383103
commit
ca957edf96
2 changed files with 13 additions and 17 deletions
|
@ -497,8 +497,8 @@ impl Function {
|
||||||
|
|
||||||
pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
|
pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
|
||||||
let scopes = db.expr_scopes(*self);
|
let scopes = db.expr_scopes(*self);
|
||||||
let syntax_mapping = db.body_with_source_map(*self).1;
|
let source_map = db.body_with_source_map(*self).1;
|
||||||
ScopesWithSyntaxMapping { scopes, syntax_mapping }
|
ScopesWithSyntaxMapping { scopes, source_map }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {
|
pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl ExprScopes {
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ScopesWithSyntaxMapping {
|
pub struct ScopesWithSyntaxMapping {
|
||||||
pub syntax_mapping: Arc<BodySourceMap>,
|
pub source_map: Arc<BodySourceMap>,
|
||||||
pub scopes: Arc<ExprScopes>,
|
pub scopes: Arc<ExprScopes>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl ScopesWithSyntaxMapping {
|
||||||
self.scopes
|
self.scopes
|
||||||
.scope_for
|
.scope_for
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope)))
|
.filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope)))
|
||||||
// find containing scope
|
// find containing scope
|
||||||
.min_by_key(|(ptr, _scope)| {
|
.min_by_key(|(ptr, _scope)| {
|
||||||
(!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len())
|
(!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len())
|
||||||
|
@ -155,7 +155,7 @@ impl ScopesWithSyntaxMapping {
|
||||||
.scopes
|
.scopes
|
||||||
.scope_for
|
.scope_for
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope)))
|
.filter_map(|(id, scope)| Some((self.source_map.expr_syntax(*id)?, scope)))
|
||||||
.map(|(ptr, scope)| (ptr.range(), scope))
|
.map(|(ptr, scope)| (ptr.range(), scope))
|
||||||
.filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r);
|
.filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r);
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ impl ScopesWithSyntaxMapping {
|
||||||
ret.and_then(|entry| {
|
ret.and_then(|entry| {
|
||||||
Some(ScopeEntryWithSyntax {
|
Some(ScopeEntryWithSyntax {
|
||||||
name: entry.name().clone(),
|
name: entry.name().clone(),
|
||||||
ptr: self.syntax_mapping.pat_syntax(entry.pat())?,
|
ptr: self.source_map.pat_syntax(entry.pat())?,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ impl ScopesWithSyntaxMapping {
|
||||||
pub fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> {
|
pub fn scope_for(&self, node: &SyntaxNode) -> Option<ScopeId> {
|
||||||
node.ancestors()
|
node.ancestors()
|
||||||
.map(SyntaxNodePtr::new)
|
.map(SyntaxNodePtr::new)
|
||||||
.filter_map(|ptr| self.syntax_mapping.syntax_expr(ptr))
|
.filter_map(|ptr| self.source_map.syntax_expr(ptr))
|
||||||
.find_map(|it| self.scopes.scope_for(it))
|
.find_map(|it| self.scopes.scope_for(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,12 +316,10 @@ mod tests {
|
||||||
let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
||||||
let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||||
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
||||||
let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
||||||
let scopes = ExprScopes::new(Arc::new(body));
|
let scopes = ExprScopes::new(Arc::new(body));
|
||||||
let scopes = ScopesWithSyntaxMapping {
|
let scopes =
|
||||||
scopes: Arc::new(scopes),
|
ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
|
||||||
syntax_mapping: Arc::new(syntax_mapping),
|
|
||||||
};
|
|
||||||
let actual = scopes
|
let actual = scopes
|
||||||
.scope_chain(marker.syntax())
|
.scope_chain(marker.syntax())
|
||||||
.flat_map(|scope| scopes.scopes.entries(scope))
|
.flat_map(|scope| scopes.scopes.entries(scope))
|
||||||
|
@ -417,12 +415,10 @@ mod tests {
|
||||||
let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||||
|
|
||||||
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
||||||
let (body, syntax_mapping) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
let (body, source_map) = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
||||||
let scopes = ExprScopes::new(Arc::new(body));
|
let scopes = ExprScopes::new(Arc::new(body));
|
||||||
let scopes = ScopesWithSyntaxMapping {
|
let scopes =
|
||||||
scopes: Arc::new(scopes),
|
ScopesWithSyntaxMapping { scopes: Arc::new(scopes), source_map: Arc::new(source_map) };
|
||||||
syntax_mapping: Arc::new(syntax_mapping),
|
|
||||||
};
|
|
||||||
let local_name_entry = scopes.resolve_local_name(name_ref).unwrap();
|
let local_name_entry = scopes.resolve_local_name(name_ref).unwrap();
|
||||||
let local_name = local_name_entry.ptr();
|
let local_name = local_name_entry.ptr();
|
||||||
assert_eq!(local_name.range(), expected_name.syntax().range());
|
assert_eq!(local_name.range(), expected_name.syntax().range());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue