Skip to content

Commit d3c4fbb

Browse files
bors[bot]matklad
andauthored
Merge #2862
2862: Move from `from_source` to `SourceBinder` r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <[email protected]>
2 parents e614356 + 846f11c commit d3c4fbb

File tree

16 files changed

+306
-430
lines changed

16 files changed

+306
-430
lines changed

crates/ra_assists/src/assist_ctx.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module defines `AssistCtx` -- the API surface that is exposed to assists.
22
use either::Either;
3-
use hir::{db::HirDatabase, InFile, SourceAnalyzer};
3+
use hir::{db::HirDatabase, InFile, SourceAnalyzer, SourceBinder};
44
use ra_db::FileRange;
55
use ra_fmt::{leading_indent, reindent};
66
use ra_syntax::{
@@ -142,12 +142,16 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
142142
pub(crate) fn covering_element(&self) -> SyntaxElement {
143143
find_covering_element(self.source_file.syntax(), self.frange.range)
144144
}
145+
pub(crate) fn source_binder(&self) -> SourceBinder<'a, DB> {
146+
SourceBinder::new(self.db)
147+
}
145148
pub(crate) fn source_analyzer(
146149
&self,
147150
node: &SyntaxNode,
148151
offset: Option<TextUnit>,
149152
) -> SourceAnalyzer {
150-
SourceAnalyzer::new(self.db, InFile::new(self.frange.file_id.into(), node), offset)
153+
let src = InFile::new(self.frange.file_id.into(), node);
154+
self.source_binder().analyze(src, offset)
151155
}
152156

153157
pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement {

crates/ra_assists/src/assists/add_new.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use format_buf::format;
2-
use hir::{db::HirDatabase, FromSource, InFile};
2+
use hir::{db::HirDatabase, InFile};
33
use join_to_string::join;
44
use ra_syntax::{
55
ast::{
@@ -136,15 +136,16 @@ fn find_struct_impl(
136136
let module = strukt.syntax().ancestors().find(|node| {
137137
ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
138138
})?;
139+
let mut sb = ctx.source_binder();
139140

140141
let struct_ty = {
141142
let src = InFile { file_id: ctx.frange.file_id.into(), value: strukt.clone() };
142-
hir::Struct::from_source(db, src)?.ty(db)
143+
sb.to_def(src)?.ty(db)
143144
};
144145

145146
let block = module.descendants().filter_map(ast::ImplBlock::cast).find_map(|impl_blk| {
146147
let src = InFile { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() };
147-
let blk = hir::ImplBlock::from_source(db, src)?;
148+
let blk = sb.to_def(src)?;
148149

149150
let same_ty = blk.target_ty(db) == struct_ty;
150151
let not_trait_impl = blk.target_trait(db).is_none();

crates/ra_hir/src/from_source.rs

Lines changed: 0 additions & 265 deletions
This file was deleted.

crates/ra_hir/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ mod from_id;
3636
mod code_model;
3737

3838
mod has_source;
39-
mod from_source;
4039

4140
pub use crate::{
4241
code_model::{
@@ -45,7 +44,6 @@ pub use crate::{
4544
MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias,
4645
TypeParam, Union, VariantDef,
4746
},
48-
from_source::FromSource,
4947
has_source::HasSource,
5048
source_analyzer::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
5149
source_binder::SourceBinder,

0 commit comments

Comments
 (0)