mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PEP8-compliant line commenter behavior in Python (PY-3153)
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.codeInsight.generation.IndentedCommenter;
|
||||
import com.intellij.lang.CodeDocumentationAwareCommenter;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PythonCommenter implements CodeDocumentationAwareCommenter {
|
||||
public class PythonCommenter implements CodeDocumentationAwareCommenter, IndentedCommenter {
|
||||
public String getLineCommentPrefix() {
|
||||
return "#";
|
||||
return "# ";
|
||||
}
|
||||
|
||||
public String getBlockCommentPrefix() {
|
||||
@@ -62,4 +64,10 @@ public class PythonCommenter implements CodeDocumentationAwareCommenter {
|
||||
public boolean isDocumentationComment(PsiComment element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Boolean forceIndentedLineComment() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def foo():
|
||||
i = 1<caret>
|
||||
j = 2
|
||||
@@ -0,0 +1,3 @@
|
||||
def foo():
|
||||
# i = 1
|
||||
j = 2
|
||||
@@ -0,0 +1,3 @@
|
||||
def foo():
|
||||
#i = 1<caret>
|
||||
j = 2
|
||||
@@ -0,0 +1,3 @@
|
||||
def foo():
|
||||
i = 1
|
||||
j = 2
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.jetbrains.python;
|
||||
|
||||
import com.intellij.codeInsight.actions.CodeInsightAction;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PyCommenterTest extends PyTestCase {
|
||||
public void testIndentedComment() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUncommentWithoutSpace() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile("commenter/" + getTestName(true) + ".py");
|
||||
CodeInsightAction action = (CodeInsightAction) ActionManager.getInstance().getAction(IdeActions.ACTION_COMMENT_LINE);
|
||||
action.actionPerformedImpl(myFixture.getFile().getProject(), myFixture.getEditor());
|
||||
myFixture.checkResultByFile("commenter/" + getTestName(true) + "_after.py", true);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user