Skip to content

Commit

Permalink
Merge pull request #5549 from sellout/optional-numbered-args
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani authored Feb 13, 2025
2 parents a897f1f + c721e88 commit 0897ae4
Show file tree
Hide file tree
Showing 13 changed files with 929 additions and 742 deletions.
28 changes: 17 additions & 11 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -703,17 +703,23 @@ loop e = do
Cli.Env {codebase} <- ask
currentBranch <- Branch.withoutTransitiveLibs <$> Cli.getCurrentBranch0
case Map.lookup command InputPatterns.patternMap of
Just (IP.InputPattern {args = argTypes}) -> do
zip argTypes args & Monoid.foldMapM \case
((argName, _, IP.ArgumentType {fzfResolver = Just IP.FZFResolver {getOptions}}), "_") -> do
pp <- Cli.getCurrentProjectPath
results <- liftIO $ getOptions codebase pp currentBranch
Cli.respond (DebugDisplayFuzzyOptions argName (Text.unpack <$> results))
((_, _, IP.ArgumentType {fzfResolver = Nothing}), "_") -> do
Cli.respond DebugFuzzyOptionsNoResolver
_ -> pure ()
Nothing -> do
Cli.respond DebugFuzzyOptionsNoResolver
Just IP.InputPattern {params} ->
either (Cli.respond . DebugFuzzyOptionsIncorrectArgs) (pure . fst)
=<< IP.foldParamsWithM
( \_ (paramName, IP.ParameterType {fzfResolver}) arg ->
if arg == "_"
then case fzfResolver of
Just IP.FZFResolver {getOptions} -> do
pp <- Cli.getCurrentProjectPath
results <- liftIO $ getOptions codebase pp currentBranch
(,[]) <$> Cli.respond (DebugDisplayFuzzyOptions paramName (Text.unpack <$> results))
Nothing -> (,[]) <$> Cli.respond DebugFuzzyOptionsNoResolver
else pure ((), [])
)
()
params
args
Nothing -> Cli.respond $ DebugFuzzyOptionsNoCommand command
DebugFormatI -> do
env <- ask
void $ runMaybeT do
Expand Down
4 changes: 4 additions & 0 deletions unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ data Output
| DisplayDebugCompletions [Completion.Completion]
| DisplayDebugLSPNameCompletions [(Text, Name, LabeledDependency)]
| DebugDisplayFuzzyOptions Text [String {- arg description, options -}]
| DebugFuzzyOptionsIncorrectArgs (NonEmpty String)
| DebugFuzzyOptionsNoCommand String
| DebugFuzzyOptionsNoResolver
| DebugTerm (Bool {- verbose mode -}) (Either (Text {- A builtin hash -}) (Term Symbol Ann))
| DebugDecl (Either (Text {- A builtin hash -}) (DD.Decl Symbol Ann)) (Maybe ConstructorId {- If 'Just' we're debugging a constructor of the given decl -})
Expand Down Expand Up @@ -620,6 +622,8 @@ isFailure o = case o of
DisplayDebugCompletions {} -> False
DisplayDebugLSPNameCompletions {} -> False
DebugDisplayFuzzyOptions {} -> False
DebugFuzzyOptionsIncorrectArgs {} -> True
DebugFuzzyOptionsNoCommand {} -> True
DebugFuzzyOptionsNoResolver {} -> True
DebugTerm {} -> False
DebugDecl {} -> False
Expand Down
9 changes: 5 additions & 4 deletions unison-cli/src/Unison/Codebase/Transcript/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import Unison.Codebase.Transcript.Parser qualified as Transcript
import Unison.Codebase.Verbosity (Verbosity, isSilent)
import Unison.Codebase.Verbosity qualified as Verbosity
import Unison.CommandLine
import Unison.CommandLine.InputPattern (InputPattern (aliases, patternName))
import Unison.CommandLine.InputPatterns (validInputs)
import Unison.CommandLine.InputPattern (aliases, patternName)
import Unison.CommandLine.InputPatterns qualified as IP
import Unison.CommandLine.OutputMessages (notifyNumbered, notifyUser)
import Unison.CommandLine.Welcome (asciiartUnison)
import Unison.Parser.Ann (Ann)
Expand Down Expand Up @@ -174,7 +174,7 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
expectFailure <- newIORef False
hasErrors <- newIORef False
mBlock <- newIORef Nothing
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< validInputs
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< IP.validInputs
let output' :: Bool -> Stanza -> IO ()
output' inputEcho msg = do
hide <- hideOutput inputEcho
Expand Down Expand Up @@ -326,7 +326,8 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
liftIO (parseInput codebase curPath getProjectRoot numberedArgs patternMap args)
>>= either
-- invalid command is treated as a failure
( \msg -> do
( \failure -> do
let msg = reportParseFailure failure
liftIO $ outputUcmResult msg
liftIO $ maybeDieWithMsg msg
Cli.returnEarlyWithoutOutput
Expand Down
Loading

0 comments on commit 0897ae4

Please sign in to comment.