mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
feat: add top level lsp: false and formatter: false to allow disabling all formatters or lsps at once
This commit is contained in:
parent
429708e3d5
commit
81ebf56cf1
4 changed files with 78 additions and 48 deletions
|
|
@ -542,36 +542,43 @@ export namespace Config {
|
|||
.describe("Custom provider configurations and model overrides"),
|
||||
mcp: z.record(z.string(), Mcp).optional().describe("MCP (Model Context Protocol) server configurations"),
|
||||
formatter: z
|
||||
.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
disabled: z.boolean().optional(),
|
||||
command: z.array(z.string()).optional(),
|
||||
environment: z.record(z.string(), z.string()).optional(),
|
||||
extensions: z.array(z.string()).optional(),
|
||||
}),
|
||||
)
|
||||
.union([
|
||||
z.literal(false),
|
||||
z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
disabled: z.boolean().optional(),
|
||||
command: z.array(z.string()).optional(),
|
||||
environment: z.record(z.string(), z.string()).optional(),
|
||||
extensions: z.array(z.string()).optional(),
|
||||
}),
|
||||
),
|
||||
])
|
||||
.optional(),
|
||||
lsp: z
|
||||
.record(
|
||||
z.string(),
|
||||
z.union([
|
||||
z.object({
|
||||
disabled: z.literal(true),
|
||||
}),
|
||||
z.object({
|
||||
command: z.array(z.string()),
|
||||
extensions: z.array(z.string()).optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
initialization: z.record(z.string(), z.any()).optional(),
|
||||
}),
|
||||
]),
|
||||
)
|
||||
.union([
|
||||
z.literal(false),
|
||||
z.record(
|
||||
z.string(),
|
||||
z.union([
|
||||
z.object({
|
||||
disabled: z.literal(true),
|
||||
}),
|
||||
z.object({
|
||||
command: z.array(z.string()),
|
||||
extensions: z.array(z.string()).optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
initialization: z.record(z.string(), z.any()).optional(),
|
||||
}),
|
||||
]),
|
||||
),
|
||||
])
|
||||
.optional()
|
||||
.refine(
|
||||
(data) => {
|
||||
if (!data) return true
|
||||
if (typeof data === "boolean") return true
|
||||
const serverIds = new Set(Object.values(LSPServer).map((s) => s.id))
|
||||
|
||||
return Object.entries(data).every(([id, config]) => {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ export namespace Format {
|
|||
const cfg = await Config.get()
|
||||
|
||||
const formatters: Record<string, Formatter.Info> = {}
|
||||
if (cfg.formatter === false) {
|
||||
log.info("all formatters are disabled")
|
||||
return {
|
||||
enabled,
|
||||
formatters,
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of Object.values(Formatter)) {
|
||||
formatters[item.name] = item
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,21 @@ export namespace LSP {
|
|||
async () => {
|
||||
const clients: LSPClient.Info[] = []
|
||||
const servers: Record<string, LSPServer.Info> = {}
|
||||
const cfg = await Config.get()
|
||||
|
||||
if (cfg.lsp === false) {
|
||||
log.info("all LSPs are disabled")
|
||||
return {
|
||||
broken: new Set<string>(),
|
||||
servers,
|
||||
clients,
|
||||
spawning: new Map<string, Promise<LSPClient.Info | undefined>>(),
|
||||
}
|
||||
}
|
||||
|
||||
for (const server of Object.values(LSPServer)) {
|
||||
servers[server.id] = server
|
||||
}
|
||||
const cfg = await Config.get()
|
||||
for (const [name, item] of Object.entries(cfg.lsp ?? {})) {
|
||||
const existing = servers[name]
|
||||
if (item.disabled) {
|
||||
|
|
|
|||
|
|
@ -1117,33 +1117,37 @@ export type Config = {
|
|||
mcp?: {
|
||||
[key: string]: McpLocalConfig | McpRemoteConfig
|
||||
}
|
||||
formatter?: {
|
||||
[key: string]: {
|
||||
disabled?: boolean
|
||||
command?: Array<string>
|
||||
environment?: {
|
||||
[key: string]: string
|
||||
}
|
||||
extensions?: Array<string>
|
||||
}
|
||||
}
|
||||
lsp?: {
|
||||
[key: string]:
|
||||
| {
|
||||
disabled: true
|
||||
}
|
||||
| {
|
||||
command: Array<string>
|
||||
extensions?: Array<string>
|
||||
formatter?:
|
||||
| false
|
||||
| {
|
||||
[key: string]: {
|
||||
disabled?: boolean
|
||||
env?: {
|
||||
command?: Array<string>
|
||||
environment?: {
|
||||
[key: string]: string
|
||||
}
|
||||
initialization?: {
|
||||
[key: string]: unknown
|
||||
}
|
||||
extensions?: Array<string>
|
||||
}
|
||||
}
|
||||
}
|
||||
lsp?:
|
||||
| false
|
||||
| {
|
||||
[key: string]:
|
||||
| {
|
||||
disabled: true
|
||||
}
|
||||
| {
|
||||
command: Array<string>
|
||||
extensions?: Array<string>
|
||||
disabled?: boolean
|
||||
env?: {
|
||||
[key: string]: string
|
||||
}
|
||||
initialization?: {
|
||||
[key: string]: unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Additional instruction files or patterns to include
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue