Skip to content
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

clojure-lsp unmarshalling json error #29

Open
scotts777 opened this issue Dec 28, 2019 · 4 comments · May be fixed by #68
Open

clojure-lsp unmarshalling json error #29

scotts777 opened this issue Dec 28, 2019 · 4 comments · May be fixed by #68
Labels
help wanted Extra attention is needed NeedsInvestigation

Comments

@scotts777
Copy link

scotts777 commented Dec 28, 2019

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"
@fhs fhs added help wanted Extra attention is needed NeedsInvestigation labels Dec 28, 2019
@fhs
Copy link
Collaborator

fhs commented Dec 28, 2019

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.

@scotts777
Copy link
Author

I'll try to investigate clojure-lsp side when I can get some time. Acme + acme-lsp is a very compelling tool!

@scotts777
Copy link
Author

scotts777 commented Jan 7, 2020

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".

  1. 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

  2. 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

  3. 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 } }

  4. Diagnostics work fine.

  5. "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

@fhs
Copy link
Collaborator

fhs commented Jan 11, 2020

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 returning Location instead of []Location
  • L comp: textDocument/completion is returning CompletionItem[] instead of CompletionList

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed NeedsInvestigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants