acme-lsp
acme-lsp copied to clipboard
clojure-lsp unmarshalling json error
Running on Mac OS X 10.15.2 with Plan 9 User Space and clojure-lsp
L hov - worked great
But
L comp, L def and L fmt all show the following in the terminal that is running acme-lsp -v
2019/12/28 17:16:52 Format failed in file manager: unmarshalling result: json: cannot unmarshal string into Go struct field CodeAction.command of type protocol.Command
The two log files that I configured in the .toml file have no contents. Here is my config file:
ProxyNetwork = "unix"
ProxyAddress = "/tmp/ns.ses.:0/acme-lsp.rpc"
AcmeNetwork = "unix"
AcmeAddress = "/tmp/ns.ses:0/acme"
WorkspaceDirectories = ["/Users/ses/Projects/Clojure/fiat-hell"]
RootDirectory = "/Users/ses/Projects/Clojure"
FormatOnPut = true
CodeActionsOnPut = ["source.organizeImports"]
[Servers]
[Servers.clojure]
Command = ["sh", "-c", "cd /Users/ses/Projects/Clojure;clojure-lsp"]
Address = ""
StderrFile = "/Users/ses/Library/Caches/acme-lsp/clojure.stderr.log"
LogFile = "/Users/ses/Library/Caches/acme-lsp/clojure.log"
[Servers.clojure.Options]
[[FilenameHandlers]]
Pattern = "(\\.deps)|(\\.clj)$"
ServerKey = "clojure"
I think it's failing to parse CodeAction
result while doing the Format. CodeAction.command
should be of type Command
(not string
) according to the spec. However, CodeAction
result can be (Command | CodeAction)[] | null
, so maybe it's returning a Command
instead of a CodeAction
? It's hard to know what's going on without looking at the RPC trace. There may be a flag in clojure-lsp
to print the json-rpc protocol trace.
I'll try to investigate clojure-lsp side when I can get some time. Acme + acme-lsp is a very compelling tool!
Looks like clojure-lsp is utilizing the library lsp4j. I was able to get RPC tracing of the calls to log. Here is what happens on a call to "L fmt".
-
I updated clojure-lsp to the latest and now receive this error when calling "L fmt"
2020/01/06 23:12:21 The accessor 'CodeActionContext.getDiagnostics()' must return a non-null value. Path: $.params.context.diagnostics L: exit 1
-
The clojure-lsp tracing receives a textDocument/didChange although nothing changed.
[Trace - 11:11:24 PM] Received notification 'textDocument/didChange' Params: { "textDocument": { "version": 0, "uri": "file:///Users/scott/Projects/Clojure/fiat-hell/src/fiat_hell/money.clj" }, "contentChanges": [ { "text":
omitting the rest of the document trace here -
There are no further commands received to format the document. This is different than when running the "L hov" command - which works. The L hov command also first sends a textDocument/didChange request, but then follows it up with this:
[Trace - 11:17:00 PM] Received request 'textDocument/hover - (18)' Params: { "textDocument": { "uri": "file:///Users/scott/Projects/Clojure/fiat-hell/src/fiat_hell/money.clj" }, "position": { "line": 6, "character": 14 } }
-
Diagnostics work fine.
-
"L comp" gives this error
2020/01/06 23:21:50 The accessor 'CompletionContext.getTriggerKind()' must return a non-null value. Path: $.params.context.triggerKind L: exit 1
thanks for any suggestions you may have
I've added a -rpc.trace
flag to acme-lsp for easier debugging. I was able to reproduce your problems. To summarize:
-
L fmt
:textDocument/codeAction
is returning[]Command
instead of[]CodeAction
-
L def
:textDocument/definition
is returningLocation
instead of[]Location
-
L comp
:textDocument/completion
is returningCompletionItem[]
instead ofCompletionList
clojure-lsp is allowed to return those according to the spec. It just differs from gopls
, which is what acme-lsp
LSP parser is based on. The first two are probably not easy to fix. Completion should be relatively easy to fix by converting the CompletionItem[]
to a CompletionList
during JSON unmarshal.
I'm not sure when I'll get around to looking deeper. If anyone wants to work on fixes, PRs are welcome. There are some workarounds to these types of JSON unmarshaling issues (see internal/lsp/protocol/compat.go), but in general it's not fun trying to unmarshal JSON union types in Go.