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

INT: Add IfLetToMatchIntention #973

Merged
merged 2 commits into from Jan 30, 2017

Conversation

Projects
None yet
3 participants
@Shiroy
Contributor

Shiroy commented Jan 29, 2017

PR for issue #962

This intention convert

if let A(value) = x {
    //Stuff for A
} else if let B(value) = x {
    //Stuff for B
} else {
    //Stuff for something else
}

to

match x {
    A(value) => {
        //Stuff for A
    },
    B(value) => {
        //Stuff for B
    },
    _ => {
        //Stuff for something else
    }
}
@Shiroy

This comment has been minimized.

Show comment
Hide comment
@Shiroy

Shiroy Jan 29, 2017

Contributor

Is there a way I can write unit tests for that intention?

Contributor

Shiroy commented Jan 29, 2017

Is there a way I can write unit tests for that intention?

@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad

matklad Jan 29, 2017

Member

Is there a way I can write unit tests for that intention?

Yes, they are in /home/matklad/projects/intellij-rust/src/test/kotlin/org/rust/ide/intentions

doAvailableTest takes two string literals with Rust code and a caret marker /*caret*/ and checks that after applying the intention to the first string, we get the second one.

doUnavailableTest checks that the intention is not available.

I haven't reviewed the code in detail, because it is WIP, but it looks good on the first blush! Could you run a reformat file action though? We place a space between if and ( in condition :)

Member

matklad commented Jan 29, 2017

Is there a way I can write unit tests for that intention?

Yes, they are in /home/matklad/projects/intellij-rust/src/test/kotlin/org/rust/ide/intentions

doAvailableTest takes two string literals with Rust code and a caret marker /*caret*/ and checks that after applying the intention to the first string, we get the second one.

doUnavailableTest checks that the intention is not available.

I haven't reviewed the code in detail, because it is WIP, but it looks good on the first blush! Could you run a reformat file action though? We place a space between if and ( in condition :)

@Shiroy Shiroy changed the title from [WIP] INT: Add IfLetToMatchIntention to INT: Add IfLetToMatchIntention Jan 29, 2017

@Shiroy

This comment has been minimized.

Show comment
Hide comment
@Shiroy

Shiroy Jan 29, 2017

Contributor

I'm done :)

Contributor

Shiroy commented Jan 29, 2017

I'm done :)

@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad

matklad Jan 30, 2017

Member

Super!

Member

matklad commented Jan 30, 2017

Super!

@matklad matklad merged commit 51ad3d0 into intellij-rust:master Jan 30, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad

matklad Jan 30, 2017

Member

(this will be in nightly in 24 hours, and in alpha the next monday).

Member

matklad commented Jan 30, 2017

(this will be in nightly in 24 hours, and in alpha the next monday).

@alygin

This comment has been minimized.

Show comment
Hide comment
@alygin

alygin Jan 30, 2017

Contributor

I believe, there must be an intention description in src/main/resources/intentionDescriptions. Without it, I got the following error:

Assertion failed: Intention Description Dir URL is null: Convert if let statement to match; IfLetToMatchIntention, PluginClassLoader[org.rust.lang, 0.1.0.SNAPSHOT]
java.lang.Throwable
	at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:168)
	at com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData.getDirURL(IntentionActionMetaData.java:109)
	at com.intellij.codeInsight.intention.impl.config.BeforeAfterActionMetaData.getDescription(BeforeAfterActionMetaData.java:155)
Contributor

alygin commented Jan 30, 2017

I believe, there must be an intention description in src/main/resources/intentionDescriptions. Without it, I got the following error:

Assertion failed: Intention Description Dir URL is null: Convert if let statement to match; IfLetToMatchIntention, PluginClassLoader[org.rust.lang, 0.1.0.SNAPSHOT]
java.lang.Throwable
	at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:168)
	at com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData.getDirURL(IntentionActionMetaData.java:109)
	at com.intellij.codeInsight.intention.impl.config.BeforeAfterActionMetaData.getDescription(BeforeAfterActionMetaData.java:155)
@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad

matklad Jan 30, 2017

Member

Yep, I need to add a test for this.

Member

matklad commented Jan 30, 2017

Yep, I need to add a test for this.

@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad
Member

matklad commented Jan 30, 2017

slavam2605 added a commit to slavam2605/intellij-rust that referenced this pull request Feb 1, 2017

INT: Add IfLetToMatchIntention (intellij-rust#973)
* INT: Add IfLetToMatchIntention

* INT : Add IfLetToMatchIntentionTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment