mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Fix auto-suggestion completion stacking if no normal completion exists (#4970)
* Fix auto-suggestion completion stacking if no normal completion exists * Add tests for auto-suggest completions
This commit is contained in:
parent
1d61d8d711
commit
9c1a751fee
3 changed files with 53 additions and 0 deletions
23
news/4668-fix-autocomplete-suggest.rst
Normal file
23
news/4668-fix-autocomplete-suggest.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* #4668 Fix ptk completion stacking when auto-suggest is on and no normal completions are generated.
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -54,6 +54,35 @@ def test_rich_completion(completion, lprefix, ptk_completion, monkeypatch, xessi
|
|||
assert completions == [ptk_completion]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"completions, document_text, ptk_completion",
|
||||
[
|
||||
(set(), "", "test_completion"),
|
||||
(set(), "test_", "test_completion"),
|
||||
({RichCompletion("test", 4, "test()", "func")}, "test", "test_completion"),
|
||||
],
|
||||
)
|
||||
def test_auto_suggest_completion(completions, document_text, ptk_completion, xession):
|
||||
lprefix = len(document_text)
|
||||
|
||||
xonsh_completer_mock = MagicMock()
|
||||
xonsh_completer_mock.complete.return_value = completions, lprefix
|
||||
|
||||
xession.env["AUTO_SUGGEST_IN_COMPLETIONS"] = True
|
||||
|
||||
ptk_completer = PromptToolkitCompleter(xonsh_completer_mock, None, None)
|
||||
ptk_completer.reserve_space = lambda: None
|
||||
ptk_completer.suggestion_completion = lambda _, __: ptk_completion
|
||||
|
||||
document_mock = MagicMock()
|
||||
document_mock.text = document_text
|
||||
document_mock.current_line = document_text
|
||||
document_mock.cursor_position_col = lprefix
|
||||
|
||||
auto_suggested = list(ptk_completer.get_completions(document_mock, MagicMock()))
|
||||
assert PTKCompletion(ptk_completion, -lprefix) in auto_suggested
|
||||
|
||||
|
||||
EXPANSION_CASES = (
|
||||
(
|
||||
"sanity",
|
||||
|
|
|
@ -72,6 +72,7 @@ class PromptToolkitCompleter(Completer):
|
|||
if sug_comp is None:
|
||||
pass
|
||||
elif len(completions) == 0:
|
||||
plen = len(prefix)
|
||||
completions = (sug_comp,)
|
||||
else:
|
||||
completions = set(completions)
|
||||
|
|
Loading…
Add table
Reference in a new issue