diff --git a/internal/lsp/cmd/definition.go b/internal/lsp/cmd/definition.go index 046dbc3f..d80c197f 100644 --- a/internal/lsp/cmd/definition.go +++ b/internal/lsp/cmd/definition.go @@ -26,11 +26,14 @@ type Definition struct { Description string `json:"description"` // description of the denoted object } -// This constant is printed in the help, and then used in a test to verify the +// These constant is printed in the help, and then used in a test to verify the // help is still valid. -// It should be the byte offset in this file of the "Set" in "flag.FlagSet" from -// the DetailedHelp method below. -const exampleOffset = 1311 +// They refer to "Set" in "flag.FlagSet" from the DetailedHelp method below. +const ( + exampleLine = 46 + exampleColumn = 47 + exampleOffset = 1319 +) // definition implements the definition noun for the query command. type definition struct { @@ -44,10 +47,11 @@ func (d *definition) DetailedHelp(f *flag.FlagSet) { fmt.Fprintf(f.Output(), ` Example: show the definition of the identifier at syntax at offset %[1]v in this file (flag.FlagSet): - $ gopls definition internal/lsp/cmd/definition.go:#%[1]v +$ gopls definition internal/lsp/cmd/definition.go:%[1]v:%[2]v +$ gopls definition internal/lsp/cmd/definition.go:#%[3]v gopls definition flags are: -`, exampleOffset) +`, exampleLine, exampleColumn, exampleOffset) f.PrintDefaults() } diff --git a/internal/lsp/cmd/definition_test.go b/internal/lsp/cmd/definition_test.go index 06fe6f9a..f4cfc6a0 100644 --- a/internal/lsp/cmd/definition_test.go +++ b/internal/lsp/cmd/definition_test.go @@ -37,13 +37,16 @@ func TestDefinitionHelpExample(t *testing.T) { return } thisFile := filepath.Join(dir, "definition.go") - args := []string{"query", "definition", fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} + baseArgs := []string{"query", "definition"} expect := regexp.MustCompile(`^[\w/\\:_]+flag[/\\]flag.go:\d+:\d+-\d+: defined here as type flag.FlagSet struct{.*}$`) - got := captureStdOut(t, func() { - tool.Main(context.Background(), &cmd.Application{}, args) - }) - if !expect.MatchString(got) { - t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got) + for _, query := range []string{fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} { + args := append(baseArgs, query) + got := captureStdOut(t, func() { + tool.Main(context.Background(), &cmd.Application{}, args) + }) + if !expect.MatchString(got) { + t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got) + } } } diff --git a/internal/lsp/cmd/export_test.go b/internal/lsp/cmd/export_test.go index 4377c8d0..05b3cd31 100644 --- a/internal/lsp/cmd/export_test.go +++ b/internal/lsp/cmd/export_test.go @@ -4,4 +4,8 @@ package cmd -const ExampleOffset = exampleOffset +const ( + ExampleLine = exampleLine + ExampleColumn = exampleColumn + ExampleOffset = exampleOffset +)