Skip to content

Commit 7aaf777

Browse files
committed
Filter out global suggestions that overlap with local
For example, don't suggest GHC.Exts.fromList when Data.Map.fromList is in scope alraedy
1 parent 478e17f commit 7aaf777

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,19 +656,21 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
656656
Down isQual -- , Down score_, _label, _detail)
657657

658658
uniqueCompl :: CompItem -> CompItem -> Ordering
659-
uniqueCompl x y =
660-
case compare (label x, importedFrom x, compKind x)
661-
(label y, importedFrom y, compKind y) of
659+
uniqueCompl candidate unique =
660+
case compare (label candidate, compKind candidate)
661+
(label unique, compKind unique) of
662662
EQ ->
663663
-- preserve completions for duplicate record fields where the only difference is in the type
664-
-- remove redundant completions with less type info
665-
if typeText x == typeText y
666-
|| isNothing (typeText x)
667-
|| isNothing (typeText y)
664+
-- remove redundant completions with less type info than the previous
665+
if (typeText candidate == typeText unique && isLocalCompletion unique)
666+
-- filter global completions when we already have a local one
667+
|| not(isLocalCompletion candidate) && isLocalCompletion unique
668668
then EQ
669-
else compare (insertText x) (insertText y)
669+
else compare (importedFrom candidate, insertText candidate) (importedFrom unique, insertText unique)
670670
other -> other
671671
where
672+
isLocalCompletion ci = isJust(typeText ci)
673+
672674
importedFrom :: CompItem -> T.Text
673675
importedFrom (provenance -> ImportedFrom m) = m
674676
importedFrom (provenance -> DefinedIn m) = m

ghcide/test/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4600,7 +4600,7 @@ packageCompletionTests =
46004600
, _label == "fromList"
46014601
]
46024602
liftIO $ take 3 compls' @?=
4603-
map Just ["fromList ${1:([Item l])}", "fromList", "fromList"]
4603+
map Just ["fromList ${1:([Item l])}"]
46044604
, testGroup "auto import snippets"
46054605
[ completionCommandTest
46064606
"import Data.Sequence"

0 commit comments

Comments
 (0)