Skip to content

Commit 0897ae4

Browse files
authored
Merge pull request #5549 from sellout/optional-numbered-args
2 parents a897f1f + c721e88 commit 0897ae4

File tree

13 files changed

+929
-742
lines changed

13 files changed

+929
-742
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,23 @@ loop e = do
703703
Cli.Env {codebase} <- ask
704704
currentBranch <- Branch.withoutTransitiveLibs <$> Cli.getCurrentBranch0
705705
case Map.lookup command InputPatterns.patternMap of
706-
Just (IP.InputPattern {args = argTypes}) -> do
707-
zip argTypes args & Monoid.foldMapM \case
708-
((argName, _, IP.ArgumentType {fzfResolver = Just IP.FZFResolver {getOptions}}), "_") -> do
709-
pp <- Cli.getCurrentProjectPath
710-
results <- liftIO $ getOptions codebase pp currentBranch
711-
Cli.respond (DebugDisplayFuzzyOptions argName (Text.unpack <$> results))
712-
((_, _, IP.ArgumentType {fzfResolver = Nothing}), "_") -> do
713-
Cli.respond DebugFuzzyOptionsNoResolver
714-
_ -> pure ()
715-
Nothing -> do
716-
Cli.respond DebugFuzzyOptionsNoResolver
706+
Just IP.InputPattern {params} ->
707+
either (Cli.respond . DebugFuzzyOptionsIncorrectArgs) (pure . fst)
708+
=<< IP.foldParamsWithM
709+
( \_ (paramName, IP.ParameterType {fzfResolver}) arg ->
710+
if arg == "_"
711+
then case fzfResolver of
712+
Just IP.FZFResolver {getOptions} -> do
713+
pp <- Cli.getCurrentProjectPath
714+
results <- liftIO $ getOptions codebase pp currentBranch
715+
(,[]) <$> Cli.respond (DebugDisplayFuzzyOptions paramName (Text.unpack <$> results))
716+
Nothing -> (,[]) <$> Cli.respond DebugFuzzyOptionsNoResolver
717+
else pure ((), [])
718+
)
719+
()
720+
params
721+
args
722+
Nothing -> Cli.respond $ DebugFuzzyOptionsNoCommand command
717723
DebugFormatI -> do
718724
env <- ask
719725
void $ runMaybeT do

unison-cli/src/Unison/Codebase/Editor/Output.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ data Output
359359
| DisplayDebugCompletions [Completion.Completion]
360360
| DisplayDebugLSPNameCompletions [(Text, Name, LabeledDependency)]
361361
| DebugDisplayFuzzyOptions Text [String {- arg description, options -}]
362+
| DebugFuzzyOptionsIncorrectArgs (NonEmpty String)
363+
| DebugFuzzyOptionsNoCommand String
362364
| DebugFuzzyOptionsNoResolver
363365
| DebugTerm (Bool {- verbose mode -}) (Either (Text {- A builtin hash -}) (Term Symbol Ann))
364366
| DebugDecl (Either (Text {- A builtin hash -}) (DD.Decl Symbol Ann)) (Maybe ConstructorId {- If 'Just' we're debugging a constructor of the given decl -})
@@ -620,6 +622,8 @@ isFailure o = case o of
620622
DisplayDebugCompletions {} -> False
621623
DisplayDebugLSPNameCompletions {} -> False
622624
DebugDisplayFuzzyOptions {} -> False
625+
DebugFuzzyOptionsIncorrectArgs {} -> True
626+
DebugFuzzyOptionsNoCommand {} -> True
623627
DebugFuzzyOptionsNoResolver {} -> True
624628
DebugTerm {} -> False
625629
DebugDecl {} -> False

unison-cli/src/Unison/Codebase/Transcript/Runner.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import Unison.Codebase.Transcript.Parser qualified as Transcript
4848
import Unison.Codebase.Verbosity (Verbosity, isSilent)
4949
import Unison.Codebase.Verbosity qualified as Verbosity
5050
import Unison.CommandLine
51-
import Unison.CommandLine.InputPattern (InputPattern (aliases, patternName))
52-
import Unison.CommandLine.InputPatterns (validInputs)
51+
import Unison.CommandLine.InputPattern (aliases, patternName)
52+
import Unison.CommandLine.InputPatterns qualified as IP
5353
import Unison.CommandLine.OutputMessages (notifyNumbered, notifyUser)
5454
import Unison.CommandLine.Welcome (asciiartUnison)
5555
import Unison.Parser.Ann (Ann)
@@ -174,7 +174,7 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
174174
expectFailure <- newIORef False
175175
hasErrors <- newIORef False
176176
mBlock <- newIORef Nothing
177-
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< validInputs
177+
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< IP.validInputs
178178
let output' :: Bool -> Stanza -> IO ()
179179
output' inputEcho msg = do
180180
hide <- hideOutput inputEcho
@@ -326,7 +326,8 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
326326
liftIO (parseInput codebase curPath getProjectRoot numberedArgs patternMap args)
327327
>>= either
328328
-- invalid command is treated as a failure
329-
( \msg -> do
329+
( \failure -> do
330+
let msg = reportParseFailure failure
330331
liftIO $ outputUcmResult msg
331332
liftIO $ maybeDieWithMsg msg
332333
Cli.returnEarlyWithoutOutput

0 commit comments

Comments
 (0)