mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-16176 Existing imports are suggested first in auto import quickfix
This commit is contained in:
@@ -177,6 +177,7 @@ public class ImportCandidateHolder implements Comparable<ImportCandidateHolder>
|
||||
}
|
||||
|
||||
int getRelevance() {
|
||||
if (myImportElement != null) return 4;
|
||||
final Project project = myImportable.getProject();
|
||||
final PsiFile psiFile = myImportable.getContainingFile();
|
||||
final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class ClassA(object):
|
||||
pass
|
||||
|
||||
|
||||
class ClassB(object):
|
||||
pass
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
from long.pkg.path import ClassA
|
||||
|
||||
print(ClassA())
|
||||
print(<error descr="Unresolved reference 'ClassB'">Clas<caret>sB</error>())
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
class ClassB(object):
|
||||
pass
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
from datetime import time
|
||||
|
||||
print(time())
|
||||
print(<error descr="Unresolved reference 'datetime'">date<caret>time</error>())
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
class datetime:
|
||||
pass
|
||||
@@ -91,7 +91,25 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
public void testAllVariantsSuggestedWhenExistingNonProjectImportFits() {
|
||||
doMultiFileAutoImportTest("Import", quickfix -> {
|
||||
final List<String> candidates = ContainerUtil.map(quickfix.getCandidates(), c -> c.getPresentableText("time"));
|
||||
assertSameElements(candidates, "time", "time from datetime");
|
||||
assertOrderedEquals(candidates, "time from datetime", "time");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// PY-16176
|
||||
public void testExistingImportsAlwaysSuggestedFirstEvenIfLonger() {
|
||||
doMultiFileAutoImportTest("Import", quickfix -> {
|
||||
final List<String> candidates = ContainerUtil.map(quickfix.getCandidates(), c -> c.getPresentableText("ClassB"));
|
||||
assertOrderedEquals(candidates, "ClassB from path", "short.ClassB");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// PY-16176
|
||||
public void testExistingImportsAlwaysSuggestedFirstEvenIfNonProject() {
|
||||
doMultiFileAutoImportTest("Import", quickfix -> {
|
||||
final List<String> candidates = ContainerUtil.map(quickfix.getCandidates(), c -> c.getPresentableText("datetime"));
|
||||
assertOrderedEquals(candidates, "datetime from datetime", "mod.datetime");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user