IDEA-92081 Reformat causes syntax error when "Ensure margin not exceeded"

This commit is contained in:
Denis.Zhdanov
2012-09-27 14:18:35 +04:00
parent 3192bf249e
commit 9d5565a376
4 changed files with 32 additions and 0 deletions
@@ -1,6 +1,10 @@
package com.jetbrains.python.formatter;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.GenericLineWrapPositionStrategy;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
@@ -22,4 +26,22 @@ public class PyLineWrapPositionStrategy extends GenericLineWrapPositionStrategy
// Symbols to wrap before
addRule(new Rule('.', WrapCondition.BEFORE));
}
@Override
protected boolean canUseOffset(@NotNull Document document, int offset, boolean virtual) {
if (virtual) {
return true;
}
CharSequence text = document.getCharsSequence();
char c = text.charAt(offset);
if (!StringUtil.isWhiteSpace(c)) {
return true;
}
int i = CharArrayUtil.shiftBackward(text, offset, " \t");
if (i < 2) {
return true;
}
return text.charAt(i - 2) != 'd' || text.charAt(i - 1) != 'e' || text.charAt(i) != 'f';
}
}
@@ -0,0 +1,2 @@
def my_function_name_which_is_rather_long:
pass
@@ -0,0 +1,2 @@
def my_function_name_which_is_rather_long:
pass
@@ -207,6 +207,12 @@ public class PyFormatterTest extends PyTestCase {
assertEquals(expected, reformatted.getText());
}
public void testWrapDefinitionWithLongLine() { // IDEA-92081
settings().RIGHT_MARGIN = 30;
settings().WRAP_LONG_LINES = true;
doTest();
}
private void doTest() {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
ApplicationManager.getApplication().runWriteAction(new Runnable() {