Skip to content

Fix autocomplete targeting between mentions - #30463

Closed
charliemarsh-oai wants to merge 7 commits into
mainfrom
charlie/fix-skill-autocomplete
Closed

Fix autocomplete targeting between mentions#30463
charliemarsh-oai wants to merge 7 commits into
mainfrom
charlie/fix-skill-autocomplete

Conversation

@charliemarsh-oai

@charliemarsh-oai charliemarsh-oai commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

When the cursor is placed between an unbound skill mention and an already bound mention, we previously preferred the token to the right. For example, with | representing the cursor:

$unbound-skill | $bound-skill continue

The popup should target $unbound-skill, but it instead targets $bound-skill, whose text is already an atomic element.

Here's an example. I've entered $simplify-code, then I move the cursor to the start of the line to add $rustdoc. But the completion sticks on the right-most token, and hitting Tab or Enter adds a duplicate copy:

Tab.mov

And after:

Untitled.mov

Stack

This is PR 3 of 3, stacked on #31191. #31190 threads exact autocomplete target ranges through insertion, and #31191 defines separator and occurrence-scoped dismissal behavior before this PR changes token affinity.

@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/fix-skill-autocomplete branch 3 times, most recently from 1035ec9 to 6df1532 Compare July 5, 2026 19:11
@charliemarsh-oai
charliemarsh-oai changed the base branch from main to charlie/autocomplete-separators July 5, 2026 19:11
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/autocomplete-separators branch from a8c0044 to b629fce Compare July 6, 2026 21:46
charliemarsh-oai added a commit that referenced this pull request Jul 6, 2026
## Summary

Autocomplete popup synchronization already identifies the active token's
range and query, but accepting a result previously discarded that range
and independently recomputed token boundaries around the cursor. Those
calculations could disagree at ambiguous cursor positions. For example,
in `@first| @second` (with `|` marking the cursor at the intervening
space), the popup targets `@second`, while the old acceptance path
replaces `@first`.

This threads the active range through legacy file search, skill
mentions, and mentions-v2 completion. File, image, and mention insertion
now replace the same token that supplied the popup query, and image
completion reuses the shared file insertion path.

## Stack

This is PR 1 of 3. #31191 builds separator and dismissal behavior on
these explicit replacement ranges, and #30463 then fixes token affinity
between adjacent mentions.
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/autocomplete-separators branch from b629fce to f183e69 Compare July 6, 2026 21:59
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/fix-skill-autocomplete branch from 6df1532 to 6920861 Compare July 6, 2026 21:59
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/autocomplete-separators branch from f183e69 to e804544 Compare July 6, 2026 22:01
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/fix-skill-autocomplete branch 2 times, most recently from 97becb0 to 156cf1e Compare July 6, 2026 23:58
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/autocomplete-separators branch from e44e267 to 304ad36 Compare July 7, 2026 00:13
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/fix-skill-autocomplete branch from 156cf1e to 6c75899 Compare July 7, 2026 00:13
charliemarsh-oai added a commit that referenced this pull request Jul 7, 2026
## Summary

Autocomplete completion previously inserted a new space even when a
separator was already present, which could leave redundant whitespace
around neighboring text. Popup dismissal also tracked only the query
string, so dismissing one token could suppress a different occurrence
with the same text.

This gives completions one horizontal-separator policy across files,
images, skills, and mentions. Existing separators are reused when
possible, ordinary suffix text remains separated, and line breaks stay
intact. Dismissal now identifies the complete whitespace-delimited token
occurrence, so offset-only edits preserve dismissal while later
identical tokens remain independent. Newly completed values beginning
with `$` or `@` can also remain closed when the next PR's affinity rule
recognizes the token to the left of the cursor.

## Examples

The examples below use `|` to represent the cursor.

### Reuse existing separators

Starting with an existing two-space gap:

```text
@ma|  next
```

After accepting `src/main.rs` and typing `foo`, completion previously
added a third separator and left both original spaces before `next`:

```text
src/main.rs foo|  next
```

After this PR, completion reuses the first existing separator as the
insertion point and preserves the second between the new text and
`next`:

```text
src/main.rs foo| next
```

### Keep a completed sigil-prefixed value closed

Starting before a line break:

```text
@ma|
next
```

and accepting a path whose result is itself prefixed with `@` produces:

```text
@scope/main.rs |
next
```

Without this PR's completion dismissal, the affinity rule in #30463
rediscovers the completed token to the left of the cursor and reopens
its popup:

```text
@scope/main.rs |
^^^^^^^^^^^^^^^ popup reopens
next
```

With this PR, the inserted occurrence is dismissed and the popup remains
closed:

```text
@scope/main.rs |
^^^^^^^^^^^^^^^ popup remains closed
next
```

### Do not dismiss an identical later occurrence

Given two identical tokens:

```text
@scope/main.rs|  @scope/main.rs
```

after dismissing the first popup with Escape and moving to the second
token, query-only dismissal previously suppressed the second popup too:

```text
@scope/main.rs  @scope/main.rs|
                   ^^^^^^^^^^^^^ popup remains closed
```

After this PR, dismissal also matches the token's ordinal among complete
tokens, so the second occurrence opens normally:

```text
@scope/main.rs  @scope/main.rs|
                   ^^^^^^^^^^^^^ popup opens
```

### Keep dismissal across offset-only edits

After dismissing `@ma`, moving to its start, and pasting an email-like
token:

```text
email@ma.com @ma|
```

the `@ma` bytes embedded in `email@ma.com` do not count as another
autocomplete token. The original `@ma` keeps its dismissal even though
its byte range moved.

## Stack

This is PR 2 of 3, stacked on #31190. It relies on the explicit
replacement ranges introduced there and provides the completion
lifecycle used by the targeting fix in #30463.
Base automatically changed from charlie/autocomplete-separators to main July 7, 2026 22:02
@charliemarsh-oai
charliemarsh-oai force-pushed the charlie/fix-skill-autocomplete branch from 6c75899 to 2d81ad6 Compare July 7, 2026 22:11
@charliemarsh-oai
charliemarsh-oai marked this pull request as ready for review July 7, 2026 22:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d81ad6cbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs Outdated
Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs Outdated
@charliemarsh-oai
charliemarsh-oai marked this pull request as draft July 7, 2026 22:43
@charliemarsh-oai
charliemarsh-oai marked this pull request as ready for review July 7, 2026 23:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ae71105ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs Outdated
Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs Outdated
Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs
@charliemarsh-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@charliemarsh-oai
charliemarsh-oai marked this pull request as draft July 7, 2026 23:59
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 1ae71105ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant