Skip to content

Commit 9eb3324

Browse files
authored
[Rust-Analyzer] Support SnippetTextEdit (#1926)
Fixes #1907
1 parent fa7ca1f commit 9eb3324

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lsp-mode.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4225,7 +4225,14 @@ The method uses `replace-buffer-contents'."
42254225
(seq-sort #'lsp--text-edit-sort-predicate)
42264226
(mapc (lambda (edit)
42274227
(progress-reporter-update reporter (cl-incf done))
4228-
(funcall apply-edit edit))))
4228+
(funcall apply-edit edit)
4229+
(when (lsp-snippet-text-edit? edit)
4230+
(-when-let ((&SnippetTextEdit :range (&RangeToPoint :start)
4231+
:insert-text-format? :new-text) edit)
4232+
(when (eq insert-text-format? lsp/insert-text-format-snippet)
4233+
(let (yas-indent-line)
4234+
(yas-expand-snippet (lsp--to-yasnippet-snippet new-text)
4235+
start (+ start (length new-text))))))))))
42294236
(when (fboundp 'undo-amalgamate-change-group)
42304237
(with-no-warnings (undo-amalgamate-change-group change-group)))
42314238
(progress-reporter-done reporter))))))

lsp-protocol.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ See `-let' for a description of the destructuring mechanism."
475475
(TextDocumentItem (:languageId :text :uri :version) nil)
476476
(TextDocumentSyncOptions nil (:change :openClose :save :willSave :willSaveWaitUntil))
477477
(TextEdit (:newText :range) nil)
478+
(SnippetTextEdit (:newText :range) (:insertTextFormat))
478479
(TypeDefinitionCapabilities nil (:dynamicRegistration :linkSupport))
479480
(TypeHierarchyCapabilities nil (:dynamicRegistration))
480481
(TypeHierarchyItem (:kind :name :range :selectionRange :uri) (:children :data :deprecated :detail :parents))

lsp-rust.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ The command should include `--message=format=json` or similar option."
568568
(when lsp-rust-analyzer-server-display-inlay-hints
569569
(lsp-rust-analyzer-inlay-hints-mode)))
570570
:ignore-messages nil
571-
:server-id 'rust-analyzer))
571+
:server-id 'rust-analyzer
572+
:custom-capabilities '((experimental . ((snippetTextEdit . ,lsp-enable-snippet ))))))
572573

573574
(defun lsp-rust-switch-server (&optional lsp-server)
574575
"Switch priorities of lsp servers, unless LSP-SERVER is already active."

0 commit comments

Comments
 (0)