Skip to content

fix(completion): fall back to shell path completion - #15442

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-nopyummnulxl
Jul 13, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-nopyummnulxl

Conversation

@Alizter

@Alizter Alizter commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Allow generated shell completion scripts to fall back to the shell's normal filename completion when cmdliner has no semantic completions to offer.

For bash, Dune now registers completion with -o default. For zsh and PowerShell, Dune keeps the cmdliner-generated completers unchanged under internal names and exposes small Dune-owned wrappers that fall back to the shell filename completer only when cmdliner returns no matches.

Related Issue and Motivation

Since #14779 moved completion script handling to cmdliner, commands such as dune runtest ... no longer fell through to normal path completion when Dune had no completions to return. This restores the expected shell fallback behavior.

Fixes #15431

Shell fallback references

Checklist

  • Tests added, if applicable.
  • Change log entry added for any user-facing changes.
  • Documentation added for any user-facing changes.

@Alizter
Alizter marked this pull request as draft July 7, 2026 20:22
@Alizter
Alizter force-pushed the push-nopyummnulxl branch from c5ea955 to 53d4f22 Compare July 7, 2026 21:55
@Alizter
Alizter requested a review from ElectreAAS July 7, 2026 21:57
@Alizter
Alizter marked this pull request as ready for review July 7, 2026 21:57
@shonfeder
shonfeder self-requested a review July 8, 2026 12:48
Comment thread bin/completion.ml Resolved

@ElectreAAS ElectreAAS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from my comments, I tested this with bash and zsh and it works :)

@Alizter
Alizter force-pushed the push-nopyummnulxl branch 2 times, most recently from 41b7075 to b1434f5 Compare July 10, 2026 17:20
@Alizter
Alizter marked this pull request as draft July 12, 2026 15:32
@Alizter

Alizter commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

Unfortunately -o bashdefault is not recognised on older versions of bash. We could either try -o bashdefault and fallback to dropping it, or drop it entirely. This however complicates the wrapper scripts so it's not clear if its worth it. I would probably err on the side of dropping because I don't see a good use-case for bash-directed completion at the moment.

@shonfeder @ElectreAAS any thoughts? I'll mark as draft until we sort this out. We could also defer looking into it for later.

@Alizter
Alizter force-pushed the push-nopyummnulxl branch from b1434f5 to e26e23f Compare July 12, 2026 16:02
@ElectreAAS

Copy link
Copy Markdown
Collaborator

-o bashdefault is not recognised on older versions of bash

I was going to ask what versions specifically, to check how old they were, but gnu.org is down so I can't even check. Incredible.
Yeah drop it

@Alizter
Alizter force-pushed the push-nopyummnulxl branch from e26e23f to bfc37ae Compare July 13, 2026 09:54
@Alizter
Alizter marked this pull request as ready for review July 13, 2026 09:55
@punchagan

Copy link
Copy Markdown
Contributor

I was going to ask what versions specifically, to check how old they were, but gnu.org is down so I can't even check. Incredible.

It seems to be supported from version 3.0 of bash, which is at least 20 years old ?

@shonfeder

Copy link
Copy Markdown
Member

I think it's ok to expect a bash updated in the last 20 years if you want completion?

@Alizter do you have a system where the completion is not working? Or what led you to think this would be a problem for users?

That said, it's only worth adding this flag if generally makes things better for users. Better to drop it if not, of course.

@Alizter

Alizter commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator Author

I was going to ask what versions specifically, to check how old they were, but gnu.org is down so I can't even check. Incredible.

It seems to be supported from version 3.0 of bash, which is at least 20 years old ?

The bash version that ships with macOS appears to be old due to the license change in bash 4.0 to GPLv3. I don't think its sensible supporting such an old version of bash, users on macos would be using zsh anyway.

@Alizter do you have a system where the completion is not working? Or what led you to think this would be a problem for users?

No, our bash completion tests were running on macos which used its default ancient bash. The solution is just to run on linux only.

I'll add the -o bashdefault flag back in and adjust the test guards.

@Alizter
Alizter force-pushed the push-nopyummnulxl branch from bfc37ae to 89ea680 Compare July 13, 2026 11:51
When cmdliner has no semantic completions to offer, let Dune completion scripts fall back to the shell normal filename completion instead of suppressing completion entirely.

Bash registers the generated completer with -o bashdefault and -o default. Zsh and PowerShell keep the cmdliner-generated completers unchanged under internal names, then expose Dune-owned wrappers that delegate to shell filename completion when cmdliner returns no matches.

Tests:
- ./dune.exe fmt
- ./dune.exe runtest test/blackbox-tests/test-cases/completion/commands.t test/blackbox-tests/test-cases/completion/bash.t
- nix develop path:. -i -c ./dune.exe runtest test/blackbox-tests/test-cases/completion/commands.t test/blackbox-tests/test-cases/completion/bash.t
- ./dune.exe build @check
- manual zsh probe via nix run nixpkgs#zsh: confirmed the generated wrapper reaches _default for a runtest path prefix
- manual PowerShell probe via nix run nixpkgs#powershell: confirmed TabExpansion2 returns completion/commands.t for a runtest path prefix

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the push-nopyummnulxl branch from 89ea680 to 89211c9 Compare July 13, 2026 13:29
@Alizter
Alizter merged commit 4aa9a49 into ocaml:main Jul 13, 2026
35 of 36 checks passed
@Alizter
Alizter deleted the push-nopyummnulxl branch July 13, 2026 15:15
@Alizter Alizter added this to the 3.25.0 milestone Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

completion doesn't fall through to underlying bash completion

4 participants