PEP8-compliant line commenter behavior in Python (PY-3153)

This commit is contained in:
Dmitry Jemerov
2013-01-25 15:46:25 +01:00
parent ae22e63210
commit 2d1ffb5592
6 changed files with 49 additions and 2 deletions
@@ -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);
}
}