Skip to content

Add inline suggestion (ghost text) rendering primitive#125

Open
anxkhn wants to merge 1 commit into
CodeEditApp:mainfrom
anxkhn:feat/inline-suggestion
Open

Add inline suggestion (ghost text) rendering primitive#125
anxkhn wants to merge 1 commit into
CodeEditApp:mainfrom
anxkhn:feat/inline-suggestion

Conversation

@anxkhn

@anxkhn anxkhn commented Jun 30, 2026

Copy link
Copy Markdown

Description

Adds a low-level rendering primitive for inline "ghost text" suggestions: text drawn after the caret that previews content the user has not typed yet (the GitHub Copilot / predictive-completion UI pattern).

New public API:

  • InlineSuggestion: a value type holding a document offset and the text to show (may be multi-line).
  • TextView.setInlineSuggestion(_:at:): show a suggestion anchored at a given offset.
  • TextView.setInlineSuggestion(_:): show a suggestion anchored at the primary caret.
  • TextView.clearInlineSuggestion(): clear it.

Implementation notes:

  • A suggestion is purely a rendering hint. It is drawn as a sibling overlay anchored at the caret and never mutates textStorage or shifts real text layout, so it cannot pollute undo, selection, or the document.
  • An InlineSuggestionManager owns the overlay view and positions it from the text view's existing layout/caret geometry; InlineSuggestionView draws the (optionally multi-line) text.
  • Passing nil or an empty string clears any existing suggestion.

This is the rendering layer of a planned native inline-completion feature for the CodeEdit stack (this package renders, CodeEditSourceEditor coordinates request/accept/dismiss, CodeEdit wires up the provider). This PR is self-contained and only touches CodeEditTextView.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

This layer is a non-visual API primitive: it adds no user-facing UI on its own, and the visible ghost text only appears once a higher layer drives it. The rendered result will be shown in the downstream CodeEditSourceEditor / CodeEdit PRs. Behavior here is covered by unit tests, including a test that the suggestion never mutates textStorage.

Testing

  • xcodebuild -scheme CodeEditTextView -destination "platform=macOS,name=My Mac" clean test: all 72 tests pass, including the new InlineSuggestionTests suite.
  • SwiftLint: 0 violations (strict) on all changed files.

Add an overlay-based inline suggestion primitive that draws dimmed ghost
text anchored at the caret without mutating textStorage or shifting real
text layout. This is the foundation for inline completions such as
GitHub Copilot.

- InlineSuggestion: Equatable model holding an offset and text.
- InlineSuggestionView: sibling NSView overlay that typesets and draws
  CTLines using the same Core Text context setup as LineFragmentRenderer.
- InlineSuggestionManager: builds CTLines from typing attributes, anchors
  the overlay at rectForOffset(offset), and repositions on layout.
- TextView gains an inlineSuggestionManager and forwarding helpers, with
  updateLayout hooks in draw(_:) and layout().
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.

Inline suggestion (ghost text) rendering primitive

1 participant