summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-11-11 12:15:33 -0500
committerDax Raad <[email protected]>2025-11-11 12:15:40 -0500
commitb0b7fd143b8d44b673f6b0a6dc4c6faaae6afe5b (patch)
tree16bdd678330696a548c487c36d4d564a3ffa1205 /packages
parent140498eb4f971e31acff3c3252e731dd0683d32a (diff)
downloadopencode-b0b7fd143b8d44b673f6b0a6dc4c6faaae6afe5b.tar.gz
opencode-b0b7fd143b8d44b673f6b0a6dc4c6faaae6afe5b.zip
tui: show LSP diagnostics inline when viewing files so users can see type errors and compilation issues without leaving the interface
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/cli/cmd/tui/routes/session/index.tsx29
-rw-r--r--packages/opencode/src/lsp/index.ts2
2 files changed, 30 insertions, 1 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
index 7b91aa3fc..746015c87 100644
--- a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
+++ b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
@@ -58,6 +58,7 @@ import { Editor } from "../../util/editor"
import { Global } from "@/global"
import fs from "fs/promises"
import stripAnsi from "strip-ansi"
+import { LSP } from "@/lsp/index.ts"
addDefaultParsers(parsers.parsers)
@@ -1201,6 +1202,8 @@ ToolRegistry.register<typeof WriteTool>({
.map((x) => x.toString().padStart(pad, " "))
})
+ const diagnostics = createMemo(() => props.metadata.diagnostics?.[props.input.filePath ?? ""] ?? [])
+
return (
<>
<ToolTitle icon="←" fallback="Preparing write..." when={props.input.filePath}>
@@ -1214,6 +1217,15 @@ ToolRegistry.register<typeof WriteTool>({
<code filetype={filetype(props.input.filePath!)} syntaxStyle={syntax()} content={code()} />
</box>
</box>
+ <Show when={diagnostics().length}>
+ <For each={diagnostics()}>
+ {(diagnostic) => (
+ <text fg={theme.error}>
+ Error [{diagnostic.range.start.line}:{diagnostic.range.start.character}]: {diagnostic.message}
+ </text>
+ )}
+ </For>
+ </Show>
</>
)
},
@@ -1391,6 +1403,12 @@ ToolRegistry.register<typeof EditTool>({
const ft = createMemo(() => filetype(props.input.filePath))
+ createEffect(() => console.log(props.metadata.diagnostics))
+ const diagnostics = createMemo(() => {
+ const arr = props.metadata.diagnostics?.[props.input.filePath ?? ""] ?? []
+ return arr.filter((x) => x.severity === 1).slice(0, 3)
+ })
+
return (
<>
<ToolTitle icon="←" fallback="Preparing edit..." when={props.input.filePath}>
@@ -1419,6 +1437,17 @@ ToolRegistry.register<typeof EditTool>({
</box>
</Match>
</Switch>
+ <Show when={diagnostics().length}>
+ <box>
+ <For each={diagnostics()}>
+ {(diagnostic) => (
+ <text fg={theme.error}>
+ Error [{diagnostic.range.start.line + 1}:{diagnostic.range.start.character + 1}] {diagnostic.message}
+ </text>
+ )}
+ </For>
+ </box>
+ </Show>
</>
)
},
diff --git a/packages/opencode/src/lsp/index.ts b/packages/opencode/src/lsp/index.ts
index 8640489b1..44cf263f0 100644
--- a/packages/opencode/src/lsp/index.ts
+++ b/packages/opencode/src/lsp/index.ts
@@ -193,10 +193,10 @@ export namespace LSP {
}
export async function touchFile(input: string, waitForDiagnostics?: boolean) {
+ log.info("touching file", { file: input })
const clients = await getClients(input)
await run(async (client) => {
if (!clients.includes(client)) return
-
const wait = waitForDiagnostics ? client.waitForDiagnostics({ path: input }) : Promise.resolve()
await client.notify.open({ path: input })
return wait