From 1024f376911ce53459bc6486aee23173a711eec0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 21 Jan 2024 16:50:34 -0500 Subject: [PATCH] Enable inlay hints for typescript. --- .../emacs/files/elisp/lang-javascript.el | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/ansible/roles/emacs/files/elisp/lang-javascript.el b/ansible/roles/emacs/files/elisp/lang-javascript.el index 33deb03..310daee 100644 --- a/ansible/roles/emacs/files/elisp/lang-javascript.el +++ b/ansible/roles/emacs/files/elisp/lang-javascript.el @@ -23,6 +23,52 @@ (run-command-on-buffer "jq" "--monochrome-output" ".") ) +(defun configure-typescript-language-server () + "Configures the typescript language server." + (when-linux + ;; Either initializationOptions or workspace/didChangeConfiguration works. + (setq eglot-workspace-configuration + (list (cons ':typescript '(:inlayHints (:includeInlayParameterNameHints + "all" + :includeInlayParameterNameHintsWhenArgumentMatchesName + t + :includeInlayFunctionParameterTypeHints + t + :includeInlayVariableTypeHints + t + :includeInlayVariableTypeHintsWhenTypeMatchesName + t + :includeInlayPRopertyDeclarationTypeHints + t + :includeInlayFunctionLikeReturnTypeHints + t + :includeInlayEnumMemberValueHints + t))))) + (eglot-ensure) + ;; (defclass my/eglot-typescript (eglot-lsp-server) () + ;; :documentation + ;; "Own eglot server class.") + + ;; (add-to-list 'eglot-server-programs + ;; '((js-mode js-ts-mode tsx-ts-mode typescript-ts-mode typescript-mode) . (my/eglot-typescript "typescript-language-server" "--stdio" :initializationOptions (:preferences (:includeInlayParameterNameHints + ;; "all" + ;; :includeInlayParameterNameHintsWhenArgumentMatchesName + ;; t + ;; :includeInlayFunctionParameterTypeHints + ;; t + ;; :includeInlayVariableTypeHints + ;; t + ;; :includeInlayVariableTypeHintsWhenTypeMatchesName + ;; t + ;; :includeInlayPRopertyDeclarationTypeHints + ;; t + ;; :includeInlayFunctionLikeReturnTypeHints + ;; t + ;; :includeInlayEnumMemberValueHints + ;; t))))) + ) + ) + (use-package tsx-ts-mode :ensure nil :pin manual @@ -33,7 +79,7 @@ :hook ( (tsx-ts-mode . (lambda () (when-linux - (eglot-ensure) + (configure-typescript-language-server) ) )) ) @@ -52,9 +98,7 @@ :commands (typescript-ts-mode) :hook ( (typescript-ts-mode . (lambda () - (when-linux - (eglot-ensure) - ) + (configure-typescript-language-server) )) ) :init