Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion crates/hir/src/semantics/pathres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ use syntax::{SyntaxNode, SyntaxTokenWithParent};
use super::SemanticsImpl;
use crate::{
container::{
ContainerId, InBlock, InContainer, InFile, InGenerateBlock, InModule, InSubroutine,
ContainerId, ContainerParent, InBlock, InContainer, InFile, InGenerateBlock, InModule,
InSubroutine,
},
db::HirDb,
file::HirFileId,
hir_def::{
Ident,
block::BlockId,
expr::declarator::DeclId,
file::{config::ConfigDeclId, library::LibraryDeclId, udp::UdpDeclId},
Expand Down Expand Up @@ -37,6 +40,32 @@ impl SemanticsImpl<'_> {
pub(in crate::semantics) fn find_container(&self, node: InFile<SyntaxNode>) -> ContainerId {
self.with_ctx(|ctx| ctx.find_container(node))
}

pub fn resolve_name(&self, cont_id: ContainerId, ident: &Ident) -> Option<PathResolution> {
resolve_name(self.db, cont_id, ident)
}
}

pub fn resolve_name(db: &dyn HirDb, cont_id: ContainerId, ident: &Ident) -> Option<PathResolution> {
ContainerParent::start_from(db, cont_id).find_map(|id| match id {
ContainerId::HirFileId(_) => db.unit_scope().get(ident).map(PathResolution::from),
ContainerId::ModuleId(module_id) => db
.module_scope(module_id)
.get(ident)
.map(|entry| PathResolution::from(InModule::new(module_id, entry))),
ContainerId::GenerateBlockId(generate_block_id) => db
.generate_block_scope(generate_block_id)
.get(ident)
.map(|entry| PathResolution::from(InGenerateBlock::new(generate_block_id, entry))),
ContainerId::BlockId(block_id) => db
.block_scope(block_id)
.get(ident)
.map(|entry| PathResolution::from(InBlock::new(block_id, entry))),
ContainerId::SubroutineId(subroutine_id) => db
.subroutine_scope(subroutine_id)
.get(ident)
.map(|entry| PathResolution::from(InSubroutine::new(subroutine_id, entry))),
})
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down
28 changes: 2 additions & 26 deletions crates/hir/src/type_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use rustc_hash::FxHashSet;
use utils::get::GetRef;

use crate::{
container::{
ContainerId, ContainerParent, InContainer, InGenerateBlock, InModule, InSubroutine,
},
container::{ContainerId, InContainer, InGenerateBlock, InModule, InSubroutine},
db::HirDb,
hir_def::{
Ident,
Expand All @@ -21,7 +19,7 @@ use crate::{
subroutine::SubroutinePortId,
typedef::TypedefId,
},
semantics::pathres::PathResolution,
semantics::pathres::{PathResolution, resolve_name},
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -424,28 +422,6 @@ fn type_of_subroutine_port(db: &dyn HirDb, port: InSubroutine<SubroutinePortId>)
.unwrap_or_else(|| TyResult::new(Ty::Unknown))
}

fn resolve_name(db: &dyn HirDb, cont_id: ContainerId, ident: &Ident) -> Option<PathResolution> {
ContainerParent::start_from(db, cont_id).find_map(|id| match id {
ContainerId::HirFileId(_) => db.unit_scope().get(ident).map(PathResolution::from),
ContainerId::ModuleId(module_id) => db
.module_scope(module_id)
.get(ident)
.map(|entry| PathResolution::from(InModule::new(module_id, entry))),
ContainerId::GenerateBlockId(generate_block_id) => db
.generate_block_scope(generate_block_id)
.get(ident)
.map(|entry| PathResolution::from(InGenerateBlock::new(generate_block_id, entry))),
ContainerId::BlockId(block_id) => db
.block_scope(block_id)
.get(ident)
.map(|entry| PathResolution::from(crate::container::InBlock::new(block_id, entry))),
ContainerId::SubroutineId(subroutine_id) => db
.subroutine_scope(subroutine_id)
.get(ident)
.map(|entry| PathResolution::from(InSubroutine::new(subroutine_id, entry))),
})
}

fn instance_target_module_id(
db: &dyn HirDb,
module_id: ModuleId,
Expand Down
27 changes: 27 additions & 0 deletions crates/ide/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,33 @@ impl Analysis {
self.with_db(|db| rename::rename(db, position, config, new_name))
}

pub fn rename_expansion_info(
&self,
position: FilePosition,
config: RenameConfig,
) -> Cancellable<RenameResult<rename::RecursiveRenameInfo>> {
self.with_db(|db| rename::rename_expansion_info(db, position, config))
}

pub fn expanded_rename(
&self,
position: FilePosition,
config: RenameConfig,
new_name: &str,
) -> Cancellable<RenameResult<SourceChange>> {
self.with_db(|db| rename::expanded_rename(db, position, config, new_name))
}

pub fn rename_conflict_info(
&self,
position: FilePosition,
config: RenameConfig,
new_name: &str,
recursive: bool,
) -> Cancellable<RenameResult<rename::RenameCollisionInfo>> {
self.with_db(|db| rename::rename_conflict_info(db, position, config, new_name, recursive))
}

pub fn format(
&self,
file_id: FileId,
Expand Down
Loading
Loading