mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-22 15:58:34 +03:00
Avoid returning absolute names unless there are no other options
This commit is contained in:
parent
0527874d97
commit
64c57bb189
@ -408,7 +408,7 @@ searchBranchExact len names queries =
|
||||
searchTypes :: HQ.HashQualified Name -> [SR.SearchResult]
|
||||
searchTypes query =
|
||||
-- a bunch of references will match a HQ ref.
|
||||
let refs = toList $ Names3.lookupHQType query names
|
||||
let refs = toList $ Names3.lookupRelativeHQType query names
|
||||
mayName r Nothing = HQ'.fromNamedReference "" r
|
||||
mayName _ (Just n) = n
|
||||
in refs <&> \r ->
|
||||
@ -426,7 +426,7 @@ searchBranchExact len names queries =
|
||||
searchTerms :: HQ.HashQualified Name -> [SR.SearchResult]
|
||||
searchTerms query =
|
||||
-- a bunch of references will match a HQ ref.
|
||||
let refs = toList $ Names3.lookupHQTerm query names
|
||||
let refs = toList $ Names3.lookupRelativeHQTerm query names
|
||||
mayName r Nothing = HQ'.fromNamedReferent "" r
|
||||
mayName _ (Just n) = n
|
||||
in refs <&> \r ->
|
||||
|
@ -121,6 +121,17 @@ shadowing prio (Names current old) =
|
||||
makeAbsolute0:: Names0 -> Names0
|
||||
makeAbsolute0 = map0 Name.makeAbsolute
|
||||
|
||||
-- Find all types whose name has a suffix matching the provided `HashQualified`,
|
||||
-- returning types with relative names if they exist, and otherwise
|
||||
-- returning types with absolute names.
|
||||
lookupRelativeHQType :: HashQualified Name -> Names -> Set Reference
|
||||
lookupRelativeHQType hq ns@Names{..} = let
|
||||
rs = lookupHQType hq ns
|
||||
keep r = any (not . Name.isAbsolute) (R.lookupRan r (Names.types currentNames))
|
||||
in case Set.filter keep rs of
|
||||
rs' | Set.null rs' -> rs
|
||||
| otherwise -> rs'
|
||||
|
||||
-- Find all types whose name has a suffix matching the provided `HashQualified`.
|
||||
lookupHQType :: HashQualified Name -> Names -> Set Reference
|
||||
lookupHQType hq Names{..} = case hq of
|
||||
@ -143,6 +154,17 @@ hasTermNamed n ns = not (Set.null $ lookupHQTerm (HQ.NameOnly n) ns)
|
||||
hasTypeNamed :: Name -> Names -> Bool
|
||||
hasTypeNamed n ns = not (Set.null $ lookupHQType (HQ.NameOnly n) ns)
|
||||
|
||||
-- Find all terms whose name has a suffix matching the provided `HashQualified`,
|
||||
-- returning terms with relative names if they exist, and otherwise
|
||||
-- returning terms with absolute names.
|
||||
lookupRelativeHQTerm :: HashQualified Name -> Names -> Set Referent
|
||||
lookupRelativeHQTerm hq ns@Names{..} = let
|
||||
rs = lookupHQTerm hq ns
|
||||
keep r = any (not . Name.isAbsolute) (R.lookupRan r (Names.terms currentNames))
|
||||
in case Set.filter keep rs of
|
||||
rs' | Set.null rs' -> rs
|
||||
| otherwise -> rs'
|
||||
|
||||
-- Find all terms whose name has a suffix matching the provided `HashQualified`.
|
||||
lookupHQTerm :: HashQualified Name -> Names -> Set Referent
|
||||
lookupHQTerm hq Names{..} = case hq of
|
||||
|
Loading…
Reference in New Issue
Block a user