on main help sign in
fix: lint noctx issues
e698239Carlos Alexandro Becker
.golangci.yml+4
@@ -33,6 +33,10 @@ linters:
33 generated: lax
33 generated: lax
34 presets:
34 presets:
35 - common-false-positives
35 - common-false-positives
36+ rules:
37+ - text: '(slog|log)\.\w+'
38+ linters:
39+ - noctx
36issues:
40issues:
37 max-issues-per-linter: 0
41 max-issues-per-linter: 0
38 max-same-issues: 0
42 max-same-issues: 0
internal/fsext/fileutil.go+5−4
@@ -1,6 +1,7 @@
1package fsext
1package fsext
2
2
3import (
3import (
4+ "context"
4 "fmt"
5 "fmt"
5 "log/slog"
6 "log/slog"
6 "os"
7 "os"
@@ -29,7 +30,7 @@ func init() {
29 }
30 }
30}
31}
31
32
32−func GetRgCmd(globPattern string) *exec.Cmd {
33+func GetRgCmd(ctx context.Context, globPattern string) *exec.Cmd {
33 if rgPath == "" {
34 if rgPath == "" {
34 return nil
35 return nil
35 }
36 }
@@ -44,10 +45,10 @@ func GetRgCmd(globPattern string) *exec.Cmd {
44 }
45 }
45 rgArgs = append(rgArgs, "--glob", globPattern)
46 rgArgs = append(rgArgs, "--glob", globPattern)
46 }
47 }
47− return exec.Command(rgPath, rgArgs...)
48+ return exec.CommandContext(ctx, rgPath, rgArgs...)
48}
49}
49
50
50−func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
51+func GetRgSearchCmd(ctx context.Context, pattern, path, include string) *exec.Cmd {
51 if rgPath == "" {
52 if rgPath == "" {
52 return nil
53 return nil
53 }
54 }
@@ -58,7 +59,7 @@ func GetRgSearchCmd(pattern, path, include string) *exec.Cmd {
58 }
59 }
59 args = append(args, path)
60 args = append(args, path)
60
61
61− return exec.Command(rgPath, args...)
62+ return exec.CommandContext(ctx, rgPath, args...)
62}
63}
63
64
64type FileInfo struct {
65type FileInfo struct {
internal/llm/tools/glob.go+3−3
@@ -114,7 +114,7 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
114 searchPath = g.workingDir
114 searchPath = g.workingDir
115 }
115 }
116
116
117− files, truncated, err := globFiles(params.Pattern, searchPath, 100)
117+ files, truncated, err := globFiles(ctx, params.Pattern, searchPath, 100)
118 if err != nil {
118 if err != nil {
119 return ToolResponse{}, fmt.Errorf("error finding files: %w", err)
119 return ToolResponse{}, fmt.Errorf("error finding files: %w", err)
120 }
120 }
@@ -138,8 +138,8 @@ func (g *globTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
138 ), nil
138 ), nil
139}
139}
140
140
141−func globFiles(pattern, searchPath string, limit int) ([]string, bool, error) {
141+func globFiles(ctx context.Context, pattern, searchPath string, limit int) ([]string, bool, error) {
142− cmdRg := fsext.GetRgCmd(pattern)
142+ cmdRg := fsext.GetRgCmd(ctx, pattern)
143 if cmdRg != nil {
143 if cmdRg != nil {
144 cmdRg.Dir = searchPath
144 cmdRg.Dir = searchPath
145 matches, err := runRipgrep(cmdRg, searchPath, limit)
145 matches, err := runRipgrep(cmdRg, searchPath, limit)
internal/llm/tools/grep.go+5−5
@@ -206,7 +206,7 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
206 searchPath = g.workingDir
206 searchPath = g.workingDir
207 }
207 }
208
208
209− matches, truncated, err := searchFiles(searchPattern, searchPath, params.Include, 100)
209+ matches, truncated, err := searchFiles(ctx, searchPattern, searchPath, params.Include, 100)
210 if err != nil {
210 if err != nil {
211 return ToolResponse{}, fmt.Errorf("error searching files: %w", err)
211 return ToolResponse{}, fmt.Errorf("error searching files: %w", err)
212 }
212 }
@@ -247,8 +247,8 @@ func (g *grepTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
247 ), nil
247 ), nil
248}
248}
249
249
250−func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
250+func searchFiles(ctx context.Context, pattern, rootPath, include string, limit int) ([]grepMatch, bool, error) {
251− matches, err := searchWithRipgrep(pattern, rootPath, include)
251+ matches, err := searchWithRipgrep(ctx, pattern, rootPath, include)
252 if err != nil {
252 if err != nil {
253 matches, err = searchFilesWithRegex(pattern, rootPath, include)
253 matches, err = searchFilesWithRegex(pattern, rootPath, include)
254 if err != nil {
254 if err != nil {
@@ -268,8 +268,8 @@ func searchFiles(pattern, rootPath, include string, limit int) ([]grepMatch, boo
268 return matches, truncated, nil
268 return matches, truncated, nil
269}
269}
270
270
271−func searchWithRipgrep(pattern, path, include string) ([]grepMatch, error) {
271+func searchWithRipgrep(ctx context.Context, pattern, path, include string) ([]grepMatch, error) {
272− cmd := fsext.GetRgSearchCmd(pattern, path, include)
272+ cmd := fsext.GetRgSearchCmd(ctx, pattern, path, include)
273 if cmd == nil {
273 if cmd == nil {
274 return nil, fmt.Errorf("ripgrep not found in $PATH")
274 return nil, fmt.Errorf("ripgrep not found in $PATH")
275 }
275 }
internal/tui/components/chat/editor/editor.go+2−1
@@ -1,6 +1,7 @@
1package editor
1package editor
2
2
3import (
3import (
4+ "context"
4 "fmt"
5 "fmt"
5 "math/rand"
6 "math/rand"
6 "net/http"
7 "net/http"
@@ -110,7 +111,7 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
110 if _, err := tmpfile.WriteString(value); err != nil {
111 if _, err := tmpfile.WriteString(value); err != nil {
111 return util.ReportError(err)
112 return util.ReportError(err)
112 }
113 }
113− c := exec.Command(editor, tmpfile.Name())
114+ c := exec.CommandContext(context.TODO(), editor, tmpfile.Name())
114 c.Stdin = os.Stdin
115 c.Stdin = os.Stdin
115 c.Stdout = os.Stdout
116 c.Stdout = os.Stdout
116 c.Stderr = os.Stderr
117 c.Stderr = os.Stderr