From 94e3fcfc4cd6ec1d45b9cdcc754c6b237b3eb06e Mon Sep 17 00:00:00 2001 From: Guillaume Brunerie Date: Sun, 31 Aug 2025 00:54:42 +0200 Subject: [PATCH 1/2] lsp-javascript: add support for "Move to file" code action --- clients/lsp-javascript.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clients/lsp-javascript.el b/clients/lsp-javascript.el index b6a94f4dcc..c0fd861c9c 100644 --- a/clients/lsp-javascript.el +++ b/clients/lsp-javascript.el @@ -824,6 +824,15 @@ to run the command in." (lsp-clients-typescript-require-resolve (f-parent (lsp-package-path 'typescript))) (lsp-package-path 'typescript)))) +(lsp-defun lsp-clients-typescript-handle-interactive-actions ((&Command :arguments? [args])) + (pcase (gethash "action" args) + ("Move to file" + (let* ((directory (file-name-directory (buffer-file-name))) + (target-file-name (expand-file-name (read-file-name "Destination file: " directory)))) + (puthash "interactiveRefactorArguments" + `((targetFile . ,target-file-name)) + args))))) + (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection (lambda () `(,(lsp-package-path 'typescript-language-server) @@ -845,6 +854,7 @@ to run the command in." (list :plugins lsp-clients-typescript-plugins)) (when lsp-clients-typescript-preferences (list :preferences lsp-clients-typescript-preferences)) + (list :supportsMoveToFileCodeAction t) `(:tsserver ( :path ,(lsp-clients-typescript-server-path) ,@lsp-clients-typescript-tsserver)))) :initialized-fn (lambda (workspace) @@ -858,6 +868,7 @@ to run the command in." (format-enable (or lsp-javascript-format-enable lsp-typescript-format-enable))) (lsp:set-server-capabilities-document-formatting-provider? caps format-enable) (lsp:set-server-capabilities-document-range-formatting-provider? caps format-enable))) + :action-filter 'lsp-clients-typescript-handle-interactive-actions :ignore-messages '("readFile .*? requested by TypeScript but content not available") :server-id 'ts-ls :request-handlers (ht ("_typescript.rename" #'lsp-javascript--rename)) From bf0c6bb7450ac462ebb50d07d51bae8a584c26f2 Mon Sep 17 00:00:00 2001 From: Guillaume Brunerie Date: Thu, 18 Sep 2025 21:46:12 +0200 Subject: [PATCH 2/2] Use lsp-get and lsp-put Co-authored-by: Danny Zhu --- clients/lsp-javascript.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/lsp-javascript.el b/clients/lsp-javascript.el index c0fd861c9c..2d90b8979e 100644 --- a/clients/lsp-javascript.el +++ b/clients/lsp-javascript.el @@ -825,13 +825,13 @@ to run the command in." (lsp-package-path 'typescript)))) (lsp-defun lsp-clients-typescript-handle-interactive-actions ((&Command :arguments? [args])) - (pcase (gethash "action" args) + (pcase (lsp-get args :action) ("Move to file" (let* ((directory (file-name-directory (buffer-file-name))) (target-file-name (expand-file-name (read-file-name "Destination file: " directory)))) - (puthash "interactiveRefactorArguments" - `((targetFile . ,target-file-name)) - args))))) + (lsp-put args + :interactiveRefactorArguments + `((targetFile . ,target-file-name))))))) (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection (lambda ()