1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00
go/gopls/doc/generate_test.go
Heschi Kreinick 6a8222ee25 gopls/doc: generate settings JSON, docs
gopls has many settings. We want to automatically generate
documentation, and we want to allow clients to perform their own
validation if they so desire.

Using all three of AST, type information, and reflection, generate a
JSON description of the settings and their default values. Add a gopls
command that prints it. Add a documentation generator that uses it to
write settings.md.

I assumed that everything not explicitly documented was experimental,
and moved it into that section. I also moved expandWorkspaceToModule to
experimental; I hope it's not long for this world, personally.

Along the way, rename many fields, make the enum matching case
insensitive, and add a stringer call so that the defaults print nicely.

Fixes golang/go#33544.

Change-Id: Ibb652002933e355ed3c6038d6ca48345b39b3025
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252322
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-09 20:53:33 +00:00

35 lines
805 B
Go

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/testenv"
)
func TestGenerated(t *testing.T) {
testenv.NeedsGoBuild(t) // This is a lie. We actually need the source code.
var opts map[string][]option
if err := json.Unmarshal([]byte(source.OptionsJson), &opts); err != nil {
t.Fatal(err)
}
doc, err := ioutil.ReadFile("settings.md")
if err != nil {
t.Fatal(err)
}
got, err := rewriteDoc(doc, opts)
if !bytes.Equal(got, doc) {
t.Error("settings.md needs updating. run: `go run gopls/doc/generate.go` from the root of tools.")
}
}