Skip to content

Commit 4eda7cd

Browse files
committed
printer: clean up config names, document them, add one new speculative config option.
'ElidePreludeTypeInfo' originates from code review discussion: #238 (comment)
1 parent 86ad1cc commit 4eda7cd

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

printer/printer.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,24 @@ type Config struct {
7272
// Not yet supported.
7373
AlwaysMarkStrings bool
7474

75-
AlwaysUseMapComplexStyle bool
75+
// Set to true if you want type info to be skipped for any type that's in the Prelude
76+
// (e.g. instead of `string<String>{` seeing only `string{` is preferred, etc).
77+
//
78+
// Not yet supported.
79+
ElidePreludeTypeInfo bool
80+
81+
// Set to true if you want maps to use "complex"-style printouts:
82+
// meaning they will print their keys on separate lines than their values,
83+
// and keys may spread across mutiple lines if appropriate.
84+
//
85+
// If not set, a heuristic will be used based on if the map is known to
86+
// have keys that are complex enough that rendering them as oneline seems likely to overload.
87+
// See Config.useCmplxKeys for exactly how that's deteremined.
88+
UseMapComplexStyleAlways bool
7689

77-
SpecificMapComplexStyle map[schema.TypeName]bool
90+
// For maps to use "complex"-style printouts (or not) per type.
91+
// See docs on UseMapComplexStyleAlways for the overview of what "complex"-style means.
92+
UseMapComplexStyleOnType map[schema.TypeName]bool
7893
}
7994

8095
func (cfg *Config) init() {
@@ -101,14 +116,14 @@ func (cfg Config) useRepr(typ schema.Type, isInKey bool) bool {
101116

102117
// useCmplxKeys decides if a map should print itself using a multi-line and extra-indented style for keys.
103118
func (cfg Config) useCmplxKeys(mapn datamodel.Node) bool {
104-
if cfg.AlwaysUseMapComplexStyle {
119+
if cfg.UseMapComplexStyleAlways {
105120
return true
106121
}
107122
tn, ok := mapn.(schema.TypedNode)
108123
if !ok {
109124
return false
110125
}
111-
force, ok := cfg.SpecificMapComplexStyle[tn.Type().Name()]
126+
force, ok := cfg.UseMapComplexStyleOnType[tn.Type().Name()]
112127
if ok {
113128
return force
114129
}

printer/printer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestTypedData(t *testing.T) {
128128
}, ts.TypeByName("WowMap"))
129129
t.Run("complex-keys-in-effect", func(t *testing.T) {
130130
cfg := Config{
131-
AlwaysUseMapComplexStyle: true,
131+
UseMapComplexStyleAlways: true,
132132
}
133133
qt.Check(t, cfg.Sprint(n), qt.CmpEquals(), wish.Dedent(`
134134
map<WowMap>{
@@ -159,7 +159,7 @@ func TestTypedData(t *testing.T) {
159159
})
160160
t.Run("complex-keys-in-disabled", func(t *testing.T) {
161161
cfg := Config{
162-
SpecificMapComplexStyle: map[schema.TypeName]bool{
162+
UseMapComplexStyleOnType: map[schema.TypeName]bool{
163163
"WowMap": false,
164164
},
165165
}

0 commit comments

Comments
 (0)