Browse Source

fix: enforce extensions requirement for custom lsp servers (#2734)

Aiden Cline 5 months ago
parent
commit
cc2bd7141f
1 changed files with 17 additions and 1 deletions
  1. 17 1
      packages/opencode/src/config/config.ts

+ 17 - 1
packages/opencode/src/config/config.ts

@@ -14,6 +14,7 @@ import { Flag } from "../flag/flag"
 import { Auth } from "../auth"
 import { type ParseError as JsoncParseError, parse as parseJsonc, printParseErrorCode } from "jsonc-parser"
 import { Instance } from "../project/instance"
+import { LSPServer } from "../lsp/server"
 
 export namespace Config {
   const log = Log.create({ service: "config" })
@@ -482,7 +483,22 @@ export namespace Config {
             }),
           ]),
         )
-        .optional(),
+        .optional()
+        .refine(
+          (data) => {
+            if (!data) return true
+            const serverIds = new Set(Object.values(LSPServer).map((s) => s.id))
+
+            return Object.entries(data).every(([id, config]) => {
+              if (config.disabled) return true
+              if (serverIds.has(id)) return true
+              return Boolean(config.extensions)
+            })
+          },
+          {
+            error: "For custom LSP servers, 'extensions' array is required.",
+          },
+        ),
       instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
       layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
       permission: z