Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: move cursor after generated constructor in GenerateConstructor action #8674

Merged
merged 1 commit into from Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,6 +15,7 @@ import org.rust.lang.core.psi.RsImplItem
import org.rust.lang.core.psi.RsPsiFactory
import org.rust.lang.core.psi.RsStructItem
import org.rust.lang.core.psi.ext.childrenOfType
import org.rust.lang.core.psi.ext.endOffset
import org.rust.lang.core.psi.ext.isTupleStruct
import org.rust.lang.core.types.Substitution
import org.rust.openapiext.checkWriteAccessAllowed
Expand Down Expand Up @@ -46,8 +47,8 @@ class GenerateConstructorHandler : BaseGenerateHandler() {

val anchor = impl.lastChild.lastChild
val constructor = createConstructor(struct, chosenFields, psiFactory, substitution)
impl.lastChild.addBefore(constructor, anchor)
editor.caretModel.moveToOffset(impl.textOffset + impl.textLength - 1)
val inserted = impl.lastChild.addBefore(constructor, anchor)
editor.caretModel.moveToOffset(inserted.endOffset)
}

private fun createConstructor(
Expand Down
Expand Up @@ -25,7 +25,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl<T> S<T> {
pub fn new(n: i32, m: T) -> Self {
Self { n, m }
}
}/*caret*/
}
""")

Expand All @@ -46,7 +46,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S {
pub fn new(n: i32, m: ()) -> Self {
Self { n, m }
}
}/*caret*/
}
""")

Expand Down Expand Up @@ -74,7 +74,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl Color {
pub fn new(field0: i32, field1: i32, field2: i32) -> Self {
Self(field0, field1, field2)
}
}/*caret*/
}
""")

Expand All @@ -95,7 +95,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S {
pub fn new() -> Self {
Self { n: (), m: () }
}
}/*caret*/
}
""")

Expand All @@ -116,7 +116,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S {
pub fn new(n: i32, m: i64) -> Self {
Self { n, m }
}
}/*caret*/
}
""")

Expand All @@ -137,7 +137,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S {
pub fn new(n: i32) -> Self {
Self { n, m: () }
}
}/*caret*/
}
""")

Expand All @@ -162,7 +162,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S {
pub fn new(n: i32, m: i64) -> Self {
Self { n, m }
}
}/*caret*/
}
""")

Expand Down Expand Up @@ -203,7 +203,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl S<i32> {
pub fn new(field0: i32) -> Self {
Self(field0)
}
}/*caret*/
}
""")

Expand All @@ -219,7 +219,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl <'a> S<'a, i32> {
pub fn new(field0: &'a i32) -> Self {
Self(field0)
}
}/*caret*/
}
""")

Expand All @@ -239,7 +239,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl System {
pub fn new(point: Coordinates) -> Self {
Self { point }
}
}/*caret*/
}
""")

Expand All @@ -263,7 +263,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl System {
pub fn new(s: foo::S) -> Self {
Self { s }
}
}/*caret*/
}
""")

Expand All @@ -283,7 +283,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
impl System {
pub fn new(field0: foo::S) -> Self {
Self(field0)
}
}/*caret*/
}
""")

Expand All @@ -304,7 +304,7 @@ class GenerateConstructorActionTest : RsGenerateBaseTest() {
fn foo(&self) {}
pub fn new(s: u32) -> Self {
Self { s }
}
}/*caret*/
}
""")
}