To start migrating HasSource::source to return an Option.
let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?);
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
- let pat: ast::Pat = match var.source(db).value.kind() {
+ let pat: ast::Pat = match var.source_old(db).value.kind() {
ast::StructKind::Tuple(field_list) => {
let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count());
make::tuple_struct_pat(path, pats).into()
let parent_name = parent.name(ctx.db());
let target_module = parent.module(ctx.db());
- let in_file_source = record_field_def.source(ctx.db());
+ let in_file_source = record_field_def.source_old(ctx.db());
let (offset, current_visibility, target) = match in_file_source.value {
hir::FieldSource::Named(it) => {
let s = it.syntax();
S: HasSource<Ast = Ast>,
Ast: AstNode + ast::VisibilityOwner,
{
- let source = x.source(db);
+ let source = x.source_old(db);
let in_file_syntax = source.syntax();
let file_id = in_file_syntax.file_id;
let syntax = in_file_syntax.value;
items
.iter()
.map(|i| match i {
- hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db).value),
- hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db).value),
- hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db).value),
+ hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source_old(db).value),
+ hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source_old(db).value),
+ hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source_old(db).value),
})
.filter(has_def_name)
.filter(|it| match it {
};
let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
- let function_decl = function_declaration(&func.source(ctx.db).value);
+ let function_decl = function_declaration(&func.source_old(ctx.db).value);
match ctx.config.snippet_cap {
Some(cap) => {
let snippet = format!("{} {{\n $0\n}}", function_decl);
let const_name = const_.name(ctx.db).map(|n| n.to_string());
if let Some(const_name) = const_name {
- let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
+ let snippet = make_const_compl_syntax(&const_.source_old(ctx.db).value);
let range = TextRange::new(const_def_node.text_range().start(), ctx.source_range().end());
impl<'a> ConstRender<'a> {
fn new(ctx: RenderContext<'a>, const_: hir::Const) -> ConstRender<'a> {
- let ast_node = const_.source(ctx.db()).value;
+ let ast_node = const_.source_old(ctx.db()).value;
ConstRender { ctx, const_, ast_node }
}
fn_: hir::Function,
) -> FunctionRender<'a> {
let name = local_name.unwrap_or_else(|| fn_.name(ctx.db()).to_string());
- let ast_node = fn_.source(ctx.db()).value;
+ let ast_node = fn_.source_old(ctx.db()).value;
FunctionRender { ctx, name, func: fn_, ast_node }
}
}
fn detail(&self) -> String {
- let ast_node = self.macro_.source(self.ctx.db()).value;
+ let ast_node = self.macro_.source_old(self.ctx.db()).value;
macro_label(&ast_node)
}
}
impl<'a> TypeAliasRender<'a> {
fn new(ctx: RenderContext<'a>, type_alias: hir::TypeAlias) -> TypeAliasRender<'a> {
- let ast_node = type_alias.source(ctx.db()).value;
+ let ast_node = type_alias.source_old(ctx.db()).value;
TypeAliasRender { ctx, type_alias, ast_node }
}
if self.is_proc_macro() {
return None;
}
- self.source(db).value.name().map(|it| it.as_name())
+ self.source_old(db).value.name().map(|it| it.as_name())
}
/// Indicate it is a proc-macro
}
pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
- let src = self.source(db);
+ let src = self.source_old(db);
let item = src.file_id.is_builtin_derive(db.upcast())?;
let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);
pub trait HasSource {
type Ast;
- fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast>;
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<Self::Ast>;
}
/// NB: Module is !HasSource, because it has two source nodes at the same time:
impl HasSource for Field {
type Ast = FieldSource;
- fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<FieldSource> {
let var = VariantId::from(self.parent);
let src = var.child_source(db.upcast());
src.map(|it| match it[self.id].clone() {
}
impl HasSource for Struct {
type Ast = ast::Struct;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Struct> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Struct> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Union {
type Ast = ast::Union;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Union> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Union> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Enum {
type Ast = ast::Enum;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Enum> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Enum> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Variant {
type Ast = ast::Variant;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Variant> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Variant> {
self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone())
}
}
impl HasSource for Function {
type Ast = ast::Fn;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Fn> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Const {
type Ast = ast::Const;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Const> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Const> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Static {
type Ast = ast::Static;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Static> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Static> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for Trait {
type Ast = ast::Trait;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for TypeAlias {
type Ast = ast::TypeAlias;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::TypeAlias> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::TypeAlias> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for MacroDef {
type Ast = ast::Macro;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Macro> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Macro> {
InFile {
file_id: self.id.ast_id.expect("MacroDef without ast_id").file_id,
value: self.id.ast_id.expect("MacroDef without ast_id").to_node(db.upcast()),
}
impl HasSource for Impl {
type Ast = ast::Impl;
- fn source(self, db: &dyn HirDatabase) -> InFile<ast::Impl> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<ast::Impl> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}
impl HasSource for TypeParam {
type Ast = Either<ast::Trait, ast::TypeParam>;
- fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
let child_source = self.id.parent.child_source(db.upcast());
child_source.map(|it| it[self.id.local_id].clone())
}
impl HasSource for LifetimeParam {
type Ast = ast::LifetimeParam;
- fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
+ fn source_old(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
let child_source = self.id.parent.child_source(db.upcast());
child_source.map(|it| it[self.id.local_id].clone())
}
let record_fields = match VariantDef::from(def_id) {
VariantDef::Struct(s) => {
module = s.module(sema.db);
- let source = s.source(sema.db);
+ let source = s.source_old(sema.db);
def_file_id = source.file_id;
let fields = source.value.field_list()?;
record_field_list(fields)?
}
VariantDef::Union(u) => {
module = u.module(sema.db);
- let source = u.source(sema.db);
+ let source = u.source_old(sema.db);
def_file_id = source.file_id;
source.value.record_field_list()?
}
VariantDef::Variant(e) => {
module = e.module(sema.db);
- let source = e.source(sema.db);
+ let source = e.source_old(sema.db);
def_file_id = source.file_id;
let fields = source.value.field_list()?;
record_field_list(fields)?
D::Ast: ast::NameOwner + ShortLabel,
{
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
let mut res = NavigationTarget::from_named(
db,
src.as_ref().map(|it| it as &dyn ast::NameOwner),
impl ToNav for hir::Impl {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
let derive_attr = self.is_builtin_derive(db);
let frange = if let Some(item) = &derive_attr {
item.syntax().original_file_range(db)
impl ToNav for hir::Field {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
match &src.value {
FieldSource::Named(it) => {
impl ToNav for hir::MacroDef {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
log::debug!("nav target {:#?}", src.value.syntax());
let mut res = NavigationTarget::from_named(
db,
impl ToNav for hir::TypeParam {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
let full_range = match &src.value {
Either::Left(it) => it.syntax().text_range(),
Either::Right(it) => it.syntax().text_range(),
impl ToNav for hir::LifetimeParam {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
- let src = self.source(db);
+ let src = self.source_old(db);
let full_range = src.value.syntax().text_range();
NavigationTarget {
file_id: src.file_id.original_file(db),
_ => None,
},
ModuleDef::Function(it) => {
- let src = it.source(sema.db);
+ let src = it.source_old(sema.db);
if src.file_id != file_id.into() {
mark::hit!(hover_macro_generated_struct_fn_doc_comment);
mark::hit!(hover_macro_generated_struct_fn_doc_attr);
if it.is_proc_macro() {
return None;
}
- let label = macro_label(&it.source(db).value);
+ let label = macro_label(&it.source_old(db).value);
from_def_source_labeled(db, it, Some(label), mod_path)
}
Definition::Field(def) => {
- let src = def.source(db).value;
+ let src = def.source_old(db).value;
if let FieldSource::Named(it) = src {
from_def_source_labeled(db, def, it.short_label(), mod_path)
} else {
D: HasSource<Ast = A> + HasAttrs + Copy,
A: ShortLabel,
{
- let short_label = def.source(db).value.short_label();
+ let short_label = def.source_old(db).value.short_label();
from_def_source_labeled(db, def, short_label, mod_path)
}
if let Definition::Local(var) = self {
let range = match var.parent(db) {
- DefWithBody::Function(f) => f.source(db).value.syntax().text_range(),
- DefWithBody::Const(c) => c.source(db).value.syntax().text_range(),
- DefWithBody::Static(s) => s.source(db).value.syntax().text_range(),
+ DefWithBody::Function(f) => f.source_old(db).value.syntax().text_range(),
+ DefWithBody::Const(c) => c.source_old(db).value.syntax().text_range(),
+ DefWithBody::Static(s) => s.source_old(db).value.syntax().text_range(),
};
let mut res = FxHashMap::default();
res.insert(file_id, Some(range));
if let Definition::LifetimeParam(param) = self {
let range = match param.parent(db) {
- hir::GenericDef::Function(it) => it.source(db).value.syntax().text_range(),
+ hir::GenericDef::Function(it) => it.source_old(db).value.syntax().text_range(),
hir::GenericDef::Adt(it) => match it {
- hir::Adt::Struct(it) => it.source(db).value.syntax().text_range(),
- hir::Adt::Union(it) => it.source(db).value.syntax().text_range(),
- hir::Adt::Enum(it) => it.source(db).value.syntax().text_range(),
+ hir::Adt::Struct(it) => it.source_old(db).value.syntax().text_range(),
+ hir::Adt::Union(it) => it.source_old(db).value.syntax().text_range(),
+ hir::Adt::Enum(it) => it.source_old(db).value.syntax().text_range(),
},
- hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(),
- hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(),
- hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(),
- hir::GenericDef::Variant(it) => it.source(db).value.syntax().text_range(),
- hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(),
+ hir::GenericDef::Trait(it) => it.source_old(db).value.syntax().text_range(),
+ hir::GenericDef::TypeAlias(it) => it.source_old(db).value.syntax().text_range(),
+ hir::GenericDef::Impl(it) => it.source_old(db).value.syntax().text_range(),
+ hir::GenericDef::Variant(it) => it.source_old(db).value.syntax().text_range(),
+ hir::GenericDef::Const(it) => it.source_old(db).value.syntax().text_range(),
};
let mut res = FxHashMap::default();
res.insert(file_id, Some(range));
}
let mut msg = format!("processing: {}", full_name);
if verbosity.is_verbose() {
- let src = f.source(db);
+ let src = f.source_old(db);
let original_file = src.file_id.original_file(db);
let path = vfs.file_path(original_file);
let syntax_range = src.value.syntax().text_range();