Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

formatting doesn't work 90% of the time when language server is enabled #1667

Closed
OneOfOne opened this issue May 7, 2018 · 15 comments
Closed
Labels

Comments

@OneOfOne
Copy link
Contributor

OneOfOne commented May 7, 2018

Like the title, there are no errors in any of the panels.

Sometimes it'll work, most of the time it doesn't.

Here's my current code settings: https://github.com/OneOfOne/dotfiles/blob/master/.config/Code/User/settings.json#L105

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 7, 2018

Are you referring to just format on save feature? Or you are having issues with manual formatting as well?
You seem to have format on type/save/paste: all the 3 enabled. Go formatters are slower in general. I would suggest to disable the format on type and paste for Go atleast

"[go]": {
	"editor.formatOnType": false,
	"editor.formatOnPaste": false,
}

@OneOfOne
Copy link
Contributor Author

OneOfOne commented May 7, 2018

Neither format on save nor manual formatting works.

@ramya-rao-a
Copy link
Contributor

Even after disabling format on type and paste?
Any errors in the console? Help -> Toggle Developer Tools -> Console?
Is this a recent thing you noticed after an update to either VS Code or the Go extension itself?

@OneOfOne
Copy link
Contributor Author

OneOfOne commented May 7, 2018

Disabling all formatOnXXX doesn't change anything, neither using "Format Document" directly.

There are no errors in the dev Console neither after save nor after "Format Document"

Only things printed in the Go output panel:

....path...>Finished running tool: /home/oneofone/bin/go build -i -o /tmp/go-code-check ...pkg-path...

....path...>Finished running tool: /home/oneofone/bin/go vet ./...

....path...>Finished running tool: /home/oneofone/code/go/bin/megacheck

Running goimports -w . from the terminal works as expected.

OneOfOne/dotfiles@9c24638

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 7, 2018

I am running out of ideas ...
One last thought is to add the setting "go.useDiffForFormatting": false and see if that helps.

If that doesnt help, can you try running the extension from source and see where its failing?
I recall you had sent a PR once to fix an issue around formatting itself, so debugging the extension shouldnt be too hard :)

@OneOfOne
Copy link
Contributor Author

OneOfOne commented May 7, 2018

I will when I get a chance, I've been very busy lately, maybe next weekend unless someone else figures it out.

@OneOfOne
Copy link
Contributor Author

OneOfOne commented May 8, 2018

So #1662 (comment) seems to have fixed this problem as well, I don't understand how it's related (I didn't dig into the code yet).

I won't close this issue yet in case it's just randomly working.

@ramya-rao-a
Copy link
Contributor

@OneOfOne I'll close this issue nevertheless. If you see this happening again, you can re-open this issue. In case the issue is locked (which it does in 10 days or so), feel free to open a new issue

@OneOfOne
Copy link
Contributor Author

So this is back, it's related to turning off go-langserver (the bug where it randomly stops is back).

@ramya-rao-a
Copy link
Contributor

So you are seeing this even after using the fix from #1662 correct?

@ramya-rao-a ramya-rao-a reopened this May 11, 2018
@ramya-rao-a
Copy link
Contributor

I randomly come across this as well, but no reliable repro steps.
One thing I've noticed is that there is a formatting error from the language server.
Looks like the language server now supports formatting and requests going there sometimes fail.

Can you keep the Output pane open, choose the "go-langserver" channel there and the next time you see formatting stop, check if the output pane has any formatting related error

@ramya-rao-a ramya-rao-a changed the title formatting doesn't work 90% of the time formatting doesn't work 90% of the time when language server is enabled May 11, 2018
@OneOfOne
Copy link
Contributor Author

langserver-go: reading on stdin, writing on stdout
Passing an initialize rootPath URI ("file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts") is deprecated. Use rootUri instead.
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'µ' '\x00'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x00'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x01'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x02'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x03'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x04'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x05'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x06'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\a'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\b'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\t'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\n'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\v'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\f'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\r'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x0e'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x0f'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x10'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x11'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¶' '\x12'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x01'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x02'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x03'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x04'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x05'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x06'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\a'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\b'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\t'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\n'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\v'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\f'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\r'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x0e'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x0f'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x10'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x12'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x13'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x14'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x15'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x16'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x17'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'·' '\x18'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for invalid position {'¸' '\x01'} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go": file only has 182 lines
[Error - 5:00:50 AM] Request textDocument/hover failed.
  Message: invalid position: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go:183:25 (file only has 182 lines)
  Code: 0 
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for out of range position &{{'\x00' '\x00'} {'Ñ' '\x00'}} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go"
[Error - 5:01:31 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:161:7: expected ';', found "new "
  Code: 0 
[Error - 5:01:35 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:161:8: expected ';', found "new "
  Code: 0 
[Error - 5:01:37 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:161:8: expected ';', found "new "
  Code: 0 
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for out of range position &{{'\x00' '\x00'} {'¶' '\x00'}} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go"
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for out of range position &{{'\x00' '\x00'} {'¶' '\x00'}} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go"
jsonrpc2 handler: notification "textDocument/didChange" handling error: received textDocument/didChange for out of range position &{{'µ' '\x01'} {'¶' '\x00'}} on "file:///home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go"
[Error - 5:03:51 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/s2ts.go:1:1: expected 'package', found ackage
  Code: 0 
[Error - 5:04:17 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:162:8: expected ';', found "new "
  Code: 0 
[Error - 5:04:34 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:161:8: expected ';', found "new "
  Code: 0 
jsonrpc2 handler: notification "$/setTraceNotification" handling error: jsonrpc2: code -32601 message: method not supported: $/setTraceNotification
[Error - 5:04:47 AM] Request textDocument/formatting failed.
  Message: /home/oneofone/code/go/src/github.com/OneOfOne/struct2ts/struct.go:161:8: expected ';', found "new "
  Code: 0 

@ramya-rao-a
Copy link
Contributor

That looks similar to what I logged in sourcegraph/go-langserver#277

@ramya-rao-a
Copy link
Contributor

@OneOfOne I've added a setting to opt in to the not yet stable features from the language server. Try the below and your formatting issues should be solved even when go.useLanguageServer is true

And when you want to try the formatting feature from the language server, add the below setting

 "go.languageServerExperimentalFeatures": {
      "format": true
    }

@OneOfOne
Copy link
Contributor Author

You rock, thanks.

I'll try it once I get home tomorrow morning.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants