[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 3a6c637 099/139: Support textDocument/rename
From: |
João Távora |
Subject: |
[elpa] externals/eglot 3a6c637 099/139: Support textDocument/rename |
Date: |
Mon, 14 May 2018 09:55:01 -0400 (EDT) |
branch: externals/eglot
commit 3a6c63723370e71b992d21019fbf863d569d024a
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Support textDocument/rename
* README.md: Mention rename support.
* eglot.el (eglot--uri-to-path): Handle uri hidden in keywords.
(eglot--apply-text-edits): New helper.
(eglot-rename): New interactive command.
(eglot--client-capabilities): Add rename capability.
---
README.md | 2 +-
eglot.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5838bc5..a8d1c8b 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ server. To skip the guess and always be prompted use `C-u M-x
eglot`.
- [ ] textDocument/executeCommand
- [ ] textDocument/format
- [x] textDocument/hover
-- [ ] textDocument/rename
+- [x] textDocument/rename
- [x] textDocument/references
- [ ] textDocument/signatureHelp
- [x] workspace/symbol
diff --git a/eglot.el b/eglot.el
index c5c99f2..9ba87ef 100644
--- a/eglot.el
+++ b/eglot.el
@@ -199,6 +199,7 @@ CONTACT is as `eglot--contact'. Returns a process object."
:definition `(:dynamicRegistration :json-false)
:documentSymbol `(:dynamicRegistration :json-false)
:documentHighlight `(:dynamicRegistration :json-false)
+ :rename `(:dynamicRegistration :json-false)
:publishDiagnostics `(:relatedInformation :json-false))
:experimental (eglot--obj)))
@@ -729,6 +730,7 @@ Meaning only return locally if successful, otherwise exit
non-locally."
(defun eglot--uri-to-path (uri)
"Convert URI to a file path."
+ (when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
(url-filename (url-generic-parse-url (url-unhex-string uri))))
(defconst eglot--kind-names
@@ -1368,6 +1370,62 @@ DUMMY is ignored"
entries))
(funcall oldfun)))
+(defun eglot--apply-text-edits (uri edits proc &optional version)
+ "Apply the EDITS for buffer of URI and return it."
+ (let* ((path (eglot--uri-to-path uri))
+ (buffer (and path
+ (find-file-noselect path))))
+ (unless buffer
+ (eglot--error "Can't find `%s' to perform server edits"))
+ (with-current-buffer buffer
+ (unless (eq proc (eglot--current-process))
+ (eglot--error "Buffer `%s' for `%s' isn't managed by %s"
+ (current-buffer) uri proc))
+ (unless (or (not version)
+ (equal version eglot--versioned-identifier))
+ (eglot--error "Edits on `%s' require version %d, you have %d"
+ uri version eglot--versioned-identifier))
+ (eglot--mapply
+ (eglot--lambda (&key range newText)
+ (save-restriction
+ (widen)
+ (save-excursion
+ (let ((start (eglot--lsp-position-to-point (plist-get range
:start))))
+ (goto-char start)
+ (delete-region start
+ (eglot--lsp-position-to-point (plist-get range
:end)))
+ (insert newText)))))
+ edits)
+ (eglot--message "%s: %s edits" (current-buffer) (length edits)))
+ buffer))
+
+(defun eglot-rename (newname)
+ "Rename the current symbol to NEWNAME."
+ (interactive
+ (list
+ (read-from-minibuffer (format "Rename `%s' to: " (symbol-at-point)))))
+ (unless (eglot--server-capable :renameProvider)
+ (eglot--error "Server can't rename!"))
+ (let* ((proc (eglot--current-process-or-lose))
+ (workspace-edit
+ (eglot--sync-request proc
+ :textDocument/rename
+ (append
+
(eglot--current-buffer-TextDocumentPositionParams)
+ (eglot--obj :newName newname))))
+ performed)
+ (cl-destructuring-bind (&key changes documentChanges)
+ workspace-edit
+ (cl-loop for change on documentChanges
+ do (push
+ (cl-destructuring-bind (&key textDocument edits) change
+ (cl-destructuring-bind (&key uri version) textDocument
+ (eglot--apply-text-edits uri edits proc version)))
+ performed))
+ (cl-loop for (uri edits) on changes by #'cddr
+ do (push (eglot--apply-text-edits uri edits proc)
+ performed)))))
+
;;; Dynamic registration
;;;
- [elpa] externals/eglot 37b7329 098/139: Reasonable textDocument/documentHighlight support, (continued)
- [elpa] externals/eglot 37b7329 098/139: Reasonable textDocument/documentHighlight support, João Távora, 2018/05/14
- [elpa] externals/eglot d1cdcf1 119/139: Friendlier M-x eglot, João Távora, 2018/05/14
- [elpa] externals/eglot 764347d 128/139: New command eglot-help-at-point and a README update, João Távora, 2018/05/14
- [elpa] externals/eglot 9bf3166 136/139: Don't define a menu if nothing to show there for now, João Távora, 2018/05/14
- [elpa] externals/eglot 54fc885 113/139: More RLS-specifics: update Flymake diags when indexing done, João Távora, 2018/05/14
- [elpa] externals/eglot 56c2e1d 104/139: Get rid of eglot-mode, João Távora, 2018/05/14
- [elpa] externals/eglot 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, João Távora, 2018/05/14
- [elpa] externals/eglot d33a9b5 103/139: Simplify eglot--signal-textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/eglot ef80455 121/139: Support :completionItem/resolve, João Távora, 2018/05/14
- [elpa] externals/eglot f89f859 114/139: Simplify mode-line updating logic, João Távora, 2018/05/14
- [elpa] externals/eglot 3a6c637 099/139: Support textDocument/rename,
João Távora <=
- [elpa] externals/eglot 581608f 115/139: Resist server failure during synchronous requests, João Távora, 2018/05/14
- [elpa] externals/eglot 56cf02d 126/139: Rework autoreconnection logic, João Távora, 2018/05/14
- [elpa] externals/eglot 4c0bfc3 139/139: Support didChangeWatchedFiles with dynamic registration, João Távora, 2018/05/14
- [elpa] externals/eglot 42177d0 107/139: New "deferred requests" that wait until server is ready, João Távora, 2018/05/14
- [elpa] externals/eglot 29f6b4c 129/139: Tweak README.md, João Távora, 2018/05/14
- [elpa] externals/eglot 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/eglot e63dad0 092/139: Simplify mode-line code with a helper., João Távora, 2018/05/14
- [elpa] externals/eglot ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/eglot 41f5922 137/139: Now send willSaveWaitUntil, João Távora, 2018/05/14
- [elpa] externals/eglot 458bc69 110/139: More correctly setup rust-mode-related autoloads, João Távora, 2018/05/14