From e90aeb62e54954c0608480f573bd093c951a94a7 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 24 Feb 2025 09:09:00 +0100 Subject: [PATCH 1/3] Add launch config for debugging the schema generation --- .vscode/launch.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index be436b55f..3bedda766 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,6 +26,15 @@ ], "console": "integratedTerminal", }, + { + "name": "JSON Schema generator", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/pkg/jsonschema/generator.go", + "cwd": "${workspaceFolder}/pkg/jsonschema", + "console": "integratedTerminal", + }, { "name": "Attach to a running Lazygit", "type": "go", From 0cc6e39f0f3f9daea0d23d855c489c0f2e4c7c67 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 24 Feb 2025 09:12:56 +0100 Subject: [PATCH 2/3] Filter out [dev] comments earlier Previously we only filtered them out from the example config section in Config.md, but they still appeared in the schema. This is not ideal, because the schema descriptions can appear in editors on mouse hover or in auto-completions. So filter them out earlier, so that they don't appear in the schema either. --- pkg/jsonschema/generate.go | 11 +++++++++++ schema/config.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/jsonschema/generate.go b/pkg/jsonschema/generate.go index 05d9f5782..d8514e3b6 100644 --- a/pkg/jsonschema/generate.go +++ b/pkg/jsonschema/generate.go @@ -56,6 +56,7 @@ func customReflect(v *config.UserConfig) *jsonschema.Schema { if err := r.AddGoComments("github.com/jesseduffield/lazygit/pkg/config", "../config"); err != nil { panic(err) } + filterOutDevComments(r) schema := r.Reflect(v) defaultConfig := config.GetDefaultConfig() userConfigSchema := schema.Definitions["UserConfig"] @@ -76,6 +77,16 @@ func customReflect(v *config.UserConfig) *jsonschema.Schema { return schema } +func filterOutDevComments(r *jsonschema.Reflector) { + for k, v := range r.CommentMap { + commentLines := strings.Split(v, "\n") + filteredCommentLines := lo.Filter(commentLines, func(line string, _ int) bool { + return !strings.Contains(line, "[dev]") + }) + r.CommentMap[k] = strings.Join(filteredCommentLines, "\n") + } +} + func setDefaultVals(rootSchema, schema *jsonschema.Schema, defaults any) { t := reflect.TypeOf(defaults) v := reflect.ValueOf(defaults) diff --git a/schema/config.json b/schema/config.json index 276cba300..cbb418667 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1468,7 +1468,7 @@ }, "editInTerminal": { "type": "boolean", - "description": "Whether lazygit suspends until an edit process returns\n[dev] Pointer to bool so that we can distinguish unset (nil) from false.\n[dev] We're naming this `editInTerminal` for backwards compatibility" + "description": "Whether lazygit suspends until an edit process returns" }, "openDirInEditor": { "type": "string", From 4845ce1e0f2b7d30a7b900e57d86b2a7e30c1b40 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 24 Feb 2025 09:17:46 +0100 Subject: [PATCH 3/3] Remove obsolete filtering from setComment This reverts the change that we made in 3b85307f67dc, it is no longer needed now. --- pkg/jsonschema/generate_config_docs.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pkg/jsonschema/generate_config_docs.go b/pkg/jsonschema/generate_config_docs.go index 731cddea9..b5228c042 100644 --- a/pkg/jsonschema/generate_config_docs.go +++ b/pkg/jsonschema/generate_config_docs.go @@ -77,20 +77,13 @@ func prepareMarshalledConfig(buffer bytes.Buffer) []byte { } func setComment(yamlNode *yaml.Node, description string) { - // Filter out lines containing "[dev]"; this allows us to add developer - // documentation to properties that don't get included in the docs - lines := strings.Split(description, "\n") - lines = lo.Filter(lines, func(s string, _ int) bool { - return !strings.Contains(s, "[dev]") - }) - // Workaround for the way yaml formats the HeadComment if it contains // blank lines: it renders these without a leading "#", but we want a // leading "#" even on blank lines. However, yaml respects it if the // HeadComment already contains a leading "#", so we prefix all lines // (including blank ones) with "#". yamlNode.HeadComment = strings.Join( - lo.Map(lines, func(s string, _ int) string { + lo.Map(strings.Split(description, "\n"), func(s string, _ int) string { if s == "" { return "#" // avoid trailing space on blank lines }