Skip to content

Commit 0e9f57b

Browse files
npajkovskyNikola Pajkovsky
andauthored
lsp-javascript: fix inlay hints (#3957)
ts-ls has dropped experimental typescript/inlayHints and now uses textDocument/inlayHint. Response structure is also different. Result: [ { "position": { "line": 24, "character": 37 }, "label": ": Promise<void>", "kind": 1, "paddingLeft": true }, Close #3934 Link: https://github.com/typescript-language-server/typescript-language-server/blob/master/CHANGELOG.md#-breaking-changes Signed-off-by: Nikola Pajkovsky <nikola@enhance.com> Co-authored-by: Nikola Pajkovsky <nikola@enhance.com>
1 parent 03e1818 commit 0e9f57b

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

clients/lsp-javascript.el

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ name (e.g. `data' variable passed as `data' parameter)."
832832
(defun lsp-javascript--update-inlay-hints (start end)
833833
(if (lsp-javascript-initialized?)
834834
(lsp-request-async
835-
"typescript/inlayHints"
835+
"textDocument/inlayHint"
836836
(lsp-make-javascript-inlay-hints-params
837837
:text-document (lsp--text-document-identifier)
838838
:range (lsp-make-range :start
@@ -841,24 +841,18 @@ name (e.g. `data' variable passed as `data' parameter)."
841841
(lsp-point-to-position end)))
842842
(lambda (res)
843843
(lsp--remove-overlays 'lsp-javascript-inlay-hint)
844-
(let ((hints (lsp-get res :inlayHints)))
845-
(unless (seq-empty-p hints)
846-
(overlay-recenter
847-
(-let* (([hint] hints)
848-
((&javascript:InlayHint :position) hint))
849-
(lsp--position-to-point position))))
850-
(-each hints
851-
(lambda (hint)
852-
(-let* (((&javascript:InlayHint :text :position :kind :whitespace-before? :whitespace-after?) hint)
853-
(pos (lsp--position-to-point position))
854-
(overlay (make-overlay pos pos nil 'front-advance 'end-advance)))
855-
(overlay-put overlay 'lsp-javascript-inlay-hint t)
856-
(overlay-put overlay 'before-string
857-
(format "%s%s%s"
858-
(if (and whitespace-before? (not (string= kind lsp/javascript-inlay-hint-kind-type-hint))) " " "")
859-
(propertize (lsp-javascript-format-inlay text kind)
860-
'font-lock-face (lsp-javascript-face-for-inlay kind))
861-
(if whitespace-after? " " ""))))))))
844+
(dolist (hint res)
845+
(-let* (((&javascript:InlayHint :label :position :kind :padding-left? :padding-right?) hint)
846+
(pos (lsp--position-to-point position))
847+
(overlay (make-overlay pos pos nil 'front-advance 'end-advance)))
848+
(when (stringp label)
849+
(overlay-put overlay 'lsp-javascript-inlay-hint t)
850+
(overlay-put overlay 'before-string
851+
(format "%s%s%s"
852+
(if padding-left? " " "")
853+
(propertize (lsp-javascript-format-inlay label kind)
854+
'font-lock-face (lsp-javascript-face-for-inlay kind))
855+
(if padding-right? " " "")))))))
862856
:mode 'tick)))
863857

864858
(defun lsp-javascript-column-at-pos (pos)

lsp-protocol.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ See `-let' for a description of the destructuring mechanism."
435435
(defconst lsp/javascript-inlay-hint-kind-type-hint "Type")
436436
(defconst lsp/javascript-inlay-hint-kind-parameter-hint "Parameter")
437437
(defconst lsp/javascript-inlay-hint-kind-enum-hint "Enum")
438-
(lsp-interface (javascript:InlayHint (:text :position :kind) (:whitespaceBefore :whitespaceAfter))
438+
(lsp-interface (javascript:InlayHint (:label :position :kind) (:paddingLeft :paddingRight?))
439439
(javascript:InlayHintsParams (:textDocument) (:range)))
440440

441441
(lsp-interface (clojure-lsp:TestTreeParams (:uri :tree) nil)

0 commit comments

Comments
 (0)