message.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. package chat
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "path/filepath"
  6. "slices"
  7. "strings"
  8. "time"
  9. "unicode"
  10. "github.com/charmbracelet/lipgloss/v2"
  11. "github.com/charmbracelet/lipgloss/v2/compat"
  12. "github.com/charmbracelet/x/ansi"
  13. "github.com/sst/opencode-sdk-go"
  14. "github.com/sst/opencode/internal/app"
  15. "github.com/sst/opencode/internal/components/diff"
  16. "github.com/sst/opencode/internal/layout"
  17. "github.com/sst/opencode/internal/styles"
  18. "github.com/sst/opencode/internal/theme"
  19. "github.com/tidwall/gjson"
  20. "golang.org/x/text/cases"
  21. "golang.org/x/text/language"
  22. )
  23. func toMarkdown(content string, width int, backgroundColor compat.AdaptiveColor) string {
  24. r := styles.GetMarkdownRenderer(width-7, backgroundColor)
  25. content = strings.ReplaceAll(content, app.RootPath+"/", "")
  26. rendered, _ := r.Render(content)
  27. lines := strings.Split(rendered, "\n")
  28. if len(lines) > 0 {
  29. firstLine := lines[0]
  30. cleaned := ansi.Strip(firstLine)
  31. nospace := strings.ReplaceAll(cleaned, " ", "")
  32. if nospace == "" {
  33. lines = lines[1:]
  34. }
  35. if len(lines) > 0 {
  36. lastLine := lines[len(lines)-1]
  37. cleaned = ansi.Strip(lastLine)
  38. nospace = strings.ReplaceAll(cleaned, " ", "")
  39. if nospace == "" {
  40. lines = lines[:len(lines)-1]
  41. }
  42. }
  43. }
  44. content = strings.Join(lines, "\n")
  45. return strings.TrimSuffix(content, "\n")
  46. }
  47. type blockRenderer struct {
  48. border bool
  49. borderColor *compat.AdaptiveColor
  50. paddingTop int
  51. paddingBottom int
  52. paddingLeft int
  53. paddingRight int
  54. marginTop int
  55. marginBottom int
  56. }
  57. type renderingOption func(*blockRenderer)
  58. func WithNoBorder() renderingOption {
  59. return func(c *blockRenderer) {
  60. c.border = false
  61. }
  62. }
  63. func WithBorderColor(color compat.AdaptiveColor) renderingOption {
  64. return func(c *blockRenderer) {
  65. c.borderColor = &color
  66. }
  67. }
  68. func WithMarginTop(padding int) renderingOption {
  69. return func(c *blockRenderer) {
  70. c.marginTop = padding
  71. }
  72. }
  73. func WithMarginBottom(padding int) renderingOption {
  74. return func(c *blockRenderer) {
  75. c.marginBottom = padding
  76. }
  77. }
  78. func WithPadding(padding int) renderingOption {
  79. return func(c *blockRenderer) {
  80. c.paddingTop = padding
  81. c.paddingBottom = padding
  82. c.paddingLeft = padding
  83. c.paddingRight = padding
  84. }
  85. }
  86. func WithPaddingLeft(padding int) renderingOption {
  87. return func(c *blockRenderer) {
  88. c.paddingLeft = padding
  89. }
  90. }
  91. func WithPaddingRight(padding int) renderingOption {
  92. return func(c *blockRenderer) {
  93. c.paddingRight = padding
  94. }
  95. }
  96. func WithPaddingTop(padding int) renderingOption {
  97. return func(c *blockRenderer) {
  98. c.paddingTop = padding
  99. }
  100. }
  101. func WithPaddingBottom(padding int) renderingOption {
  102. return func(c *blockRenderer) {
  103. c.paddingBottom = padding
  104. }
  105. }
  106. func renderContentBlock(
  107. content string,
  108. width int,
  109. align lipgloss.Position,
  110. options ...renderingOption,
  111. ) string {
  112. t := theme.CurrentTheme()
  113. renderer := &blockRenderer{
  114. border: true,
  115. paddingTop: 1,
  116. paddingBottom: 1,
  117. paddingLeft: 2,
  118. paddingRight: 2,
  119. }
  120. for _, option := range options {
  121. option(renderer)
  122. }
  123. borderColor := t.BackgroundPanel()
  124. if renderer.borderColor != nil {
  125. borderColor = *renderer.borderColor
  126. }
  127. style := styles.NewStyle().
  128. Foreground(t.TextMuted()).
  129. Background(t.BackgroundPanel()).
  130. Width(width).
  131. PaddingTop(renderer.paddingTop).
  132. PaddingBottom(renderer.paddingBottom).
  133. PaddingLeft(renderer.paddingLeft).
  134. PaddingRight(renderer.paddingRight).
  135. AlignHorizontal(lipgloss.Left)
  136. if renderer.border {
  137. style = style.
  138. BorderStyle(lipgloss.ThickBorder()).
  139. BorderLeft(true).
  140. BorderRight(true).
  141. BorderLeftForeground(borderColor).
  142. BorderLeftBackground(t.Background()).
  143. BorderRightForeground(t.BackgroundPanel()).
  144. BorderRightBackground(t.Background())
  145. }
  146. content = style.Render(content)
  147. content = lipgloss.PlaceHorizontal(
  148. width,
  149. lipgloss.Left,
  150. content,
  151. styles.WhitespaceStyle(t.Background()),
  152. )
  153. content = lipgloss.PlaceHorizontal(
  154. layout.Current.Viewport.Width,
  155. align,
  156. content,
  157. styles.WhitespaceStyle(t.Background()),
  158. )
  159. if renderer.marginTop > 0 {
  160. for range renderer.marginTop {
  161. content = "\n" + content
  162. }
  163. }
  164. if renderer.marginBottom > 0 {
  165. for range renderer.marginBottom {
  166. content = content + "\n"
  167. }
  168. }
  169. return content
  170. }
  171. func renderText(
  172. message opencode.Message,
  173. text string,
  174. author string,
  175. showToolDetails bool,
  176. width int,
  177. align lipgloss.Position,
  178. toolCalls ...opencode.ToolInvocationPart,
  179. ) string {
  180. t := theme.CurrentTheme()
  181. timestamp := time.UnixMilli(int64(message.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM")
  182. if time.Now().Format("02 Jan 2006") == timestamp[:11] {
  183. // don't show the date if it's today
  184. timestamp = timestamp[12:]
  185. }
  186. info := fmt.Sprintf("%s (%s)", author, timestamp)
  187. messageStyle := styles.NewStyle().
  188. Background(t.BackgroundPanel()).
  189. Foreground(t.Text())
  190. if message.Role == opencode.MessageRoleUser {
  191. messageStyle = messageStyle.Width(width - 6)
  192. }
  193. content := messageStyle.Render(text)
  194. if message.Role == opencode.MessageRoleAssistant {
  195. content = toMarkdown(text, width, t.BackgroundPanel())
  196. }
  197. if !showToolDetails && toolCalls != nil && len(toolCalls) > 0 {
  198. content = content + "\n\n"
  199. for _, toolCall := range toolCalls {
  200. title := renderToolTitle(toolCall, message.Metadata, width)
  201. metadata := opencode.MessageMetadataTool{}
  202. if _, ok := message.Metadata.Tool[toolCall.ToolInvocation.ToolCallID]; ok {
  203. metadata = message.Metadata.Tool[toolCall.ToolInvocation.ToolCallID]
  204. }
  205. style := styles.NewStyle()
  206. if _, ok := metadata.ExtraFields["error"]; ok {
  207. style = style.Foreground(t.Error())
  208. }
  209. title = style.Render(title)
  210. title = "∟ " + title + "\n"
  211. content = content + title
  212. }
  213. }
  214. content = strings.Join([]string{content, info}, "\n")
  215. switch message.Role {
  216. case opencode.MessageRoleUser:
  217. return renderContentBlock(
  218. content,
  219. width,
  220. align,
  221. WithBorderColor(t.Secondary()),
  222. )
  223. case opencode.MessageRoleAssistant:
  224. return renderContentBlock(
  225. content,
  226. width,
  227. align,
  228. WithBorderColor(t.Accent()),
  229. )
  230. }
  231. return ""
  232. }
  233. func renderToolDetails(
  234. toolCall opencode.ToolInvocationPart,
  235. messageMetadata opencode.MessageMetadata,
  236. width int,
  237. align lipgloss.Position,
  238. ) string {
  239. ignoredTools := []string{"todoread"}
  240. if slices.Contains(ignoredTools, toolCall.ToolInvocation.ToolName) {
  241. return ""
  242. }
  243. toolCallID := toolCall.ToolInvocation.ToolCallID
  244. metadata := opencode.MessageMetadataTool{}
  245. if _, ok := messageMetadata.Tool[toolCallID]; ok {
  246. metadata = messageMetadata.Tool[toolCallID]
  247. }
  248. var result *string
  249. if toolCall.ToolInvocation.Result != "" {
  250. result = &toolCall.ToolInvocation.Result
  251. }
  252. if toolCall.ToolInvocation.State == "partial-call" {
  253. title := renderToolTitle(toolCall, messageMetadata, width)
  254. return renderContentBlock(title, width, align)
  255. }
  256. toolArgsMap := make(map[string]any)
  257. if toolCall.ToolInvocation.Args != nil {
  258. value := toolCall.ToolInvocation.Args
  259. if m, ok := value.(map[string]any); ok {
  260. toolArgsMap = m
  261. keys := make([]string, 0, len(toolArgsMap))
  262. for key := range toolArgsMap {
  263. keys = append(keys, key)
  264. }
  265. slices.Sort(keys)
  266. }
  267. }
  268. body := ""
  269. finished := result != nil && *result != ""
  270. t := theme.CurrentTheme()
  271. switch toolCall.ToolInvocation.ToolName {
  272. case "read":
  273. preview := metadata.ExtraFields["preview"]
  274. if preview != nil && toolArgsMap["filePath"] != nil {
  275. filename := toolArgsMap["filePath"].(string)
  276. body = preview.(string)
  277. body = renderFile(filename, body, width, WithTruncate(6))
  278. }
  279. case "edit":
  280. if filename, ok := toolArgsMap["filePath"].(string); ok {
  281. diffField := metadata.ExtraFields["diff"]
  282. if diffField != nil {
  283. patch := diffField.(string)
  284. var formattedDiff string
  285. formattedDiff, _ = diff.FormatUnifiedDiff(
  286. filename,
  287. patch,
  288. diff.WithWidth(width-2),
  289. )
  290. formattedDiff = strings.TrimSpace(formattedDiff)
  291. formattedDiff = styles.NewStyle().
  292. BorderStyle(lipgloss.ThickBorder()).
  293. BorderBackground(t.Background()).
  294. BorderForeground(t.BackgroundPanel()).
  295. BorderLeft(true).
  296. BorderRight(true).
  297. Render(formattedDiff)
  298. body = strings.TrimSpace(formattedDiff)
  299. body = renderContentBlock(
  300. body,
  301. width,
  302. align,
  303. WithNoBorder(),
  304. WithPadding(0),
  305. )
  306. if diagnostics := renderDiagnostics(metadata, filename); diagnostics != "" {
  307. body += "\n" + renderContentBlock(diagnostics, width, align)
  308. }
  309. title := renderToolTitle(toolCall, messageMetadata, width)
  310. title = renderContentBlock(title, width, align)
  311. content := title + "\n" + body
  312. return content
  313. }
  314. }
  315. case "write":
  316. if filename, ok := toolArgsMap["filePath"].(string); ok {
  317. if content, ok := toolArgsMap["content"].(string); ok {
  318. body = renderFile(filename, content, width)
  319. if diagnostics := renderDiagnostics(metadata, filename); diagnostics != "" {
  320. body += "\n\n" + diagnostics
  321. }
  322. }
  323. }
  324. case "bash":
  325. stdout := metadata.JSON.ExtraFields["stdout"]
  326. if !stdout.IsNull() {
  327. command := toolArgsMap["command"].(string)
  328. stdout := stdout.Raw()
  329. body = fmt.Sprintf("```console\n> %s\n%s```", command, stdout)
  330. body = toMarkdown(body, width, t.BackgroundPanel())
  331. }
  332. case "webfetch":
  333. if format, ok := toolArgsMap["format"].(string); ok && result != nil {
  334. body = *result
  335. body = truncateHeight(body, 10)
  336. if format == "html" || format == "markdown" {
  337. body = toMarkdown(body, width, t.BackgroundPanel())
  338. }
  339. }
  340. case "todowrite":
  341. todos := metadata.JSON.ExtraFields["todos"]
  342. if !todos.IsNull() && finished {
  343. strTodos := todos.Raw()
  344. todos := gjson.Parse(strTodos)
  345. for _, todo := range todos.Array() {
  346. content := todo.Get("content").String()
  347. switch todo.Get("status").String() {
  348. case "completed":
  349. body += fmt.Sprintf("- [x] %s\n", content)
  350. // case "in-progress":
  351. // body += fmt.Sprintf("- [ ] %s\n", content)
  352. default:
  353. body += fmt.Sprintf("- [ ] %s\n", content)
  354. }
  355. }
  356. body = toMarkdown(body, width, t.BackgroundPanel())
  357. }
  358. case "task":
  359. summary := metadata.JSON.ExtraFields["summary"]
  360. if !summary.IsNull() {
  361. strValue := summary.Raw()
  362. toolcalls := gjson.Parse(strValue).Array()
  363. steps := []string{}
  364. for _, toolcall := range toolcalls {
  365. call := toolcall.Value().(map[string]any)
  366. if toolInvocation, ok := call["toolInvocation"].(map[string]any); ok {
  367. data, _ := json.Marshal(toolInvocation)
  368. var toolCall opencode.ToolInvocationPart
  369. _ = json.Unmarshal(data, &toolCall)
  370. if metadata, ok := call["metadata"].(map[string]any); ok {
  371. data, _ = json.Marshal(metadata)
  372. var toolMetadata opencode.MessageMetadataTool
  373. _ = json.Unmarshal(data, &toolMetadata)
  374. step := renderToolTitle(toolCall, messageMetadata, width)
  375. step = "∟ " + step
  376. steps = append(steps, step)
  377. }
  378. }
  379. }
  380. body = strings.Join(steps, "\n")
  381. }
  382. default:
  383. if result == nil {
  384. empty := ""
  385. result = &empty
  386. }
  387. body = *result
  388. body = truncateHeight(body, 10)
  389. }
  390. error := ""
  391. if err, ok := metadata.ExtraFields["error"].(bool); ok && err {
  392. if message, ok := metadata.ExtraFields["message"].(string); ok {
  393. error = message
  394. }
  395. }
  396. if error != "" {
  397. body = styles.NewStyle().
  398. Foreground(t.Error()).
  399. Background(t.BackgroundPanel()).
  400. Render(error)
  401. }
  402. if body == "" && error == "" && result != nil {
  403. body = *result
  404. body = truncateHeight(body, 10)
  405. }
  406. title := renderToolTitle(toolCall, messageMetadata, width)
  407. content := title + "\n\n" + body
  408. return renderContentBlock(content, width, align)
  409. }
  410. func renderToolName(name string) string {
  411. switch name {
  412. case "webfetch":
  413. return "Fetch"
  414. case "todowrite", "todoread":
  415. return "Plan"
  416. default:
  417. normalizedName := name
  418. if strings.HasPrefix(name, "opencode_") {
  419. normalizedName = strings.TrimPrefix(name, "opencode_")
  420. }
  421. return cases.Title(language.Und).String(normalizedName)
  422. }
  423. }
  424. func renderToolTitle(
  425. toolCall opencode.ToolInvocationPart,
  426. messageMetadata opencode.MessageMetadata,
  427. width int,
  428. ) string {
  429. // TODO: handle truncate to width
  430. if toolCall.ToolInvocation.State == "partial-call" {
  431. return renderToolAction(toolCall.ToolInvocation.ToolName)
  432. }
  433. toolArgs := ""
  434. toolArgsMap := make(map[string]any)
  435. if toolCall.ToolInvocation.Args != nil {
  436. value := toolCall.ToolInvocation.Args
  437. if m, ok := value.(map[string]any); ok {
  438. toolArgsMap = m
  439. keys := make([]string, 0, len(toolArgsMap))
  440. for key := range toolArgsMap {
  441. keys = append(keys, key)
  442. }
  443. slices.Sort(keys)
  444. firstKey := ""
  445. if len(keys) > 0 {
  446. firstKey = keys[0]
  447. }
  448. toolArgs = renderArgs(&toolArgsMap, firstKey)
  449. }
  450. }
  451. title := renderToolName(toolCall.ToolInvocation.ToolName)
  452. switch toolCall.ToolInvocation.ToolName {
  453. case "read":
  454. toolArgs = renderArgs(&toolArgsMap, "filePath")
  455. title = fmt.Sprintf("%s %s", title, toolArgs)
  456. case "edit", "write":
  457. if filename, ok := toolArgsMap["filePath"].(string); ok {
  458. title = fmt.Sprintf("%s %s", title, relative(filename))
  459. }
  460. case "bash", "task":
  461. if description, ok := toolArgsMap["description"].(string); ok {
  462. title = fmt.Sprintf("%s %s", title, description)
  463. }
  464. case "webfetch":
  465. toolArgs = renderArgs(&toolArgsMap, "url")
  466. title = fmt.Sprintf("%s %s", title, toolArgs)
  467. case "todowrite", "todoread":
  468. // title is just the tool name
  469. default:
  470. toolName := renderToolName(toolCall.ToolInvocation.ToolName)
  471. title = fmt.Sprintf("%s %s", toolName, toolArgs)
  472. }
  473. return title
  474. }
  475. func renderToolAction(name string) string {
  476. switch name {
  477. case "task":
  478. return "Searching..."
  479. case "bash":
  480. return "Writing command..."
  481. case "edit":
  482. return "Preparing edit..."
  483. case "webfetch":
  484. return "Fetching from the web..."
  485. case "glob":
  486. return "Finding files..."
  487. case "grep":
  488. return "Searching content..."
  489. case "list":
  490. return "Listing directory..."
  491. case "read":
  492. return "Reading file..."
  493. case "write":
  494. return "Preparing write..."
  495. case "todowrite", "todoread":
  496. return "Planning..."
  497. case "patch":
  498. return "Preparing patch..."
  499. }
  500. return "Working..."
  501. }
  502. type fileRenderer struct {
  503. filename string
  504. content string
  505. height int
  506. }
  507. type fileRenderingOption func(*fileRenderer)
  508. func WithTruncate(height int) fileRenderingOption {
  509. return func(c *fileRenderer) {
  510. c.height = height
  511. }
  512. }
  513. func renderFile(
  514. filename string,
  515. content string,
  516. width int,
  517. options ...fileRenderingOption) string {
  518. t := theme.CurrentTheme()
  519. renderer := &fileRenderer{
  520. filename: filename,
  521. content: content,
  522. }
  523. for _, option := range options {
  524. option(renderer)
  525. }
  526. lines := []string{}
  527. for line := range strings.SplitSeq(content, "\n") {
  528. line = strings.TrimRightFunc(line, unicode.IsSpace)
  529. line = strings.ReplaceAll(line, "\t", " ")
  530. lines = append(lines, line)
  531. }
  532. content = strings.Join(lines, "\n")
  533. if renderer.height > 0 {
  534. content = truncateHeight(content, renderer.height)
  535. }
  536. content = fmt.Sprintf("```%s\n%s\n```", extension(renderer.filename), content)
  537. content = toMarkdown(content, width, t.BackgroundPanel())
  538. return content
  539. }
  540. func renderArgs(args *map[string]any, titleKey string) string {
  541. if args == nil || len(*args) == 0 {
  542. return ""
  543. }
  544. keys := make([]string, 0, len(*args))
  545. for key := range *args {
  546. keys = append(keys, key)
  547. }
  548. slices.Sort(keys)
  549. title := ""
  550. parts := []string{}
  551. for _, key := range keys {
  552. value := (*args)[key]
  553. if value == nil {
  554. continue
  555. }
  556. if key == "filePath" || key == "path" {
  557. value = relative(value.(string))
  558. }
  559. if key == titleKey {
  560. title = fmt.Sprintf("%s", value)
  561. continue
  562. }
  563. parts = append(parts, fmt.Sprintf("%s=%v", key, value))
  564. }
  565. if len(parts) == 0 {
  566. return title
  567. }
  568. return fmt.Sprintf("%s (%s)", title, strings.Join(parts, ", "))
  569. }
  570. func truncateHeight(content string, height int) string {
  571. lines := strings.Split(content, "\n")
  572. if len(lines) > height {
  573. return strings.Join(lines[:height], "\n")
  574. }
  575. return content
  576. }
  577. func relative(path string) string {
  578. path = strings.TrimPrefix(path, app.CwdPath+"/")
  579. return strings.TrimPrefix(path, app.RootPath+"/")
  580. }
  581. func extension(path string) string {
  582. ext := filepath.Ext(path)
  583. if ext == "" {
  584. ext = ""
  585. } else {
  586. ext = strings.ToLower(ext[1:])
  587. }
  588. return ext
  589. }
  590. // Diagnostic represents an LSP diagnostic
  591. type Diagnostic struct {
  592. Range struct {
  593. Start struct {
  594. Line int `json:"line"`
  595. Character int `json:"character"`
  596. } `json:"start"`
  597. } `json:"range"`
  598. Severity int `json:"severity"`
  599. Message string `json:"message"`
  600. }
  601. // renderDiagnostics formats LSP diagnostics for display in the TUI
  602. func renderDiagnostics(metadata opencode.MessageMetadataTool, filePath string) string {
  603. if diagnosticsData, ok := metadata.ExtraFields["diagnostics"].(map[string]any); ok {
  604. if fileDiagnostics, ok := diagnosticsData[filePath].([]any); ok {
  605. var errorDiagnostics []string
  606. for _, diagInterface := range fileDiagnostics {
  607. diagMap, ok := diagInterface.(map[string]any)
  608. if !ok {
  609. continue
  610. }
  611. // Parse the diagnostic
  612. var diag Diagnostic
  613. diagBytes, err := json.Marshal(diagMap)
  614. if err != nil {
  615. continue
  616. }
  617. if err := json.Unmarshal(diagBytes, &diag); err != nil {
  618. continue
  619. }
  620. // Only show error diagnostics (severity === 1)
  621. if diag.Severity != 1 {
  622. continue
  623. }
  624. line := diag.Range.Start.Line + 1 // 1-based
  625. column := diag.Range.Start.Character + 1 // 1-based
  626. errorDiagnostics = append(errorDiagnostics, fmt.Sprintf("Error [%d:%d] %s", line, column, diag.Message))
  627. }
  628. if len(errorDiagnostics) == 0 {
  629. return ""
  630. }
  631. t := theme.CurrentTheme()
  632. var result strings.Builder
  633. for _, diagnostic := range errorDiagnostics {
  634. if result.Len() > 0 {
  635. result.WriteString("\n")
  636. }
  637. result.WriteString(styles.NewStyle().Foreground(t.Error()).Render(diagnostic))
  638. }
  639. return result.String()
  640. }
  641. }
  642. return ""
  643. // diagnosticsData should be a map[string][]Diagnostic
  644. // strDiagnosticsData := diagnosticsData.Raw()
  645. // diagnosticsMap := gjson.Parse(strDiagnosticsData).Value().(map[string]any)
  646. // fileDiagnostics, ok := diagnosticsMap[filePath]
  647. // if !ok {
  648. // return ""
  649. // }
  650. // diagnosticsList, ok := fileDiagnostics.([]any)
  651. // if !ok {
  652. // return ""
  653. // }
  654. }