Skip to content

Commit

Permalink
complete: use conditional-sync for cobraV2 completions
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Nov 16, 2023
1 parent ba2b886 commit 595f905
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- decode: work around `convert-meta on` in bash >= 5.2 with broken locale (reported by 3ximus) `#D2069` 226f9718
- canvas: adjust GraphemeClusterBreak of hankaku-kana voiced marks `#D2077` 31d168cc
- canvas: update tables and grapheme clusters for Unicode 15.1.0 `#D2078` 503bb38b 9d84b424 9d84b424
- complete: use conditional-sync for cobraV2 completions (reported by sebhoss) `#D2084` xxxxxxxx

## Contrib

Expand Down
30 changes: 28 additions & 2 deletions lib/core-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@ function ble/complete/progcomp/.filter-and-split-compgen {
return 0
} 2>/dev/null

function ble/complete/progcomp/.cobraV2.patch {
function ble/complete/progcomp/patch:cobraV2/extract_activeHelp.patch {
local cobra_version=$1
if ((cobra_version<10500)); then
local -a completions
Expand Down Expand Up @@ -3628,6 +3628,21 @@ function ble/complete/progcomp/.cobraV2.patch {
fi
}

function ble/complete/progcomp/patch:cobraV2/get_completion_results.advice {
local -a orig_words
orig_words=("${words[@]}")
local -a words
words=(ble/complete/progcomp/patch:cobraV2/get_completion_results.invoke "${orig_words[@]:1}")
ble/function#advice/do
}
function ble/complete/progcomp/patch:cobraV2/get_completion_results.invoke {
local -a invoke_args; invoke_args=("$@")
local invoke_command="${orig_words[0]} \"\${invoke_args[@]}\""
ble/util/conditional-sync \
'builtin eval -- "$invoke_command"' \
"! ble/complete/check-cancel <&$_ble_util_fd_stdin" 128 progressive-weight:killall
}

## @fn ble/complete/progcomp/.compgen opts
##
## @param[in] opts
Expand Down Expand Up @@ -3735,7 +3750,18 @@ function ble/complete/progcomp/.compgen {
if ble/is-function "__${comp_func#__start_}_extract_activeHelp"; then
cobra_version=10500 # v1.5.0 (Release 2022-06-21)
fi
ble/function#advice around "$target" "ble/complete/progcomp/.cobraV2.patch $cobra_version"
ble/function#advice around "$target" "ble/complete/progcomp/patch:cobraV2/extract_activeHelp.patch $cobra_version"
fi

# https://github.com/akinomyoga/ble.sh/issues/353#issuecomment-1813801048
# Note: Some programs can be slow to generate completions for internet
# access or another reason. Since the go programs called by cobraV2
# completions are supposed to be an independent executable file (without
# being shell functions), we can safely call them inside a subshell for
# ble/util/conditional-sync.
local target=__${comp_func#__start_}_get_completion_results
if ble/is-function "$target"; then
ble/function#advice around "$target" ble/complete/progcomp/patch:cobraV2/get_completion_results.advice
fi
fi

Expand Down
15 changes: 15 additions & 0 deletions note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,21 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2023-11-16

* completino(kubectl): 補完で hang する。timeout は 32s ある (reported by sebhoss) [#D2084]
https://github.com/akinomyoga/ble.sh/issues/353#issuecomment-1811985511

提供された補完設定を確認する限りは cobraV2 による補完設定の様である。実際に
binary を呼んでいる箇所を conditional-sync に置き換えれば十分だろう。binary
は words[0] を使って読み取っている。基本的には words[0] を置き換えるだけで
処理を摩り替える事ができるだろう。実装した。

動作確認も行った。kubectl に対しては確認していないが gh に対して gh を
sleep 5 に置き換える事によって遅い時の振る舞いのテストを行った。置き換える
前はちゃんと動いていて、置き換えた後も補完は動かないが block する事なく入力
する事ができる。OK

2023-11-10

* contrib/integration/fzf-git: エラーメッセージが出る (reported by dgudim) [#D2083]
Expand Down

0 comments on commit 595f905

Please sign in to comment.