diff --git a/python/src/com/jetbrains/python/PythonCommenter.java b/python/src/com/jetbrains/python/PythonCommenter.java index d9bab90ddffe..160725039542 100644 --- a/python/src/com/jetbrains/python/PythonCommenter.java +++ b/python/src/com/jetbrains/python/PythonCommenter.java @@ -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; + } } diff --git a/python/testData/commenter/indentedComment.py b/python/testData/commenter/indentedComment.py new file mode 100644 index 000000000000..ceed15ada543 --- /dev/null +++ b/python/testData/commenter/indentedComment.py @@ -0,0 +1,3 @@ +def foo(): + i = 1 + j = 2 diff --git a/python/testData/commenter/indentedComment_after.py b/python/testData/commenter/indentedComment_after.py new file mode 100644 index 000000000000..109b35d666a6 --- /dev/null +++ b/python/testData/commenter/indentedComment_after.py @@ -0,0 +1,3 @@ +def foo(): + # i = 1 + j = 2 diff --git a/python/testData/commenter/uncommentWithoutSpace.py b/python/testData/commenter/uncommentWithoutSpace.py new file mode 100644 index 000000000000..2d6a58dc75f7 --- /dev/null +++ b/python/testData/commenter/uncommentWithoutSpace.py @@ -0,0 +1,3 @@ +def foo(): + #i = 1 + j = 2 diff --git a/python/testData/commenter/uncommentWithoutSpace_after.py b/python/testData/commenter/uncommentWithoutSpace_after.py new file mode 100644 index 000000000000..091901c10491 --- /dev/null +++ b/python/testData/commenter/uncommentWithoutSpace_after.py @@ -0,0 +1,3 @@ +def foo(): + i = 1 + j = 2 diff --git a/python/testSrc/com/jetbrains/python/PyCommenterTest.java b/python/testSrc/com/jetbrains/python/PyCommenterTest.java new file mode 100644 index 000000000000..8e4ef5bced5c --- /dev/null +++ b/python/testSrc/com/jetbrains/python/PyCommenterTest.java @@ -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); + + } +}