internal/lsp/cmd: add a -vv flag for higher verbosity

Add a higher log level for the command-line. This uses the verboseOutput
setting.

Updates golang/go#40139

Change-Id: I9b7edcda12b0431058c9cfe1413b7c5fc016c026
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2020-07-09 19:16:55 -04:00
parent f1c4188a97
commit 7342f9734a
2 changed files with 18 additions and 7 deletions

View File

@ -57,12 +57,15 @@ type Application struct {
// The environment variables to use.
env []string
// Support for remote lsp server
// Support for remote LSP server.
Remote string `flag:"remote" help:"forward all commands to a remote lsp specified by this flag. With no special prefix, this is assumed to be a TCP address. If prefixed by 'unix;', the subsequent address is assumed to be a unix domain socket. If 'auto', or prefixed by 'auto;', the remote address is automatically resolved based on the executing environment."`
// Enable verbose logging
// Verbose enables verbose logging.
Verbose bool `flag:"v" help:"verbose output"`
// VeryVerbose enables a higher level of verbosity in logging output.
VeryVerbose bool `flag:"vv" help:"very verbose output"`
// Control ocagent export of telemetry
OCAgent string `flag:"ocagent" help:"the address of the ocagent (e.g. http://localhost:55678), or off"`
@ -71,6 +74,10 @@ type Application struct {
PrepareOptions func(*source.Options)
}
func (a *Application) verbose() bool {
return a.Verbose || a.VeryVerbose
}
// New returns a new Application ready to run.
func New(name, wd string, env []string, options func(*source.Options)) *Application {
if wd == "" {
@ -339,15 +346,15 @@ func (c *cmdClient) LogMessage(ctx context.Context, p *protocol.LogMessageParams
case protocol.Warning:
log.Print("Warning:", p.Message)
case protocol.Info:
if c.app.Verbose {
if c.app.verbose() {
log.Print("Info:", p.Message)
}
case protocol.Log:
if c.app.Verbose {
if c.app.verbose() {
log.Print("Log:", p.Message)
}
default:
if c.app.Verbose {
if c.app.verbose() {
log.Print(p.Message)
}
}
@ -382,7 +389,7 @@ func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ParamConfigur
}
env[l[0]] = l[1]
}
results[i] = map[string]interface{}{
m := map[string]interface{}{
"env": env,
"analyses": map[string]bool{
"fillreturns": true,
@ -391,6 +398,10 @@ func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ParamConfigur
"undeclaredname": true,
},
}
if c.app.VeryVerbose {
m["verboseOutput"] = true
}
results[i] = m
}
return results, nil
}

View File

@ -32,7 +32,7 @@ func (v *version) DetailedHelp(f *flag.FlagSet) {
// Run prints version information to stdout.
func (v *version) Run(ctx context.Context, args ...string) error {
debug.PrintVersionInfo(ctx, os.Stdout, v.app.Verbose, debug.PlainText)
debug.PrintVersionInfo(ctx, os.Stdout, v.app.verbose(), debug.PlainText)
return nil
}