Skip to content

feat: AI ghost text + STruC++ LSP autocomplete coexistence - #892

Merged
thiagoralves merged 1 commit into
developmentfrom
feat/ai-lsp-autocomplete-coexistence
Jun 24, 2026
Merged

feat: AI ghost text + STruC++ LSP autocomplete coexistence#892
thiagoralves merged 1 commit into
developmentfrom
feat/ai-lsp-autocomplete-coexistence

Conversation

@thiagoralves

@thiagoralves thiagoralves commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

The Structured Text editor previously treated AI inline completions and the STruC++ LSP suggest widget as mutually exclusive — when AI was enabled, the LSP auto-dropdown was suppressed (quickSuggestions: false, inlineSuggest.suppressSuggestions: true). Since the LSP completions are faster and deterministic (especially for variables and struct-member access like my_struct.value_a.point_b), hiding them behind the slower AI stream hurt the editing flow.

Both completion sources are independent Monaco providers, so they can run at the same time. This PR makes them coexist, splitting acceptance by key.

Behavior

Key AI enabled AI disabled
Tab Commits the AI ghost text — even while the LSP dropdown is open Accepts the LSP dropdown (unchanged)
Enter / ↑↓+Enter Accepts the LSP dropdown Accepts the LSP dropdown
Tab (dropdown open, no ghost text) Swallowed — reserved for AI Accepts the LSP dropdown

The Tab overrides are gated on a custom Monaco context key (openplcAiLspCoexistence) driven by inlineCompletionsActive, so toggling AI on/off takes effect without remounting the editor. This mirrors the VS Code + Copilot model.

Changes

  • monaco/ai-lsp-coexistence.ts (new): installs the two Tab keybinding overrides via editor.addCommand, gated on the context key.
  • monaco/index.tsx: stop forcing quickSuggestions: false; set inlineSuggest.suppressSuggestions: false; wire the helper in the mount handler + a useEffect that keeps the context key in sync with AI state.

Note

This is the byte-identical companion to openplc-web PR autonomy-logic/openplc-web#544 — both repos share this editor surface and must stay in sync. Validated manually in the web app (LSP dropdown + AI ghost text coexisting, Tab→AI, Enter→LSP, AI-off fallback) and typechecks clean here.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved editor behavior so AI inline suggestions and code-completion dropdowns can appear together more smoothly.
    • Added smarter Tab handling to prioritize the most relevant suggestion when both assistance types are available.
  • Bug Fixes

    • Prevented the suggestion list from being accidentally accepted in cases where an AI inline suggestion should take precedence.
    • Kept editor assistance behavior in sync as inline suggestions are turned on and off.

The ST editor previously made AI inline completions and the LSP suggest
widget mutually exclusive: when AI was on, the LSP auto-dropdown was
suppressed (`quickSuggestions: false`, `inlineSuggest.suppressSuggestions:
true`). The LSP completions are faster and deterministic (especially for
variables and struct members), so hiding them behind the slower AI stream
hurt the editing flow.

Both completion sources are independent Monaco providers, so they can run
at once. Now:

- The LSP dropdown auto-opens in both modes (Enter / arrow-keys accept it).
- The AI ghost text renders alongside it; Tab commits it — even while the
  suggest widget is open (Monaco's default reserves Tab for the dropdown).
- While the dropdown is open with no ghost text, Tab is swallowed (reserved
  for AI) so it never accepts an LSP item.
- When AI is off, Tab falls back to accepting the LSP dropdown as before.

The Tab overrides are gated on a custom context key driven by
`inlineCompletionsActive`, so toggling AI on/off takes effect without
remounting the editor.

Byte-identical companion change to openplc-web (shared editor surface).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a new ai-lsp-coexistence.ts module that registers Monaco Tab keybinding overrides controlled by a context key, allowing AI inline completions and the LSP suggest widget to coexist. MonacoEditor installs the controller on mount and keeps it synced with inlineCompletionsActive, while quickSuggestions and suppressSuggestions options are updated to stop hiding the LSP dropdown during AI ghost text display.

Changes

AI/LSP coexistence keybinding integration

Layer / File(s) Summary
AiLspCoexistenceController contract and keybinding implementation
src/frontend/components/_features/[workspace]/editor/monaco/ai-lsp-coexistence.ts
Defines the AiLspCoexistenceController type with setActive(boolean). installAiLspCoexistenceKeybindings creates a Monaco context key (openplcAiLspCoexistence), registers two Tab command overrides gated on the key plus LSP/AI predicates (commit AI inline or no-op), and returns the controller.
MonacoEditor mount, option, and sync wiring
src/frontend/components/_features/[workspace]/editor/monaco/index.tsx
Imports and stores the coexistence controller in coexistenceRef, installs keybindings on editor mount with initial active state, removes the conditional quickSuggestions disabling, sets suppressSuggestions: false, and adds a useEffect to call setActive whenever inlineCompletionsActive or editorInstanceId changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Autonomy-Logic/openplc-editor#739: Modifies the same index.tsx inline-completion enablement toggle logic (inlineCompletionsEnabled) that the new coexistence controller now reads and reacts to via inlineCompletionsActive.

Suggested labels

enhancement

Suggested reviewers

  • JoaoGSP

🐇 A context key hops into place,
Tab key tricks now elegantly grace,
LSP dropdown stays in view,
While AI ghost text peeks through too —
No more collisions, what a space!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: AI ghost text and STruC++ LSP autocomplete coexistence.
Description check ✅ Passed The description covers summary, behavior, implementation changes, and validation, with only template sections missing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ai-lsp-autocomplete-coexistence

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/frontend/components/_features/[workspace]/editor/monaco/index.tsx (1)

1238-1243: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Gate coexistence on the inline provider actually existing.

inlineCompletionsActive can be true even when aiPort?.registerInlineCompletions is missing, but the provider effect returns early at Line 793. In that state the Tab overrides still activate and the no-ghost path swallows LSP Tab even though AI ghost text can never appear.

Proposed fix
   const inlineCompletionsActive =
     capabilities.hasAIAssistant &&
+    Boolean(aiPort?.registerInlineCompletions) &&
     aiState.isEnabled &&
     aiState.hasConsented &&
     aiState.preferences.inlineCompletionsEnabled
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/frontend/components/_features/`[workspace]/editor/monaco/index.tsx around
lines 1238 - 1243, The inline-completions coexistence flag is too broad:
`inlineCompletionsActive` can be true even when
`aiPort?.registerInlineCompletions` is unavailable, which leaves the Tab
override logic enabled without any AI ghost text provider. Update the
`inlineCompletionsActive` condition in the Monaco editor component to also
require the inline provider to exist, and keep the provider effect and
Tab-handling branches aligned so `registerInlineCompletions`-gated behavior only
activates when the AI inline provider can actually be registered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/frontend/components/_features/`[workspace]/editor/monaco/index.tsx:
- Around line 1238-1243: The inline-completions coexistence flag is too broad:
`inlineCompletionsActive` can be true even when
`aiPort?.registerInlineCompletions` is unavailable, which leaves the Tab
override logic enabled without any AI ghost text provider. Update the
`inlineCompletionsActive` condition in the Monaco editor component to also
require the inline provider to exist, and keep the provider effect and
Tab-handling branches aligned so `registerInlineCompletions`-gated behavior only
activates when the AI inline provider can actually be registered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fa568e4c-290d-4cfc-8a8c-dafe70ee9764

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5c539 and 3c673e0.

📒 Files selected for processing (2)
  • src/frontend/components/_features/[workspace]/editor/monaco/ai-lsp-coexistence.ts
  • src/frontend/components/_features/[workspace]/editor/monaco/index.tsx

@thiagoralves
thiagoralves merged commit b86c4f2 into development Jun 24, 2026
13 checks passed
@thiagoralves
thiagoralves deleted the feat/ai-lsp-autocomplete-coexistence branch June 24, 2026 05:48
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.

1 participant