Golang中gopls帮助文本缺少标志的解决方案
Golang中gopls帮助文本缺少标志的解决方案
我发现 gopls 命令有一个有点奇怪的行为,但不知道这是否是预期的情况,所以想请教一下。
我执行了 gopls help 并得到了以下结果:
gopls: Unknown command help
The Go Language source tools.
Usage: gopls [flags] <command> [command-flags] [command-args]
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:
main:
serve : run a server for Go code using the Language Server Protocol
version : print the gopls version information
bug : report a bug in gopls
features:
check : show diagnostic results for the specified file
definition : show declaration of selected identifier
folding_ranges : display selected file's folding ranges
format : format the code according to the go standard
highlight : display selected identifier's highlights
implementation : display selected identifier's implementation
imports : updates import statements
inspect : inspect server state (daemon mode only)
links : list links in a file
prepare_rename : test validity of a rename operation at location
references : display selected identifier's references
rename : rename selected identifier
signature : display selected identifier's signature
fix : apply suggested fixes
symbols : display selected file's symbols
workspace_symbol : search symbols in workspace
gopls flags are:
如上所示,帮助文本的末尾缺少标志列表。
另一方面,我执行了 gopls --help 并得到了以下结果:
The Go Language source tools.
Usage: gopls [flags] <command> [command-flags] [command-args]
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:
main:
serve : run a server for Go code using the Language Server Protocol
version : print the gopls version information
bug : report a bug in gopls
features:
check : show diagnostic results for the specified file
definition : show declaration of selected identifier
folding_ranges : display selected file's folding ranges
format : format the code according to the go standard
highlight : display selected identifier's highlights
implementation : display selected identifier's implementation
imports : updates import statements
inspect : inspect server state (daemon mode only)
links : list links in a file
prepare_rename : test validity of a rename operation at location
references : display selected identifier's references
rename : rename selected identifier
signature : display selected identifier's signature
fix : apply suggested fixes
symbols : display selected file's symbols
workspace_symbol : search symbols in workspace
gopls flags are:
-debug string
serve debug information on the supplied address
-listen string
address on which to listen for remote connections. If prefixed by 'unix;', the subsequent address is assumed to be a unix domain socket. Otherwise, TCP is used.
-listen.timeout duration
when used with -listen, shut down the server when there are no connected clients for this duration
-logfile string
filename to log to. if value is "auto", then logging to a default output file is enabled
-mode string
no effect
-ocagent string
the address of the ocagent, or off (default "off")
-port int
port on which to run gopls for debugging purposes
-profile.cpu string
write CPU profile to this file
-profile.mem string
write memory profile to this file
-profile.trace string
write trace log to this file
-remote string
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.
-remote.debug string
when used with -remote=auto, the -debug value used to start the daemon
-remote.listen.timeout duration
when used with -remote=auto, the -listen.timeout value used to start the daemon (default 1m0s)
-remote.logfile string
when used with -remote=auto, the -logfile value used to start the daemon (default "auto")
-rpc.trace
print the full rpc trace in lsp inspector format
-v verbose output
帮助文本的末尾正确列出了标志。
这是预期的行为吗?感谢您的帮助。
构建信息
我使用了 2020年6月15日 星期一 12:45:09 UTC 的最新主分支。
~/projects/golang/tools/gopls
❯ ./gopls -v version
Build info
----------
golang.org/x/tools/gopls master
golang.org/x/tools/gopls@(devel)
github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/tools@v0.0.0-20200515220128-d3bf790afa53 => ../
golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
Go info
-------
go version go1.14 darwin/amd64
~/projects/golang/tools/gopls
❯ git rev-parse HEAD
54c614fe050cac95ace393a63f164149942ecbde
~/projects/golang/tools/gopls
❯ git status
On branch master
Your branch is up to date with 'origin/master'
更多关于Golang中gopls帮助文本缺少标志的解决方案的实战教程也可以访问 https://www.itying.com/category-94-b0.html
更多关于Golang中gopls帮助文本缺少标志的解决方案的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
这是 gopls 命令的一个已知行为。gopls help 命令实际上是一个子命令,而 --help 是一个全局标志。当使用 gopls help 时,它尝试执行 help 子命令,但这个子命令不存在,所以只显示了基本的帮助信息而没有标志列表。
正确的使用方式应该是:
gopls --help- 显示所有全局标志gopls <command> --help- 显示特定命令的标志
例如,要查看 serve 命令的标志:
gopls serve --help
输出示例:
run a server for Go code using the Language Server Protocol
Usage: gopls serve [serve-flags]
The serve command runs the Go language server.
serve flags:
-port int
port on which to run gopls for debugging purposes
对于其他命令也是如此:
gopls check --help
gopls format --help
gopls definition --help
如果你需要查看所有可用的标志,包括全局标志和命令特定标志,可以这样组合使用:
gopls --help serve
或者查看特定命令的完整帮助:
gopls --help check
这种设计符合许多命令行工具的惯例,其中 --help 是全局标志,而 help 可能是一个子命令(如果实现的话)。在 gopls 中,help 子命令没有被实现,所以会显示错误信息。

