Skip to content

Commit c607677

Browse files
move lsp diagnostics routes to tui.ts to avoid type instantiation depth limit error in server.ts
lsp_diagnostics defaults to "true"
1 parent 6c9b3c2 commit c607677

8 files changed

Lines changed: 108 additions & 102 deletions

File tree

packages/app/src/context/global-sync.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type State = {
5252
[name: string]: McpStatus
5353
}
5454
lsp: LspStatus[]
55-
lsp_diagnostics: boolean | undefined
55+
lsp_diagnostics: boolean
5656
vcs: VcsInfo | undefined
5757
limit: number
5858
message: {
@@ -99,7 +99,7 @@ function createGlobalSync() {
9999
permission: {},
100100
mcp: {},
101101
lsp: [],
102-
lsp_diagnostics: undefined,
102+
lsp_diagnostics: true,
103103
vcs: undefined,
104104
limit: 5,
105105
message: {},
@@ -174,7 +174,7 @@ function createGlobalSync() {
174174
loadSessions(directory),
175175
sdk.mcp.status().then((x) => setStore("mcp", x.data!)),
176176
sdk.lsp.status().then((x) => setStore("lsp", x.data!)),
177-
sdk.lsp.diagnostics.status().then((x) => setStore("lsp_diagnostics", x.data?.enabled)),
177+
sdk.lsp.diagnostics.status().then((x) => setStore("lsp_diagnostics", x.data?.enabled ?? true)),
178178
sdk.vcs.get().then((x) => setStore("vcs", x.data)),
179179
sdk.permission.list().then((x) => {
180180
const grouped: Record<string, PermissionRequest[]> = {}

packages/app/src/pages/session.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,13 @@ export default function Page() {
443443
onSelect: async () => {
444444
await sdk.client.lsp.diagnostics.toggle()
445445
const status = await sdk.client.lsp.diagnostics.status()
446-
sync.set("lsp_diagnostics", status.data?.enabled)
447-
showToast({
448-
title: "LSP Diagnostics",
449-
description: `Diagnostics ${status.data?.enabled ? "enabled" : "disabled"}`,
450-
})
446+
if (status.data) {
447+
sync.set("lsp_diagnostics", status.data.enabled)
448+
showToast({
449+
title: "LSP Diagnostics",
450+
description: `Diagnostics ${status.data.enabled ? "enabled" : "disabled"}`,
451+
})
452+
}
451453
},
452454
},
453455
{

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,14 @@ function App() {
372372
onSelect: async () => {
373373
await sdk.client.lsp.diagnostics.toggle()
374374
const status = await sdk.client.lsp.diagnostics.status()
375-
sync.set("lsp_diagnostics", status.data?.enabled)
376-
toast.show({
377-
variant: "info",
378-
message: `LSP diagnostics ${status.data?.enabled ? "enabled" : "disabled"}`,
379-
duration: 2000,
380-
})
375+
if (status.data) {
376+
sync.set("lsp_diagnostics", status.data.enabled)
377+
toast.show({
378+
variant: "info",
379+
message: `LSP diagnostics ${status.data.enabled ? "enabled" : "disabled"}`,
380+
duration: 2000,
381+
})
382+
}
381383
},
382384
},
383385
{

packages/opencode/src/cli/cmd/tui/context/sync.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
6060
[messageID: string]: Part[]
6161
}
6262
lsp: LspStatus[]
63-
lsp_diagnostics: boolean | undefined
63+
lsp_diagnostics: boolean
6464
mcp: {
6565
[key: string]: McpStatus
6666
}
@@ -91,7 +91,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
9191
message: {},
9292
part: {},
9393
lsp: [],
94-
lsp_diagnostics: undefined,
94+
lsp_diagnostics: true,
9595
mcp: {},
9696
mcp_resource: {},
9797
formatter: [],
@@ -302,7 +302,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
302302
...(args.continue ? [] : [sessionListPromise]),
303303
sdk.client.command.list().then((x) => setStore("command", reconcile(x.data ?? []))),
304304
sdk.client.lsp.status().then((x) => setStore("lsp", reconcile(x.data!))),
305-
sdk.client.lsp.diagnostics.status().then((x) => setStore("lsp_diagnostics", x.data?.enabled)),
305+
sdk.client.lsp.diagnostics.status().then((x) => setStore("lsp_diagnostics", x.data?.enabled ?? true)),
306306
sdk.client.mcp.status().then((x) => setStore("mcp", reconcile(x.data!))),
307307
sdk.client.experimental.resource.list().then((x) => setStore("mcp_resource", reconcile(x.data ?? {}))),
308308
sdk.client.formatter.status().then((x) => setStore("formatter", reconcile(x.data!))),

packages/opencode/src/server/server.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { PermissionNext } from "@/permission/next"
5151
import { Installation } from "@/installation"
5252
import { MDNS } from "./mdns"
5353
import { Worktree } from "../worktree"
54+
import ignore from "ignore"
5455

5556
// @ts-ignore This global is needed to prevent ai-sdk from logging warnings to stdout https://github.com/vercel/ai/blob/2dc67e0ef538307f21368db32d5a12345d98831b/packages/ai/src/logger/log-warnings.ts#L85
5657
globalThis.AI_SDK_LOG_WARNINGS = false
@@ -2403,49 +2404,6 @@ export namespace Server {
24032404
return c.json(await LSP.status())
24042405
},
24052406
)
2406-
.get(
2407-
"/lsp/diagnostics/status",
2408-
describeRoute({
2409-
summary: "Get LSP diagnostics toggle status",
2410-
description: "Returns the current state of LSP diagnostics toggle",
2411-
operationId: "lsp.diagnostics.status",
2412-
responses: {
2413-
200: {
2414-
description: "LSP diagnostics toggle status",
2415-
content: {
2416-
"application/json": {
2417-
schema: resolver(LSP.DiagnosticsStatus),
2418-
},
2419-
},
2420-
},
2421-
},
2422-
}),
2423-
async (c) => {
2424-
return c.json(await LSP.diagnosticsStatus())
2425-
},
2426-
)
2427-
.post(
2428-
"/lsp/diagnostics/toggle",
2429-
describeRoute({
2430-
summary: "Toggle LSP diagnostics",
2431-
description: "Toggle whether LSP diagnostics are sent to the model",
2432-
operationId: "lsp.diagnostics.toggle",
2433-
responses: {
2434-
200: {
2435-
description: "Updated diagnostics status",
2436-
content: {
2437-
"application/json": {
2438-
schema: resolver(LSP.DiagnosticsStatus),
2439-
},
2440-
},
2441-
},
2442-
},
2443-
}),
2444-
async (c) => {
2445-
const enabled = await LSP.toggleDiagnostics()
2446-
return c.json({ enabled })
2447-
},
2448-
)
24492407
.get(
24502408
"/formatter",
24512409
describeRoute({

packages/opencode/src/server/tui.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Hono, type Context } from "hono"
22
import { describeRoute, resolver, validator } from "hono-openapi"
33
import { z } from "zod"
44
import { AsyncQueue } from "../util/queue"
5+
import { LSP } from "@/lsp"
56

67
const TuiRequest = z.object({
78
path: z.string(),
@@ -69,3 +70,46 @@ export const TuiRoute = new Hono()
6970
return c.json(true)
7071
},
7172
)
73+
.get(
74+
"/lsp/diagnostics/status",
75+
describeRoute({
76+
summary: "Get LSP diagnostics toggle status",
77+
description: "Returns the current state of LSP diagnostics toggle",
78+
operationId: "lsp.diagnostics.status",
79+
responses: {
80+
200: {
81+
description: "LSP diagnostics toggle status",
82+
content: {
83+
"application/json": {
84+
schema: resolver(LSP.DiagnosticsStatus),
85+
},
86+
},
87+
},
88+
},
89+
}),
90+
async (c) => {
91+
return c.json(await LSP.diagnosticsStatus())
92+
},
93+
)
94+
.post(
95+
"/lsp/diagnostics/toggle",
96+
describeRoute({
97+
summary: "Toggle LSP diagnostics",
98+
description: "Toggle whether LSP diagnostics are sent to the model",
99+
operationId: "lsp.diagnostics.toggle",
100+
responses: {
101+
200: {
102+
description: "Updated diagnostics status",
103+
content: {
104+
"application/json": {
105+
schema: resolver(LSP.DiagnosticsStatus),
106+
},
107+
},
108+
},
109+
},
110+
}),
111+
async (c) => {
112+
const enabled = await LSP.toggleDiagnostics()
113+
return c.json({ enabled })
114+
},
115+
)

packages/sdk/js/src/v2/gen/sdk.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ export class Diagnostics extends HeyApiClient {
24982498
) {
24992499
const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }])
25002500
return (options?.client ?? this.client).get<LspDiagnosticsStatusResponses, unknown, ThrowOnError>({
2501-
url: "/lsp/diagnostics/status",
2501+
url: "/tui/control/lsp/diagnostics/status",
25022502
...options,
25032503
...params,
25042504
})
@@ -2517,7 +2517,7 @@ export class Diagnostics extends HeyApiClient {
25172517
) {
25182518
const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "directory" }] }])
25192519
return (options?.client ?? this.client).post<LspDiagnosticsToggleResponses, unknown, ThrowOnError>({
2520-
url: "/lsp/diagnostics/toggle",
2520+
url: "/tui/control/lsp/diagnostics/toggle",
25212521
...options,
25222522
...params,
25232523
})

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,16 +1980,16 @@ export type LspStatus = {
19801980
status: "connected" | "error"
19811981
}
19821982

1983-
export type LspDiagnosticsStatus = {
1984-
enabled: boolean
1985-
}
1986-
19871983
export type FormatterStatus = {
19881984
name: string
19891985
extensions: Array<string>
19901986
enabled: boolean
19911987
}
19921988

1989+
export type LspDiagnosticsStatus = {
1990+
enabled: boolean
1991+
}
1992+
19931993
export type OAuth = {
19941994
type: "oauth"
19951995
refresh: string
@@ -4238,42 +4238,6 @@ export type LspStatusResponses = {
42384238

42394239
export type LspStatusResponse = LspStatusResponses[keyof LspStatusResponses]
42404240

4241-
export type LspDiagnosticsStatusData = {
4242-
body?: never
4243-
path?: never
4244-
query?: {
4245-
directory?: string
4246-
}
4247-
url: "/lsp/diagnostics/status"
4248-
}
4249-
4250-
export type LspDiagnosticsStatusResponses = {
4251-
/**
4252-
* LSP diagnostics toggle status
4253-
*/
4254-
200: LspDiagnosticsStatus
4255-
}
4256-
4257-
export type LspDiagnosticsStatusResponse = LspDiagnosticsStatusResponses[keyof LspDiagnosticsStatusResponses]
4258-
4259-
export type LspDiagnosticsToggleData = {
4260-
body?: never
4261-
path?: never
4262-
query?: {
4263-
directory?: string
4264-
}
4265-
url: "/lsp/diagnostics/toggle"
4266-
}
4267-
4268-
export type LspDiagnosticsToggleResponses = {
4269-
/**
4270-
* Updated diagnostics status
4271-
*/
4272-
200: LspDiagnosticsStatus
4273-
}
4274-
4275-
export type LspDiagnosticsToggleResponse = LspDiagnosticsToggleResponses[keyof LspDiagnosticsToggleResponses]
4276-
42774241
export type FormatterStatusData = {
42784242
body?: never
42794243
path?: never
@@ -4586,6 +4550,42 @@ export type TuiControlResponseResponses = {
45864550

45874551
export type TuiControlResponseResponse = TuiControlResponseResponses[keyof TuiControlResponseResponses]
45884552

4553+
export type LspDiagnosticsStatusData = {
4554+
body?: never
4555+
path?: never
4556+
query?: {
4557+
directory?: string
4558+
}
4559+
url: "/tui/control/lsp/diagnostics/status"
4560+
}
4561+
4562+
export type LspDiagnosticsStatusResponses = {
4563+
/**
4564+
* LSP diagnostics toggle status
4565+
*/
4566+
200: LspDiagnosticsStatus
4567+
}
4568+
4569+
export type LspDiagnosticsStatusResponse = LspDiagnosticsStatusResponses[keyof LspDiagnosticsStatusResponses]
4570+
4571+
export type LspDiagnosticsToggleData = {
4572+
body?: never
4573+
path?: never
4574+
query?: {
4575+
directory?: string
4576+
}
4577+
url: "/tui/control/lsp/diagnostics/toggle"
4578+
}
4579+
4580+
export type LspDiagnosticsToggleResponses = {
4581+
/**
4582+
* Updated diagnostics status
4583+
*/
4584+
200: LspDiagnosticsStatus
4585+
}
4586+
4587+
export type LspDiagnosticsToggleResponse = LspDiagnosticsToggleResponses[keyof LspDiagnosticsToggleResponses]
4588+
45894589
export type AuthSetData = {
45904590
body?: Auth
45914591
path: {

0 commit comments

Comments
 (0)