New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: gopls doesn't format my codes while saving or changing #41926
Comments
@tigeran2020: Can you please share collect |
@stamblerre
|
This looks like a partial log--do you mind sharing the complete log? |
hear is: [Trace - 15:25:48.229 PM] Received response 'shutdown - (26)' in 0ms. [Trace - 15:25:48.229 PM] Received notification 'window/logMessage'. [Trace - 15:25:48.229 PM] Sending notification 'exit'. [Trace - 15:25:48.280 PM] Sending request 'initialize - (0)'. [Trace - 15:25:48.281 PM] Received response 'initialize - (0)' in 1ms. [Trace - 15:25:48.281 PM] Sending notification 'initialized'. [Trace - 15:25:48.282 PM] Received request 'window/workDoneProgress/create - (1)'. [Trace - 15:25:48.282 PM] Sending notification 'textDocument/didOpen'. [Trace - 15:25:48.284 PM] Sending response 'window/workDoneProgress/create - (1)' in 2ms. [Trace - 15:25:48.284 PM] Received notification '$/progress'. [Trace - 15:25:48.284 PM] Received request 'workspace/configuration - (2)'. [Trace - 15:25:48.287 PM] Sending response 'workspace/configuration - (2)' in 2ms. [Trace - 15:25:48.299 PM] Sending request 'textDocument/documentSymbol - (1)'. [Trace - 15:25:48.300 PM] Sending request 'textDocument/codeAction - (2)'. [Trace - 15:25:48.300 PM] Sending request 'textDocument/documentLink - (3)'. [Trace - 15:25:48.330 PM] Received request 'client/registerCapability - (3)'. [Trace - 15:25:48.330 PM] Received notification 'window/logMessage'. [Info - 3:25:48 PM] 2020/10/13 15:25:48 go env for /root/src/gotest [Trace - 15:25:48.330 PM] Sending response 'client/registerCapability - (3)' in 0ms. [Trace - 15:25:48.330 PM] Received request 'client/registerCapability - (4)'. [Trace - 15:25:48.330 PM] Sending response 'client/registerCapability - (4)' in 0ms. [Trace - 15:25:48.377 PM] Received notification 'window/logMessage'. [Info - 3:25:48 PM] 2020/10/13 15:25:48 go/packages.Load [Trace - 15:25:48.397 PM] Received notification '$/progress'. [Trace - 15:25:48.477 PM] Received response 'textDocument/documentSymbol - (1)' in 177ms. [Trace - 15:25:48.477 PM] Received response 'textDocument/codeAction - (2)' in 177ms. [Trace - 15:25:48.477 PM] Received response 'textDocument/documentLink - (3)' in 177ms. [Trace - 15:25:48.502 PM] Sending request 'textDocument/foldingRange - (4)'. [Trace - 15:25:48.503 PM] Received response 'textDocument/foldingRange - (4)' in 0ms. [Trace - 15:25:48.549 PM] Sending request 'textDocument/codeLens - (5)'. [Trace - 15:25:48.549 PM] Received response 'textDocument/codeLens - (5)' in 0ms. [Trace - 15:25:52.939 PM] Sending request 'textDocument/hover - (6)'. [Trace - 15:25:52.940 PM] Received response 'textDocument/hover - (6)' in 0ms. [Trace - 15:25:53.277 PM] Sending notification 'textDocument/didChange'. [Trace - 15:25:53.476 PM] Sending request 'textDocument/foldingRange - (7)'. [Trace - 15:25:53.477 PM] Received response 'textDocument/foldingRange - (7)' in 0ms. [Trace - 15:25:53.531 PM] Sending request 'textDocument/codeLens - (8)'. [Trace - 15:25:53.531 PM] Received response 'textDocument/codeLens - (8)' in 0ms. [Trace - 15:25:53.615 PM] Sending request 'textDocument/documentSymbol - (9)'. [Trace - 15:25:53.616 PM] Received response 'textDocument/documentSymbol - (9)' in 0ms. [Trace - 15:25:53.741 PM] Sending request 'textDocument/codeAction - (10)'. [Trace - 15:25:53.741 PM] Received response 'textDocument/codeAction - (10)' in 0ms. [Trace - 15:25:54.266 PM] Sending request 'textDocument/documentLink - (11)'. [Trace - 15:25:54.266 PM] Received response 'textDocument/documentLink - (11)' in 0ms. [Trace - 15:25:54.286 PM] Sending notification 'textDocument/didSave'. [Trace - 15:25:54.495 PM] Sending notification 'workspace/didChangeWatchedFiles'. [Trace - 15:26:18.477 PM] Received notification 'window/logMessage'. [Info - 3:26:18 PM] 2020/10/13 15:26:18 background imports cache refresh starting [Trace - 15:26:18.560 PM] Received notification 'window/logMessage'. [Info - 3:26:18 PM] 2020/10/13 15:26:18 background refresh finished after 82.603936ms |
Your log doesn't seem to have errors, but you're right that I'm not seeing any formatting requests. Do you have the following in your VS Code settings? "[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"editor.formatOnSave": true,
} |
@stamblerre I hadn't. But it still doesn't work after I have add these settings. |
[Trace - 10:17:27.663 AM] Sending request 'initialize - (0)'. [Trace - 10:17:27.665 AM] Received response 'initialize - (0)' in 1ms. [Trace - 10:17:27.683 AM] Sending notification 'initialized'. [Trace - 10:17:27.683 AM] Received request 'window/workDoneProgress/create - (1)'. [Trace - 10:17:27.684 AM] Sending notification 'textDocument/didOpen'. [Trace - 10:17:27.695 AM] Sending response 'window/workDoneProgress/create - (1)' in 12ms. [Trace - 10:17:27.695 AM] Received notification '$/progress'. [Trace - 10:17:27.696 AM] Received request 'workspace/configuration - (2)'. [Trace - 10:17:27.713 AM] Sending response 'workspace/configuration - (2)' in 17ms. [Trace - 10:17:27.715 AM] Sending request 'textDocument/documentSymbol - (1)'. [Trace - 10:17:27.716 AM] Sending request 'textDocument/codeAction - (2)'. [Trace - 10:17:27.717 AM] Sending request 'textDocument/documentLink - (3)'. [Trace - 10:17:27.757 AM] Received request 'client/registerCapability - (3)'. [Trace - 10:17:27.757 AM] Received notification 'window/logMessage'. [Info - 10:17:27 AM] 2020/10/15 10:17:27 go env for /root/src/gotest [Trace - 10:17:27.760 AM] Sending response 'client/registerCapability - (3)' in 2ms. [Trace - 10:17:27.760 AM] Received request 'client/registerCapability - (4)'. [Trace - 10:17:27.761 AM] Sending response 'client/registerCapability - (4)' in 0ms. [Trace - 10:17:27.804 AM] Received notification 'window/logMessage'. [Info - 10:17:27 AM] 2020/10/15 10:17:27 go/packages.Load [Trace - 10:17:27.824 AM] Received notification '$/progress'. [Trace - 10:17:27.908 AM] Sending request 'textDocument/foldingRange - (4)'. [Trace - 10:17:27.912 AM] Received response 'textDocument/documentSymbol - (1)' in 196ms. [Trace - 10:17:27.912 AM] Received response 'textDocument/codeAction - (2)' in 196ms. [Trace - 10:17:27.913 AM] Received response 'textDocument/documentLink - (3)' in 195ms. [Trace - 10:17:27.913 AM] Received response 'textDocument/foldingRange - (4)' in 5ms. [Trace - 10:17:27.964 AM] Sending request 'textDocument/codeLens - (5)'. [Trace - 10:17:27.964 AM] Received response 'textDocument/codeLens - (5)' in 0ms. [Trace - 10:17:28.678 AM] Sending request 'textDocument/codeAction - (6)'. [Trace - 10:17:28.679 AM] Received response 'textDocument/codeAction - (6)' in 0ms. [Trace - 10:17:28.714 AM] Sending request 'textDocument/codeAction - (7)'. [Trace - 10:17:28.715 AM] Received response 'textDocument/codeAction - (7)' in 0ms. [Trace - 10:17:29.067 AM] Sending notification 'textDocument/didSave'. [Trace - 10:17:29.349 AM] Sending notification 'workspace/didChangeWatchedFiles'. [Trace - 10:17:29.804 AM] Sending request 'textDocument/codeAction - (8)'. [Trace - 10:17:29.804 AM] Received response 'textDocument/codeAction - (8)' in 0ms. [Trace - 10:17:29.896 AM] Sending notification 'textDocument/didSave'. [Trace - 10:17:30.130 AM] Sending request 'textDocument/codeAction - (9)'. [Trace - 10:17:30.131 AM] Received response 'textDocument/codeAction - (9)' in 0ms. [Trace - 10:17:30.189 AM] Sending notification 'textDocument/didSave'. [Trace - 10:17:30.189 AM] Sending notification 'workspace/didChangeWatchedFiles'. [Trace - 10:17:30.471 AM] Sending notification 'workspace/didChangeWatchedFiles'. [Trace - 10:17:57.913 AM] Received notification 'window/logMessage'. [Info - 10:17:57 AM] 2020/10/15 10:17:57 background imports cache refresh starting [Trace - 10:18:02.272 AM] Received notification 'window/logMessage'. [Info - 10:18:02 AM] 2020/10/15 10:18:02 background refresh finished after 4.35913356s [Trace - 10:18:23.515 AM] Sending notification '$/setTraceNotification'. [Trace - 10:18:23.522 AM] Sending request 'shutdown - (10)'. [Trace - 10:18:23.522 AM] Received response 'shutdown - (10)' in 0ms. [Trace - 10:18:23.522 AM] Received notification 'window/logMessage'. [Trace - 10:18:23.526 AM] Sending notification 'exit'. [Info - 10:18:23 AM] 2020/10/15 10:18:23 go env for /root/src/gotest [Info - 10:18:23 AM] 2020/10/15 10:18:23 go/packages.Load [Info - 10:19:04 AM] 2020/10/15 10:19:04 background imports cache refresh starting [Info - 10:19:04 AM] 2020/10/15 10:19:04 background refresh finished after 79.147271ms [Info - 10:19:38 AM] 2020/10/15 10:19:38 background imports cache refresh starting [Info - 10:19:38 AM] 2020/10/15 10:19:38 background refresh finished after 19.247537ms |
this is my setting: {
"editor.formatOnSave": true,
"go.formatTool": "gofmt",
"go.useLanguageServer": true,
"go.languageServerFlags": [
"serve",
"-rpc.trace",
"--debug=localhost:6060"
],
"[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"editor.formatOnSave": true,
}
} |
Please make sure to restart the editor after you update those settings (just in case). I see the |
Closing, as there hasn't been any activity on this issue for over a month. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="git.code.oa.com"
GONOSUMDB="git.code.oa.com"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE="git.code.oa.com"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/src/gotest/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build557597222=/tmp/go-build -gno-record-gcc-switches"
go env
OutputWhat did you do?
opened vscode, installed latest gopls, toggled
use go language server
setting,opened folder ~/src/gotest/, executed
go mod init hello
at directory ~/src/gotest/,created a new file
main.go
, and write codes as below:and saved it.
What did you expect to see?
codes formated as below:
What did you see instead?
codes not changed.
more information
I used command
gopls main.go
dirrectly, it formated my codes correctly.The text was updated successfully, but these errors were encountered: