From 9eb332486eea74daf6cbb4be20ea462a8208fc4c Mon Sep 17 00:00:00 2001 From: Ivan Yonchovski Date: Sat, 18 Jul 2020 12:53:06 +0300 Subject: [PATCH] [Rust-Analyzer] Support SnippetTextEdit (#1926) Fixes #1907 --- lsp-mode.el | 9 ++++++++- lsp-protocol.el | 1 + lsp-rust.el | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index 9a5acc6b726..67272210792 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -4225,7 +4225,14 @@ The method uses `replace-buffer-contents'." (seq-sort #'lsp--text-edit-sort-predicate) (mapc (lambda (edit) (progress-reporter-update reporter (cl-incf done)) - (funcall apply-edit edit)))) + (funcall apply-edit edit) + (when (lsp-snippet-text-edit? edit) + (-when-let ((&SnippetTextEdit :range (&RangeToPoint :start) + :insert-text-format? :new-text) edit) + (when (eq insert-text-format? lsp/insert-text-format-snippet) + (let (yas-indent-line) + (yas-expand-snippet (lsp--to-yasnippet-snippet new-text) + start (+ start (length new-text)))))))))) (when (fboundp 'undo-amalgamate-change-group) (with-no-warnings (undo-amalgamate-change-group change-group))) (progress-reporter-done reporter)))))) diff --git a/lsp-protocol.el b/lsp-protocol.el index 47f2a12affd..2db6ff9fabf 100644 --- a/lsp-protocol.el +++ b/lsp-protocol.el @@ -475,6 +475,7 @@ See `-let' for a description of the destructuring mechanism." (TextDocumentItem (:languageId :text :uri :version) nil) (TextDocumentSyncOptions nil (:change :openClose :save :willSave :willSaveWaitUntil)) (TextEdit (:newText :range) nil) + (SnippetTextEdit (:newText :range) (:insertTextFormat)) (TypeDefinitionCapabilities nil (:dynamicRegistration :linkSupport)) (TypeHierarchyCapabilities nil (:dynamicRegistration)) (TypeHierarchyItem (:kind :name :range :selectionRange :uri) (:children :data :deprecated :detail :parents)) diff --git a/lsp-rust.el b/lsp-rust.el index 6c6cf13fe43..ab00e8b3850 100644 --- a/lsp-rust.el +++ b/lsp-rust.el @@ -568,7 +568,8 @@ The command should include `--message=format=json` or similar option." (when lsp-rust-analyzer-server-display-inlay-hints (lsp-rust-analyzer-inlay-hints-mode))) :ignore-messages nil - :server-id 'rust-analyzer)) + :server-id 'rust-analyzer + :custom-capabilities '((experimental . ((snippetTextEdit . ,lsp-enable-snippet )))))) (defun lsp-rust-switch-server (&optional lsp-server) "Switch priorities of lsp servers, unless LSP-SERVER is already active."