Skip to content

Commit

Permalink
[Rust-Analyzer] Support SnippetTextEdit (#1926)
Browse files Browse the repository at this point in the history
Fixes #1907
  • Loading branch information
yyoncho authored Jul 18, 2020
1 parent fa7ca1f commit 9eb3324
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand Down
1 change: 1 addition & 0 deletions lsp-protocol.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion lsp-rust.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 9eb3324

Please sign in to comment.