Skip to content

Conversation

@nathanrpage97
Copy link

@nathanrpage97 nathanrpage97 commented Feb 25, 2021

Provide an autocomplete that is similar to IPython for files.

Will face issues with a few of the different edge cases (including spaces in files). But it gives the general idea of how to implement.

@nathanrpage97 nathanrpage97 marked this pull request as draft February 25, 2021 00:46
@nathanrpage97 nathanrpage97 marked this pull request as ready for review February 25, 2021 01:02
@jonathanslenders
Copy link
Member

There is a PathCompleter built-in: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/completion/filesystem.py#L13
Is this different? Or can the example use that completer?

@nathanrpage97
Copy link
Author

oh wow, I couldn't find anything in the docs on this. Let me close this.

@nathanrpage97
Copy link
Author

Actually, the big difference is that this completer works at any "word" instead of the whole document text.

@nathanrpage97 nathanrpage97 reopened this Feb 26, 2021
@nathanrpage97
Copy link
Author

Let me see if I can add a flag to the builtin PathCompleter that will enable it to be used from any position.

@jonathanslenders
Copy link
Member

If the path can appear at any "word" position, how is the output text handled by the application in that case?

In ptpython, PathCompleter is for instance combined with GrammarCompleter to allow path completion within quoted strings, (also automatically quoting/unquoting during completion). See: https://github.com/prompt-toolkit/ptpython/blob/master/ptpython/completer.py#L87 NestedCompleter also works nicely with PathCompleter I think. (https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/completion/nested.py#L16)

I prefer different completers to be composable, rather then having all possible options and complexity in each completer. We could maybe split the WordCompleter in one completer that takes care of the tokenization and another one that holds the dictionary and is actually a SentenceCompleter (this latter does not exist, but that would be if sentence=True was passed to WordCompleter). What you want is then to compose this new WordCompleter with the Pathcompleter.

@nathanrpage97 nathanrpage97 marked this pull request as draft February 26, 2021 20:50
@nathanrpage97
Copy link
Author

nathanrpage97 commented Feb 26, 2021

Just saw this message. How about providing the ptpython version, simplified to just the path component, in the examples/ as AdvancedPathCompleter? That way it's not introducing too much opinionated complexity to the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants