mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-15 02:09:36 +00:00
Fix generate_trait_from_impl whitespace after vis
Input:
```rust
struct Foo;
impl F$0oo {
pub fn a_func() -> Option<()> {
Some(())
}
}
```
Old:
```rust
struct Foo;
trait NewTrait {
fn a_func() -> Option<()>;
}
impl NewTrait for Foo {
fn a_func() -> Option<()> {
Some(())
}
}
```
This PR fixed:
```rust
struct Foo;
trait NewTrait {
fn a_func() -> Option<()>;
}
impl NewTrait for Foo {
fn a_func() -> Option<()> {
Some(())
}
}
```
This commit is contained in:
parent
b5b10fb10f
commit
cf299690a9
1 changed files with 9 additions and 3 deletions
|
|
@ -3,7 +3,7 @@ use ide_db::assists::AssistId;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
AstNode, SyntaxKind, T,
|
AstNode, SyntaxKind, T,
|
||||||
ast::{
|
ast::{
|
||||||
self, HasGenericParams, HasName,
|
self, HasGenericParams, HasName, HasVisibility,
|
||||||
edit_in_place::{HasVisibilityEdit, Indent},
|
edit_in_place::{HasVisibilityEdit, Indent},
|
||||||
make,
|
make,
|
||||||
},
|
},
|
||||||
|
|
@ -164,6 +164,12 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
|
||||||
/// `E0449` Trait items always share the visibility of their trait
|
/// `E0449` Trait items always share the visibility of their trait
|
||||||
fn remove_items_visibility(item: &ast::AssocItem) {
|
fn remove_items_visibility(item: &ast::AssocItem) {
|
||||||
if let Some(has_vis) = ast::AnyHasVisibility::cast(item.syntax().clone()) {
|
if let Some(has_vis) = ast::AnyHasVisibility::cast(item.syntax().clone()) {
|
||||||
|
if let Some(vis) = has_vis.visibility()
|
||||||
|
&& let Some(token) = vis.syntax().next_sibling_or_token()
|
||||||
|
&& token.kind() == SyntaxKind::WHITESPACE
|
||||||
|
{
|
||||||
|
ted::remove(token);
|
||||||
|
}
|
||||||
has_vis.set_visibility(None);
|
has_vis.set_visibility(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -333,11 +339,11 @@ impl F$0oo {
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
trait NewTrait {
|
trait NewTrait {
|
||||||
fn a_func() -> Option<()>;
|
fn a_func() -> Option<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewTrait for Foo {
|
impl NewTrait for Foo {
|
||||||
fn a_func() -> Option<()> {
|
fn a_func() -> Option<()> {
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue