Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/tui/internal/completions/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package completions
import (
"context"
"log/slog"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -36,12 +38,23 @@ func (cg *filesContextGroup) getGitFiles() []CompletionSuggestion {
return files[i].Added+files[i].Removed > files[j].Added+files[j].Removed
})

cwd, err := os.Getwd()
for _, file := range files {
// Convert path from relative to git repo root to relative to current working directory
relativePath := file.Path
if err == nil {
if absPath := filepath.Join(cg.app.Project.Worktree, file.Path); absPath != "" {
if relPath, err := filepath.Rel(cwd, absPath); err == nil {
relativePath = relPath
}
}
}

displayFunc := func(s styles.Style) string {
t := theme.CurrentTheme()
green := s.Foreground(t.Success()).Render
red := s.Foreground(t.Error()).Render
display := file.Path
display := relativePath
if file.Added > 0 {
display += green(" +" + strconv.Itoa(int(file.Added)))
}
Expand All @@ -52,7 +65,7 @@ func (cg *filesContextGroup) getGitFiles() []CompletionSuggestion {
}
item := CompletionSuggestion{
Display: displayFunc,
Value: file.Path,
Value: relativePath,
ProviderID: cg.GetId(),
RawData: file,
}
Expand Down