mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-12401 inline refactoring looses comments
This commit is contained in:
@@ -42,6 +42,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.refactoring.util.RefactoringMessageDialog;
|
||||
import com.intellij.util.Query;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonLanguage;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction;
|
||||
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
|
||||
@@ -95,7 +96,7 @@ public class PyInlineLocalHandler extends InlineActionHandler {
|
||||
invoke(project, editor, (PyTargetExpression)element, refExpr);
|
||||
}
|
||||
|
||||
public static void invoke(final Project project, final Editor editor, PyTargetExpression local, PyReferenceExpression refExpr) {
|
||||
public static void invoke(final Project project, final Editor editor, final PyTargetExpression local, PyReferenceExpression refExpr) {
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, local)) return;
|
||||
|
||||
final HighlightManager highlightManager = HighlightManager.getInstance(project);
|
||||
@@ -187,6 +188,12 @@ public class PyInlineLocalHandler extends InlineActionHandler {
|
||||
PsiElement[] exprs = new PsiElement[refsToInline.length];
|
||||
final PyExpression value = prepareValue(def, localName, project);
|
||||
final PyExpression withParent = PyElementGenerator.getInstance(project).createExpressionFromText("(" + value.getText() + ")");
|
||||
final PsiElement lastChild = def.getLastChild();
|
||||
if (lastChild != null && lastChild.getNode().getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
|
||||
final PsiElement parent = def.getParent();
|
||||
if (parent != null) parent.addBefore(lastChild, def);
|
||||
}
|
||||
|
||||
for (int i = 0, refsToInlineLength = refsToInline.length; i < refsToInlineLength; i++) {
|
||||
PsiElement element = refsToInline[i];
|
||||
if (PyReplaceExpressionUtil.isNeedParenthesis((PyExpression)element, value)) {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# some clever comment
|
||||
value = "aaaaaa" + "bbbbb"
|
||||
@@ -0,0 +1,2 @@
|
||||
temp = "aaaaaa" # some clever comment
|
||||
value = te<caret>mp + "bbbbb"
|
||||
@@ -80,4 +80,8 @@ public class PyInlineLocalTest extends PyTestCase {
|
||||
public void testPy5832() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testComment() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user