Skip to content

Use composable autocomplete provider instead of replacing the editor#570

Merged
dmtrKovalenko merged 1 commit into
dmtrKovalenko:mainfrom
LinYS77:pi-fff-composable-autocomplete
Jun 5, 2026
Merged

Use composable autocomplete provider instead of replacing the editor#570
dmtrKovalenko merged 1 commit into
dmtrKovalenko:mainfrom
LinYS77:pi-fff-composable-autocomplete

Conversation

@LinYS77
Copy link
Copy Markdown
Contributor

@LinYS77 LinYS77 commented Jun 4, 2026

Summary

This PR changes pi-fff to provide its FFF-backed @ file mentions through Pi's composable autocomplete provider API instead of replacing the
editor component.

The current implementation installs a custom editor with ctx.ui.setEditorComponent(...) only to customize autocomplete behavior. That gives
pi-fff ownership of the whole editor surface, even though the extension only needs to contribute file mention suggestions.

Using ctx.ui.addAutocompleteProvider(...) keeps the same @ mention functionality while allowing pi-fff to compose cleanly with other editor
extensions.

Changes

  • Remove the custom FffEditor wrapper.
  • Stop calling ctx.ui.setEditorComponent(...).
  • Register FFF @ mentions with ctx.ui.addAutocompleteProvider(...).
  • Delegate non-FFF autocomplete behavior to the existing provider.
  • Keep mode/tool behavior unchanged.

Testing

  • cd packages/pi-fff && bun test test/
  • cd packages/fff-node && npm run build
  • cd packages/pi-fff && bun run typecheck
  • git diff --check

@dmtrKovalenko
Copy link
Copy Markdown
Owner

@SamuelLHuber do you have any objections?

@dmtrKovalenko
Copy link
Copy Markdown
Owner

@gustav-fff review this PR

@SamuelLHuber
Copy link
Copy Markdown
Collaborator

looks good reading it. will test the branch now

Copy link
Copy Markdown
Collaborator

@SamuelLHuber SamuelLHuber left a comment

Choose a reason for hiding this comment

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

good one. tested and verified locally on my machine too

@dmtrKovalenko dmtrKovalenko merged commit f56c38b into dmtrKovalenko:main Jun 5, 2026
48 of 49 checks passed
@gustav-fff
Copy link
Copy Markdown
Collaborator

[triage-bot] DIRECTED: LGTM.

Composition via addAutocompleteProvider((current) => ...) is correct. Mention path tries first, falls through to current on null/abort/throw. shouldEnableMentions() evaluated per-call so /fff-mode toggles take effect without re-registration — the removed applyEditorMode re-apply on mode change is intentional and safe.

Notes (non-blocking):

  • applyCompletion always delegates to current. Works because item.value already encodes @"path with space"/@path, so prefix-length replace produces the right result. If a future base provider gets clever about prefix handling (e.g. unquoting), mention insertion could regress — worth a single inline test that asserts the inserted line for an @-mention.
  • catch {} in getSuggestions swallows native errors silently. Acceptable for autocomplete UX, but a pi.notify/debug log on first failure would help diagnose FileFinder startup races (pi-fff: parallel ffgrep calls can hang indefinitely due to unsynchronized ensureFinder singleton #403-class issues).
  • shouldTriggerFileCompletion defaults to true when base lacks it — fine for mentions, but could double-fire base file completion alongside @ results in some hosts. Watch in real session.

Tests pass: bun test test/ → 17 pass.

Honk-Honk 🪿

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.

4 participants