fix: lint noctx issues

Carlos Alexandro Becker created

ignored slog because in our case it doesn't matter.

Change summary

.golangci.yml                                 |  4 ++++
internal/fsext/fileutil.go                    |  9 +++++----
internal/llm/tools/glob.go                    |  6 +++---
internal/llm/tools/grep.go                    | 10 +++++-----
internal/tui/components/chat/editor/editor.go |  3 ++-
5 files changed, 19 insertions(+), 13 deletions(-)

Detailed changes

.golangci.yml 🔗

@@ -33,6 +33,10 @@ linters:
     generated: lax
     presets:
       - common-false-positives
+    rules:
+      - text: '(slog|log)\.\w+'
+        linters:
+          - noctx
 issues:
   max-issues-per-linter: 0
   max-same-issues: 0

internal/fsext/fileutil.go 🔗

@@ -1,6 +1,7 @@
 package fsext
 
 import (
+	"context"
 	"fmt"
 	"log/slog"
 	"os"
@@ -29,7 +30,7 @@ func init() {
 	}
 }
 
-func GetRgCmd(globPattern string) *exec.Cmd {
+func GetRgCmd(ctx context.Context, globPattern string) *exec.Cmd {
 	if rgPath == "" {
 		return nil
 	}
@@ -44,10 +45,10 @@ func GetRgCmd(globPattern string) *exec.Cmd {
 		}
 		rgArgs = append(rgArgs, "--glob", globPattern)
 	}
-	return exec.Command(rgPath, rgArgs...)
+	return exec.CommandContext(ctx, rgPath, rgArgs...)
 }
 
-func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
+func GetRgSearchCmd(ctx context.Context, pattern, path, include string) *exec.Cmd {
 	if rgPath == "" {
 		return nil
 	}
@@ -58,7 +59,7 @@ func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
 	}
 	args = append(args, path)
 
-	return exec.Command(rgPath, args...)
+	return exec.CommandContext(ctx, rgPath, args...)
 }
 
 type FileInfo struct {

internal/llm/tools/glob.go 🔗

@@ -114,7 +114,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 		searchPath = g.workingDir
 	}
 
-	files, truncated, err := globFiles(params.Pattern, searchPath, 100)
+	files, truncated, err := globFiles(ctx, params.Pattern, searchPath, 100)
 	if err != nil {
 		return ToolResponse{}, fmt.Errorf("error finding files: %w", err)
 	}
@@ -138,8 +138,8 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 	), nil
 }
 
-func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
-	cmdRg := fsext.GetRgCmd(pattern)
+func globFiles(ctx context.Context, pattern, searchPath string, limit int) ([]string, bool, error) {
+	cmdRg := fsext.GetRgCmd(ctx, pattern)
 	if cmdRg != nil {
 		cmdRg.Dir = searchPath
 		matches, err := runRipgrep(cmdRg, searchPath, limit)

internal/llm/tools/grep.go 🔗

@@ -206,7 +206,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 		searchPath = g.workingDir
 	}
 
-	matches, truncated, err := searchFiles(searchPattern, searchPath, params.Include, 100)
+	matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100)
 	if err != nil {
 		return ToolResponse{}, fmt.Errorf("error searching files: %w", err)
 	}
@@ -247,8 +247,8 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
 	), nil
 }
 
-func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
-	matches, err := searchWithRipgrep(pattern, rootPath, include)
+func searchFiles(ctx context.Context, pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
+	matches, err := searchWithRipgrep(ctx, pattern, rootPath, include)
 	if err != nil {
 		matches, err = searchFilesWithRegex(pattern, rootPath, include)
 		if err != nil {
@@ -268,8 +268,8 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo
 	return matches, truncated, nil
 }
 
-func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) {
-	cmd := fsext.GetRgSearchCmd(pattern, path, include)
+func searchWithRipgrep(ctx context.Context, pattern, path, include string) ([]grepMatch, error) {
+	cmd := fsext.GetRgSearchCmd(ctx, pattern, path, include)
 	if cmd == nil {
 		return nil, fmt.Errorf("ripgrep not found in $PATH")
 	}

internal/tui/components/chat/editor/editor.go 🔗

@@ -1,6 +1,7 @@
 package editor
 
 import (
+	"context"
 	"fmt"
 	"math/rand"
 	"net/http"
@@ -110,7 +111,7 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
 	if _, err := tmpfile.WriteString(value); err != nil {
 		return util.ReportError(err)
 	}
-	c := exec.Command(editor, tmpfile.Name())
+	c := exec.CommandContext(context.TODO(), editor, tmpfile.Name())
 	c.Stdin = os.Stdin
 	c.Stdout = os.Stdout
 	c.Stderr = os.Stderr