Skip to content

Comments

feat: expose LSP functionality through @opencode-ai/plugin#14228

Open
aSidorenkoCodePPI wants to merge 5 commits intoanomalyco:devfrom
aSidorenkoCodePPI:feat/expose-lsp-plugin-sdk
Open

feat: expose LSP functionality through @opencode-ai/plugin#14228
aSidorenkoCodePPI wants to merge 5 commits intoanomalyco:devfrom
aSidorenkoCodePPI:feat/expose-lsp-plugin-sdk

Conversation

@aSidorenkoCodePPI
Copy link

@aSidorenkoCodePPI aSidorenkoCodePPI commented Feb 19, 2026

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

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Two things:

  1. Expose LSP functions to custom tools — adds lsp to the plugin ToolContext so custom tools in .opencode/tool/ can call touchFile, diagnostics, diagnosticPretty, and hover (same functions built-in edit/write tools already use internally).

  2. Register/override LSP servers from plugins — adds an lsp field to plugin Hooks so plugins can declare LSP server configs. This lets you move LSP overrides out of opencode.json into reusable plugin files.

Example plugin (.opencode/plugins/jdtls-lombok.ts):

export default async function () {
  const home = process.env.HOME
  return {
    lsp: {
      jdtls: { disabled: true },
      "jdtls-lombok": {
        command: [
          `${home}/.local/share/opencode/bin/jdtls/bin/jdtls`,
          `--jvm-arg=-javaagent:${home}/dev-tools/jars/lombok.jar`,
          `-configuration`,
          `${home}/.local/share/opencode/bin/jdtls/config_linux`,
          `-data`,
          `/tmp/opencode-jdtls-data`,
        ],
        extensions: [".java"],
      },
    },
  }
}

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/servers codepath as cfg.lsp entries. Added a test that verifies custom tools receive ctx.lsp with all expected functions.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 19, 2026 02:25
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 / LspContext types and a new ctx.lsp field to the plugin ToolContext.
  • Wired the runtime LSP module into the plugin tool context in ToolRegistry so 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.

@aSidorenkoCodePPI aSidorenkoCodePPI marked this pull request as draft February 19, 2026 02:29
aSidorenkoCodePPI and others added 4 commits February 19, 2026 03:30
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>
@aSidorenkoCodePPI aSidorenkoCodePPI marked this pull request as ready for review February 19, 2026 02:49
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.

[FEATURE]: Export LSP functionality through @opencode-ai/plugin for custom tools

1 participant