mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
proper fix for PY-11879
This commit is contained in:
@@ -17,14 +17,17 @@ package com.jetbrains.python.documentation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceBase;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PythonStringUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.ParamHelper;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
@@ -37,10 +40,10 @@ import java.util.Set;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class DocStringParameterReference extends PsiReferenceBase<PsiElement> implements PsiReferenceEx {
|
||||
public class DocStringParameterReference extends PsiReferenceBase<PyStringLiteralExpression> implements PsiReferenceEx {
|
||||
private final StructuredDocStringBase.ReferenceType myType;
|
||||
|
||||
public DocStringParameterReference(PsiElement element, TextRange range, StructuredDocStringBase.ReferenceType refType) {
|
||||
public DocStringParameterReference(PyStringLiteralExpression element, TextRange range, StructuredDocStringBase.ReferenceType refType) {
|
||||
super(element, range);
|
||||
myType = refType;
|
||||
}
|
||||
@@ -159,4 +162,18 @@ public class DocStringParameterReference extends PsiReferenceBase<PsiElement> im
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
TextRange range = getRangeInElement();
|
||||
Pair<String, String> quotes = PythonStringUtil.getQuotes(range.substring(myElement.getText()));
|
||||
|
||||
if (quotes != null) {
|
||||
range = TextRange.create(range.getStartOffset() + quotes.first.length(), range.getEndOffset() - quotes.second.length());
|
||||
}
|
||||
|
||||
String newName = range.replace(myElement.getText(), newElementName);
|
||||
myElement.updateText(newName);
|
||||
return myElement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,22 +59,22 @@ public class DocStringReferenceProvider extends PsiReferenceProvider {
|
||||
// XXX: It does not work with multielement docstrings
|
||||
StructuredDocString docString = DocStringUtil.parse(text);
|
||||
if (docString != null) {
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getTagArguments(StructuredDocStringBase.PARAM_TAGS),
|
||||
StructuredDocStringBase.ReferenceType.PARAMETER));
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getTagArguments(StructuredDocStringBase.PARAM_TYPE_TAGS),
|
||||
StructuredDocStringBase.ReferenceType.PARAMETER_TYPE));
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getKeywordArgumentSubstrings(), StructuredDocStringBase.ReferenceType.KEYWORD));
|
||||
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getTagArguments("var"),
|
||||
StructuredDocStringBase.ReferenceType.VARIABLE));
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getTagArguments("cvar"),
|
||||
StructuredDocStringBase.ReferenceType.CLASS_VARIABLE));
|
||||
result.addAll(referencesFromNames(element, offset, docString,
|
||||
result.addAll(referencesFromNames(expr, offset, docString,
|
||||
docString.getTagArguments("ivar"),
|
||||
StructuredDocStringBase.ReferenceType.INSTANCE_VARIABLE));
|
||||
result.addAll(returnTypes(element, docString, offset));
|
||||
@@ -96,7 +96,7 @@ public class DocStringReferenceProvider extends PsiReferenceProvider {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private static List<PsiReference> referencesFromNames(PsiElement element,
|
||||
private static List<PsiReference> referencesFromNames(PyStringLiteralExpression element,
|
||||
int offset,
|
||||
StructuredDocString docString,
|
||||
List<Substring> paramNames,
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.AbstractElementManipulator;
|
||||
import com.jetbrains.python.PythonStringUtil;
|
||||
import com.jetbrains.python.psi.PyElementGenerator;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
@@ -33,8 +34,9 @@ public class PyStringLiteralExpressionManipulator extends AbstractElementManipul
|
||||
}
|
||||
|
||||
String newName = range.replace(element.getText(), newContent);
|
||||
element.updateText(newName);
|
||||
return element;
|
||||
|
||||
return (PyStringLiteralExpressionImpl)element
|
||||
.replace(PyElementGenerator.getInstance(element.getProject()).createStringLiteralAlreadyEscaped(newName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user