@@ -9,6 +9,9 @@ import (
99 "time"
1010
1111 tea "charm.land/bubbletea/v2"
12+ "github.com/hexops/gotextdiff"
13+ "github.com/hexops/gotextdiff/myers"
14+ "github.com/hexops/gotextdiff/span"
1215 "github.com/rs/zerolog/log"
1316 "github.com/xonecas/symb/internal/delta"
1417 "github.com/xonecas/symb/internal/llm"
@@ -131,6 +134,34 @@ func (m Model) sendToLLM(userInput string) tea.Cmd {
131134 return func() tea.Msg { return llmUserMsg{content: userInput} }
132135 }
133136
137+func (m Model) sendDiffToLLM() tea.Cmd {
138+ return func() tea.Msg {
139+ if m.editorFilePath == "" {
140+ return nil
141+ }
142+ onDisk, err := os.ReadFile(m.editorFilePath)
143+ if err != nil {
144+ return nil
145+ }
146+ current := m.editor.Value()
147+ if current == string(onDisk) {
148+ return nil
149+ }
150+ uri := span.URIFromPath(m.editorFilePath)
151+ edits := myers.ComputeEdits(uri, string(onDisk), current)
152+ if len(edits) == 0 {
153+ return nil
154+ }
155+ diff := fmt.Sprint(gotextdiff.ToUnified(m.editorFilePath, m.editorFilePath, string(onDisk), edits))
156+ if strings.TrimSpace(diff) == "" {
157+ return nil
158+ }
159+ content := "Apply the following diff:\n```diff\n" + diff + "\n```"
160+ return llmUserMsg{content: content}
161+ }
162+}
163+
164+
134165 func (m Model) waitForLLMUpdate() tea.Cmd {
135166 ch := m.updateChan
136167 return func() tea.Msg {