xonsh/tests
Daniel Shimon 224fc55e41
Completion context (#4017)
* completion-context: Add CompletionContextParser placeholder

Implements the xonsh (tab-)completion context parser.
This parser is meant to parse a (possibly incomplete) command line.

* completers: tools: Implement ``contextual_completer`` decorator

This is used to mark completers that want to use the parsed completion context.

* completers: Enable using contextual completers in xonsh/completer.py

* completers: readline, ptk, jupyter: Enable using contextual completers

Pass ``multiline_text`` and ``cursor_index`` to ``Completer.complete()``

* parsers: base: Refactor out a ``raise_parse_error`` function

* tokenize: Enable ``tolerant`` mode

If ``tolerant`` is True, yield ERRORTOKEN instead of
    throwing an exception when encountering an error.

* lexer: Enable ``tolerant`` mode

Tokenize without extra checks (e.g. paren matching).
When True, ERRORTOKEN contains the erroneous string instead of an error msg.

* tests: lexer: Test ``tolerant`` mode

* completion-context: Implement simple CommandContext parsing

* completion-context: tests: Test simple CommandContext parsing

* completion-context: Implement parsing sub-commands

* completion-context: tests: Test parsing sub-commands

* completion-context: Add news file

* completion-context: parser: Add parser table path to relevant locations

Code-coverage, mypy ignore list, etc.

* completion-context: Implement parsing partial strings and line continuations

* completion-context: tests: Test parsing partial strings and line continuations

* completion-context: Convert ``Span`` object to a ``slice``

* completion-context: Refactor out ``create_command`` and ``cursor_in_span``

* completion-context: Implement handling empty commands

* completion-context: tests: Test handling empty commands

* completion-context: Implement handling multiple commands

Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`

* completion-context: tests: Test handling multiple commands

Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`

* completion-context: Implement handling python context

* completion-context: tests: Test handling python context

* completers: tools: Add `contextual_command_completer`

* completers: Make `complete_skipper` contextual

* completers: Make `complete_from_man` contextual

* completers: Make `complete_from_bash` contextual and add test

* completers: Make `complete_pip` contextual and update tests

* completers: Keep opening string quote if it exists

* completion-context: Handle cursor after a closing quote

For example - cursor at the end of ``ls "/usr/"``.
1. The closing quote will be appended to all completions.
 I.e the completion ``/usr/bin`` will turn into ``/usr/bin"``
2. If not specified, lprefix will cover the closing prefix.
 I.e for ``ls "/usr/"``, the default lprefix will be 6 to include the closing quote.

* completion-context: tests: Test handling cursor after a closing quote

* completion-context: Fix bug with multiple empty commands

e.g. `;;;`

* completion-context: tests: Speed up tests

From ~15 seconds to ~500 ms

* completion-context: Expand commands and subcommands

* completion-context: Simplify `commands` rules

* completion-context: Simplify `sub_expression` rules

* completion-context: Simplify editing a multi-command token

* completion-context: Inline `create_command`

* completion-context: Implement `contextual_command_completer_for` helper

* completers: Make `complete_cd`/`complete_rmdir` contextual and add tests

* completers: path: Don't append a double-backslash in a raw string

When completing a path, if a raw string is used (e.g. `r"C:\Windows\"`),
there's no reason to append a double-backslash (e.g. `r"C:\Windows\\"`).

* completers: Make `complete_xonfig`/`complete_xontrib` contextual and add tests

* completers: Make `complete_completer` contextual and add tests

* completers: Make `complete_import` contextual and add tests

* completion-context: Add python `ctx` attribute

* completion: tools: Simplify `RichCompletion` attributes handling

* completers: Make `base`, `python`, and `commands` contextual

* Add tests
* No need for `python_mode` completer anymore

* completion: tools: Add `append_space` attribute to `RichCompletion`

* completion-context: Get all lines in a main python context

* xontrib: jedi: Make the `jedi` completer contextual

* completers: tools: Remove `get_ptk_completer` and `PromptToolkitCompleter.current_document`

These aren't needed anymore now that contextual completers can access the multiline code (via `PythonContext.multiline_code`).

* completion-context: ptk: Expand aliases

* completion-context: jupyter: Expand aliases and fix line handling

* completer: Preserve custom prefix after closing quote

* completers: bash: Ensure bash completion uses the complete prefix

* completers: pip: Append a space after a pip command

* completers: pip: Prevent bad package name completions

* completers: Remove a common prefix from `RichCompletion` if `display` wasn't provided

* completion-context: Treat cursor at edge of `&& || | ;` as normal args

This will be used for completing a space

* completers: Complete end proc keywords correctly
2021-03-30 13:37:56 -04:00
..
aliases black updates to tests and docs 2020-08-26 10:10:59 -05:00
bin Run same wc,pwd,cat from tests/bin on Windows. 2020-08-10 01:43:51 -04:00
completers Completion context (#4017) 2021-03-30 13:37:56 -04:00
fake_lib more mocks for test_xonfig_kernel 2020-09-23 04:35:44 -04:00
histories Fix tests 2020-09-23 21:15:37 +02:00
man1 tests for man completion 2015-06-17 22:58:05 +02:00
procs Procs Initial Refactor (#3897) 2020-10-20 10:21:11 -04:00
prompt Add a better test suite for "vc.py", and fix "include_untracked" logic (#4041) 2021-01-05 09:26:19 -05:00
scripts xonsh script.xsh should not fail over 2017-01-11 21:59:42 +08:00
test_lib Fix legitimate builtins has no attribute __xonsh__ errors 2020-08-10 13:24:10 +02:00
xontribs Completion context (#4017) 2021-03-30 13:37:56 -04:00
xpack test subpackage 2015-03-29 22:53:33 -05:00
.somedotfile dotfile matching 2018-09-12 18:12:02 -04:00
bashrc.sh added tests for foreign shells 2015-10-10 19:52:53 -04:00
batch.bat Add test for sourcing bat file on windows 2016-04-18 00:41:11 +02:00
conftest.py Finalize f-string handler transition 2020-08-17 13:41:11 +02:00
run_pwd.xsh more fixes 2016-09-09 00:58:32 -04:00
sample.xsh fixed up dashing 2018-11-08 13:16:44 -05:00
test_aliases.py Add 'dict' merging operation for the aliases class (#4037) 2021-01-04 12:44:21 -05:00
test_ansi_colors.py ansi color fix + unit tests extended with new (non-pygments) values 2020-10-27 17:28:19 +01:00
test_ast.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_base_shell.py many test fixes 2018-09-13 14:03:35 -04:00
test_bashisms.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_builtins.py Procs Initial Refactor (#3897) 2020-10-20 10:21:11 -04:00
test_cli_utils.py Completer py api (#4018) 2020-12-16 14:26:22 -05:00
test_color_tools.py Fix tests 2020-09-23 21:15:37 +02:00
test_commands_cache.py use isinstance for check type 2019-05-23 01:12:58 +09:00
test_completer.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_completion_context.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_contexts.py black tests 2018-08-30 09:18:49 -05:00
test_dirstack.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_dirstack_unc.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_environ.py Add groups to env vars (#4026) 2021-01-04 12:21:44 -05:00
test_events.py some fixes, but not enough 2019-02-12 18:32:11 -05:00
test_execer.py Add execx/evalx EOL tests 2020-03-19 11:56:11 +01:00
test_foreign_shells.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_history.py Fix garbage collection of JSON history specified in seconds. (#4098) 2021-03-22 16:20:36 -04:00
test_history_sqlite.py Add $HISTCONTROL=ignorespace support (#4062) 2021-01-25 16:37:29 -05:00
test_imphooks.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_integrations.py Add test for leading variable initialization 2020-09-04 21:55:12 +02:00
test_jsonutils.py black tests 2018-08-30 09:18:49 -05:00
test_jupyter_kernel.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_lazyasd.py black tests 2018-08-30 09:18:49 -05:00
test_lazyjson.py black tests 2018-08-30 09:18:49 -05:00
test_lexer.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_main.py Py39 support (#4101) 2021-02-17 12:31:33 -05:00
test_man.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_mpl.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_news.py Remove vended ptk (#4107) 2021-03-01 11:56:32 -05:00
test_parser.py Py39 support (#4101) 2021-02-17 12:31:33 -05:00
test_path_completers.py Path complete given path literal (#3828) 2020-11-16 09:46:42 -05:00
test_pipelines.py Added casting CommandPipeline to int, hash, str (#4205) 2021-03-30 13:36:01 -04:00
test_platform.py black tests 2018-08-30 09:18:49 -05:00
test_ptk_completer.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_ptk_highlight.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_ptk_history.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_ptk_multiline.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_ptk_shell.py Cleanup remaining vended ptk bits (#4130) 2021-03-01 16:55:23 -05:00
test_pyghooks.py re-apply original changes 2020-10-27 15:23:58 +01:00
test_python_completers.py Completion context (#4017) 2021-03-30 13:37:56 -04:00
test_readline_shell.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_shell.py feat: Added ability to set XONSH_HISTORY_FILE (#4175) 2021-03-16 17:07:11 -04:00
test_tools.py Add $COMPLETION_MODE='menu-complete' to enable readline menu-complete (#3876) 2020-11-05 16:12:15 -05:00
test_vox.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
test_wizard.py Flake8 1 (#3550) 2020-05-05 06:42:28 -04:00
test_xonfig.py more mocks for test_xonfig_kernel 2020-09-23 04:35:44 -04:00
test_xonsh.xsh many test fixes 2018-09-13 14:03:35 -04:00
test_xontribs.py refactor: replace xontribs.json with xontribs_meta.py 2020-11-10 22:12:27 +05:30
test_xoreutils.py black updates to tests and docs 2020-08-26 10:10:59 -05:00
tools.py Cleanup per review. 2020-09-11 01:11:29 -04:00