Skip to content

Commit 0203136

Browse files
authored
Make sure that {} is presented when using plists (#2240)
- fixes #1807
1 parent b76b85e commit 0203136

File tree

1 file changed

+54
-34
lines changed

1 file changed

+54
-34
lines changed

lsp-mode.el

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6116,6 +6116,12 @@ WORKSPACE is the active workspace."
61166116
(let ((json-encoding-pretty-print t))
61176117
(json-encode (json-read-from-string msg))))
61186118

6119+
(defvar lsp-parsed-message nil
6120+
"This will store the string representation of the json message.
6121+
6122+
In some cases like #1807 we lose information during json
6123+
deserialization.")
6124+
61196125
(defun lsp--create-filter-function (workspace)
61206126
"Make filter for the workspace."
61216127
(let ((body-received 0)
@@ -6154,22 +6160,22 @@ WORKSPACE is the active workspace."
61546160
(push this-body body)
61556161
(setf body-received (+ body-received body-bytes))
61566162
(when (>= chunk-length left-to-receive)
6157-
(lsp--parser-on-message
6158-
(condition-case err
6159-
(let ((parsed-message (decode-coding-string
6160-
(apply #'concat
6161-
(nreverse
6162-
(prog1 body
6163-
(setf leftovers nil
6164-
body-length nil
6165-
body-received nil
6166-
body nil)))) 'utf-8)))
6167-
(lsp--read-json parsed-message))
6168-
(error
6169-
(lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwith message %s"
6170-
(concat leftovers input)
6171-
err)))
6172-
workspace))))))))
6163+
(let ((lsp-parsed-message (decode-coding-string
6164+
(apply #'concat
6165+
(nreverse
6166+
(prog1 body
6167+
(setf leftovers nil
6168+
body-length nil
6169+
body-received nil
6170+
body nil)))) 'utf-8)))
6171+
(lsp--parser-on-message
6172+
(condition-case err
6173+
(lsp--read-json lsp-parsed-message)
6174+
(error
6175+
(lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwith message %s"
6176+
(concat leftovers input)
6177+
err)))
6178+
workspace)))))))))
61736179

61746180
(defvar-local lsp--line-col-to-point-hash-table nil
61756181
"Hash table with keys (line . col) and values that are either point positions or markers.")
@@ -6750,24 +6756,38 @@ SESSION is the active session."
67506756
(lsp--spinner-stop)
67516757
(signal 'lsp-empty-response-error (list "initialize")))
67526758

6753-
(setf (lsp--workspace-server-capabilities workspace) (lsp:initialize-result-capabilities
6754-
response)
6755-
(lsp--workspace-status workspace) 'initialized)
6756-
6757-
(with-lsp-workspace workspace
6758-
(lsp-notify "initialized" lsp--empty-ht))
6759-
6760-
(when initialized-fn (funcall initialized-fn workspace))
6761-
6762-
(->> workspace
6763-
(lsp--workspace-buffers)
6764-
(mapc (lambda (buffer)
6765-
(lsp-with-current-buffer buffer
6766-
(lsp--open-in-workspace workspace)))))
6767-
6768-
(with-lsp-workspace workspace
6769-
(run-hooks 'lsp-after-initialize-hook))
6770-
(lsp--info "%s initialized successfully" (lsp--workspace-print workspace)))
6759+
(let* ((capabilities (lsp:initialize-result-capabilities response))
6760+
(json-object-type 'hash-table)
6761+
(text-document-sync (-some-> lsp-parsed-message
6762+
(json-read-from-string)
6763+
(ht-get "result")
6764+
(ht-get "capabilities")
6765+
(ht-get "textDocumentSync")))
6766+
(save (when (ht? text-document-sync)
6767+
(ht-get text-document-sync "save"))))
6768+
;; see #1807
6769+
(when (and (ht? save) (ht-empty? save))
6770+
(-> capabilities
6771+
(lsp:server-capabilities-text-document-sync?)
6772+
(lsp:set-text-document-sync-options-save? save)))
6773+
6774+
(setf (lsp--workspace-server-capabilities workspace) capabilities
6775+
(lsp--workspace-status workspace) 'initialized)
6776+
6777+
(with-lsp-workspace workspace
6778+
(lsp-notify "initialized" lsp--empty-ht))
6779+
6780+
(when initialized-fn (funcall initialized-fn workspace))
6781+
6782+
(->> workspace
6783+
(lsp--workspace-buffers)
6784+
(mapc (lambda (buffer)
6785+
(lsp-with-current-buffer buffer
6786+
(lsp--open-in-workspace workspace)))))
6787+
6788+
(with-lsp-workspace workspace
6789+
(run-hooks 'lsp-after-initialize-hook))
6790+
(lsp--info "%s initialized successfully" (lsp--workspace-print workspace))))
67716791
:mode 'detached))
67726792
workspace))
67736793

0 commit comments

Comments
 (0)