mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-92081 Reformat causes syntax error when "Ensure margin not exceeded"
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user