Skip to content

Commit fd01ca3

Browse files
authored
Filter out dev comments from schema (#4319)
- **PR Description** 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.
2 parents 17ab91e + 4845ce1 commit fd01ca3

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

.vscode/launch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
],
2727
"console": "integratedTerminal",
2828
},
29+
{
30+
"name": "JSON Schema generator",
31+
"type": "go",
32+
"request": "launch",
33+
"mode": "auto",
34+
"program": "${workspaceFolder}/pkg/jsonschema/generator.go",
35+
"cwd": "${workspaceFolder}/pkg/jsonschema",
36+
"console": "integratedTerminal",
37+
},
2938
{
3039
"name": "Attach to a running Lazygit",
3140
"type": "go",

pkg/jsonschema/generate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func customReflect(v *config.UserConfig) *jsonschema.Schema {
5656
if err := r.AddGoComments("github.com/jesseduffield/lazygit/pkg/config", "../config"); err != nil {
5757
panic(err)
5858
}
59+
filterOutDevComments(r)
5960
schema := r.Reflect(v)
6061
defaultConfig := config.GetDefaultConfig()
6162
userConfigSchema := schema.Definitions["UserConfig"]
@@ -76,6 +77,16 @@ func customReflect(v *config.UserConfig) *jsonschema.Schema {
7677
return schema
7778
}
7879

80+
func filterOutDevComments(r *jsonschema.Reflector) {
81+
for k, v := range r.CommentMap {
82+
commentLines := strings.Split(v, "\n")
83+
filteredCommentLines := lo.Filter(commentLines, func(line string, _ int) bool {
84+
return !strings.Contains(line, "[dev]")
85+
})
86+
r.CommentMap[k] = strings.Join(filteredCommentLines, "\n")
87+
}
88+
}
89+
7990
func setDefaultVals(rootSchema, schema *jsonschema.Schema, defaults any) {
8091
t := reflect.TypeOf(defaults)
8192
v := reflect.ValueOf(defaults)

pkg/jsonschema/generate_config_docs.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,13 @@ func prepareMarshalledConfig(buffer bytes.Buffer) []byte {
7777
}
7878

7979
func setComment(yamlNode *yaml.Node, description string) {
80-
// Filter out lines containing "[dev]"; this allows us to add developer
81-
// documentation to properties that don't get included in the docs
82-
lines := strings.Split(description, "\n")
83-
lines = lo.Filter(lines, func(s string, _ int) bool {
84-
return !strings.Contains(s, "[dev]")
85-
})
86-
8780
// Workaround for the way yaml formats the HeadComment if it contains
8881
// blank lines: it renders these without a leading "#", but we want a
8982
// leading "#" even on blank lines. However, yaml respects it if the
9083
// HeadComment already contains a leading "#", so we prefix all lines
9184
// (including blank ones) with "#".
9285
yamlNode.HeadComment = strings.Join(
93-
lo.Map(lines, func(s string, _ int) string {
86+
lo.Map(strings.Split(description, "\n"), func(s string, _ int) string {
9487
if s == "" {
9588
return "#" // avoid trailing space on blank lines
9689
}

schema/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@
14681468
},
14691469
"editInTerminal": {
14701470
"type": "boolean",
1471-
"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"
1471+
"description": "Whether lazygit suspends until an edit process returns"
14721472
},
14731473
"openDirInEditor": {
14741474
"type": "string",

0 commit comments

Comments
 (0)