ipython/ipython

Only trigger filename completion in special syntax or strings

クローズ

#14,501 opened on 2024/08/22

 (3 件のコメント) (5 件のリアクション) (0 人の担当者)Python (4,400 件のフォーク)batch import
help wantedtab-completion

Repository metrics

Stars
 (16,095 個のスター)
PR merge metrics
 (平均マージ 11d 1h) (30d で 22 merged PRs)

説明

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. https://github.com/ipython/ipython/pull/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 https://github.com/ipython/ipython/pull/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 https://github.com/ipython/ipython/issues/11530)

コントリビューターガイド