fix: Wrong completion context for chained commands in zsh
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Start with lib/src/installer/shell_completion_configuration.dart and CompletionState.fromEnvironment, which the issue identifies as passing and reading the completion context. Check the existing completion tests and how the words passed after completion -- relate to COMP_CWORD. Done means commands after |, && or ; suggest the current command’s options, while existing bash completion still works.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Thank you for this cool lib! I'm facing a minor bug when used with zsh.
In zsh, completing a command that isn't at the start of the command line (after |, && or ;) uses the wrong context. The zsh script passes COMP_LINE="$BUFFER", which is zsh's whole edit buffer, and CompletionState.fromEnvironment reads the arguments from COMP_LINE. So everything typed before the current command is treated as CLI arguments.
Steps To Reproduce
Take a CLI my_cli built on CompletionCommandRunner, with commands foo and bar that have different options, and install its completion in zsh with my_cli install-completion-files.
my_cli foo | my_cli bar <TAB>suggestsfoo's options. The request is parsed asfoo | my_cli bar '', sofoois taken as the command being completed.cd somewhere && my_cli bar <TAB>suggests nothing, so zsh falls back to file names.
Without a shell, this is the request zsh sends for step 1:
ZSH_NAME=zsh COMP_LINE='my_cli foo | my_cli bar ' COMP_POINT=24 COMP_CWORD=2 \
my_cli completion -- my_cli bar ''
It prints foo's options.
Expected Behavior
A command after |, && or ; completes the same way as at the start of the line. Both my_cli foo | my_cli bar <TAB> and cd somewhere && my_cli bar <TAB> suggest bar's options, just like my_cli bar <TAB>. Bash already behaves this way.
Additional Context
Cause
- The zsh template in
lib/src/installer/shell_completion_configuration.dartrunsCOMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" … completion -- "${words[@]}".$BUFFERis the whole edit buffer, while$wordsand$CURRENTcover only the current command. CompletionState.fromEnvironmenttakes the arguments fromCOMP_LINE(line.trimLeft().split(' ').skip(1)) and ignores the words passed aftercompletion --.- Bash isn't affected, because bash itself limits
COMP_LINEto the current command. With bash 3.2,echo x | mycmd a <TAB>setsCOMP_LINEtomycmd a.
Suggested fix
Build the arguments from the words the scripts already pass after completion --, up to COMP_CWORD, instead of from COMP_LINE. Both scripts pass only the current command's words there, so this fixes zsh without changing the scripts or making users reinstall them.
Workaround
Until this is fixed, a CLI can narrow COMP_LINE itself before the request is handled, in its CompletionCommandRunner subclass:
@override
Future<int?> runCommand(ArgResults topLevelResults) {
final command = topLevelResults.command;
if (command?.name == HandleCompletionRequestCommand.commandName) {
final words = command!.rest; // the words after `completion --`
final environment = Platform.environment;
final cword = int.tryParse(environment['COMP_CWORD'] ?? '');
if (cword != null && cword >= 0 && cword < words.length) {
final line = words.take(cword + 1).join(' ');
environmentOverride = {...environment, 'COMP_LINE': line, 'COMP_POINT': '${line.length}'};
}
}
return super.runCommand(topLevelResults);
}
Environment
- cli_completion 0.6.0
- Dart 3.13.3
- zsh 5.9, macOS (arm64)
- Ngôn ngữ chính
- Dart
- Star
- 54
- Fork
- 6
- Merge trung bình
- 24 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của VeryGoodOpenSource/cli_completion
-
feature p3
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
VeryGoodOpenSource/cli_completion#91 · 2 bình luận · 1 reaction ·
-
Better shell completionĐang mởfeature p3
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
VeryGoodOpenSource/cli_completion#90 · 1 bình luận · 1 reaction ·
-
feat: CLI-user configurable auto installCó thể đã có người làm @vgvbot đã nhận 56 ngày trước. Đang mởfeature p2
VeryGoodOpenSource/cli_completion#55 · 1 bình luận · 1 reaction · 1 người được giao ·
-
feature p2
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
VeryGoodOpenSource/cli_completion#47 · 2 bình luận · 2 reaction ·
Tất cả issue của VeryGoodOpenSource/cli_completion
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: The daily reminder keeps its old language after the app language changesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbacklog:low bug localization
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
simonoppowa/OpenNutriTracker#1366 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Mobile reading view shows a sender without display name as "<[email protected]>" with angle bracketsĐang mởai-driven-qa bug Cosmetic
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linagora/tmail-flutter#4999 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
waiting for response
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 72/100
flutter/flutter#194381 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
newrelic/newrelic-flutter-agent#243 · 3 bình luận ·