xonecas.io
62159
Sy

symb / commit 2a44236

feat: lsp diagnostics in conberstion after edits

xonecas2026-02-14 2a44236613e9d7dc8f840a9fcd7bd5f439e1b2b6 parent 7c2c2da

2 files changed

internal/tui/styles.go+5−2
@@ -18,8 +18,9 @@ var (
1818 ColorSurface = ColorHighlight // Selection highlight — reuse accent
1919
2020 // Semantic aliases
21- ColorError = lipgloss.Color("#932e2e")
22- ColorLinkBg = lipgloss.Color("#111111") // Subtle hover background for clickable elements
21+ ColorError = lipgloss.Color("#932e2e")
22+ ColorWarning = lipgloss.Color("#8a6d2b")
23+ ColorLinkBg = lipgloss.Color("#111111") // Subtle hover background for clickable elements
2324 )
2425
2526 // Styles holds all pre-built lipgloss styles used across the TUI.
@@ -30,6 +31,7 @@ type Styles struct {
3031 Muted lipgloss.Style // Reasoning, secondary
3132 Dim lipgloss.Style // Timestamps, placeholders
3233 Error lipgloss.Style // Errors
34+ Warning lipgloss.Style // Warnings
3335 ToolCall lipgloss.Style // Tool call arrows
3436 ToolArrow lipgloss.Style // Tool arrow symbol
3537
@@ -53,6 +55,7 @@ func DefaultStyles() Styles {
5355 Muted: bg.Foreground(ColorMuted),
5456 Dim: bg.Foreground(ColorDim),
5557 Error: bg.Foreground(ColorError),
58+ Warning: bg.Foreground(ColorWarning),
5659 ToolCall: bg.Foreground(ColorDim),
5760 ToolArrow: bg.Foreground(ColorMuted),
5861
internal/tui/update.go+42−5
@@ -340,7 +340,10 @@ func (m *Model) applyToolResultMsg(msg llmToolResultMsg) {
340340 // Grep and Shell show all lines (each clickable); others truncate.
341341 showFull := toolName == "Grep" || toolName == "Shell"
342342
343- lines := strings.Split(msg.content, "\n")
343+ // Split diagnostic lines from the main content so they're always shown.
344+ body, diagLines := extractDiagLines(msg.content)
345+
346+ lines := strings.Split(body, "\n")
344347 preview := lines
345348 truncated := false
346349 if !showFull && len(lines) > maxPreviewLines {
@@ -349,25 +352,59 @@ func (m *Model) applyToolResultMsg(msg llmToolResultMsg) {
349352 }
350353
351354 arrow := m.styles.ToolArrow.Render("←") + " "
355+ entry := func(display string) convEntry {
356+ return convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine}
357+ }
352358 var wasBottom bool
353359 for i, line := range preview {
354- display := m.styles.Dim.Render(line)
360+ display := m.styleToolResultLine(line)
355361 if i == 0 {
356362 display = arrow + display
357- wasBottom = m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
363+ wasBottom = m.appendConv(entry(display))
358364 } else {
359- m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
365+ m.appendConv(entry(display))
360366 }
361367 }
362368 if truncated {
363369 hint := fmt.Sprintf(" ... %d more lines (click to view)", len(lines)-maxPreviewLines)
364- m.appendConv(convEntry{display: m.styles.Muted.Render(hint), kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
370+ m.appendConv(entry(m.styles.Muted.Render(hint)))
371+ }
372+ for _, dl := range diagLines {
373+ m.appendConv(entry(m.styleToolResultLine(dl)))
365374 }
366375 if wasBottom {
367376 m.scrollOffset = 0
368377 }
369378 }
370379
380+// extractDiagLines splits diagnostic lines from tool result content.
381+// Returns the body without the diagnostics block and the ERROR/WARNING lines.
382+func extractDiagLines(content string) (body string, diags []string) {
383+ idx := strings.Index(content, "\nLSP diagnostics:")
384+ if idx < 0 {
385+ return content, nil
386+ }
387+ for _, dl := range strings.Split(content[idx+1:], "\n") {
388+ if strings.HasPrefix(dl, "ERROR ") || strings.HasPrefix(dl, "WARNING ") {
389+ diags = append(diags, dl)
390+ }
391+ }
392+ return content[:idx], diags
393+}
394+
395+// styleToolResultLine applies semantic styling to a tool result line.
396+// Diagnostic lines (ERROR/WARNING) get colored; everything else is dim.
397+func (m *Model) styleToolResultLine(line string) string {
398+ switch {
399+ case strings.HasPrefix(line, "ERROR "):
400+ return m.styles.Error.Render(line)
401+ case strings.HasPrefix(line, "WARNING "):
402+ return m.styles.Warning.Render(line)
403+ default:
404+ return m.styles.Dim.Render(line)
405+ }
406+}
407+
371408 // toolCallEditLine extracts the target line from an Edit tool call's arguments.
372409 // Returns the start line of the edit operation (replace/insert/delete), or 0.
373410 func toolCallEditLine(args json.RawMessage) int {