diff --git a/changelog.md b/changelog.md index cde37bd6..d82ae66a 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,7 @@ Breaking Changes Features --------- * Add `--warn-batch` flag, which is off by default. +* Override `min_completion_trigger` for the `/command` form. Bug Fixes diff --git a/mycli/main_modes/repl.py b/mycli/main_modes/repl.py index 1c3d2247..adf8147e 100644 --- a/mycli/main_modes/repl.py +++ b/mycli/main_modes/repl.py @@ -102,6 +102,8 @@ def complete_while_typing_filter() -> bool: return True app = get_app() text = app.current_buffer.text.lstrip() + if text.startswith('/') and not text.startswith('/*'): + return True text_len = len(text) if text_len < MIN_COMPLETION_TRIGGER: return False diff --git a/mycli/myclirc b/mycli/myclirc index e48978d7..b61aecbe 100644 --- a/mycli/myclirc +++ b/mycli/myclirc @@ -9,7 +9,8 @@ show_warnings = False # possible completions will be listed. smart_completion = True -# Minimum characters typed before offering completion suggestions. +# Minimum characters typed before offering completion suggestions. Forward +# slash for a command is an exception which always offers completions. # Suggestion: 3. min_completion_trigger = 1 diff --git a/test/myclirc b/test/myclirc index 919f0f4e..5a744972 100644 --- a/test/myclirc +++ b/test/myclirc @@ -9,7 +9,8 @@ show_warnings = False # possible completions will be listed. smart_completion = True -# Minimum characters typed before offering completion suggestions. +# Minimum characters typed before offering completion suggestions. Forward +# slash for a command is an exception which always offers completions. # Suggestion: 3. min_completion_trigger = 1 diff --git a/test/pytests/test_main_modes_repl.py b/test/pytests/test_main_modes_repl.py index d7efc544..cfddd78e 100644 --- a/test/pytests/test_main_modes_repl.py +++ b/test/pytests/test_main_modes_repl.py @@ -283,6 +283,24 @@ def test_complete_while_typing_filter_covers_threshold_and_word_rules(monkeypatc assert repl_mode.complete_while_typing_filter() is True +def test_complete_while_typing_filter_always_completes_slash_commands( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(repl_mode, 'MIN_COMPLETION_TRIGGER', 3) + monkeypatch.setattr(repl_mode, 'get_app', lambda: SimpleNamespace(current_buffer=SimpleNamespace(text='/'))) + + assert repl_mode.complete_while_typing_filter() is True + + +def test_complete_while_typing_filter_does_not_treat_block_comments_as_slash_commands( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(repl_mode, 'MIN_COMPLETION_TRIGGER', 3) + monkeypatch.setattr(repl_mode, 'get_app', lambda: SimpleNamespace(current_buffer=SimpleNamespace(text='/*'))) + + assert repl_mode.complete_while_typing_filter() is False + + def test_repl_create_history(monkeypatch: pytest.MonkeyPatch) -> None: cli = make_repl_cli() monkeypatch.setenv('MYCLI_HISTFILE', '~/override-history')