@@ -6116,6 +6116,12 @@ WORKSPACE is the active workspace."
6116
6116
(let ((json-encoding-pretty-print t))
6117
6117
(json-encode (json-read-from-string msg))))
6118
6118
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
+
6119
6125
(defun lsp--create-filter-function (workspace)
6120
6126
"Make filter for the workspace."
6121
6127
(let ((body-received 0)
@@ -6154,22 +6160,22 @@ WORKSPACE is the active workspace."
6154
6160
(push this-body body)
6155
6161
(setf body-received (+ body-received body-bytes))
6156
6162
(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) ))))))))
6173
6179
6174
6180
(defvar-local lsp--line-col-to-point-hash-table nil
6175
6181
"Hash table with keys (line . col) and values that are either point positions or markers.")
@@ -6750,24 +6756,38 @@ SESSION is the active session."
6750
6756
(lsp--spinner-stop)
6751
6757
(signal 'lsp-empty-response-error (list "initialize")))
6752
6758
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))))
6771
6791
:mode 'detached))
6772
6792
workspace))
6773
6793
0 commit comments