Skip to content

Fix regression accepting pathname completion#1582

Merged
rolandwalker merged 1 commit intomainfrom
RW/fix-regression-source-accept-suggestion
Feb 19, 2026
Merged

Fix regression accepting pathname completion#1582
rolandwalker merged 1 commit intomainfrom
RW/fix-regression-source-accept-suggestion

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Feb 18, 2026

Description

Ensure that when accepting a pathname completion, the path as typed is accepted and not modified into an invalid path. See #1557 for an image. The regression is most evident when typing a path with a leading ./.

Changes

  • Use a Literal for the include argument to last_word()
  • Create a separate length-measurement string for pathname completions, based on a different last-word cleanup regex.
  • Remove some todo comments from tests which are now resolved.

The logic of length_based_on_path assumes that if any of the suggestions are pathnames, then all of the suggestions are pathnames, which is currently true, and likely to remain true.

It would be nice to have a test which simulated accepting the first suggestion, to check that the filled-in completion does not get mangled, as happened before.

Let's say this fixes #1557, because it fixes the actual regression. There are some other behaviors listed there which may not be desirable but were not caused by #1500 . Let's open separate issues if we want to do further work on pathname completion. For example, there is no pathname completion for \edit <pathname> at all. And completion on ~/ does not seem to provide candidates.

I'm also not 100% clear on the subtleties of last_word(), and why the alphanum_underscore cleanup regex is the best one for this case, but it does work exactly right per @scottnemes 's diagnosis, and the relevant change was indeed introduced in #1500. Maybe there should be a cleanup regex named pathnames, for clarity.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 18, 2026
@github-actions
Copy link

Findings (most severe first)

  1. Path completion can regress for filenames with - or .
    In get_completions, path completions now use last_word(..., include='alphanum_underscore') to compute the replacement length. That regex splits on - and .. Example: typing source my-file would yield last_for_len_paths == "file", so applying a completion like my-file.sql would replace only file, producing my-my-file.sql. Same for foo.bar.
    This is a correctness regression for common filenames. Consider using a pathname-specific regex that matches the last path segment (e.g., r"([^/\\\s]+)$"), or introduce a pathnames cleanup regex (as hinted in the PR body) and use that here.
    Files: mycli/sqlcompleter.py, mycli/packages/parseutils.py.

  2. length_based_on_path applies to all completions once any file suggestion appears
    If suggest_type() ever returns mixed types (e.g., file + keyword), length_based_on_path forces the path-based replacement length for non-path completions too. That will produce incorrect insertion lengths for those non-path items.
    If mixed types are impossible, consider asserting that or adding a guard. Otherwise compute start_position per completion type instead of globally.
    File: mycli/sqlcompleter.py.

Tests / Edge Cases

  1. Missing insertion correctness tests
    The new test checks the suggested texts, but not the start_position / actual inserted result. The regression was about mangled insertion, so a direct test that applies the completion would catch this and similar issues.
    File: test/test_smart_completion_public_schema_only.py.

  2. No coverage for - or . in filenames
    Add a test for completing source my-file or source foo.bar to protect against the regression described above.
    File: test/test_smart_completion_public_schema_only.py.

  3. Test writes a real file in CWD
    test_source_leading_dot_suggestions_completion creates/removes script_for_test_suite.sql in the repo root. If that file already exists, the test will truncate it. Consider using tmp_path + monkeypatch.chdir to isolate filesystem effects.
    File: test/test_smart_completion_public_schema_only.py.

If you want, I can sketch a minimal patch for the pathname regex + targeted tests.

@rolandwalker rolandwalker force-pushed the RW/fix-regression-source-accept-suggestion branch from bbafa1b to 17d3d1c Compare February 18, 2026 11:30
Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

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

Nice! Verified path completion behavior is working as expected.

Ensure that when accepting a pathname completion, the path as typed is
accepted and not modified into an invalid path.

Changes
 * use a Literal for the include argument to last_word()
 * create a separate length-measurement string for pathname completions,
   based on a different last-word cleanup regex
 * remove some todo comments from tests which are now resolved

The logic of length_based_on_path assumes that if _any_ of the
suggestions are pathnames, then _all_ of the suggestions are pathnames,
which is currently true, and likely to remain true.

It would be nice to have a test which simulated accepting the first
suggestion, to check that the filled-in completion does not get mangled,
as happened before.
@rolandwalker rolandwalker force-pushed the RW/fix-regression-source-accept-suggestion branch from 17d3d1c to 75f144e Compare February 19, 2026 10:25
@rolandwalker rolandwalker merged commit 4452b8b into main Feb 19, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/fix-regression-source-accept-suggestion branch February 19, 2026 10:51
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.

Regression in completions on filenames with source

2 participants

Comments