mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
use more consistent naming
I think this is the first time I use global rename for rust-analyzer itself :-)
This commit is contained in:
parent
61349a3d18
commit
8118dc1bb9
@ -115,7 +115,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> {
|
||||
self.token_at_offset().find(|it| it.kind() == kind)
|
||||
}
|
||||
|
||||
pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<N> {
|
||||
pub(crate) fn find_node_at_offset<N: AstNode>(&self) -> Option<N> {
|
||||
find_node_at_offset(self.source_file.syntax(), self.frange.range.start())
|
||||
}
|
||||
pub(crate) fn covering_element(&self) -> SyntaxElement {
|
||||
|
@ -26,7 +26,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn add_derive(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let nominal = ctx.node_at_offset::<ast::NominalDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
|
||||
let node_start = derive_insertion_offset(&nominal)?;
|
||||
ctx.add_action(AssistId("add_derive"), "add `#[derive]`", |edit| {
|
||||
let derive_attr = nominal
|
||||
|
@ -22,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let stmt = ctx.node_at_offset::<LetStmt>()?;
|
||||
let stmt = ctx.find_node_at_offset::<LetStmt>()?;
|
||||
let expr = stmt.initializer()?;
|
||||
let pat = stmt.pat()?;
|
||||
// Must be a binding
|
||||
|
@ -28,7 +28,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn add_impl(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let nominal = ctx.node_at_offset::<ast::NominalDef>()?;
|
||||
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
|
||||
let name = nominal.name()?;
|
||||
ctx.add_action(AssistId("add_impl"), "add impl", |edit| {
|
||||
edit.target(nominal.syntax().text_range());
|
||||
|
@ -96,7 +96,7 @@ fn add_missing_impl_members_inner(
|
||||
assist_id: &'static str,
|
||||
label: &'static str,
|
||||
) -> Option<Assist> {
|
||||
let impl_node = ctx.node_at_offset::<ast::ImplBlock>()?;
|
||||
let impl_node = ctx.find_node_at_offset::<ast::ImplBlock>()?;
|
||||
let impl_item_list = impl_node.item_list()?;
|
||||
|
||||
let trait_def = {
|
||||
|
@ -24,7 +24,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn apply_demorgan(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let expr = ctx.node_at_offset::<ast::BinExpr>()?;
|
||||
let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
|
||||
let op = expr.op_kind()?;
|
||||
let op_range = expr.op_token()?.text_range();
|
||||
let opposite_op = opposite_logic_op(op)?;
|
||||
|
@ -547,7 +547,7 @@ pub fn auto_import_text_edit(
|
||||
}
|
||||
|
||||
pub(crate) fn auto_import(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let path: ast::Path = ctx.node_at_offset()?;
|
||||
let path: ast::Path = ctx.find_node_at_offset()?;
|
||||
// We don't want to mess with use statements
|
||||
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() {
|
||||
return None;
|
||||
|
@ -23,7 +23,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// pub(crate) fn frobnicate() {}
|
||||
// ```
|
||||
pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
if let Some(vis) = ctx.node_at_offset::<ast::Visibility>() {
|
||||
if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() {
|
||||
return change_vis(ctx, vis);
|
||||
}
|
||||
add_vis(ctx)
|
||||
|
@ -36,7 +36,7 @@ use crate::{
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn convert_to_guarded_return(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let if_expr: ast::IfExpr = ctx.node_at_offset()?;
|
||||
let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
|
||||
let expr = if_expr.condition()?.expr()?;
|
||||
let then_block = if_expr.then_branch()?.block()?;
|
||||
if if_expr.else_branch().is_some() {
|
||||
|
@ -32,7 +32,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?;
|
||||
let match_expr = ctx.find_node_at_offset::<ast::MatchExpr>()?;
|
||||
let match_arm_list = match_expr.match_arm_list()?;
|
||||
|
||||
// We already have some match arms, so we don't provide any assists.
|
||||
|
@ -19,7 +19,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn flip_binexpr(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let expr = ctx.node_at_offset::<BinExpr>()?;
|
||||
let expr = ctx.find_node_at_offset::<BinExpr>()?;
|
||||
let lhs = expr.lhs()?.syntax().clone();
|
||||
let rhs = expr.rhs()?.syntax().clone();
|
||||
let op_range = expr.op_token()?.text_range();
|
||||
|
@ -24,7 +24,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?;
|
||||
let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?;
|
||||
let bind_pat = match let_stmt.pat()? {
|
||||
ast::Pat::BindPat(pat) => pat,
|
||||
_ => return None,
|
||||
|
@ -27,7 +27,7 @@ use ra_syntax::ast::{AstNode, MatchArm};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn merge_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let current_arm = ctx.node_at_offset::<MatchArm>()?;
|
||||
let current_arm = ctx.find_node_at_offset::<MatchArm>()?;
|
||||
|
||||
// We check if the following match arm matches this one. We could, but don't,
|
||||
// compare to the previous match arm as well.
|
||||
|
@ -23,7 +23,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let type_param_list = ctx.node_at_offset::<ast::TypeParamList>()?;
|
||||
let type_param_list = ctx.find_node_at_offset::<ast::TypeParamList>()?;
|
||||
|
||||
let mut type_params = type_param_list.type_params();
|
||||
if type_params.all(|p| p.type_bound_list().is_none()) {
|
||||
|
@ -33,7 +33,7 @@ use crate::{Assist, AssistCtx, AssistId};
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let match_arm = ctx.node_at_offset::<MatchArm>()?;
|
||||
let match_arm = ctx.find_node_at_offset::<MatchArm>()?;
|
||||
let guard = match_arm.guard()?;
|
||||
let space_before_guard = guard.syntax().prev_sibling_or_token();
|
||||
|
||||
@ -91,7 +91,7 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let match_arm: MatchArm = ctx.node_at_offset::<MatchArm>()?;
|
||||
let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?;
|
||||
let last_match_pat = match_arm.pats().last()?;
|
||||
|
||||
let arm_body = match_arm.expr()?;
|
||||
|
@ -8,7 +8,7 @@ use ra_syntax::{
|
||||
};
|
||||
|
||||
pub(crate) fn remove_dbg(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let macro_call = ctx.node_at_offset::<ast::MacroCall>()?;
|
||||
let macro_call = ctx.find_node_at_offset::<ast::MacroCall>()?;
|
||||
|
||||
if !is_valid_macrocall(¯o_call, "dbg")? {
|
||||
return None;
|
||||
|
@ -8,7 +8,7 @@ use ra_syntax::{ast, AstNode};
|
||||
use crate::{Assist, AssistCtx, AssistId};
|
||||
|
||||
pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
|
||||
let if_expr: ast::IfExpr = ctx.node_at_offset()?;
|
||||
let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
|
||||
let cond = if_expr.condition()?;
|
||||
let pat = cond.pat()?;
|
||||
let expr = cond.expr()?;
|
||||
|
Loading…
Reference in New Issue
Block a user