Skip to content

Only trigger filename completion in special syntax or strings #14501

Description

@jasongrout

Right now filename completions trigger in all sorts of situations, for example:

def f(x): pass
f(x=<TAB>

If there are a lot of files in a directory, this can overwhelm the completions.

To check this programmatically, you can do:

from IPython.core.completer import provisionalcompleter
with provisionalcompleter():
    print(list(i for i in get_ipython().Completer.completions('f(x=', 4) if 'file' in i._origin))

and notice that completions are returned for files in the local directory.

As mentioned here, it would be nice if completers had more semantic context about the match request automatically available to them (for example, if we were in a string, etc.). In this case, it would be great if the filename matcher only matched if we were in special syntax (e.g., lines starting with ! or a %magic line), or if we were in a string. #12128 implemented an "are we in a string" check for Jedi.

My proposal here is that we:

  1. abstract out the "are we in a string" check from Improves detection of whether tab-completion is in a string and suppresses Jedi #12128 to a function
  2. Use that function in the file matcher to only return matches if we are in a string or special syntax.

(FYI, another path completion issue is #11530)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions