Skip to content
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
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ shellCompletion envPAT completionStyle subcommand curWord prevWord =

gitCompletions : Config => Lazy Octokit -> Promise' (List String)
gitCompletions gh =
gitOpts gh completionStyle subcommand curWord prevWord
githubOpts gh completionStyle subcommand curWord prevWord

completions : Promise' (List String)
completions = do
Expand Down
40 changes: 27 additions & 13 deletions src/ShellCompletion/Common.idr
Original file line number Diff line number Diff line change
Expand Up @@ -260,24 +260,38 @@ configuredOpts _ _ _ _ = []

hashifyIfPrefix : (substr : String) -> (issueNumber : Integer) -> Maybe String
hashifyIfPrefix substr num =
let hashified = hashify $ show num
in if substr `isPrefixOf` hashified
then Just hashified
let numStr := show num
in if substr `isPrefixOf` numStr
then Just . hashify $ numStr
else Nothing

namespace TestHashifyIfPrefix
testUnhashedMatch : hashifyIfPrefix "12" 1234 === Just "#1234"
testUnhashedMatch =
let postulateIntegerShown : show 1234 === "1234"
postulateIntegerShown = believe_me (Refl {x="1234"})
in rewrite postulateIntegerShown in Refl

testUnhashedNonMatch : hashifyIfPrefix "34" 1234 === Nothing
testUnhashedNonMatch =
let postulateIntegerShown : show 1234 === "1234"
postulateIntegerShown = believe_me (Refl {x="1234"})
in rewrite postulateIntegerShown in Refl

export
gitOpts : Config =>
Lazy Octokit
-> (s : CompletionStyle)
-> (subcommand : String)
-> (curWord : String)
-> (prevWord : String)
-> Promise' (List String)
gitOpts @{config} gh _ "quick" partialArg _ = do
githubOpts : Config =>
Lazy Octokit
-> (s : CompletionStyle)
-> (subcommand : String)
-> (curWord : String)
-> (prevWord : String)
-> Promise' (List String)
githubOpts @{config} gh _ "quick" partialArg _ = do
issues <- listIssues @{gh} config.org config.repo
let partialArg' = unhashify partialArg
let str = stringify . completionResult
pure $
mapMaybe (\i => str . (, i.title) <$> hashifyIfPrefix partialArg i.number)
mapMaybe (\i => str . (, i.title) <$> hashifyIfPrefix partialArg' i.number)
issues
gitOpts _ _ _ _ _ = pure []
githubOpts _ _ _ _ _ = pure []

4 changes: 2 additions & 2 deletions src/ShellCompletion/Util.idr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public export
unslugify : String -> String
unslugify = pack . replaceOn '◌' ' ' . unpack

export
public export
hashify : String -> String
hashify = strCons '#'

Expand Down Expand Up @@ -56,7 +56,7 @@ namespace TestUnhashify
test5 : unhashify "\\#hello" = "hello"
test5 = Refl

export
public export
isPrefixOf : (s : CompletionStyle) => String -> CompletionResult -> Bool
isPrefixOf str = isPrefixOf str . name

Expand Down