summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-04-16 21:19:01 -0400
committerGitHub <[email protected]>2026-04-17 01:19:01 +0000
commit8afb625bab10c44e5b0437af4550f020f332cdf5 (patch)
treed789bd6f35e1fdbe4d9ffd4bd0dc132b5425b02c
parentc59df636cc3d9b203e2b84dcefecba15eda5b457 (diff)
downloadopencode-8afb625bab10c44e5b0437af4550f020f332cdf5.tar.gz
opencode-8afb625bab10c44e5b0437af4550f020f332cdf5.zip
refactor: extract Diagnostic namespace into lsp/diagnostic.ts + self-reexport (#22983)
-rw-r--r--packages/opencode/src/lsp/diagnostic.ts29
-rw-r--r--packages/opencode/src/lsp/lsp.ts28
2 files changed, 30 insertions, 27 deletions
diff --git a/packages/opencode/src/lsp/diagnostic.ts b/packages/opencode/src/lsp/diagnostic.ts
new file mode 100644
index 000000000..4bc085e78
--- /dev/null
+++ b/packages/opencode/src/lsp/diagnostic.ts
@@ -0,0 +1,29 @@
+import * as LSPClient from "./client"
+
+const MAX_PER_FILE = 20
+
+export function pretty(diagnostic: LSPClient.Diagnostic) {
+ const severityMap = {
+ 1: "ERROR",
+ 2: "WARN",
+ 3: "INFO",
+ 4: "HINT",
+ }
+
+ const severity = severityMap[diagnostic.severity || 1]
+ const line = diagnostic.range.start.line + 1
+ const col = diagnostic.range.start.character + 1
+
+ return `${severity} [${line}:${col}] ${diagnostic.message}`
+}
+
+export function report(file: string, issues: LSPClient.Diagnostic[]) {
+ const errors = issues.filter((item) => item.severity === 1)
+ if (errors.length === 0) return ""
+ const limited = errors.slice(0, MAX_PER_FILE)
+ const more = errors.length - MAX_PER_FILE
+ const suffix = more > 0 ? `\n... and ${more} more` : ""
+ return `<diagnostics file="${file}">\n${limited.map(pretty).join("\n")}${suffix}\n</diagnostics>`
+}
+
+export * as Diagnostic from "./diagnostic"
diff --git a/packages/opencode/src/lsp/lsp.ts b/packages/opencode/src/lsp/lsp.ts
index d895e7325..97af8209b 100644
--- a/packages/opencode/src/lsp/lsp.ts
+++ b/packages/opencode/src/lsp/lsp.ts
@@ -505,30 +505,4 @@ export const layer = Layer.effect(
export const defaultLayer = layer.pipe(Layer.provide(Config.defaultLayer))
-export namespace Diagnostic {
- const MAX_PER_FILE = 20
-
- export function pretty(diagnostic: LSPClient.Diagnostic) {
- const severityMap = {
- 1: "ERROR",
- 2: "WARN",
- 3: "INFO",
- 4: "HINT",
- }
-
- const severity = severityMap[diagnostic.severity || 1]
- const line = diagnostic.range.start.line + 1
- const col = diagnostic.range.start.character + 1
-
- return `${severity} [${line}:${col}] ${diagnostic.message}`
- }
-
- export function report(file: string, issues: LSPClient.Diagnostic[]) {
- const errors = issues.filter((item) => item.severity === 1)
- if (errors.length === 0) return ""
- const limited = errors.slice(0, MAX_PER_FILE)
- const more = errors.length - MAX_PER_FILE
- const suffix = more > 0 ? `\n... and ${more} more` : ""
- return `<diagnostics file="${file}">\n${limited.map(pretty).join("\n")}${suffix}\n</diagnostics>`
- }
-}
+export * as Diagnostic from "./diagnostic"