config-schema: allow "command-env"-style for editors and fix tools

The `CommandNameAndArgs` struct is used in multiple places to specify
external tools. Previously, the schema only allowed for this in
`ui.pager`.

This commit adds a few sample configs which define variables editors and
fix tools as commands with env vars.

The schema has also been updated to make these valid.
This commit is contained in:
Jonas Greitemann 2025-04-17 17:09:04 +02:00 committed by Jonas Greitemann
parent d35dd31c87
commit bf2c01e74b
4 changed files with 68 additions and 41 deletions

View File

@ -47,6 +47,13 @@
], ],
"default": "diff" "default": "diff"
}, },
"command": {
"type": ["string", "array"],
"minItems": 1,
"items": {
"type": "string"
}
},
"command-env": { "command-env": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -108,23 +115,16 @@
"default": "auto" "default": "auto"
}, },
"pager": { "pager": {
"description": "Pager to use for displaying command output",
"default": "less -FRX",
"oneOf": [ "oneOf": [
{ {
"type": "string" "$ref": "#/properties/ui/definitions/command"
},
{
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
}, },
{ {
"$ref": "#/properties/ui/definitions/command-env" "$ref": "#/properties/ui/definitions/command-env"
} }
], ]
"description": "Pager to use for displaying command output",
"default": "less -FRX"
}, },
"streampager": { "streampager": {
"type": "object", "type": "object",
@ -169,12 +169,15 @@
"default": "color-words" "default": "color-words"
}, },
"tool": { "tool": {
"type": ["array", "string"], "description": "External tool for generating diffs",
"minItems": 1, "oneOf": [
"items": { {
"type": "string" "$ref": "#/properties/ui/definitions/command"
}, },
"description": "External tool for generating diffs" {
"$ref": "#/properties/ui/definitions/command-env"
}
]
} }
} }
}, },
@ -210,26 +213,25 @@
"default": true "default": true
}, },
"editor": { "editor": {
"type": ["array", "string"], "description": "Editor to use for commands that involve editing text",
"minItems": 1, "oneOf": [
"items": { {
"type": "string" "$ref": "#/properties/ui/definitions/command"
}, },
"description": "Editor to use for commands that involve editing text" {
"$ref": "#/properties/ui/definitions/command-env"
}
]
}, },
"diff-editor": { "diff-editor": {
"description": "Editor tool to use for editing diffs", "description": "Editor tool to use for editing diffs",
"default": ":builtin", "default": ":builtin",
"oneOf": [ "oneOf": [
{ {
"type": "string" "$ref": "#/properties/ui/definitions/command"
}, },
{ {
"type": "array", "$ref": "#/properties/ui/definitions/command-env"
"minItems": 1,
"items": {
"type": "string"
}
} }
] ]
}, },
@ -238,14 +240,10 @@
"default": ":builtin", "default": ":builtin",
"oneOf": [ "oneOf": [
{ {
"type": "string" "$ref": "#/properties/ui/definitions/command"
}, },
{ {
"type": "array", "$ref": "#/properties/ui/definitions/command-env"
"minItems": 1,
"items": {
"type": "string"
}
} }
] ]
}, },
@ -752,12 +750,15 @@
"description": "Settings for how specific filesets are affected by a tool", "description": "Settings for how specific filesets are affected by a tool",
"properties": { "properties": {
"command": { "command": {
"type": "array", "description": "Arguments used to execute this tool",
"minItems": 1, "oneOf": [
"items": { {
"type": "string" "$ref": "#/properties/ui/definitions/command"
}, },
"description": "Arguments used to execute this tool" {
"$ref": "#/properties/ui/definitions/command-env"
}
]
}, },
"patterns": { "patterns": {
"type": "array", "type": "array",

View File

@ -0,0 +1,8 @@
#:schema ../../../src/config-schema.json
[fix.tools.clang-format.command]
command = [
"/usr/bin/clang-format",
"--sort-includes",
"--assume-filename=$path",
]
env = { NO_COLOR = 1 }

View File

@ -0,0 +1,3 @@
#:schema ../../../src/config-schema.json
[fix.tools.clang-format]
command = "/usr/bin/clang-format"

View File

@ -0,0 +1,15 @@
#:schema ../../../src/config-schema.json
[ui]
editor = { command = ["C:/Program Files/Notepad++/notepad++.exe", "-multiInst", "-notabbar", "-nosession", "-noPlugin"], env = {} }
[ui.diff-editor]
command = ["diffedit3", "$left", "$right"]
env = { RUST_LOG = "poem=debug" }
[ui.merge-editor]
command = ["diffedit3", "$left", "$base", "$right"]
env = { RUST_LOG = "poem=debug" }
[ui.diff.tool]
command = ["difft", "--color=always", "$left", "$right"]
env = { DFT_BACKGROUND = "light" }