Skip to content

Commit

Permalink
internal/lsp: have tests report a different application name to the m…
Browse files Browse the repository at this point in the history
…ain gopls binary

Change-Id: I246dc9c468ee35586a8332ebdf41f23521adbc6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
ianthehat committed Jul 18, 2019
1 parent 38daa65 commit 625c92e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/gopls/main.go
Expand Up @@ -19,5 +19,5 @@ import (

func main() {
debug.Version += "-cmd.gopls"
tool.Main(context.Background(), cmd.New("", nil), os.Args[1:])
tool.Main(context.Background(), cmd.New("gopls-legacy", "", nil), os.Args[1:])
}
2 changes: 1 addition & 1 deletion gopls/main.go
Expand Up @@ -17,5 +17,5 @@ import (
)

func main() {
tool.Main(context.Background(), cmd.New("", nil), os.Args[1:])
tool.Main(context.Background(), cmd.New("gopls", "", nil), os.Args[1:])
}
8 changes: 6 additions & 2 deletions internal/lsp/cmd/cmd.go
Expand Up @@ -45,6 +45,9 @@ type Application struct {
// The base cache to use for sessions from this application.
cache source.Cache

// The name of the binary, used in help and telemetry.
name string

// The working directory to run commands in.
wd string

Expand All @@ -59,20 +62,21 @@ type Application struct {
}

// Returns a new Application ready to run.
func New(wd string, env []string) *Application {
func New(name, wd string, env []string) *Application {
if wd == "" {
wd, _ = os.Getwd()
}
app := &Application{
cache: cache.New(),
name: name,
wd: wd,
env: env,
}
return app
}

// Name implements tool.Application returning the binary name.
func (app *Application) Name() string { return "gopls" }
func (app *Application) Name() string { return app.name }

// Usage implements tool.Application returning empty extra argument usage.
func (app *Application) Usage() string { return "<command> [command-flags] [command-args]" }
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/cmd/cmd_test.go
Expand Up @@ -39,7 +39,7 @@ func testCommandLine(t *testing.T, exporter packagestest.Exporter) {
r := &runner{
exporter: exporter,
data: data,
app: cmd.New(data.Config.Dir, data.Exported.Config.Env),
app: cmd.New("gopls-test", data.Config.Dir, data.Exported.Config.Env),
ctx: tests.Context(t),
}
tests.Run(t, r, data)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/cmd/definition_test.go
Expand Up @@ -55,7 +55,7 @@ func TestDefinitionHelpExample(t *testing.T) {
fmt.Sprintf("%v:#%v", thisFile, cmd.ExampleOffset)} {
args := append(baseArgs, query)
got := captureStdOut(t, func() {
tool.Main(tests.Context(t), cmd.New("", nil), args)
tool.Main(tests.Context(t), cmd.New("gopls-test", "", nil), args)
})
if !expect.MatchString(got) {
t.Errorf("test with %v\nexpected:\n%s\ngot:\n%s", args, expect, got)
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/cmd/format_test.go
Expand Up @@ -37,7 +37,7 @@ func (r *runner) Format(t *testing.T, data tests.Formats) {
//TODO: our error handling differs, for now just skip unformattable files
continue
}
app := cmd.New(r.data.Config.Dir, r.data.Config.Env)
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Config.Env)
got := captureStdOut(t, func() {
tool.Main(r.ctx, app, append([]string{"-remote=internal", "format"}, args...))
})
Expand Down

0 comments on commit 625c92e

Please sign in to comment.