Skip to content

Refactor is_inside_quotes()#1574

Merged
rolandwalker merged 1 commit intomainfrom
RW/refactor-is-inside-quotes
Feb 16, 2026
Merged

Refactor is_inside_quotes()#1574
rolandwalker merged 1 commit intomainfrom
RW/refactor-is-inside-quotes

Conversation

@rolandwalker
Copy link
Contributor

@rolandwalker rolandwalker commented Feb 16, 2026

Description

  • Rename without underscore, as it might be used in another file.
  • Recognize backtick quoting, including doubled backticks as escapes.
  • Accept negative numbers for pos.
  • escaped should not be toggled to True unless inside a double- or single-quoted string.
  • Return a string or False, typed as Literal.
  • Optimize: is not in is much faster than looping.

Motivation: to improve completions which start with backtick.

xref #1564 .

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 16, 2026
@github-actions
Copy link

Findings

  1. Regression: enum value suggestions suppressed for backtick-quoted identifiers.
    _enum_value_suggestion now treats any non-False return from is_inside_quotes as “inside quotes”, which includes 'backtick'. That will block enum suggestions for \table`.`column`even though backticks are identifier quotes, not string literals. Action: Restrict this check to'single'/'double'only. For example:if is_inside_quotes(...) in ['single', 'double']:. File: mycli/packages/completion_engine.py:21-27`

  2. Edge case: cursor between doubled backticks is treated as outside quotes.
    If a user types an escaped backtick inside a backtick-quoted identifier, the cursor between the two backticks (e.g., select `a|b``) is still inside the identifier. The current toggle logic flips off after the first backtick, sois_inside_quoteswould returnFalseat that cursor position. That can re-enable completions unexpectedly. Action: Consider handling doubled-backtick escape inside backticks, or document that this edge case is acceptable. File:mycli/packages/completion_engine.py:56-68`

Missing Tests / Edge Cases

  1. Add a test for enum suggestions with backtick-quoted identifiers to prevent regression.
    Suggested case: text="select t.c = " should still trigger enum value suggestions.
    File: test/test_completion_engine.py

  2. Add a test for cursor between doubled backticks if you choose to support that behavior.
    File: test/test_completion_engine.py

Notes

  • No security concerns found.
  • I did not run tests locally.

If you want, I can draft the test cases and a minimal fix for the enum suggestion behavior.

@rolandwalker rolandwalker force-pushed the RW/refactor-is-inside-quotes branch 2 times, most recently from e0a4977 to 921644d Compare February 16, 2026 19:56
@rolandwalker
Copy link
Contributor Author

Addressed both of the Codex findings. The doubling of backticks as escapes was a good point.

@rolandwalker rolandwalker force-pushed the RW/refactor-is-inside-quotes branch 3 times, most recently from 82dd9c5 to 8d5072b Compare February 16, 2026 20:40
@rolandwalker rolandwalker added the codex request Codex review for an updated PR label Feb 16, 2026
@scottnemes
Copy link
Contributor

scottnemes commented Feb 16, 2026

Could you give some examples of what you're addressing here? It's unclear to me what the goal is. I.e. I see:

select "json = no suggestions
select 'json = no suggestions
select `jso = suggestions after three characters
select ``js = suggestions after two characters

@rolandwalker
Copy link
Contributor Author

Sorry if I was unclear @scottnemes . This is just an enabling refactor, which does not itself change any functionality other than fixing some bugs in which "inside quotes" was wrongly determined.

But, we would need this to attack #1564 .

@rolandwalker rolandwalker added codex request Codex review for an updated PR and removed codex request Codex review for an updated PR labels Feb 16, 2026
@github-actions
Copy link

Findings

  1. Potential IndexError for pos > len(text)
    is_inside_quotes() now loops for index in range(0, pos) and indexes text[index]. If callers pass a pos larger than len(text), this will raise IndexError. Previously text[:pos] was safe for oversized positions. Suggest clamping pos = min(pos, len(text)) after the negative-index normalization.
    File: mycli/packages/completion_engine.py

  2. Edge-case semantics for negative positions
    The new normalization pos = len(text) + pos + 1 changes meaning vs prior slicing. For example pos=-2 now scans up to len-1 (inclusive), which is not the same as text[: -2] behavior. That may be intended, but it’s a behavioral change for existing callers using negative positions. If this is deliberate, consider a short comment or a test covering pos=-len(text) and pos<-len(text) so the semantics are locked.
    File: mycli/packages/completion_engine.py

Missing tests / edge cases

  1. Add a test for pos > len(text) to ensure it doesn’t throw and returns a sensible value (likely False).
    File: test/test_completion_engine.py

If you want, I can propose a small patch to clamp pos and add the test.

 * rename without underscore, as it might be used in another file
 * recognize backtick quoting, including doubled backticks as escapes
 * accept negative numbers for "pos"
 * "escaped" should not be toggled to "True" unless inside a double- or
   single-quoted string
 * return a string or "False", typed as Literal
 * optimize: "is not in" is much faster than looping

Motivation: to improve completions which start with backtick.
@rolandwalker rolandwalker force-pushed the RW/refactor-is-inside-quotes branch from 8d5072b to 7f6ebdf Compare February 16, 2026 22:11
@rolandwalker rolandwalker merged commit 9b5e421 into main Feb 16, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/refactor-is-inside-quotes branch February 16, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex request Codex review for an updated PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments