From 795b3692197acf75ff13ed8a14c9a11d4b32ec5f Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Thu, 3 Apr 2025 17:36:40 +0200 Subject: [PATCH] small fixes --- internal/llm/tools/edit.go | 4 ++-- internal/lsp/util/edit.go | 8 ++++---- internal/lsp/watcher/watcher.go | 2 +- internal/tui/components/core/button.go | 6 +++--- internal/tui/components/repl/messages.go | 6 ------ internal/tui/layout/grid.go | 4 ++-- internal/tui/layout/overlay.go | 7 +------ 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go index c84bbd7a053ec8ed68e3b68c5983b366bf046ac0..a5877044bf9f51b1f4dc1ced0d48694f1096580d 100644 --- a/internal/llm/tools/edit.go +++ b/internal/llm/tools/edit.go @@ -80,7 +80,7 @@ func (e *editTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) if err != nil { return NewTextErrorResponse(fmt.Sprintf("error creating file: %s", err)), nil } - return NewTextErrorResponse(result), nil + return NewTextResponse(result), nil } if params.NewString == "" { @@ -88,7 +88,7 @@ func (e *editTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error) if err != nil { return NewTextErrorResponse(fmt.Sprintf("error deleting content: %s", err)), nil } - return NewTextErrorResponse(result), nil + return NewTextResponse(result), nil } result, err := replaceContent(params.FilePath, params.OldString, params.NewString) diff --git a/internal/lsp/util/edit.go b/internal/lsp/util/edit.go index 180429ce563724f17a8bbd73dab579b6957d3bf1..3b94fb39ff70afd463aac83bb7ffd698e43a3e6f 100644 --- a/internal/lsp/util/edit.go +++ b/internal/lsp/util/edit.go @@ -34,9 +34,9 @@ func applyTextEdits(uri protocol.DocumentUri, edits []protocol.TextEdit) error { lines := strings.Split(string(content), lineEnding) // Check for overlapping edits - for i := 0; i < len(edits); i++ { + for i, edit1 := range edits { for j := i + 1; j < len(edits); j++ { - if rangesOverlap(edits[i].Range, edits[j].Range) { + if rangesOverlap(edit1.Range, edits[j].Range) { return fmt.Errorf("overlapping edits detected between edit %d and %d", i, j) } } @@ -54,7 +54,7 @@ func applyTextEdits(uri protocol.DocumentUri, edits []protocol.TextEdit) error { // Apply each edit for _, edit := range sortedEdits { - newLines, err := applyTextEdit(lines, edit, lineEnding) + newLines, err := applyTextEdit(lines, edit) if err != nil { return fmt.Errorf("failed to apply edit: %w", err) } @@ -82,7 +82,7 @@ func applyTextEdits(uri protocol.DocumentUri, edits []protocol.TextEdit) error { return nil } -func applyTextEdit(lines []string, edit protocol.TextEdit, lineEnding string) ([]string, error) { +func applyTextEdit(lines []string, edit protocol.TextEdit) ([]string, error) { startLine := int(edit.Range.Start.Line) endLine := int(edit.Range.End.Line) startChar := int(edit.Range.Start.Character) diff --git a/internal/lsp/watcher/watcher.go b/internal/lsp/watcher/watcher.go index a9d057c711ce40d9206f32675997b08771073049..7a6eaacc52df14bf3428de4aae5abdd4f3d69d14 100644 --- a/internal/lsp/watcher/watcher.go +++ b/internal/lsp/watcher/watcher.go @@ -347,7 +347,7 @@ func matchesSimpleGlob(pattern, path string) bool { // Otherwise, check if any path component matches pathComponents := strings.Split(path, "/") - for i := 0; i < len(pathComponents); i++ { + for i := range pathComponents { subPath := strings.Join(pathComponents[i:], "/") if strings.HasSuffix(subPath, rest) { return true diff --git a/internal/tui/components/core/button.go b/internal/tui/components/core/button.go index 102957e0ec8c05fc05ce1a0041232036426efe6b..090fbc1ee510fb6912a3b47a76556f5c1bf0140a 100644 --- a/internal/tui/components/core/button.go +++ b/internal/tui/components/core/button.go @@ -67,7 +67,7 @@ const ( // ButtonMsg is sent when a button is clicked type ButtonMsg struct { ID string - Payload interface{} + Payload any } // ButtonCmp represents a clickable button component @@ -79,7 +79,7 @@ type ButtonCmp struct { state ButtonState variant ButtonVariant keyMap ButtonKeyMap - payload interface{} + payload any style lipgloss.Style hoverStyle lipgloss.Style } @@ -107,7 +107,7 @@ func (b *ButtonCmp) WithVariant(variant ButtonVariant) *ButtonCmp { } // WithPayload sets the payload sent with button events -func (b *ButtonCmp) WithPayload(payload interface{}) *ButtonCmp { +func (b *ButtonCmp) WithPayload(payload any) *ButtonCmp { b.payload = payload return b } diff --git a/internal/tui/components/repl/messages.go b/internal/tui/components/repl/messages.go index 2b5e599aa46764ee21316d90d978e595225cd4a9..30ce4be7c9e20a5b4dba487703ee052d0f4b869d 100644 --- a/internal/tui/components/repl/messages.go +++ b/internal/tui/components/repl/messages.go @@ -5,7 +5,6 @@ import ( "fmt" "sort" "strings" - "time" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/viewport" @@ -41,7 +40,6 @@ type messagesCmp struct { height int focused bool cachedView string - timeLoaded time.Time } func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -424,9 +422,6 @@ func (m *messagesCmp) projectDiagnostics() string { } if len(errorDiagnostics) == 0 && len(warnDiagnostics) == 0 && len(hintDiagnostics) == 0 && len(infoDiagnostics) == 0 { - if time.Since(m.timeLoaded) < time.Second*10 { - return "Loading diagnostics..." - } return "No diagnostics" } @@ -496,7 +491,6 @@ func (m *messagesCmp) SetSize(width int, height int) { } func (m *messagesCmp) Init() tea.Cmd { - m.timeLoaded = time.Now() return nil } diff --git a/internal/tui/layout/grid.go b/internal/tui/layout/grid.go index d6f0b4ab9149997e41dc6658274345ad0784ac75..6be493e2c2f7536612660350e7e017f7e9600444 100644 --- a/internal/tui/layout/grid.go +++ b/internal/tui/layout/grid.go @@ -127,10 +127,10 @@ func (g *gridLayout) View() string { // Render each row rows := make([]string, g.rows) - for i := 0; i < g.rows; i++ { + for i := range g.rows { // Render each column in this row cols := make([]string, len(g.panes[i])) - for j := 0; j < len(g.panes[i]); j++ { + for j := range g.panes[i] { if g.panes[i][j] == nil { cols[j] = "" continue diff --git a/internal/tui/layout/overlay.go b/internal/tui/layout/overlay.go index 87cc80e68e4d623cda3a5bdc87adeed7dd557463..22f9e00fe0594b749b2b489b1831f4a6cb6571cf 100644 --- a/internal/tui/layout/overlay.go +++ b/internal/tui/layout/overlay.go @@ -159,12 +159,7 @@ func max(a, b int) int { return b } -func min(a, b int) int { - if a < b { - return a - } - return b -} + type whitespace struct { style termenv.Style