lsp.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package tools
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/opencode-ai/opencode/internal/lsp/discovery/tool"
  7. )
  8. // ConfigureLspServerTool is a tool for configuring LSP servers
  9. type ConfigureLspServerTool struct{}
  10. // NewConfigureLspServerTool creates a new ConfigureLspServerTool
  11. func NewConfigureLspServerTool() *ConfigureLspServerTool {
  12. return &ConfigureLspServerTool{}
  13. }
  14. // Info returns information about the tool
  15. func (t *ConfigureLspServerTool) Info() ToolInfo {
  16. return ToolInfo{
  17. Name: "configureLspServer",
  18. Description: "Searches for an LSP server for the given language",
  19. Parameters: map[string]any{
  20. "language": map[string]any{
  21. "type": "string",
  22. "description": "The language identifier (e.g., \"go\", \"typescript\", \"python\")",
  23. },
  24. },
  25. Required: []string{"language"},
  26. }
  27. }
  28. // Run executes the tool
  29. func (t *ConfigureLspServerTool) Run(ctx context.Context, params ToolCall) (ToolResponse, error) {
  30. result, err := tool.ConfigureLspServer(ctx, json.RawMessage(params.Input))
  31. if err != nil {
  32. return NewTextErrorResponse(err.Error()), nil
  33. }
  34. // Convert the result to JSON
  35. resultJSON, err := json.MarshalIndent(result, "", " ")
  36. if err != nil {
  37. return NewTextErrorResponse(fmt.Sprintf("Failed to marshal result: %v", err)), nil
  38. }
  39. return NewTextResponse(string(resultJSON)), nil
  40. }