Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow UCM commands to have “unprocessed” arguments #5549

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading