mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-20 14:57:41 +03:00
alphabetically sort structured find output
This commit is contained in:
parent
0e857033fb
commit
672d85205d
@ -4,6 +4,7 @@
|
||||
|
||||
module Unison.Util.Alphabetical where
|
||||
|
||||
import Data.List qualified as List
|
||||
import Data.List.NonEmpty qualified as List (NonEmpty)
|
||||
import Data.RFC5051 qualified as RFC5051
|
||||
import Data.Text (Text)
|
||||
@ -17,6 +18,12 @@ import Data.Text (Text)
|
||||
class (Eq n) => Alphabetical n where
|
||||
compareAlphabetical :: n -> n -> Ordering
|
||||
|
||||
sortAlphabetically :: Alphabetical a => [a] -> [a]
|
||||
sortAlphabetically as = (\(OrderAlphabetically a) -> a) <$> List.sort (map OrderAlphabetically as)
|
||||
|
||||
sortAlphabeticallyOn :: Alphabetical a => (b -> a) -> [b] -> [b]
|
||||
sortAlphabeticallyOn f = List.sortOn (OrderAlphabetically . f)
|
||||
|
||||
instance Alphabetical Text where
|
||||
compareAlphabetical = RFC5051.compareUnicode
|
||||
|
||||
|
@ -201,6 +201,7 @@ import Unison.Typechecker.TypeLookup qualified as TypeLookup
|
||||
import Unison.UnisonFile (TypecheckedUnisonFile)
|
||||
import Unison.UnisonFile qualified as UF
|
||||
import Unison.UnisonFile.Names qualified as UF
|
||||
import Unison.Util.Alphabetical qualified as Alphabetical
|
||||
import Unison.Util.Find qualified as Find
|
||||
import Unison.Util.List (nubOrdOn, uniqueBy)
|
||||
import Unison.Util.Monoid qualified as Monoid
|
||||
@ -1750,7 +1751,7 @@ handleStructuredFindI rule = do
|
||||
pure $ (t, maybe False (\e -> any ($ e) rules) oe)
|
||||
ok t = pure (t, False)
|
||||
results0 <- traverse ok results
|
||||
let results = [(hq, r) | ((hq, r), True) <- results0]
|
||||
let results = Alphabetical.sortAlphabeticallyOn fst [(hq, r) | ((hq, r), True) <- results0]
|
||||
let toNumArgs = Text.unpack . Reference.toText . Referent.toReference . view _2
|
||||
#numberedArgs .= map toNumArgs results
|
||||
Cli.respond (ListStructuredFind (fst <$> results))
|
||||
|
Loading…
Reference in New Issue
Block a user