@@ -66,7 +66,7 @@ func Generate(inputFile string, skipCleanup bool) ([]byte, error) {
6666}
6767
6868// readGoplsAPI returns the output of `gopls api-json`.
69- func readGoplsAPI () (* APIJSON , error ) {
69+ func readGoplsAPI () (* API , error ) {
7070 version , err := exec .Command ("gopls" , "-v" , "version" ).Output ()
7171 if err != nil {
7272 return nil , fmt .Errorf ("failed to check gopls version: %v" , err )
@@ -78,7 +78,7 @@ func readGoplsAPI() (*APIJSON, error) {
7878 return nil , fmt .Errorf ("failed to run gopls: %v" , err )
7979 }
8080
81- api := & APIJSON {}
81+ api := & API {}
8282 if err := json .Unmarshal (out , api ); err != nil {
8383 return nil , fmt .Errorf ("failed to unmarshal: %v" , err )
8484 }
@@ -87,37 +87,37 @@ func readGoplsAPI() (*APIJSON, error) {
8787
8888// extractOptions extracts the options from APIJSON.
8989// It may rearrange the ordering and documentation for better presentation.
90- func extractOptions (api * APIJSON ) ([]* OptionJSON , error ) {
90+ func extractOptions (api * API ) ([]* Option , error ) {
9191 type sortableOptionJSON struct {
92- * OptionJSON
92+ * Option
9393 section string
9494 }
9595 options := []sortableOptionJSON {}
9696 for k , v := range api .Options {
9797 for _ , o := range v {
98- options = append (options , sortableOptionJSON {OptionJSON : o , section : k })
98+ options = append (options , sortableOptionJSON {Option : o , section : k })
9999 }
100100 }
101101 sort .SliceStable (options , func (i , j int ) bool {
102- pi := priority (options [i ].OptionJSON )
103- pj := priority (options [j ].OptionJSON )
102+ pi := priority (options [i ].Option )
103+ pj := priority (options [j ].Option )
104104 if pi == pj {
105105 return options [i ].Name < options [j ].Name
106106 }
107107 return pi < pj
108108 })
109109
110- opts := []* OptionJSON {}
110+ opts := []* Option {}
111111 for _ , v := range options {
112- if name := statusName (v .OptionJSON ); name != "" {
113- v .OptionJSON .Doc = name + " " + v .OptionJSON .Doc
112+ if name := statusName (v .Option ); name != "" {
113+ v .Option .Doc = name + " " + v .Option .Doc
114114 }
115- opts = append (opts , v .OptionJSON )
115+ opts = append (opts , v .Option )
116116 }
117117 return opts , nil
118118}
119119
120- func priority (opt * OptionJSON ) int {
120+ func priority (opt * Option ) int {
121121 switch toStatus (opt .Status ) {
122122 case Experimental :
123123 return 10
@@ -127,7 +127,7 @@ func priority(opt *OptionJSON) int {
127127 return 1000
128128}
129129
130- func statusName (opt * OptionJSON ) string {
130+ func statusName (opt * Option ) string {
131131 switch toStatus (opt .Status ) {
132132 case Experimental :
133133 return "(Experimental)"
@@ -171,8 +171,8 @@ func rewritePackageJSON(newSettings, inFile string) ([]byte, error) {
171171
172172// asVSCodeSettings converts the given options to match the VS Code settings
173173// format.
174- func asVSCodeSettings (options []* OptionJSON ) ([]byte , error ) {
175- seen := map [string ][]* OptionJSON {}
174+ func asVSCodeSettings (options []* Option ) ([]byte , error ) {
175+ seen := map [string ][]* Option {}
176176 for _ , opt := range options {
177177 seen [opt .Hierarchy ] = append (seen [opt .Hierarchy ], opt )
178178 }
@@ -195,7 +195,7 @@ func asVSCodeSettings(options []*OptionJSON) ([]byte, error) {
195195 return json .Marshal (goProperties )
196196}
197197
198- func collectProperties (m map [string ][]* OptionJSON ) (goplsProperties , goProperties map [string ]* Object , err error ) {
198+ func collectProperties (m map [string ][]* Option ) (goplsProperties , goProperties map [string ]* Object , err error ) {
199199 var sorted []string
200200 var containsEmpty bool
201201 for k := range m {
@@ -248,7 +248,7 @@ func collectProperties(m map[string][]*OptionJSON) (goplsProperties, goPropertie
248248 return goplsProperties , goProperties , nil
249249}
250250
251- func toObject (opt * OptionJSON ) (* Object , error ) {
251+ func toObject (opt * Option ) (* Object , error ) {
252252 doc := opt .Doc
253253 if mappedTo , ok := associatedToExtensionProperties [opt .Name ]; ok {
254254 doc = fmt .Sprintf ("%v\n If unspecified, values of `%v` will be propagated.\n " , doc , strings .Join (mappedTo , ", " ))
@@ -295,7 +295,7 @@ func toObject(opt *OptionJSON) (*Object, error) {
295295 return obj , nil
296296}
297297
298- func formatOptionDefault (opt * OptionJSON ) interface {} {
298+ func formatOptionDefault (opt * Option ) interface {} {
299299 // Each key will have its own default value, instead of one large global
300300 // one. (Alternatively, we can build the default from the keys.)
301301 if len (opt .EnumKeys .Keys ) > 0 {
@@ -388,18 +388,18 @@ const (
388388 None
389389)
390390
391- // APIJSON is the output json type of ` gopls api-json` .
392- // Types copied from golang.org/x/tools/internal/lsp/source/options.go.
393- type APIJSON struct {
394- Options map [ string ][] * OptionJSON
395- Commands [] * CommandJSON
396- Lenses []* LensJSON
397- Analyzers []* AnalyzerJSON
391+ // API is a JSON-encodable representation of gopls' public interfaces .
392+ //
393+ // Types are copied from golang.org/x/tools/gopls/internal/doc/api.go.
394+ type API struct {
395+ Options map [ string ][] * Option
396+ Lenses []* Lens
397+ Analyzers []* Analyzer
398398}
399399
400- type OptionJSON struct {
400+ type Option struct {
401401 Name string
402- Type string
402+ Type string // T = bool | string | int | enum | any | []T | map[T]T | time.Duration
403403 Doc string
404404 EnumKeys EnumKeys
405405 EnumValues []EnumValue
@@ -414,29 +414,32 @@ type EnumKeys struct {
414414}
415415
416416type EnumKey struct {
417- Name string
417+ Name string // in JSON syntax (quoted)
418418 Doc string
419419 Default string
420420}
421421
422422type EnumValue struct {
423- Value string
424- Doc string
423+ Value string // in JSON syntax (quoted)
424+ Doc string // doc comment; always starts with `Value`
425425}
426426
427- type CommandJSON struct {
428- Command string
429- Title string
430- Doc string
427+ type Lens struct {
428+ FileType string // e.g. "Go", "go.mod"
429+ Lens string
430+ Title string
431+ Doc string
432+ Default bool
431433}
432434
433- type LensJSON struct {
434- Lens string
435- Title string
436- Doc string
435+ type Analyzer struct {
436+ Name string
437+ Doc string // from analysis.Analyzer.Doc ("title: summary\ndescription"; not Markdown)
438+ URL string
439+ Default bool
437440}
438441
439- type AnalyzerJSON struct {
442+ type Hint struct {
440443 Name string
441444 Doc string
442445 Default bool
0 commit comments