feat: expose LSP functionality through @opencode-ai/plugin#14228
Open
aSidorenkoCodePPI wants to merge 5 commits intoanomalyco:devfrom
Open
feat: expose LSP functionality through @opencode-ai/plugin#14228aSidorenkoCodePPI wants to merge 5 commits intoanomalyco:devfrom
aSidorenkoCodePPI wants to merge 5 commits intoanomalyco:devfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR exposes selected LSP capabilities (touchFile, diagnostics, diagnosticPretty, hover) to custom tools authored via @opencode-ai/plugin, enabling .opencode/tool(s)/ tools to validate edits with the same diagnostics flow used by built-in editing tools. It addresses the feature request in #4410 by threading an lsp API through the plugin ToolContext.
Changes:
- Added
LspDiagnostic/LspContexttypes and a newctx.lspfield to the pluginToolContext. - Wired the runtime
LSPmodule into the plugin tool context inToolRegistryso custom tools can call LSP methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/plugin/src/tool.ts | Defines the public plugin-side LSP types and adds lsp onto ToolContext. |
| packages/opencode/src/tool/registry.ts | Injects an lsp implementation into the plugin tool execution context using packages/opencode’s LSP module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Make `lsp` optional on `ToolContext` to avoid breaking change - Remove unnecessary type casts in registry wiring - Fix `hover` return type to `Promise<(unknown | null)[]>` - Add test verifying `ctx.lsp` is provided to custom tools Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Exclude `lsp` from Plugin.trigger's Hooks constraint (not a callable hook) - Add explicit type for `diagnostic` parameter to avoid implicit any Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #4410
Related: #8032, #9472, #9573, #5345, #2318, #7184, #11509, #13070, #10938, #11617, #7780, #12426, #3116, #5535, #5837, #8518, #9308, #9534, #10009, #10073, #10685, #12522
Type of change
What does this PR do?
Two things:
Expose LSP functions to custom tools — adds
lspto the pluginToolContextso custom tools in.opencode/tool/can calltouchFile,diagnostics,diagnosticPretty, andhover(same functions built-inedit/writetools already use internally).Register/override LSP servers from plugins — adds an
lspfield to pluginHooksso plugins can declare LSP server configs. This lets you move LSP overrides out ofopencode.jsoninto reusable plugin files.Example plugin (
.opencode/plugins/jdtls-lombok.ts):How did you verify your code works?
Checked types compile and confirmed the wiring matches how built-in tools and config-based LSP overrides already work. Plugin LSP entries go through the exact same
spawn/serverscodepath ascfg.lspentries. Added a test that verifies custom tools receivectx.lspwith all expected functions.Screenshots / recordings
N/A — no UI changes.
Checklist