mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 09:44:21 +01:00
add initial lsp support
This commit is contained in:
@@ -9,10 +9,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kujtimiihoxha/termai/internal/config"
|
||||
"github.com/kujtimiihoxha/termai/internal/lsp"
|
||||
"github.com/kujtimiihoxha/termai/internal/permission"
|
||||
)
|
||||
|
||||
type writeTool struct{}
|
||||
type writeTool struct {
|
||||
lspClients map[string]*lsp.Client
|
||||
}
|
||||
|
||||
const (
|
||||
WriteToolName = "write"
|
||||
@@ -96,6 +99,8 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
|
||||
if err = os.MkdirAll(dir, 0o755); err != nil {
|
||||
return NewTextErrorResponse(fmt.Sprintf("Failed to create parent directories: %s", err)), nil
|
||||
}
|
||||
|
||||
notifyLspOpenFile(ctx, filePath, w.lspClients)
|
||||
p := permission.Default.Request(
|
||||
permission.CreatePermissionRequest{
|
||||
Path: filePath,
|
||||
@@ -122,7 +127,10 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
|
||||
recordFileWrite(filePath)
|
||||
recordFileRead(filePath)
|
||||
|
||||
return NewTextResponse(fmt.Sprintf("File successfully written: %s", filePath)), nil
|
||||
result := fmt.Sprintf("File successfully written: %s", filePath)
|
||||
result = fmt.Sprintf("<result>\n%s\n</result>", result)
|
||||
result += appendDiagnostics(filePath, w.lspClients)
|
||||
return NewTextResponse(result), nil
|
||||
}
|
||||
|
||||
func writeDescription() string {
|
||||
@@ -156,6 +164,8 @@ TIPS:
|
||||
- Always include descriptive comments when making changes to existing code`
|
||||
}
|
||||
|
||||
func NewWriteTool() BaseTool {
|
||||
return &writeTool{}
|
||||
func NewWriteTool(lspClients map[string]*lsp.Client) BaseTool {
|
||||
return &writeTool{
|
||||
lspClients,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user