[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot a9010f1 01/12: Implement formatting (#19)
From: |
João Távora |
Subject: |
[elpa] externals/eglot a9010f1 01/12: Implement formatting (#19) |
Date: |
Fri, 22 Jun 2018 11:52:15 -0400 (EDT) |
branch: externals/eglot
commit a9010f1924fa31f686824585cbcf5057c8892afc
Author: mkcms <address@hidden>
Commit: João Távora <address@hidden>
Implement formatting (#19)
Implement textDocument/formatting
* eglot.el (eglot-format-buffer): New command to format
current buffer.
* eglot-tests.el (formatting): New test.
---
eglot-tests.el | 20 ++++++++++++++++++++
eglot.el | 29 +++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/eglot-tests.el b/eglot-tests.el
index 1a25371..602606c 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -375,6 +375,26 @@ Pass TIMEOUT to `eglot--with-timeout'."
(while (not eldoc-last-message) (accept-process-output nil 0.1))
(should (string-match "^exit" eldoc-last-message))))))
+(ert-deftest formatting ()
+ "Test document formatting in a python LSP"
+ (skip-unless (and (executable-find "pyls")
+ (or (executable-find "yapf")
+ (executable-find "autopep8"))))
+ (eglot--with-dirs-and-files
+ '(("project" . (("something.py" . "def foo():pass"))))
+ (eglot--with-timeout 4
+ (with-current-buffer
+ (eglot--find-file-noselect "project/something.py")
+ (should (eglot--tests-connect))
+ (search-forward ":")
+ (eglot-format-buffer)
+ (should (looking-at "pass"))
+ (should (or
+ ;; yapf
+ (string= (buffer-string) "def foo():\n pass\n")
+ ;; autopep8
+ (string= (buffer-string) "def foo(): pass\n")))))))
+
(ert-deftest javascript-basic ()
"Test basic autocompletion in a python LSP"
(skip-unless (executable-find "~/.yarn/bin/javascript-typescript-stdio"))
diff --git a/eglot.el b/eglot.el
index ecfde4a..98802de 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1382,6 +1382,35 @@ DUMMY is ignored."
:workspace/symbol
(list :query pattern)))))
+(defun eglot-format-buffer ()
+ "Format contents of current buffer."
+ (interactive)
+ (unless (eglot--server-capable :documentFormattingProvider)
+ (eglot--error "Server can't format!"))
+ (let* ((server (eglot--current-server-or-lose))
+ (resp
+ (eglot--request
+ server
+ :textDocument/formatting
+ (list :textDocument (eglot--TextDocumentIdentifier)
+ :options (list
+ :tabSize tab-width
+ :insertSpaces (not indent-tabs-mode)))
+ :textDocument/formatting))
+ (before-point
+ (buffer-substring (max (- (point) 60) (point-min)) (point)))
+ (after-point
+ (buffer-substring (point) (min (+ (point) 60) (point-max))))
+ (regexp (and (not (bobp))
+ (replace-regexp-in-string
+ "[\s\t\n\r]+" "[\s\t\n\r]+"
+ (concat "\\(" (regexp-quote after-point) "\\)")))))
+ (when resp
+ (save-excursion
+ (eglot--apply-text-edits resp))
+ (when (and (bobp) regexp (search-forward-regexp regexp nil t))
+ (goto-char (match-beginning 1))))))
+
(defun eglot-completion-at-point ()
"EGLOT's `completion-at-point' function."
(let ((bounds (bounds-of-thing-at-point 'symbol))
- [elpa] externals/eglot updated (a1f1dd6 -> 0176264), João Távora, 2018/06/22
- [elpa] externals/eglot 04ef055 11/12: Close #27: empty ranges are valid in LSP, João Távora, 2018/06/22
- [elpa] externals/eglot 0176264 12/12: * eglot.el (Version): Bump to 0.11, João Távora, 2018/06/22
- [elpa] externals/eglot 610d95b 03/12: Use gfm-mode for formatted strings (#20), João Távora, 2018/06/22
- [elpa] externals/eglot 0cde01f 05/12: Close #26: Guess server for js2-mode and rjsx-mode, João Távora, 2018/06/22
- [elpa] externals/eglot 364348d 04/12: Close #25: Improve eglot-ensure and mention it in README.md, João Távora, 2018/06/22
- [elpa] externals/eglot efc0f45 02/12: Minor cleanup to new textDocument/formatting feature, João Távora, 2018/06/22
- [elpa] externals/eglot a9010f1 01/12: Implement formatting (#19),
João Távora <=
- [elpa] externals/eglot 17ef74e 07/12: Defer textDocument/formatting requests, João Távora, 2018/06/22
- [elpa] externals/eglot 0b9cffe 08/12: Per #22: Apply text edits atomically, João Távora, 2018/06/22
- [elpa] externals/eglot 48c3f45 10/12: Close #22: Apply text edits as a single undoable edit, João Távora, 2018/06/22
- [elpa] externals/eglot cbc418c 06/12: Per #22: Simplify eglot-format-buffer, João Távora, 2018/06/22
- [elpa] externals/eglot df5e72e 09/12: Close #23: Report progress when applying edits, João Távora, 2018/06/22