Rename with_ast -> with_value
This commit is contained in:
parent
fa50b16cb2
commit
51baaf298d
@ -33,19 +33,19 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -
|
||||
match_ast! {
|
||||
match (node.value) {
|
||||
ast::Module(it) => {
|
||||
let src = node.with_ast(it);
|
||||
let src = node.with_value(it);
|
||||
Some(crate::Module::from_declaration(db, src)?.resolver(db))
|
||||
},
|
||||
ast::SourceFile(it) => {
|
||||
let src = node.with_ast(crate::ModuleSource::SourceFile(it));
|
||||
let src = node.with_value(crate::ModuleSource::SourceFile(it));
|
||||
Some(crate::Module::from_definition(db, src)?.resolver(db))
|
||||
},
|
||||
ast::StructDef(it) => {
|
||||
let src = node.with_ast(it);
|
||||
let src = node.with_value(it);
|
||||
Some(Struct::from_source(db, src)?.resolver(db))
|
||||
},
|
||||
ast::EnumDef(it) => {
|
||||
let src = node.with_ast(it);
|
||||
let src = node.with_value(it);
|
||||
Some(Enum::from_source(db, src)?.resolver(db))
|
||||
},
|
||||
_ => match node.value.kind() {
|
||||
@ -157,7 +157,7 @@ impl SourceAnalyzer {
|
||||
let scopes = def.expr_scopes(db);
|
||||
let scope = match offset {
|
||||
None => scope_for(&scopes, &source_map, node),
|
||||
Some(offset) => scope_for_offset(&scopes, &source_map, node.with_ast(offset)),
|
||||
Some(offset) => scope_for_offset(&scopes, &source_map, node.with_value(offset)),
|
||||
};
|
||||
let resolver = expr::resolver_for_scope(db, def, scope);
|
||||
SourceAnalyzer {
|
||||
@ -173,7 +173,7 @@ impl SourceAnalyzer {
|
||||
resolver: node
|
||||
.value
|
||||
.ancestors()
|
||||
.find_map(|it| try_get_resolver_for_node(db, node.with_ast(&it)))
|
||||
.find_map(|it| try_get_resolver_for_node(db, node.with_value(&it)))
|
||||
.unwrap_or_default(),
|
||||
body_owner: None,
|
||||
body_source_map: None,
|
||||
|
@ -174,7 +174,7 @@ impl ExpansionInfo {
|
||||
|
||||
let token = algo::find_covering_element(&self.expanded.value, range).into_token()?;
|
||||
|
||||
Some(self.expanded.with_ast(token))
|
||||
Some(self.expanded.with_value(token))
|
||||
}
|
||||
|
||||
pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> {
|
||||
@ -192,7 +192,7 @@ impl ExpansionInfo {
|
||||
range + tt.value.syntax().text_range().start(),
|
||||
)
|
||||
.into_token()?;
|
||||
Some(tt.with_ast(token))
|
||||
Some(tt.with_value(token))
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ impl<T> Source<T> {
|
||||
}
|
||||
|
||||
// Similarly, naming here is stupid...
|
||||
pub fn with_ast<U>(&self, value: U) -> Source<U> {
|
||||
pub fn with_value<U>(&self, value: U) -> Source<U> {
|
||||
Source::new(self.file_id, value)
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ impl<T> Source<T> {
|
||||
Source::new(self.file_id, f(self.value))
|
||||
}
|
||||
pub fn as_ref(&self) -> Source<&T> {
|
||||
self.with_ast(&self.value)
|
||||
self.with_value(&self.value)
|
||||
}
|
||||
pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode {
|
||||
db.parse_or_expand(self.file_id).expect("source created from invalid file")
|
||||
|
@ -148,7 +148,7 @@ impl NavigationTarget {
|
||||
//FIXME: use `_` instead of empty string
|
||||
let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default();
|
||||
let focus_range =
|
||||
node.value.name().map(|it| original_range(db, node.with_ast(it.syntax())).range);
|
||||
node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range);
|
||||
let frange = original_range(db, node.map(|it| it.syntax()));
|
||||
|
||||
NavigationTarget::from_syntax(
|
||||
@ -232,7 +232,7 @@ impl ToNav for hir::Module {
|
||||
let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
||||
match &src.value {
|
||||
ModuleSource::SourceFile(node) => {
|
||||
let frange = original_range(db, src.with_ast(node.syntax()));
|
||||
let frange = original_range(db, src.with_value(node.syntax()));
|
||||
|
||||
NavigationTarget::from_syntax(
|
||||
frange.file_id,
|
||||
@ -245,7 +245,7 @@ impl ToNav for hir::Module {
|
||||
)
|
||||
}
|
||||
ModuleSource::Module(node) => {
|
||||
let frange = original_range(db, src.with_ast(node.syntax()));
|
||||
let frange = original_range(db, src.with_value(node.syntax()));
|
||||
|
||||
NavigationTarget::from_syntax(
|
||||
frange.file_id,
|
||||
@ -285,12 +285,12 @@ impl ToNav for hir::StructField {
|
||||
match &src.value {
|
||||
FieldSource::Named(it) => NavigationTarget::from_named(
|
||||
db,
|
||||
src.with_ast(it),
|
||||
src.with_value(it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
),
|
||||
FieldSource::Pos(it) => {
|
||||
let frange = original_range(db, src.with_ast(it.syntax()));
|
||||
let frange = original_range(db, src.with_value(it.syntax()));
|
||||
NavigationTarget::from_syntax(
|
||||
frange.file_id,
|
||||
"".into(),
|
||||
|
@ -28,7 +28,7 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi
|
||||
.value
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find_map(|it| expansion.map_token_up(node.with_ast(&it)));
|
||||
.find_map(|it| expansion.map_token_up(node.with_value(&it)));
|
||||
|
||||
match token {
|
||||
Some(it) => {
|
||||
@ -54,7 +54,7 @@ pub(crate) fn descend_into_macros(
|
||||
return None;
|
||||
}
|
||||
let source_analyzer =
|
||||
hir::SourceAnalyzer::new(db, token.with_ast(token.value.parent()).as_ref(), None);
|
||||
hir::SourceAnalyzer::new(db, token.with_value(token.value.parent()).as_ref(), None);
|
||||
let exp = source_analyzer.expand(db, ¯o_call)?;
|
||||
exp.map_token_down(db, token.as_ref())
|
||||
})
|
||||
|
@ -25,11 +25,11 @@ pub(crate) fn goto_definition(
|
||||
let res = match_ast! {
|
||||
match (token.value.parent()) {
|
||||
ast::NameRef(name_ref) => {
|
||||
let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec();
|
||||
let navs = reference_definition(db, token.with_value(&name_ref)).to_vec();
|
||||
RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())
|
||||
},
|
||||
ast::Name(name) => {
|
||||
let navs = name_definition(db, token.with_ast(&name))?;
|
||||
let navs = name_definition(db, token.with_value(&name))?;
|
||||
RangeInfo::new(name.syntax().text_range(), navs)
|
||||
|
||||
},
|
||||
@ -99,7 +99,7 @@ pub(crate) fn name_definition(
|
||||
|
||||
if let Some(module) = ast::Module::cast(parent.clone()) {
|
||||
if module.has_semi() {
|
||||
let src = name.with_ast(module);
|
||||
let src = name.with_value(module);
|
||||
if let Some(child_module) = hir::Module::from_declaration(db, src) {
|
||||
let nav = child_module.to_nav(db);
|
||||
return Some(vec![nav]);
|
||||
@ -107,7 +107,7 @@ pub(crate) fn name_definition(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(nav) = named_target(db, name.with_ast(&parent)) {
|
||||
if let Some(nav) = named_target(db, name.with_value(&parent)) {
|
||||
return Some(vec![nav]);
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::StructDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -128,7 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::EnumDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -136,7 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::EnumVariant(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -144,7 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::FnDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -152,7 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::TypeAliasDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -160,7 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::ConstDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -168,7 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::StaticDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -176,7 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::TraitDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -184,7 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::RecordFieldDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -192,7 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::Module(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
it.short_label(),
|
||||
))
|
||||
@ -200,7 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||
ast::MacroCall(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
node.with_ast(&it),
|
||||
node.with_value(&it),
|
||||
it.doc_comment_text(),
|
||||
None,
|
||||
))
|
||||
|
@ -22,7 +22,7 @@ pub(crate) fn goto_type_definition(
|
||||
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())
|
||||
})?;
|
||||
|
||||
let analyzer = hir::SourceAnalyzer::new(db, token.with_ast(&node), None);
|
||||
let analyzer = hir::SourceAnalyzer::new(db, token.with_value(&node), None);
|
||||
|
||||
let ty: hir::Ty = if let Some(ty) =
|
||||
ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e))
|
||||
|
@ -174,7 +174,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
ast::NameRef(name_ref) => {
|
||||
let mut no_fallback = false;
|
||||
if let Some(name_kind) =
|
||||
classify_name_ref(db, token.with_ast(&name_ref)).map(|d| d.kind)
|
||||
classify_name_ref(db, token.with_value(&name_ref)).map(|d| d.kind)
|
||||
{
|
||||
res.extend(hover_text_from_name_kind(db, name_kind, &mut no_fallback))
|
||||
}
|
||||
@ -196,7 +196,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
}
|
||||
},
|
||||
ast::Name(name) => {
|
||||
if let Some(name_kind) = classify_name(db, token.with_ast(&name)).map(|d| d.kind) {
|
||||
if let Some(name_kind) = classify_name(db, token.with_value(&name)).map(|d| d.kind) {
|
||||
res.extend(hover_text_from_name_kind(db, name_kind, &mut true));
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
match_ast! {
|
||||
match parent {
|
||||
ast::BindPat(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let local = hir::Local::from_source(db, src)?;
|
||||
Some(NameDefinition {
|
||||
visibility: None,
|
||||
@ -28,7 +28,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
},
|
||||
ast::RecordFieldDef(it) => {
|
||||
let ast = hir::FieldSource::Named(it);
|
||||
let src = name.with_ast(ast);
|
||||
let src = name.with_value(ast);
|
||||
let field = hir::StructField::from_source(db, src)?;
|
||||
Some(from_struct_field(db, field))
|
||||
},
|
||||
@ -36,42 +36,42 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
let def = {
|
||||
if !it.has_semi() {
|
||||
let ast = hir::ModuleSource::Module(it);
|
||||
let src = name.with_ast(ast);
|
||||
let src = name.with_value(ast);
|
||||
hir::Module::from_definition(db, src)
|
||||
} else {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
hir::Module::from_declaration(db, src)
|
||||
}
|
||||
}?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::StructDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Struct::from_source(db, src)?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::EnumDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Enum::from_source(db, src)?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::TraitDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Trait::from_source(db, src)?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::StaticDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Static::from_source(db, src)?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::EnumVariant(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::EnumVariant::from_source(db, src)?;
|
||||
Some(from_module_def(db, def.into(), None))
|
||||
},
|
||||
ast::FnDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Function::from_source(db, src)?;
|
||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
@ -80,7 +80,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
}
|
||||
},
|
||||
ast::ConstDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::Const::from_source(db, src)?;
|
||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
@ -89,7 +89,7 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
}
|
||||
},
|
||||
ast::TypeAliasDef(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::TypeAlias::from_source(db, src)?;
|
||||
if parent.parent().and_then(ast::ItemList::cast).is_some() {
|
||||
Some(from_assoc_item(db, def.into()))
|
||||
@ -98,11 +98,11 @@ pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Opti
|
||||
}
|
||||
},
|
||||
ast::MacroCall(it) => {
|
||||
let src = name.with_ast(it);
|
||||
let src = name.with_value(it);
|
||||
let def = hir::MacroDef::from_source(db, src.clone())?;
|
||||
|
||||
let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
|
||||
let module = Module::from_definition(db, src.with_ast(module_src))?;
|
||||
let module = Module::from_definition(db, src.with_value(module_src))?;
|
||||
|
||||
Some(NameDefinition {
|
||||
visibility: None,
|
||||
@ -149,9 +149,9 @@ pub(crate) fn classify_name_ref(
|
||||
}
|
||||
}
|
||||
|
||||
let ast = ModuleSource::from_child_node(db, name_ref.with_ast(&parent));
|
||||
let ast = ModuleSource::from_child_node(db, name_ref.with_value(&parent));
|
||||
// FIXME: find correct container and visibility for each case
|
||||
let container = Module::from_definition(db, name_ref.with_ast(ast))?;
|
||||
let container = Module::from_definition(db, name_ref.with_value(ast))?;
|
||||
let visibility = None;
|
||||
|
||||
if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user