mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Rename Source::ast -> Source::value
This commit is contained in:
parent
e975f6364c
commit
36e3fc9d54
43 changed files with 226 additions and 214 deletions
|
@ -54,7 +54,7 @@ impl<'a> CompletionContext<'a> {
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), ast: src },
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
);
|
||||
let token =
|
||||
original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?;
|
||||
|
|
|
@ -169,7 +169,7 @@ impl Completions {
|
|||
None => return,
|
||||
};
|
||||
|
||||
let ast_node = macro_.source(ctx.db).ast;
|
||||
let ast_node = macro_.source(ctx.db).value;
|
||||
let detail = macro_label(&ast_node);
|
||||
|
||||
let docs = macro_.docs(ctx.db);
|
||||
|
@ -201,7 +201,7 @@ impl Completions {
|
|||
) {
|
||||
let data = func.data(ctx.db);
|
||||
let name = name.unwrap_or_else(|| data.name().to_string());
|
||||
let ast_node = func.source(ctx.db).ast;
|
||||
let ast_node = func.source(ctx.db).value;
|
||||
let detail = function_label(&ast_node);
|
||||
|
||||
let mut builder =
|
||||
|
@ -234,7 +234,7 @@ impl Completions {
|
|||
}
|
||||
|
||||
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
|
||||
let ast_node = constant.source(ctx.db).ast;
|
||||
let ast_node = constant.source(ctx.db).value;
|
||||
let name = match ast_node.name() {
|
||||
Some(name) => name,
|
||||
_ => return,
|
||||
|
@ -250,7 +250,7 @@ impl Completions {
|
|||
}
|
||||
|
||||
pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
|
||||
let type_def = type_alias.source(ctx.db).ast;
|
||||
let type_def = type_alias.source(ctx.db).value;
|
||||
let name = match type_def.name() {
|
||||
Some(name) => name,
|
||||
_ => return,
|
||||
|
|
|
@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
|||
});
|
||||
let source_file = db.parse(file_id).tree();
|
||||
let src =
|
||||
hir::Source { file_id: file_id.into(), ast: hir::ModuleSource::SourceFile(source_file) };
|
||||
hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) };
|
||||
if let Some(m) = hir::Module::from_definition(db, src) {
|
||||
m.diagnostics(db, &mut sink);
|
||||
};
|
||||
|
|
|
@ -48,12 +48,12 @@ impl FunctionSignature {
|
|||
|
||||
pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self {
|
||||
let doc = function.docs(db);
|
||||
let ast_node = function.source(db).ast;
|
||||
let ast_node = function.source(db).value;
|
||||
FunctionSignature::from(&ast_node).with_doc_opt(doc)
|
||||
}
|
||||
|
||||
pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> {
|
||||
let node: ast::StructDef = st.source(db).ast;
|
||||
let node: ast::StructDef = st.source(db).value;
|
||||
match node.kind() {
|
||||
ast::StructKind::Named(_) => return None,
|
||||
_ => (),
|
||||
|
@ -87,7 +87,7 @@ impl FunctionSignature {
|
|||
db: &db::RootDatabase,
|
||||
variant: hir::EnumVariant,
|
||||
) -> Option<Self> {
|
||||
let node: ast::EnumVariant = variant.source(db).ast;
|
||||
let node: ast::EnumVariant = variant.source(db).value;
|
||||
match node.kind() {
|
||||
ast::StructKind::Named(_) | ast::StructKind::Unit => return None,
|
||||
_ => (),
|
||||
|
@ -126,7 +126,7 @@ impl FunctionSignature {
|
|||
}
|
||||
|
||||
pub(crate) fn from_macro(db: &db::RootDatabase, macro_def: hir::MacroDef) -> Option<Self> {
|
||||
let node: ast::MacroCall = macro_def.source(db).ast;
|
||||
let node: ast::MacroCall = macro_def.source(db).value;
|
||||
|
||||
let params = vec![];
|
||||
|
||||
|
|
|
@ -86,9 +86,9 @@ impl NavigationTarget {
|
|||
name,
|
||||
None,
|
||||
frange.range,
|
||||
src.ast.syntax().kind(),
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
src.value.syntax().kind(),
|
||||
src.value.doc_comment_text(),
|
||||
src.value.short_label(),
|
||||
);
|
||||
}
|
||||
module.to_nav(db)
|
||||
|
@ -146,9 +146,9 @@ impl NavigationTarget {
|
|||
description: Option<String>,
|
||||
) -> NavigationTarget {
|
||||
//FIXME: use `_` instead of empty string
|
||||
let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default();
|
||||
let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default();
|
||||
let focus_range =
|
||||
node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range);
|
||||
node.value.name().map(|it| original_range(db, node.with_ast(it.syntax())).range);
|
||||
let frange = original_range(db, node.map(|it| it.syntax()));
|
||||
|
||||
NavigationTarget::from_syntax(
|
||||
|
@ -156,7 +156,7 @@ impl NavigationTarget {
|
|||
name,
|
||||
focus_range,
|
||||
frange.range,
|
||||
node.ast.syntax().kind(),
|
||||
node.value.syntax().kind(),
|
||||
docs,
|
||||
description,
|
||||
)
|
||||
|
@ -220,8 +220,8 @@ where
|
|||
NavigationTarget::from_named(
|
||||
db,
|
||||
src.as_ref().map(|it| it as &dyn ast::NameOwner),
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
src.value.doc_comment_text(),
|
||||
src.value.short_label(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ impl ToNav for hir::Module {
|
|||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||
let src = self.definition_source(db);
|
||||
let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
||||
match &src.ast {
|
||||
match &src.value {
|
||||
ModuleSource::SourceFile(node) => {
|
||||
let frange = original_range(db, src.with_ast(node.syntax()));
|
||||
|
||||
|
@ -271,7 +271,7 @@ impl ToNav for hir::ImplBlock {
|
|||
"impl".into(),
|
||||
None,
|
||||
frange.range,
|
||||
src.ast.syntax().kind(),
|
||||
src.value.syntax().kind(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
|
@ -282,7 +282,7 @@ impl ToNav for hir::StructField {
|
|||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||
let src = self.source(db);
|
||||
|
||||
match &src.ast {
|
||||
match &src.value {
|
||||
FieldSource::Named(it) => NavigationTarget::from_named(
|
||||
db,
|
||||
src.with_ast(it),
|
||||
|
@ -308,11 +308,11 @@ impl ToNav for hir::StructField {
|
|||
impl ToNav for hir::MacroDef {
|
||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||
let src = self.source(db);
|
||||
log::debug!("nav target {:#?}", src.ast.syntax());
|
||||
log::debug!("nav target {:#?}", src.value.syntax());
|
||||
NavigationTarget::from_named(
|
||||
db,
|
||||
src.as_ref().map(|it| it as &dyn ast::NameOwner),
|
||||
src.ast.doc_comment_text(),
|
||||
src.value.doc_comment_text(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ impl ToNav for hir::AssocItem {
|
|||
impl ToNav for hir::Local {
|
||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||
let src = self.source(db);
|
||||
let (full_range, focus_range) = match src.ast {
|
||||
let (full_range, focus_range) = match src.value {
|
||||
Either::A(it) => {
|
||||
(it.syntax().text_range(), it.name().map(|it| it.syntax().text_range()))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi
|
|||
None => {
|
||||
return FileRange {
|
||||
file_id: node.file_id.original_file(db),
|
||||
range: node.ast.text_range(),
|
||||
range: node.value.text_range(),
|
||||
}
|
||||
}
|
||||
Some(it) => it,
|
||||
|
@ -25,14 +25,18 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi
|
|||
// *Second*, we should handle recurside macro expansions
|
||||
|
||||
let token = node
|
||||
.ast
|
||||
.value
|
||||
.descendants_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find_map(|it| expansion.map_token_up(node.with_ast(&it)));
|
||||
|
||||
match token {
|
||||
Some(it) => FileRange { file_id: it.file_id.original_file(db), range: it.ast.text_range() },
|
||||
None => FileRange { file_id: node.file_id.original_file(db), range: node.ast.text_range() },
|
||||
Some(it) => {
|
||||
FileRange { file_id: it.file_id.original_file(db), range: it.value.text_range() }
|
||||
}
|
||||
None => {
|
||||
FileRange { file_id: node.file_id.original_file(db), range: node.value.text_range() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,13 +48,13 @@ pub(crate) fn descend_into_macros(
|
|||
let src = Source::new(file_id.into(), token);
|
||||
|
||||
successors(Some(src), |token| {
|
||||
let macro_call = token.ast.ancestors().find_map(ast::MacroCall::cast)?;
|
||||
let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
|
||||
let tt = macro_call.token_tree()?;
|
||||
if !token.ast.text_range().is_subrange(&tt.syntax().text_range()) {
|
||||
if !token.value.text_range().is_subrange(&tt.syntax().text_range()) {
|
||||
return None;
|
||||
}
|
||||
let source_analyzer =
|
||||
hir::SourceAnalyzer::new(db, token.with_ast(token.ast.parent()).as_ref(), None);
|
||||
hir::SourceAnalyzer::new(db, token.with_ast(token.value.parent()).as_ref(), None);
|
||||
let exp = source_analyzer.expand(db, ¯o_call)?;
|
||||
exp.map_token_down(db, token.as_ref())
|
||||
})
|
||||
|
|
|
@ -46,7 +46,7 @@ fn expand_macro_recur(
|
|||
let mut replaces = FxHashMap::default();
|
||||
|
||||
for child in children.into_iter() {
|
||||
let source = hir::Source::new(macro_file_id, source.ast);
|
||||
let source = hir::Source::new(macro_file_id, source.value);
|
||||
let new_node = expand_macro_recur(db, source, &child)?;
|
||||
|
||||
replaces.insert(child.syntax().clone().into(), new_node.into());
|
||||
|
@ -139,7 +139,7 @@ mod tests {
|
|||
}
|
||||
macro_rules! baz {
|
||||
() => { foo!(); }
|
||||
}
|
||||
}
|
||||
f<|>oo!();
|
||||
"#,
|
||||
);
|
||||
|
@ -156,7 +156,7 @@ fn b(){}
|
|||
r#"
|
||||
//- /lib.rs
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
() => {
|
||||
fn some_thing() -> u32 {
|
||||
let a = 0;
|
||||
a + 10
|
||||
|
@ -172,7 +172,7 @@ fn b(){}
|
|||
fn some_thing() -> u32 {
|
||||
let a = 0;
|
||||
a+10
|
||||
}
|
||||
}
|
||||
"###);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ pub(crate) fn goto_definition(
|
|||
let token = descend_into_macros(db, position.file_id, token);
|
||||
|
||||
let res = match_ast! {
|
||||
match (token.ast.parent()) {
|
||||
match (token.value.parent()) {
|
||||
ast::NameRef(name_ref) => {
|
||||
let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec();
|
||||
RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())
|
||||
|
@ -84,7 +84,7 @@ pub(crate) fn reference_definition(
|
|||
};
|
||||
|
||||
// Fallback index based approach:
|
||||
let navs = crate::symbol_index::index_resolve(db, name_ref.ast)
|
||||
let navs = crate::symbol_index::index_resolve(db, name_ref.value)
|
||||
.into_iter()
|
||||
.map(|s| s.to_nav(db))
|
||||
.collect();
|
||||
|
@ -95,7 +95,7 @@ pub(crate) fn name_definition(
|
|||
db: &RootDatabase,
|
||||
name: Source<&ast::Name>,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let parent = name.ast.syntax().parent()?;
|
||||
let parent = name.value.syntax().parent()?;
|
||||
|
||||
if let Some(module) = ast::Module::cast(parent.clone()) {
|
||||
if module.has_semi() {
|
||||
|
@ -116,7 +116,7 @@ pub(crate) fn name_definition(
|
|||
|
||||
fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> {
|
||||
match_ast! {
|
||||
match (node.ast) {
|
||||
match (node.value) {
|
||||
ast::StructDef(it) => {
|
||||
Some(NavigationTarget::from_named(
|
||||
db,
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn goto_type_definition(
|
|||
let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?;
|
||||
let token = descend_into_macros(db, position.file_id, token);
|
||||
|
||||
let node = token.ast.ancestors().find_map(|token| {
|
||||
let node = token.value.ancestors().find_map(|token| {
|
||||
token
|
||||
.ancestors()
|
||||
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())
|
||||
|
|
|
@ -101,11 +101,11 @@ fn hover_text_from_name_kind(
|
|||
return match name_kind {
|
||||
Macro(it) => {
|
||||
let src = it.source(db);
|
||||
hover_text(src.ast.doc_comment_text(), Some(macro_label(&src.ast)))
|
||||
hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value)))
|
||||
}
|
||||
Field(it) => {
|
||||
let src = it.source(db);
|
||||
match src.ast {
|
||||
match src.value {
|
||||
hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ fn hover_text_from_name_kind(
|
|||
hir::AssocItem::TypeAlias(it) => from_def_source(db, it),
|
||||
},
|
||||
Def(it) => match it {
|
||||
hir::ModuleDef::Module(it) => match it.definition_source(db).ast {
|
||||
hir::ModuleDef::Module(it) => match it.definition_source(db).value {
|
||||
hir::ModuleSource::Module(it) => {
|
||||
hover_text(it.doc_comment_text(), it.short_label())
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ fn hover_text_from_name_kind(
|
|||
A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
|
||||
{
|
||||
let src = def.source(db);
|
||||
hover_text(src.ast.doc_comment_text(), src.ast.short_label())
|
||||
hover_text(src.value.doc_comment_text(), src.value.short_label())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
let mut res = HoverResult::new();
|
||||
|
||||
let mut range = match_ast! {
|
||||
match (token.ast.parent()) {
|
||||
match (token.value.parent()) {
|
||||
ast::NameRef(name_ref) => {
|
||||
let mut no_fallback = false;
|
||||
if let Some(name_kind) =
|
||||
|
@ -211,7 +211,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||
};
|
||||
|
||||
if range.is_none() {
|
||||
let node = token.ast.ancestors().find(|n| {
|
||||
let node = token.value.ancestors().find(|n| {
|
||||
ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()
|
||||
})?;
|
||||
let frange = FileRange { file_id: position.file_id, range: node.text_range() };
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn goto_implementation(
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), ast: src },
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
)?;
|
||||
|
||||
if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) {
|
||||
|
@ -42,11 +42,11 @@ fn impls_for_def(
|
|||
) -> Option<Vec<NavigationTarget>> {
|
||||
let ty = match node {
|
||||
ast::NominalDef::StructDef(def) => {
|
||||
let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() };
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: def.clone() };
|
||||
hir::Struct::from_source(db, src)?.ty(db)
|
||||
}
|
||||
ast::NominalDef::EnumDef(def) => {
|
||||
let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() };
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: def.clone() };
|
||||
hir::Enum::from_source(db, src)?.ty(db)
|
||||
}
|
||||
};
|
||||
|
@ -69,7 +69,7 @@ fn impls_for_trait(
|
|||
node: &ast::TraitDef,
|
||||
module: hir::Module,
|
||||
) -> Option<Vec<NavigationTarget>> {
|
||||
let src = hir::Source { file_id: position.file_id.into(), ast: node.clone() };
|
||||
let src = hir::Source { file_id: position.file_id.into(), value: node.clone() };
|
||||
let tr = hir::Trait::from_source(db, src)?;
|
||||
|
||||
let krate = module.krate();
|
||||
|
|
|
@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
|||
let src = hir::ModuleSource::from_position(db, position);
|
||||
let module = match hir::Module::from_definition(
|
||||
db,
|
||||
hir::Source { file_id: position.file_id.into(), ast: src },
|
||||
hir::Source { file_id: position.file_id.into(), value: src },
|
||||
) {
|
||||
None => return Vec::new(),
|
||||
Some(it) => it,
|
||||
|
@ -23,7 +23,8 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
|||
pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
|
||||
let src = hir::ModuleSource::from_file_id(db, file_id);
|
||||
let module =
|
||||
match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src }) {
|
||||
match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src })
|
||||
{
|
||||
Some(it) => it,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::db::RootDatabase;
|
|||
|
||||
pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> {
|
||||
let _p = profile("classify_name");
|
||||
let parent = name.ast.syntax().parent()?;
|
||||
let parent = name.value.syntax().parent()?;
|
||||
|
||||
match_ast! {
|
||||
match parent {
|
||||
|
@ -121,7 +121,7 @@ pub(crate) fn classify_name_ref(
|
|||
) -> Option<NameDefinition> {
|
||||
let _p = profile("classify_name_ref");
|
||||
|
||||
let parent = name_ref.ast.syntax().parent()?;
|
||||
let parent = name_ref.value.syntax().parent()?;
|
||||
let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None);
|
||||
|
||||
if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
|
||||
|
@ -142,7 +142,7 @@ pub(crate) fn classify_name_ref(
|
|||
tested_by!(goto_definition_works_for_record_fields);
|
||||
if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) {
|
||||
let variant_def = analyzer.resolve_record_literal(&record_lit)?;
|
||||
let hir_path = Path::from_name_ref(name_ref.ast);
|
||||
let hir_path = Path::from_name_ref(name_ref.value);
|
||||
let hir_name = hir_path.as_ident()?;
|
||||
let field = variant_def.field(db, hir_name)?;
|
||||
return Some(from_struct_field(db, field));
|
||||
|
@ -162,7 +162,7 @@ pub(crate) fn classify_name_ref(
|
|||
}
|
||||
}
|
||||
|
||||
let path = name_ref.ast.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||
let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?;
|
||||
let resolved = analyzer.resolve_path(db, &path)?;
|
||||
match resolved {
|
||||
PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))),
|
||||
|
|
|
@ -32,9 +32,9 @@ pub(crate) struct NameDefinition {
|
|||
pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition {
|
||||
let container = item.module(db);
|
||||
let visibility = match item {
|
||||
AssocItem::Function(f) => f.source(db).ast.visibility(),
|
||||
AssocItem::Const(c) => c.source(db).ast.visibility(),
|
||||
AssocItem::TypeAlias(a) => a.source(db).ast.visibility(),
|
||||
AssocItem::Function(f) => f.source(db).value.visibility(),
|
||||
AssocItem::Const(c) => c.source(db).value.visibility(),
|
||||
AssocItem::TypeAlias(a) => a.source(db).value.visibility(),
|
||||
};
|
||||
let kind = NameKind::AssocItem(item);
|
||||
NameDefinition { kind, container, visibility }
|
||||
|
@ -45,8 +45,8 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe
|
|||
let parent = field.parent_def(db);
|
||||
let container = parent.module(db);
|
||||
let visibility = match parent {
|
||||
VariantDef::Struct(s) => s.source(db).ast.visibility(),
|
||||
VariantDef::EnumVariant(e) => e.source(db).ast.parent_enum().visibility(),
|
||||
VariantDef::Struct(s) => s.source(db).value.visibility(),
|
||||
VariantDef::EnumVariant(e) => e.source(db).value.parent_enum().visibility(),
|
||||
};
|
||||
NameDefinition { kind, container, visibility }
|
||||
}
|
||||
|
@ -60,22 +60,22 @@ pub(super) fn from_module_def(
|
|||
let (container, visibility) = match def {
|
||||
ModuleDef::Module(it) => {
|
||||
let container = it.parent(db).or_else(|| Some(it)).unwrap();
|
||||
let visibility = it.declaration_source(db).and_then(|s| s.ast.visibility());
|
||||
let visibility = it.declaration_source(db).and_then(|s| s.value.visibility());
|
||||
(container, visibility)
|
||||
}
|
||||
ModuleDef::EnumVariant(it) => {
|
||||
let container = it.module(db);
|
||||
let visibility = it.source(db).ast.parent_enum().visibility();
|
||||
let visibility = it.source(db).value.parent_enum().visibility();
|
||||
(container, visibility)
|
||||
}
|
||||
ModuleDef::Function(it) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Const(it) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Static(it) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Trait(it) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()),
|
||||
ModuleDef::Function(it) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Const(it) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Static(it) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Trait(it) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).value.visibility()),
|
||||
ModuleDef::BuiltinType(..) => (module.unwrap(), None),
|
||||
};
|
||||
NameDefinition { kind, container, visibility }
|
||||
|
|
|
@ -55,11 +55,11 @@ fn rename_mod(
|
|||
) -> Option<SourceChange> {
|
||||
let mut source_file_edits = Vec::new();
|
||||
let mut file_system_edits = Vec::new();
|
||||
let module_src = hir::Source { file_id: position.file_id.into(), ast: ast_module.clone() };
|
||||
let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() };
|
||||
if let Some(module) = hir::Module::from_declaration(db, module_src) {
|
||||
let src = module.definition_source(db);
|
||||
let file_id = src.file_id.original_file(db);
|
||||
match src.ast {
|
||||
match src.value {
|
||||
ModuleSource::SourceFile(..) => {
|
||||
let mod_path: RelativePathBuf = db.file_relative_path(file_id);
|
||||
// mod is defined in path/to/dir/mod.rs
|
||||
|
|
|
@ -73,9 +73,9 @@ impl NameDefinition {
|
|||
|
||||
if let NameKind::Local(var) = self.kind {
|
||||
let range = match var.parent(db) {
|
||||
DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(),
|
||||
DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(),
|
||||
DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(),
|
||||
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(),
|
||||
};
|
||||
let mut res = FxHashMap::default();
|
||||
res.insert(file_id, Some(range));
|
||||
|
@ -91,7 +91,7 @@ impl NameDefinition {
|
|||
let parent_src = parent_module.definition_source(db);
|
||||
let file_id = parent_src.file_id.original_file(db);
|
||||
|
||||
match parent_src.ast {
|
||||
match parent_src.value {
|
||||
ModuleSource::Module(m) => {
|
||||
let range = Some(m.syntax().text_range());
|
||||
res.insert(file_id, range);
|
||||
|
@ -135,7 +135,7 @@ impl NameDefinition {
|
|||
}
|
||||
|
||||
let mut res = FxHashMap::default();
|
||||
let range = match module_src.ast {
|
||||
let range = match module_src.value {
|
||||
ModuleSource::Module(m) => Some(m.syntax().text_range()),
|
||||
ModuleSource::SourceFile(_) => None,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue