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

Open
opened 2026-02-16 17:37:48 -05:00 by yindo · 1 comment
Owner

Originally created by @markuest on GitHub (Nov 17, 2025).

Originally assigned to: @rekram1-node on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

We have very specific requirements for code changes and have built a custom tool in .opencode/tool/ for this purpose. Currently, the LSP module (packages/opencode/src/lsp/index.ts) is only available to opencode's built-in tools and cannot be accessed by custom tools created via @opencode-ai/plugin.

Built-in tools like edit, write and lsp_diagnostics use LSP functions to validate code changes:

await LSP.touchFile(filePath, true)  
const diagnostics = await LSP.diagnostics()

The lsp_diagnostics tool would be a good candidate to work around this issue, but packages/opencode/src/tool/lsp-diagnostics.txt says "do not use". When creating custom tools in .opencode/tool/, users can only import from @opencode-ai/plugin, which doesn't expose LSP functionality.

Use Case

If my reading of the source is correct, custom tools that modify code files need to:

  1. Notify the language server of file changes via LSP.touchFile()
  2. Retrieve diagnostics to validate changes via LSP.diagnostics()
  3. Format diagnostic output using LSP.Diagnostic.pretty()

Proposed Solution

Export LSP functionality through @opencode-ai/plugin to enable custom tools to:

  • Call LSP.touchFile(filepath, waitForDiagnostics) to notify language servers of file changes
  • Call LSP.diagnostics() to retrieve validation errors and warnings
  • Access LSP.Diagnostic.pretty() for formatting diagnostic output
  • Optionally access LSP.hover() for hover information

Alternative Workarounds

  • Fork opencode and add tools directly to the codebase
  • Update and use the lsp_diagnostics tool
  • Use built-in edit/write tools instead of custom editing tools (this violates our requirements)
Originally created by @markuest on GitHub (Nov 17, 2025). Originally assigned to: @rekram1-node on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ### Problem We have very specific requirements for code changes and have built a custom tool in `.opencode/tool/` for this purpose. Currently, the LSP module (`packages/opencode/src/lsp/index.ts`) is only available to opencode's built-in tools and cannot be accessed by custom tools created via `@opencode-ai/plugin`. Built-in tools like `edit`, `write` and `lsp_diagnostics` use LSP functions to validate code changes: ```ts await LSP.touchFile(filePath, true) const diagnostics = await LSP.diagnostics() ``` The `lsp_diagnostics` tool would be a good candidate to work around this issue, but `packages/opencode/src/tool/lsp-diagnostics.txt` says "do not use". When creating custom tools in `.opencode/tool/`, users can only import from `@opencode-ai/plugin`, which doesn't expose LSP functionality. ### Use Case If my reading of the source is correct, custom tools that modify code files need to: 1. Notify the language server of file changes via `LSP.touchFile()` 1. Retrieve diagnostics to validate changes via `LSP.diagnostics()` 1. Format diagnostic output using `LSP.Diagnostic.pretty()` ### Proposed Solution Export LSP functionality through `@opencode-ai/plugin` to enable custom tools to: - Call `LSP.touchFile(filepath, waitForDiagnostics)` to notify language servers of file changes - Call `LSP.diagnostics()` to retrieve validation errors and warnings - Access `LSP.Diagnostic.pretty()` for formatting diagnostic output - Optionally access `LSP.hover()` for hover information ### Alternative Workarounds - Fork opencode and add tools directly to the codebase - Update and use the `lsp_diagnostics` tool - Use built-in edit/write tools instead of custom editing tools (this violates our requirements)
yindo added the discussion label 2026-02-16 17:37:48 -05:00
Author
Owner

@rekram1-node commented on GitHub (Nov 17, 2025):

Yeah that's valid

@rekram1-node commented on GitHub (Nov 17, 2025): Yeah that's valid
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2917