diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index e0737ad3e5..fe957c50f8 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -61,10 +61,10 @@ type Application struct { Remote string `flag:"remote" help:"*EXPERIMENTAL* - forward all commands to a remote lsp"` // Enable verbose logging - Verbose bool `flag:"v" help:"Verbose output"` + Verbose bool `flag:"v" help:"verbose output"` // Control ocagent export of telemetry - OCAgent string `flag:"ocagent" help:"The address of the ocagent, or off"` + OCAgent string `flag:"ocagent" help:"the address of the ocagent, or off"` // PrepareOptions is called to update the options when a new view is built. // It is primarily to allow the behavior of gopls to be modified by hooks. @@ -101,9 +101,22 @@ func (app *Application) ShortHelp() string { // This includes the short help for all the sub commands. func (app *Application) DetailedHelp(f *flag.FlagSet) { fmt.Fprint(f.Output(), ` +gopls is a Go language server. It is typically used with an editor to provide +language features. When no command is specified, gopls will default to the 'serve' +command. The language features can also be accessed via the gopls command-line interface. + Available commands are: +`, app.Name(), app.Name(), app.Serve.Name()) + fmt.Fprint(f.Output(), ` +main: `) - for _, c := range app.commands() { + for _, c := range app.mainCommands() { + fmt.Fprintf(f.Output(), " %s : %v\n", c.Name(), c.ShortHelp()) + } + fmt.Fprint(f.Output(), ` +features: +`) + for _, c := range app.featureCommands() { fmt.Fprintf(f.Output(), " %s : %v\n", c.Name(), c.ShortHelp()) } fmt.Fprint(f.Output(), ` @@ -138,9 +151,22 @@ func (app *Application) Run(ctx context.Context, args ...string) error { // command line. // The command is specified by the first non flag argument. func (app *Application) commands() []tool.Application { + var commands []tool.Application + commands = append(commands, app.mainCommands()...) + commands = append(commands, app.featureCommands()...) + return commands +} + +func (app *Application) mainCommands() []tool.Application { return []tool.Application{ &app.Serve, + &version{app: app}, &bug{}, + } +} + +func (app *Application) featureCommands() []tool.Application { + return []tool.Application{ &check{app: app}, &foldingRanges{app: app}, &format{app: app}, @@ -154,7 +180,6 @@ func (app *Application) commands() []tool.Application { &signature{app: app}, &suggestedfix{app: app}, &symbols{app: app}, - &version{app: app}, } } diff --git a/internal/lsp/cmd/serve.go b/internal/lsp/cmd/serve.go index 2fdec959a7..df99f4ae03 100644 --- a/internal/lsp/cmd/serve.go +++ b/internal/lsp/cmd/serve.go @@ -34,8 +34,8 @@ type Serve struct { Mode string `flag:"mode" help:"no effect"` Port int `flag:"port" help:"port on which to run gopls for debugging purposes"` Address string `flag:"listen" help:"address on which to listen for remote connections"` - Trace bool `flag:"rpc.trace" help:"Print the full rpc trace in lsp inspector format"` - Debug string `flag:"debug" help:"Serve debug information on the supplied address"` + Trace bool `flag:"rpc.trace" help:"print the full rpc trace in lsp inspector format"` + Debug string `flag:"debug" help:"serve debug information on the supplied address"` app *Application } diff --git a/internal/tool/tool.go b/internal/tool/tool.go index b50569aced..9865d2a6b1 100644 --- a/internal/tool/tool.go +++ b/internal/tool/tool.go @@ -102,6 +102,11 @@ func Main(ctx context.Context, app Application, args []string) { // error. func Run(ctx context.Context, app Application, args []string) error { s := flag.NewFlagSet(app.Name(), flag.ExitOnError) + s.Usage = func() { + fmt.Fprint(s.Output(), app.ShortHelp()) + fmt.Fprintf(s.Output(), "\n\nUsage: %v [flags] %v\n", app.Name(), app.Usage()) + app.DetailedHelp(s) + } p := addFlags(s, reflect.StructField{}, reflect.ValueOf(app)) s.Parse(args)