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
TYPE: implement SelfManagingCommenter #5416
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 It looks much simpler than I expected! Thanks!
Added test for space after line comment settings and fixed the rest. Should There's something weird with the //<caret>
fn foo() {} it returns //
<caret>fn foo() {} even though when I try it in the IDE, it behaves correctly. |
It looks like no, simple
This was tricky, but I found the reason. There is a mutable state in I've changed the code of private fun checkOption(optionProperty: KMutableProperty0<Boolean>,
@Language("Rust") before: String,
@Language("Rust") afterOn: String,
@Language("Rust") afterOff: String,
actionId: String,
trimIndent: Boolean = true) {
val initialValue = optionProperty.get()
optionProperty.set(true)
try {
checkEditorAction(before, afterOn, actionId, trimIndent = trimIndent)
resetActionManagerState()
optionProperty.set(false)
checkEditorAction(before, afterOff, actionId, trimIndent = trimIndent)
resetActionManagerState()
} finally {
optionProperty.set(initialValue)
}
}
private fun settings() = CodeStyle.getSettings(project).getCommonSettings(RsLanguage)
/**
* Resets [com.intellij.openapi.actionSystem.impl.ActionManagerImpl.myPrevPerformedActionId].
* Otherwise it affect [com.intellij.codeInsight.generation.CommentByLineCommentHandler.invoke]
* (see `startingNewLineComment` condition there).
*/
private fun resetActionManagerState() {
myFixture.performEditorAction(EMPTY_ACTION_ID)
}
override fun setUp() {
super.setUp()
ActionManager.getInstance().registerAction(EMPTY_ACTION_ID, EmptyAction.createEmptyAction("empty", null, true))
}
override fun tearDown() {
try {
super.tearDown()
} finally {
ActionManager.getInstance().unregisterAction(EMPTY_ACTION_ID)
}
}
companion object {
private const val EMPTY_ACTION_ID = "!!!EmptyAction"
} |
Thank you! It works locally, but it seems that CI is not happy for some reason.. |
Hmm |
tryBuild failed: |
Let's also add this: override fun checkEditorAction(before: String, after: String, actionId: String, trimIndent: Boolean, testmark: Testmark?) {
super.checkEditorAction(before, after, actionId, trimIndent, testmark)
resetActionManagerState()
} Looks like it fails on CI because of different test order when tests are run by Gradle |
👍 |
This PR solves #5388 with a pretty heavyweight solution of implementing
SelfManagingCommenter
. The implementation is pretty basic, but it passes all the originalRsCommenter
tests and some new ones that I have added.It seems to work for basic use cases, if you can find some counter-examples where it breaks, let me know and I'll add them to the test suite.
Fixes: #5388