From 630ae204da1f84c1aa3eb440a25bbff6dae01281 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 23 Mar 2011 20:24:38 +0100 Subject: [PATCH] prefer shorter names when sorting import candidate list --- .../codeInsight/imports/ImportCandidateHolder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/codeInsight/imports/ImportCandidateHolder.java b/python/src/com/jetbrains/python/codeInsight/imports/ImportCandidateHolder.java index 3d2bf2eb5de4..856ef19bca0f 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/ImportCandidateHolder.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/ImportCandidateHolder.java @@ -138,7 +138,18 @@ class ImportCandidateHolder implements Comparable { public int compareTo(Object o) { ImportCandidateHolder rhs = (ImportCandidateHolder) o; - return rhs.getRelevance() - getRelevance(); + int lRelevance = getRelevance(); + int rRelevance = rhs.getRelevance(); + if (rRelevance != lRelevance) { + return rRelevance - lRelevance; + } + // prefer shorter paths + if (myPath != null && rhs.myPath != null) { + int lDots = StringUtil.isEmpty(myPath) ? -1 : StringUtil.countChars(myPath, '.'); + int rDots = StringUtil.isEmpty(rhs.myPath) ? -1 : StringUtil.countChars(rhs.myPath, '.'); + return lDots - rDots; + } + return 0; } int getRelevance() {