mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 20:31:59 +00:00
Formatting issues resolved
This commit is contained in:
parent
7b200890c4
commit
41cd1732b7
3 changed files with 18 additions and 13 deletions
|
|
@ -7,7 +7,10 @@ use syntax::{
|
|||
match_ast, ted,
|
||||
};
|
||||
|
||||
use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder, utils::find_struct_definition_from_cursor};
|
||||
use crate::{
|
||||
AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder,
|
||||
utils::find_struct_definition_from_cursor,
|
||||
};
|
||||
|
||||
// Assist: convert_named_struct_to_tuple_struct
|
||||
//
|
||||
|
|
@ -374,7 +377,6 @@ impl A {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn convert_struct_referenced_via_self_kw() {
|
||||
check_assist(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ use syntax::{
|
|||
match_ast, ted,
|
||||
};
|
||||
|
||||
use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder, utils::find_struct_definition_from_cursor};
|
||||
use crate::{
|
||||
AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder,
|
||||
utils::find_struct_definition_from_cursor,
|
||||
};
|
||||
|
||||
// Assist: convert_tuple_struct_to_named_struct
|
||||
//
|
||||
|
|
@ -356,7 +359,7 @@ impl A {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[test]
|
||||
fn convert_simple_struct_cursor_on_visibility_keyword() {
|
||||
check_assist(
|
||||
convert_tuple_struct_to_named_struct,
|
||||
|
|
|
|||
|
|
@ -1150,22 +1150,22 @@ pub fn is_body_const(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> bo
|
|||
}
|
||||
|
||||
/// Gets the struct definition from a context
|
||||
pub(crate) fn find_struct_definition_from_cursor(ctx: &AssistContext<'_>)
|
||||
-> Option<Either<ast::Struct, ast::Variant>>
|
||||
{
|
||||
ctx.find_node_at_offset::<ast::Name>().and_then(|name| name.syntax().parent())
|
||||
pub(crate) fn find_struct_definition_from_cursor(
|
||||
ctx: &AssistContext<'_>,
|
||||
) -> Option<Either<ast::Struct, ast::Variant>> {
|
||||
ctx.find_node_at_offset::<ast::Name>()
|
||||
.and_then(|name| name.syntax().parent())
|
||||
.or(find_struct_keyword(ctx).and_then(|kw| kw.parent()))
|
||||
.or(ctx.find_node_at_offset::<ast::Visibility>().and_then(|visibility| visibility.syntax().parent()))
|
||||
.or(ctx
|
||||
.find_node_at_offset::<ast::Visibility>()
|
||||
.and_then(|visibility| visibility.syntax().parent()))
|
||||
.and_then(<Either<ast::Struct, ast::Variant>>::cast)
|
||||
}
|
||||
|
||||
fn find_struct_keyword(ctx: &AssistContext<'_>) -> Option<SyntaxToken> {
|
||||
// Attempt to find the token at the current cursor offset
|
||||
ctx
|
||||
.token_at_offset()
|
||||
.find(|leaf| match leaf.kind() {
|
||||
ctx.token_at_offset().find(|leaf| match leaf.kind() {
|
||||
STRUCT_KW => true,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue