|
@@ -8,8 +8,8 @@ import (
|
|
|
|
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
- "github.com/sst/opencode/internal/app"
|
|
|
|
|
"github.com/sst/opencode/internal/config"
|
|
"github.com/sst/opencode/internal/config"
|
|
|
|
|
+ "github.com/sst/opencode/internal/tui/app"
|
|
|
// "github.com/sst/opencode/internal/diff"
|
|
// "github.com/sst/opencode/internal/diff"
|
|
|
"github.com/sst/opencode/internal/history"
|
|
"github.com/sst/opencode/internal/history"
|
|
|
"github.com/sst/opencode/internal/pubsub"
|
|
"github.com/sst/opencode/internal/pubsub"
|
|
@@ -216,17 +216,17 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
|
|
|
// TODO: History service not implemented in API yet
|
|
// TODO: History service not implemented in API yet
|
|
|
return
|
|
return
|
|
|
/*
|
|
/*
|
|
|
- // Get all latest files for this session
|
|
|
|
|
- latestFiles, err := m.app.History.ListLatestSessionFiles(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Get all latest files for this session
|
|
|
|
|
+ latestFiles, err := m.app.History.ListLatestSessionFiles(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Get all files for this session (to find initial versions)
|
|
|
|
|
- allFiles, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Get all files for this session (to find initial versions)
|
|
|
|
|
+ allFiles, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
// Clear the existing map to rebuild it
|
|
// Clear the existing map to rebuild it
|
|
@@ -236,28 +236,75 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
- // Process each latest file
|
|
|
|
|
- for _, file := range latestFiles {
|
|
|
|
|
|
|
+ // Process each latest file
|
|
|
|
|
+ for _, file := range latestFiles {
|
|
|
|
|
+ // Skip if this is the initial version (no changes to show)
|
|
|
|
|
+ if file.Version == history.InitialVersion {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Find the initial version for this specific file
|
|
|
|
|
+ var initialVersion history.File
|
|
|
|
|
+ for _, v := range allFiles {
|
|
|
|
|
+ if v.Path == file.Path && v.Version == history.InitialVersion {
|
|
|
|
|
+ initialVersion = v
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Skip if we can't find the initial version
|
|
|
|
|
+ if initialVersion.ID == "" {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ if initialVersion.Content == file.Content {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Calculate diff between initial and latest version
|
|
|
|
|
+ _, additions, removals := diff.GenerateDiff(initialVersion.Content, file.Content, file.Path)
|
|
|
|
|
+
|
|
|
|
|
+ // Only add to modified files if there are changes
|
|
|
|
|
+ if additions > 0 || removals > 0 {
|
|
|
|
|
+ // Remove working directory prefix from file path
|
|
|
|
|
+ displayPath := file.Path
|
|
|
|
|
+ workingDir := config.WorkingDirectory()
|
|
|
|
|
+ displayPath = strings.TrimPrefix(displayPath, workingDir)
|
|
|
|
|
+ displayPath = strings.TrimPrefix(displayPath, "/")
|
|
|
|
|
+
|
|
|
|
|
+ m.modFiles[displayPath] = struct {
|
|
|
|
|
+ additions int
|
|
|
|
|
+ removals int
|
|
|
|
|
+ }{
|
|
|
|
|
+ additions: additions,
|
|
|
|
|
+ removals: removals,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ */
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (m *sidebarCmp) processFileChanges(ctx context.Context, file history.File) {
|
|
|
|
|
+ // TODO: History service not implemented in API yet
|
|
|
|
|
+ return
|
|
|
|
|
+ /*
|
|
|
// Skip if this is the initial version (no changes to show)
|
|
// Skip if this is the initial version (no changes to show)
|
|
|
if file.Version == history.InitialVersion {
|
|
if file.Version == history.InitialVersion {
|
|
|
- continue
|
|
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Find the initial version for this specific file
|
|
|
|
|
- var initialVersion history.File
|
|
|
|
|
- for _, v := range allFiles {
|
|
|
|
|
- if v.Path == file.Path && v.Version == history.InitialVersion {
|
|
|
|
|
- initialVersion = v
|
|
|
|
|
- break
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Find the initial version for this file
|
|
|
|
|
+ initialVersion, err := m.findInitialVersion(ctx, file.Path)
|
|
|
|
|
+ if err != nil || initialVersion.ID == "" {
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Skip if we can't find the initial version
|
|
|
|
|
- if initialVersion.ID == "" {
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Skip if content hasn't changed
|
|
|
if initialVersion.Content == file.Content {
|
|
if initialVersion.Content == file.Content {
|
|
|
- continue
|
|
|
|
|
|
|
+ // If this file was previously modified but now matches the initial version,
|
|
|
|
|
+ // remove it from the modified files list
|
|
|
|
|
+ displayPath := getDisplayPath(file.Path)
|
|
|
|
|
+ delete(m.modFiles, displayPath)
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Calculate diff between initial and latest version
|
|
// Calculate diff between initial and latest version
|
|
@@ -265,12 +312,7 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
|
|
|
|
|
|
|
|
// Only add to modified files if there are changes
|
|
// Only add to modified files if there are changes
|
|
|
if additions > 0 || removals > 0 {
|
|
if additions > 0 || removals > 0 {
|
|
|
- // Remove working directory prefix from file path
|
|
|
|
|
- displayPath := file.Path
|
|
|
|
|
- workingDir := config.WorkingDirectory()
|
|
|
|
|
- displayPath = strings.TrimPrefix(displayPath, workingDir)
|
|
|
|
|
- displayPath = strings.TrimPrefix(displayPath, "/")
|
|
|
|
|
-
|
|
|
|
|
|
|
+ displayPath := getDisplayPath(file.Path)
|
|
|
m.modFiles[displayPath] = struct {
|
|
m.modFiles[displayPath] = struct {
|
|
|
additions int
|
|
additions int
|
|
|
removals int
|
|
removals int
|
|
@@ -278,53 +320,11 @@ func (m *sidebarCmp) loadModifiedFiles(ctx context.Context) {
|
|
|
additions: additions,
|
|
additions: additions,
|
|
|
removals: removals,
|
|
removals: removals,
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // If no changes, remove from modified files
|
|
|
|
|
+ displayPath := getDisplayPath(file.Path)
|
|
|
|
|
+ delete(m.modFiles, displayPath)
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- */
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (m *sidebarCmp) processFileChanges(ctx context.Context, file history.File) {
|
|
|
|
|
- // TODO: History service not implemented in API yet
|
|
|
|
|
- return
|
|
|
|
|
- /*
|
|
|
|
|
- // Skip if this is the initial version (no changes to show)
|
|
|
|
|
- if file.Version == history.InitialVersion {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Find the initial version for this file
|
|
|
|
|
- initialVersion, err := m.findInitialVersion(ctx, file.Path)
|
|
|
|
|
- if err != nil || initialVersion.ID == "" {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Skip if content hasn't changed
|
|
|
|
|
- if initialVersion.Content == file.Content {
|
|
|
|
|
- // If this file was previously modified but now matches the initial version,
|
|
|
|
|
- // remove it from the modified files list
|
|
|
|
|
- displayPath := getDisplayPath(file.Path)
|
|
|
|
|
- delete(m.modFiles, displayPath)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Calculate diff between initial and latest version
|
|
|
|
|
- _, additions, removals := diff.GenerateDiff(initialVersion.Content, file.Content, file.Path)
|
|
|
|
|
-
|
|
|
|
|
- // Only add to modified files if there are changes
|
|
|
|
|
- if additions > 0 || removals > 0 {
|
|
|
|
|
- displayPath := getDisplayPath(file.Path)
|
|
|
|
|
- m.modFiles[displayPath] = struct {
|
|
|
|
|
- additions int
|
|
|
|
|
- removals int
|
|
|
|
|
- }{
|
|
|
|
|
- additions: additions,
|
|
|
|
|
- removals: removals,
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- // If no changes, remove from modified files
|
|
|
|
|
- displayPath := getDisplayPath(file.Path)
|
|
|
|
|
- delete(m.modFiles, displayPath)
|
|
|
|
|
- }
|
|
|
|
|
*/
|
|
*/
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -333,22 +333,22 @@ func (m *sidebarCmp) findInitialVersion(ctx context.Context, path string) (histo
|
|
|
// TODO: History service not implemented in API yet
|
|
// TODO: History service not implemented in API yet
|
|
|
return history.File{}, fmt.Errorf("history service not implemented")
|
|
return history.File{}, fmt.Errorf("history service not implemented")
|
|
|
/*
|
|
/*
|
|
|
- // Get all versions of this file for the session
|
|
|
|
|
- fileVersions, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return history.File{}, err
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Get all versions of this file for the session
|
|
|
|
|
+ fileVersions, err := m.app.History.ListBySession(ctx, m.app.CurrentSession.ID)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return history.File{}, err
|
|
|
|
|
+ }
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
- // Find the initial version
|
|
|
|
|
- for _, v := range fileVersions {
|
|
|
|
|
- if v.Path == path && v.Version == history.InitialVersion {
|
|
|
|
|
- return v, nil
|
|
|
|
|
|
|
+ // Find the initial version
|
|
|
|
|
+ for _, v := range fileVersions {
|
|
|
|
|
+ if v.Path == path && v.Version == history.InitialVersion {
|
|
|
|
|
+ return v, nil
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- return history.File{}, fmt.Errorf("initial version not found")
|
|
|
|
|
|
|
+ return history.File{}, fmt.Errorf("initial version not found")
|
|
|
*/
|
|
*/
|
|
|
}
|
|
}
|
|
|
|
|
|