mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
internal/lsp, internal/tool: clean up command line of gopls
Descriptions of certain commands were changed to not start with capital letter. All of the commands were splitted into so called main commands and feature commands. Package tool did have a limitation that revealed itself when command was invoked only with `-h`, i.e. `gopls -h`. Limitation was that in above mentioned case, FlagSet.Parse() was intercepting `-h` flag and printing just default usage. Updates golang/go#35855 Change-Id: I9bd27fc72e8fb8d18025d95ebcae974dd5583e91 Reviewed-on: https://go-review.googlesource.com/c/tools/+/210359 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
49a3e744a4
commit
a0e659d513
@ -61,10 +61,10 @@ type Application struct {
|
|||||||
Remote string `flag:"remote" help:"*EXPERIMENTAL* - forward all commands to a remote lsp"`
|
Remote string `flag:"remote" help:"*EXPERIMENTAL* - forward all commands to a remote lsp"`
|
||||||
|
|
||||||
// Enable verbose logging
|
// Enable verbose logging
|
||||||
Verbose bool `flag:"v" help:"Verbose output"`
|
Verbose bool `flag:"v" help:"verbose output"`
|
||||||
|
|
||||||
// Control ocagent export of telemetry
|
// 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.
|
// 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.
|
// 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.
|
// This includes the short help for all the sub commands.
|
||||||
func (app *Application) DetailedHelp(f *flag.FlagSet) {
|
func (app *Application) DetailedHelp(f *flag.FlagSet) {
|
||||||
fmt.Fprint(f.Output(), `
|
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:
|
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.Fprintf(f.Output(), " %s : %v\n", c.Name(), c.ShortHelp())
|
||||||
}
|
}
|
||||||
fmt.Fprint(f.Output(), `
|
fmt.Fprint(f.Output(), `
|
||||||
@ -138,9 +151,22 @@ func (app *Application) Run(ctx context.Context, args ...string) error {
|
|||||||
// command line.
|
// command line.
|
||||||
// The command is specified by the first non flag argument.
|
// The command is specified by the first non flag argument.
|
||||||
func (app *Application) commands() []tool.Application {
|
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{
|
return []tool.Application{
|
||||||
&app.Serve,
|
&app.Serve,
|
||||||
|
&version{app: app},
|
||||||
&bug{},
|
&bug{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *Application) featureCommands() []tool.Application {
|
||||||
|
return []tool.Application{
|
||||||
&check{app: app},
|
&check{app: app},
|
||||||
&foldingRanges{app: app},
|
&foldingRanges{app: app},
|
||||||
&format{app: app},
|
&format{app: app},
|
||||||
@ -154,7 +180,6 @@ func (app *Application) commands() []tool.Application {
|
|||||||
&signature{app: app},
|
&signature{app: app},
|
||||||
&suggestedfix{app: app},
|
&suggestedfix{app: app},
|
||||||
&symbols{app: app},
|
&symbols{app: app},
|
||||||
&version{app: app},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ type Serve struct {
|
|||||||
Mode string `flag:"mode" help:"no effect"`
|
Mode string `flag:"mode" help:"no effect"`
|
||||||
Port int `flag:"port" help:"port on which to run gopls for debugging purposes"`
|
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"`
|
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"`
|
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"`
|
Debug string `flag:"debug" help:"serve debug information on the supplied address"`
|
||||||
|
|
||||||
app *Application
|
app *Application
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,11 @@ func Main(ctx context.Context, app Application, args []string) {
|
|||||||
// error.
|
// error.
|
||||||
func Run(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 := 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))
|
p := addFlags(s, reflect.StructField{}, reflect.ValueOf(app))
|
||||||
s.Parse(args)
|
s.Parse(args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user