@@ -63,6 +63,9 @@ func doMain(baseDir string, write bool) (bool, error) {
63
63
if ok , err := rewriteFile (filepath .Join (baseDir , "gopls/doc/analyzers.md" ), api , write , rewriteAnalyzers ); ! ok || err != nil {
64
64
return ok , err
65
65
}
66
+ if ok , err := rewriteFile (filepath .Join (baseDir , "gopls/doc/inlayHints.md" ), api , write , rewriteInlayHints ); ! ok || err != nil {
67
+ return ok , err
68
+ }
66
69
67
70
return true , nil
68
71
}
@@ -102,6 +105,7 @@ func loadAPI() (*source.APIJSON, error) {
102
105
} {
103
106
api .Analyzers = append (api .Analyzers , loadAnalyzers (m )... )
104
107
}
108
+ api .Hints = loadHints (source .AllInlayHints )
105
109
for _ , category := range []reflect.Value {
106
110
reflect .ValueOf (defaults .UserOptions ),
107
111
} {
@@ -146,6 +150,14 @@ func loadAPI() (*source.APIJSON, error) {
146
150
Default : def ,
147
151
})
148
152
}
153
+ case "hints" :
154
+ for _ , a := range api .Hints {
155
+ opt .EnumKeys .Keys = append (opt .EnumKeys .Keys , source.EnumKey {
156
+ Name : fmt .Sprintf ("%q" , a .Name ),
157
+ Doc : a .Doc ,
158
+ Default : strconv .FormatBool (a .Default ),
159
+ })
160
+ }
149
161
}
150
162
}
151
163
}
@@ -488,6 +500,23 @@ func loadAnalyzers(m map[string]*source.Analyzer) []*source.AnalyzerJSON {
488
500
return json
489
501
}
490
502
503
+ func loadHints (m map [string ]* source.Hint ) []* source.HintJSON {
504
+ var sorted []string
505
+ for _ , h := range m {
506
+ sorted = append (sorted , h .Name )
507
+ }
508
+ sort .Strings (sorted )
509
+ var json []* source.HintJSON
510
+ for _ , name := range sorted {
511
+ h := m [name ]
512
+ json = append (json , & source.HintJSON {
513
+ Name : h .Name ,
514
+ Doc : h .Doc ,
515
+ })
516
+ }
517
+ return json
518
+ }
519
+
491
520
func lowerFirst (x string ) string {
492
521
if x == "" {
493
522
return x
@@ -699,6 +728,21 @@ func rewriteAnalyzers(doc []byte, api *source.APIJSON) ([]byte, error) {
699
728
return replaceSection (doc , "Analyzers" , section .Bytes ())
700
729
}
701
730
731
+ func rewriteInlayHints (doc []byte , api * source.APIJSON ) ([]byte , error ) {
732
+ section := bytes .NewBuffer (nil )
733
+ for _ , hint := range api .Hints {
734
+ fmt .Fprintf (section , "## **%v**\n \n " , hint .Name )
735
+ fmt .Fprintf (section , "%s\n \n " , hint .Doc )
736
+ switch hint .Default {
737
+ case true :
738
+ fmt .Fprintf (section , "**Enabled by default.**\n \n " )
739
+ case false :
740
+ fmt .Fprintf (section , "**Disabled by default. Enable it by setting `\" hints\" : {\" %s\" : true}`.**\n \n " , hint .Name )
741
+ }
742
+ }
743
+ return replaceSection (doc , "Hints" , section .Bytes ())
744
+ }
745
+
702
746
func replaceSection (doc []byte , sectionName string , replacement []byte ) ([]byte , error ) {
703
747
re := regexp .MustCompile (fmt .Sprintf (`(?s)<!-- BEGIN %v.* -->\n(.*?)<!-- END %v.* -->` , sectionName , sectionName ))
704
748
idx := re .FindSubmatchIndex (doc )
0 commit comments