Skip to content

Strictly suppress file_matcher in attribute completions#15081

Merged
krassowski merged 13 commits into
ipython:mainfrom
Darshan808:suppress-file-completion-enh
Nov 28, 2025
Merged

Strictly suppress file_matcher in attribute completions#15081
krassowski merged 13 commits into
ipython:mainfrom
Darshan808:suppress-file-completion-enh

Conversation

@Darshan808
Copy link
Copy Markdown
Collaborator

Fixes #15031

Description

The current logic only suppresses matchers if they are in the suppress set and there are matching results. As a result, file_matcher can still display file matches when attribute completion fails. This PR updates the logic to always suppress file_matcher during attribute completion, regardless of whether any attributes were successfully matched.

@krassowski krassowski added this to the 9.8 milestone Nov 21, 2025
Copy link
Copy Markdown
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break completion on ls automagic:

Before This PR as of now
Image Image

Can you add a test for the ls case?

COPYING.rst
IPython
LICENSE
MANIFEST.in
README.rst
SECURITY.md
__pycache__
_build_meta.py
codecov.yml
docs
examples
ipython.egg-info
long_description.rst
pyproject.toml
scripts
setup.cfg
setup.py
setupbase.py
tests
tools case
@Darshan808
Copy link
Copy Markdown
Collaborator Author

Oops, I didn't realize backticks inside double quotes get executed. My git commit -m "fix ls . case" ended up expanding the command.
Anyways, cases like ls file.<tab> still don't complete or suggest files with the same name but different extensions, since they're treated as attribute completion. This doesn't seem trivial to fix. Should we address it in this PR, or would it be better to open a separate issue?

@krassowski
Copy link
Copy Markdown
Member

Anyways, cases like ls file. still don't complete or suggest files with the same name but different extensions, since they're treated as attribute completion. This doesn't seem trivial to fix. Should we address it in this PR, or would it be better to open a separate issue?

We should not introduce regressions in this PR. Let's take a step back and think about it differently.

I think there is only a limited set of commands which can be auto-evaluated without ! which are stored in get_ipython().alias_manager.aliases. It feels that we should determine whether we are completing in such CLI alias, line magics (%), or bang expressions (!). This would be similar to _determine_completion_context but I would probably add a separate method for simplicity. The logic for detecting if we are completing in cli-alias should be along the lines of

does the line start with a string enumerated in aliases followed by a whitespace character and there is no Python variable which overshadows it (as in there is no ls = 1 or similar defined)

Comment thread IPython/core/completer.py Outdated
Comment on lines +3698 to +3716
file_matcher_id = _get_matcher_id(self.file_matcher)
python_matcher_id = _get_matcher_id(self.python_matcher)
jedi_matcher_id = _get_matcher_id(self._jedi_matcher)
# If this is attribute completion and it explicitly
# recommends suppressing the file matcher, do so.
if (
(matcher_id == python_matcher_id or matcher_id == jedi_matcher_id)
and isinstance(suppression_recommended, set)
and file_matcher_id in suppression_recommended
):
should_suppress = True
else:
should_suppress = (
(suppression_config is True)
or (
suppression_recommended
and (suppression_config is not False)
)
) and has_any_completions(result)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at how this requires hard-coding matcher-specific behaviour (or breaking backward compatibility) I now think it would be better to go with your initial idea of short-circuiting in file_matcher itself.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense!

Copy link
Copy Markdown
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Darshan808!

@krassowski krassowski merged commit 3255e6f into ipython:main Nov 28, 2025
20 checks passed
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.

Suppress paths tab completion when completing a method/attribute

2 participants