From b14931f7b467ccef59cd0c65b4d4a2fe594ae735 Mon Sep 17 00:00:00 2001 From: Arya Irani Date: Sat, 6 Jul 2024 14:37:55 -0400 Subject: [PATCH] avoid numeric vs textual clash in args length error `numerals` doesn't seem to be maintained anymore, however --- stack.yaml | 5 +++++ stack.yaml.lock | 7 +++++++ unison-cli/package.yaml | 1 + unison-cli/src/Unison/CommandLine/InputPatterns.hs | 8 +++++++- unison-cli/unison-cli.cabal | 3 +++ unison-src/transcripts/input-parse-errors.output.md | 2 +- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/stack.yaml b/stack.yaml index 477547cab..ba6491bc9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -64,9 +64,14 @@ extra-deps: - recover-rtti-0.4.2@sha256:c179a303921126d8d782264e14f386c96e54a270df74be002e4c4ec3c8c7aebd,4529 - lsp-2.2.0.0@sha256:82fbf4b69d94d8d22543be71f89986b3e90050032d671fb3de3f8253ea1e5b6f,3550 - lsp-types-2.0.2.0@sha256:a9a51c3cea0726d91fe63fa0670935ee720f7b31bc3f3b33b2483fc538152677,29421 + - numerals-0.4.1@sha256:f138b4a0efbde3b3c6cbccb788eff683cb8a5d046f449729712fd174c5ee8a78,11430 - row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071 - network-udp-0.0.0 +allow-newer: true +allow-newer-deps: + - numerals + ghc-options: # All packages "$locals": -Wall -Werror -Wno-name-shadowing -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info #-freverse-errors diff --git a/stack.yaml.lock b/stack.yaml.lock index 4f98b610b..52d286156 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -75,6 +75,13 @@ packages: size: 45527 original: hackage: lsp-types-2.0.2.0@sha256:a9a51c3cea0726d91fe63fa0670935ee720f7b31bc3f3b33b2483fc538152677,29421 +- completed: + hackage: numerals-0.4.1@sha256:f138b4a0efbde3b3c6cbccb788eff683cb8a5d046f449729712fd174c5ee8a78,11430 + pantry-tree: + sha256: c616791b08f1792fd1d4ca03c6d2c773dedb25b24b66454c97864aefd85a5d0a + size: 13751 + original: + hackage: numerals-0.4.1@sha256:f138b4a0efbde3b3c6cbccb788eff683cb8a5d046f449729712fd174c5ee8a78,11430 - completed: hackage: row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071 pantry-tree: diff --git a/unison-cli/package.yaml b/unison-cli/package.yaml index 923d0c7ae..d64ed16ae 100644 --- a/unison-cli/package.yaml +++ b/unison-cli/package.yaml @@ -54,6 +54,7 @@ dependencies: - network-udp - network-uri - nonempty-containers + - numerals - open-browser - optparse-applicative >= 0.16.1.0 - pretty-simple diff --git a/unison-cli/src/Unison/CommandLine/InputPatterns.hs b/unison-cli/src/Unison/CommandLine/InputPatterns.hs index ae2886e2d..b1a6f1541 100644 --- a/unison-cli/src/Unison/CommandLine/InputPatterns.hs +++ b/unison-cli/src/Unison/CommandLine/InputPatterns.hs @@ -152,6 +152,8 @@ import System.Console.Haskeline.Completion (Completion (Completion)) import System.Console.Haskeline.Completion qualified as Haskeline import System.Console.Haskeline.Completion qualified as Line import Text.Megaparsec qualified as Megaparsec +import Text.Numeral (defaultInflection) +import Text.Numeral.Language.ENG qualified as Numeral import U.Codebase.HashTags (CausalHash (..)) import U.Codebase.Sqlite.DbId (ProjectBranchId) import U.Codebase.Sqlite.Project qualified as Sqlite @@ -342,7 +344,11 @@ wrongStructuredArgument expected actual = wrongArgsLength :: Text -> [a] -> Either (P.Pretty CT.ColorText) b wrongArgsLength expected args = - Left . P.text $ "I expected " <> expected <> ", but received " <> Text.pack (show $ length args) <> "." + let foundCount = + if null args + then "none" + else fromMaybe (tShow $ length args) $ Numeral.us_cardinal defaultInflection (length args) + in Left . P.text $ "I expected " <> expected <> ", but received " <> foundCount <> "." patternName :: InputPattern -> P.Pretty P.ColorText patternName = fromString . I.patternName diff --git a/unison-cli/unison-cli.cabal b/unison-cli/unison-cli.cabal index 1382e183a..97441927c 100644 --- a/unison-cli/unison-cli.cabal +++ b/unison-cli/unison-cli.cabal @@ -230,6 +230,7 @@ library , network-udp , network-uri , nonempty-containers + , numerals , open-browser , optparse-applicative >=0.16.1.0 , pretty-simple @@ -371,6 +372,7 @@ executable transcripts , network-udp , network-uri , nonempty-containers + , numerals , open-browser , optparse-applicative >=0.16.1.0 , pretty-simple @@ -519,6 +521,7 @@ test-suite cli-tests , network-udp , network-uri , nonempty-containers + , numerals , open-browser , optparse-applicative >=0.16.1.0 , pretty-simple diff --git a/unison-src/transcripts/input-parse-errors.output.md b/unison-src/transcripts/input-parse-errors.output.md index 9eced0311..ee1af109d 100644 --- a/unison-src/transcripts/input-parse-errors.output.md +++ b/unison-src/transcripts/input-parse-errors.output.md @@ -68,7 +68,7 @@ scratch/main> update arg Sorry, I wasn’t sure how to process your request: - I expected no arguments, but received 1. + I expected no arguments, but received one. You can run `help update` for more information on using `update`.