mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix indent after inserting newline after comment in function body (PY-641)
This commit is contained in:
@@ -33,7 +33,7 @@ public class PyBlock implements ASTBlock {
|
||||
private final ASTNode _node;
|
||||
private final Wrap _wrap;
|
||||
private final CodeStyleSettings mySettings;
|
||||
private List<Block> _subBlocks = null;
|
||||
private List<PyBlock> _subBlocks = null;
|
||||
private final Alignment _childListAlignment;
|
||||
private final TokenSet _listElementTypes;
|
||||
private static final boolean DUMP_FORMATTING_BLOCKS = false;
|
||||
@@ -78,8 +78,8 @@ public class PyBlock implements ASTBlock {
|
||||
return new ArrayList<Block>(_subBlocks);
|
||||
}
|
||||
|
||||
private List<Block> buildSubBlocks() {
|
||||
List<Block> blocks = new ArrayList<Block>();
|
||||
private List<PyBlock> buildSubBlocks() {
|
||||
List<PyBlock> blocks = new ArrayList<PyBlock>();
|
||||
for (ASTNode child = _node.getFirstChildNode(); child != null; child = child.getTreeNext()) {
|
||||
|
||||
IElementType childType = child.getElementType();
|
||||
@@ -263,7 +263,7 @@ public class PyBlock implements ASTBlock {
|
||||
return ChildAttributes.DELEGATE_TO_PREV_CHILD;
|
||||
}
|
||||
|
||||
PyBlock insertAfterBlock = (PyBlock)_subBlocks.get(newChildIndex - 1);
|
||||
PyBlock insertAfterBlock = _subBlocks.get(newChildIndex - 1);
|
||||
|
||||
ASTNode prevNode = insertAfterBlock.getNode();
|
||||
PsiElement prevElt = prevNode.getPsi();
|
||||
@@ -327,10 +327,13 @@ public class PyBlock implements ASTBlock {
|
||||
private Indent getChildIndent(int newChildIndex) {
|
||||
ASTNode lastChild = getLastNonSpaceChild(_node, false);
|
||||
if (lastChild != null && lastChild.getElementType() == PyElementTypes.STATEMENT_LIST && _subBlocks.size() >= newChildIndex) {
|
||||
PyBlock insertAfterBlock = (PyBlock)_subBlocks.get(newChildIndex - 1);
|
||||
int prevIndex = newChildIndex-1;
|
||||
while (prevIndex > 0 && _subBlocks.get(prevIndex).getNode().getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
|
||||
prevIndex--;
|
||||
}
|
||||
PyBlock insertAfterBlock = _subBlocks.get(prevIndex);
|
||||
ASTNode afterNode = insertAfterBlock.getNode();
|
||||
|
||||
|
||||
// handle pressing Enter after colon and before first statement in
|
||||
// existing statement list
|
||||
if (afterNode.getElementType() == PyElementTypes.STATEMENT_LIST || afterNode.getElementType() == PyTokenTypes.COLON) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
from AddToImportFromFoo import bar,foo
|
||||
from AddToImportFromFoo import bar, foo
|
||||
|
||||
foo # must get imported
|
||||
|
||||
@@ -136,6 +136,10 @@ public class PyIndentTest extends PyLightFixtureTestCase {
|
||||
doTest("{<caret>}", "{\n <caret>\n}");
|
||||
}
|
||||
|
||||
public void testIndentAfterComment() { // PY-641
|
||||
doTest("def foo():\n #some_call()<caret>\n another_call()", "def foo():\n #some_call()\n <caret>\n another_call()");
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: formatter core problem?
|
||||
public void testAlignListBeforeEquals() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user