Skip to content

Commit 0332f15

Browse files
Add support for "Move to file" interactive code action (#4866)
* lsp-javascript: add support for "Move to file" code action * Use lsp-get and lsp-put Co-authored-by: Danny Zhu <[email protected]> --------- Co-authored-by: Danny Zhu <[email protected]>
1 parent e8bf2e8 commit 0332f15

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clients/lsp-javascript.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,15 @@ to run the command in."
824824
(lsp-clients-typescript-require-resolve (f-parent (lsp-package-path 'typescript)))
825825
(lsp-package-path 'typescript))))
826826

827+
(lsp-defun lsp-clients-typescript-handle-interactive-actions ((&Command :arguments? [args]))
828+
(pcase (lsp-get args :action)
829+
("Move to file"
830+
(let* ((directory (file-name-directory (buffer-file-name)))
831+
(target-file-name (expand-file-name (read-file-name "Destination file: " directory))))
832+
(lsp-put args
833+
:interactiveRefactorArguments
834+
`((targetFile . ,target-file-name)))))))
835+
827836
(lsp-register-client
828837
(make-lsp-client :new-connection (lsp-stdio-connection (lambda ()
829838
`(,(lsp-package-path 'typescript-language-server)
@@ -845,6 +854,7 @@ to run the command in."
845854
(list :plugins lsp-clients-typescript-plugins))
846855
(when lsp-clients-typescript-preferences
847856
(list :preferences lsp-clients-typescript-preferences))
857+
(list :supportsMoveToFileCodeAction t)
848858
`(:tsserver ( :path ,(lsp-clients-typescript-server-path)
849859
,@lsp-clients-typescript-tsserver))))
850860
:initialized-fn (lambda (workspace)
@@ -858,6 +868,7 @@ to run the command in."
858868
(format-enable (or lsp-javascript-format-enable lsp-typescript-format-enable)))
859869
(lsp:set-server-capabilities-document-formatting-provider? caps format-enable)
860870
(lsp:set-server-capabilities-document-range-formatting-provider? caps format-enable)))
871+
:action-filter 'lsp-clients-typescript-handle-interactive-actions
861872
:ignore-messages '("readFile .*? requested by TypeScript but content not available")
862873
:server-id 'ts-ls
863874
:request-handlers (ht ("_typescript.rename" #'lsp-javascript--rename))

0 commit comments

Comments
 (0)