emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.04k stars 139 forks source link

lsp-interface seems broken for (Hover (:contents) (:range)) #486

Closed cfraizer closed 4 years ago

cfraizer commented 4 years ago

Background

Say, I receive a message like this:

[Trace - 05:51:18 PM] Received response 'textDocument/hover - (72)' in 115ms.
Result: {
  "contents": [
    {
      "language": "java",
      "value": "java.lang.String"
    },
    "The `String` class represents character strings. …"
  ]
}

NOTE: the "contents" key has an array value consisting of a JSON object followed by a JSON string.

NOTE: I abbreviated the actual string for this bug. It was really long.

When I receive that message, I eventually get an error with the backtrace below. The value passed to lsp-marked-string\? is a cons with a hash-table in the car like this:

#s(hash-table size 2 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("language" "java" "value" "java.lang.String"))

The cdr of the value passed to lsp-marked-string\? is another cons with the long string in its car and an empty vector in its cdr.

The Problem

lsp-marked-string\? checks to see if its argument (parameter object) is:

Backtrace

Debugger entered--Lisp error: (wrong-type-argument plistp (#<hash-table equal 2/2 0x1fe8c067dbc7> "The `String` class represents character strings. A..." . []))
  plist-member((#<hash-table equal 2/2 0x1fe8c067dbc7> "The `String` class represents character strings. A..." . []) :language)
  (lambda (prop) (plist-member object prop))(:language)
  -all\?((lambda (prop) (plist-member object prop)) (:language :value))
  (cond ((ht\? object) (-all\? (let ((keys (ht-keys object))) (lambda (prop) (member prop keys))) '("language" "value"))) ((listp object) (-all\? (lambda (prop) (plist-member object prop)) '(:language :value))))
  lsp-marked-string\?((#<hash-table equal 2/2 0x1fe8c067dbc7> "The `String` class represents character strings. A..." . []))
  lsp-ui-doc--extract((#<hash-table equal 2/2 0x1fe8c067dbc7> "The `String` class represents character strings. A..." . []))
  lsp-ui-doc--callback(#<hash-table equal 1/1 0x1fe8c0677ea9> (329 . 335) #<buffer RestServiceApplication.java>)
  #f(compiled-function (hover) #<bytecode 0x26f12731d3622e1>)(#<hash-table equal 1/1 0x1fe8c0677ea9>)
  apply(#f(compiled-function (hover) #<bytecode 0x26f12731d3622e1>) #<hash-table equal 1/1 0x1fe8c0677ea9>)
  #f(compiled-function (&rest args) #<bytecode 0xe8a99754c25f328>)(#<hash-table equal 1/1 0x1fe8c0677ea9>)
  #f(compiled-function (result) #<bytecode -0xd842d2c46470a2f>)(#<hash-table equal 1/1 0x1fe8c067dbf7>)
  #f(compiled-function (result) #<bytecode -0x6d44642f48fc6d1>)(#<hash-table equal 1/1 0x1fe8c067dbf7>)
  lsp--parser-on-message(#<hash-table equal 3/3 0x1fe8c067dc87> #s(lsp--workspace :ewoc #s(ewoc :buffer #<buffer *lsp-log: jdtls:55345*> :pretty-printer lsp--log-entry-pp :header [[[... #5 "" #<marker at 162222 in *lsp-log: jdtls:55345*>] #4 DL-LIST #<marker at 162222 in *lsp-log: jdtls:55345*>] [#4 [#5 ... ... #<marker at 297 in *lsp-log: jdtls:55345*>] #s(lsp--log-entry :timestamp "05:49:00 PM" :process-time nil :type outgoing-req :method "textDocument/hover" :id 54 :body ...) #<marker at 1 in *lsp-log: jdtls:55345*>] "" #<marker at 1 in *lsp-log: jdtls:55345*>] :footer [[[... #5 ... #<marker at 149741 in *lsp-log: jdtls:55345*>] #4 #s(lsp--log-entry :timestamp "08:12:18 PM" :process-time 199 :type incoming-resp :method "textDocument/hover" :id 85 :body #<hash-table equal 1/1 0x1fe8c067dbf7>) #<marker at 156608 in *lsp-log: jdtls:55345*>] [#4 [#5 ... "" #<marker at 1 in *lsp-log: jdtls:55345*>] DL-LIST #<marker at 162222 in *lsp-log: jdtls:55345*>] "" #<marker at 162222 in *lsp-log: jdtls:55345*>] :dll [[[... #5 ... #<marker at 156608 in *lsp-log: jdtls:55345*>] #4 "" #<marker at 162222 in *lsp-log: jdtls:55345*>] [#4 [#5 ... ... #<marker at 1 in *lsp-log: jdtls:55345*>] "" #<marker at 1 in *lsp-log: jdtls:55345*>] DL-LIST #<marker at 162222 in *lsp-log: jdtls:55345*>] :last-node nil :hf-pp insert) :server-capabilities #<hash-table equal 17/17 0x1fe8d928d575> :registered-server-capabilities (#s(lsp--registered-capability :id "6fb55f79-596d-4f42-bdda-46c48d0d6fb6" :method "workspace/didChangeWatchedFiles" :options #<hash-table equal 1/1 0x1fe8d934ddb1>) #s(lsp--registered-capability :id "be411674-d48f-4d75-ace2-04ae80acba52" :method "textDocument/rename" :options #<hash-table equal 1/1 0x1fe8d9363389>) #s(lsp--registered-capability :id "fadfcbdc-fdef-4c6c-b95f-33ca01bdcf6a" :method "textDocument/rangeFormatting" :options nil) #s(lsp--registered-capability :id "ca048f42-5dda-45bc-ab8b-8a5e89fb69e4" :method "textDocument/formatting" :options nil) #s(lsp--registered-capability :id "2ef9d197-cac0-4519-a3c5-9f81a511e2f4" :method "workspace/didChangeWorkspaceFolders" :options nil) #s(lsp--registered-capability :id "6cd5bb6a-ba7d-437f-bce0-ef574a6ba88c" :method "textDocument/foldingRange" :options nil) #s(lsp--registered-capability :id "61f4dc86-02eb-42ba-8854-29a79f138925" :method "textDocument/codeAction" :options #<hash-table equal 1/1 0x1fe8b96bbf4d>) #s(lsp--registered-capability :id "test-id" :method "workspace/didChangeWatchedFiles" :options #<hash-table equal 1/65 0x1fe8b9f317c1>)) :root "/Users/colinf/src/spring/gs-rest-servi..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode -0x3ec03b6ba17842e>) :test\? lsp-java--locate-server-jar) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 5/65 0x1fe8b973d4c3> :request-handlers #<hash-table equal 1/65 0x1fe8b973d799> :response-handlers #<hash-table eql 23/65 0x1fe8b973e081> :prefix-function nil :uri-handlers #<hash-table equal 1/65 0x1fe8b973dc3d> :action-handlers #<hash-table equal 9/65 0x1fe8b973d83d> :major-modes (java-mode) :activation-fn nil :priority 0 :server-id jdtls :multi-root t :initialization-options #f(compiled-function () #<bytecode 0xf8a6ec93121f078>) :custom-capabilities nil :library-folders-fn #f(compiled-function (workspace) #<bytecode 0x61422e901e7f2b6>) :before-file-open-fn #f(compiled-function (workspace) #<bytecode -0x84809915e8ef183>) :initialized-fn #f(compiled-function (workspace) #<bytecode 0x1ce57d68a4537dd6>) :remote? nil :completion-in-comments? t :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x1fe8b973e357> :download-server-fn lsp-java--ensure-server :download-in-progress? nil :buffers nil) :host-root nil :proc #<process jdtls> :cmd-proc #<process jdtls> :buffers (#<buffer RestServiceApplication.java>) :semantic-highlighting-faces nil :semantic-highlighting-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x1fe8d52b4135> :watches #<hash-table equal 0/65 0x1fe8d52b4155> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x1fe8d52b3935> :work-done-tokens #<hash-table equal 0/65 0x1fe8d52b3955>))
  #f(compiled-function (proc input) #<bytecode 0x11ad9fc14b14739d>)(#<process jdtls> "Content-Length: 5767\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":85,\"...")
cfraizer commented 4 years ago

I apologize up-front for the fact that (1) I wasn't sure the best way to fix this; and (2) I wasn't even sure how to present this information. I am convinced that the message I am receiving (from the jdtls language server) is valid, but that it causes errors when processed by lsp-ui.

If I can help in any way, please let me know.

cfraizer commented 4 years ago

I originally pasted the wrong backtrace into this bug. Replaced.

yyoncho commented 4 years ago

are you sure you are running latest lsp-ui?

(lsp-ui-doc--callback
 (lsp--read-json 
  " {\n  \"contents\": [\n    {\n      \"language\": \"java\",\n      \"value\": \"java.lang.String\"\n    },\n    \"The `String` class represents character strings. …\"\n  ]\n}")
 (cons (point-min) (point-max))

 (current-buffer))

Evaluating this from scratch buffer works fine in emacs -q.

cfraizer commented 4 years ago

After lots of painful searching, I found that the problem happens when I invoke (lsp-java-boot-lens-mode) in my java-mode-hook, but not otherwise. [I assume I added that when I first started trying to use lsp-mode and lsp-java.]

[I thought perhaps I was being hampered by using the pre-release emacs-28 I built, so I built emacs-27.1. Right after I did that, it became available as a pre-built binary through homebrew. D'oh!]

I'll probably try to track down what causes this to break with that mode, but you can certainly close this bug. Thank you for all your kind help.