use more precise name

This commit is contained in:
Aleksey Kladov 2021-05-22 16:23:07 +03:00
parent 47d7434dde
commit e6776c3e1b
3 changed files with 7 additions and 12 deletions

View File

@ -15,7 +15,7 @@ mod assist_context;
#[cfg(test)]
mod tests;
pub mod utils;
pub mod ast_transform;
pub mod path_transform;
use std::str::FromStr;

View File

@ -1,4 +1,4 @@
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
//! See `PathTransform`
use hir::{HirDisplay, SemanticsScope};
use ide_db::helpers::mod_path_to_ast;
use rustc_hash::FxHashMap;
@ -7,7 +7,7 @@ use syntax::{
ted,
};
/// `AstTransform` helps with applying bulk transformations to syntax nodes.
/// `PathTransform` substitutes path in SyntaxNodes in bulk.
///
/// This is mostly useful for IDE code generation. If you paste some existing
/// code into a new context (for example, to add method overrides to an `impl`
@ -30,18 +30,13 @@ use syntax::{
/// }
/// }
/// ```
///
/// So, a single `AstTransform` describes such function from `SyntaxNode` to
/// `SyntaxNode`. Note that the API here is a bit too high-order and high-brow.
/// We'd want to somehow express this concept simpler, but so far nobody got to
/// simplifying this!
pub(crate) struct AstTransform<'a> {
pub(crate) struct PathTransform<'a> {
pub(crate) subst: (hir::Trait, ast::Impl),
pub(crate) target_scope: &'a SemanticsScope<'a>,
pub(crate) source_scope: &'a SemanticsScope<'a>,
}
impl<'a> AstTransform<'a> {
impl<'a> PathTransform<'a> {
pub(crate) fn apply(&self, item: ast::AssocItem) {
if let Some(ctx) = self.build_ctx() {
ctx.apply(item)

View File

@ -24,7 +24,7 @@ use syntax::{
use crate::{
assist_context::{AssistBuilder, AssistContext},
ast_transform::AstTransform,
path_transform::PathTransform,
};
pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
@ -133,7 +133,7 @@ pub fn add_trait_assoc_items_to_impl(
) -> (ast::Impl, ast::AssocItem) {
let source_scope = sema.scope_for_def(trait_);
let transform = AstTransform {
let transform = PathTransform {
subst: (trait_, impl_.clone()),
source_scope: &source_scope,
target_scope: &target_scope,