Skip to content

WIP: fix #2570 compspec -o fallback semantics in line completion - #2594

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2570-compspec-fallback
Nov 2, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2570-compspec-fallback

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Engine root-cause fix for niubash#828 (TAB completion zero candidates whenever a complete -D default compspec — e.g. fzf's — yields empty COMPREPLY).

What

complete_line_candidates_with_dynamic parsed the compspec -o options but never applied their fallback semantics in the interactive line-completion path. This change mirrors the compgen path's dirnames/plusdirs block into the line path and materializes the -o default / -o bashdefault sets on a still-empty result, in GNU's own layering order.

GNU ownership (bash-5.3 tree, read first-hand):

  • pcomplete.c:1435-1457 gen_compspec_completions: dirnames replaces an empty result; plusdirs appends whenever the dirnames branch did not fire.
  • bashline.c:1801-1822 attempt_shell_completion + bashline.c:1830 bash_default_completion: default = readline filename completion; bashdefault = $-variable / ~-username / @-hostname / command-position sets only (a plain word completes nothing under bashdefault alone).
  • bashline.c:4930 bash_directory_completion_matches: appended directories are word-filtered.

Verified against GNU bash 5.3.20 on a real PTY across a 14-case matrix before coding.

Pins & guards

  • tests/issue2570_compspec_fallback.rs: 9 tests — 9 passed / 0 failed (build slot + scrubbed cargo; corroborated by direct parallel + serial runs of the built binary).
  • Guards: 19 completion/compgen targets — 82 passed / 0 failed (issue523_compgen_quoted_tilde_regressions is #![cfg(windows)], covered by Windows CI); issue1597 included at 14/14.

Full record (GNU law, oracle matrix, per-option trigger table, phantom-tally adjudication note, residuals): ~/workspace/rubash-wave-20261102/w15-2570/REPORT.md in the wave workdir.

Residuals: bashdefault's $(/${ command-substitution shapes and glob-pattern words are not materialized; the pre-existing both-required -P/-S wrap condition is untouched.

Refs #2570

complete_line_candidates_with_dynamic parsed COPT_DIRNAMES /
COPT_PLUSDIRS / COPT_DEFAULT / COPT_BASHDEFAULT but never applied
their fallback semantics, so a compspec whose function yields an
empty COMPREPLY produced zero candidates in the interactive line
path. With fzf's -D registration present that blanks TAB completion
for every command on unix (niubash#828).

GNU ownership, read first-hand in the bash-5.3 tree:
- pcomplete.c:1435-1457 gen_compspec_completions: dirnames REPLACES
  an empty generated result; plusdirs APPENDS directory candidates
  whenever the dirnames branch did not fire (empty and non-empty
  results alike), generated via gen_action_completions(CA_DIRECTORY)
  -> bashline.c:4930 bash_directory_completion_matches, i.e.
  word-filtered like the CA_DIRECTORY action.
- bashline.c:1801-1822 attempt_shell_completion: with the result
  still empty, COPT_DEFAULT leaves readline's filename completion
  open and COPT_BASHDEFAULT falls into bash_default_completion
  (bashline.c:1830): $-variable, ~-username, @-hostname and
  command-position sets; a plain argument word completes nothing
  under -o bashdefault alone.

The fix mirrors the compgen path's existing dirnames/plusdirs block
into the line path (same directory_candidates_matching helper,
fallback candidates never -X filtered, never -P/-S wrapped) and
materializes the default/bashdefault sets on the still-empty result
via two new helpers. Behavior verified against GNU bash 5.3.20 on a
real PTY across a 14-case matrix (empty/non-empty x
default/bashdefault/dirnames/plusdirs x plain/$/~/@ words).

Regression pins: tests/issue2570_compspec_fallback.rs (9 tests:
-o default fill, bashdefault plain-empty/$/~ shapes, dirnames fill,
plusdirs append + word-filtering, no-option no-fallback, the
fzf-shaped -D registration end to end, dirnames-over-default
precedence, dirnames non-empty no-fire, default prefix filtering).
Guards: 19 completion/compgen targets, 82 passed / 0 failed
(issue523 is cfg(windows)-only). Full record in the wave REPORT.md.

Refs #2570
@caomengxuan666
caomengxuan666 force-pushed the fix/2570-compspec-fallback branch from 3e18d01 to 11a8b32 Compare November 2, 2026 10:11
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 2, 2026 10:42
@caomengxuan666
caomengxuan666 merged commit 7b03045 into master Nov 2, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 2, 2026
…te helpers (captain integration)

The #2575 settings threading changed path_completion_candidates to take
&ReadlineCompletionSettings, but the #2594 fallback helpers
(directory_candidates_matching / filename_candidates_matching) predated
the merge point and kept the old arity, so the combined tree did not
compile. Per the #2575 design (apply_completion_actions_with_settings:
the line path threads the live readline settings; pcomplete.c's static
generators behind the compgen builtin compare with defaults), the line
completion callers now pass the live settings and the compgen-builtin
callers pass ReadlineCompletionSettings::default(). No behavior change
beyond the settings the fallback listings now honor on the line path
(hidden-file suppression inside path_completion_candidates).
caomengxuan666 added a commit that referenced this pull request Nov 3, 2026
…ry '/' under filename semantics (captain)

The #2621 engine change materializes GNU's rl_filename_completion_desired mark (pcomplete.c:1461-1462) in the candidate list itself, because this engine's list is final for the host. The six fallback pins from #2594 asserted the pre-marking bare contract; they now assert the marked forms, and a new pin covers the -o filenames generator face plus its gating (no option -> bare).
@caomengxuan666
caomengxuan666 deleted the fix/2570-compspec-fallback branch November 3, 2026 09:07
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.

1 participant