Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve emacs support #353

Merged
merged 7 commits into from
Jun 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plugin/emacs: add LSP Mode support
Signed-off-by: wagner riffel <[email protected]>
wgrr committed Jun 13, 2021
commit 88874b305e7bfc40a3bc48aad4153e639de589fd
1 change: 1 addition & 0 deletions plugin/emacs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ include(GNUInstallDirs)

install(
FILES flycheck-quicklintjs.el
FILES lsp-quicklintjs.el
FILES eglot-quicklintjs.el
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp"
)
63 changes: 63 additions & 0 deletions plugin/emacs/lsp-quicklintjs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
;;; lsp-quicklintjs --- LSP support for quick-lint-js -*- lexical-binding: t; -*-

;;; Commentary:

;; LSP Mode support for quick-lint-js.

;; Example usage in your init.el:
;;
;; (require 'lsp-quicklintjs)
;;
;; (defun my-lsp-quicklintjs-setup ()
;; "Configure lsp-quicklintjs for better experience."
;; ;; Remove the time to wait after last change before automatically checking
;; ;; buffer. The default is 0.5 (500ms)
;; (setq-local lsp-idle-delay 0))
;; (add-hook 'js-mode-hook #'my-lsp-quicklintjs-setup)

;;; Code:

(require 'lsp-mode)

(defgroup lsp-quicklintjs nil
"quick-lint-js LSP Mode integration."
:link '(url-link :tag "Website" "https://quick-lint-js.com"))

(defcustom lsp-quicklintjs-program "quick-lint-js"
"Path to quick-lint-js program to run."
:group 'lsp-quicklintjs
:type 'stringp)

(defcustom lsp-quicklintjs-args nil
"Arguments to quick-lint-js."
:group 'lsp-quicklintjs
:type '(repeat string))

(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection `(,lsp-quicklintjs-program "--lsp-server"
,@lsp-quicklintjs-args))
:major-modes '(js-mode)
:server-id 'quick-lint-js))

(provide 'lsp-quicklintjs)

;; quick-lint-js finds bugs in JavaScript programs.
;; Copyright (C) 2020 Matthew Glazar
;;
;; This file is part of quick-lint-js.
;;
;; quick-lint-js is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; quick-lint-js is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

;;; lsp-quicklintjs.el ends here
9 changes: 8 additions & 1 deletion plugin/emacs/test/quicklintjs-test.el
Original file line number Diff line number Diff line change
@@ -26,10 +26,11 @@
(package-refresh-contents))

(quicklintjs-install-deps (if (>= emacs-major-version 26)
'(flycheck eglot)
'(flycheck eglot lsp-mode)
'(flycheck)))
(def-flycheck-tests)
(def-eglot-tests)
(def-lsp-tests)
(ert-run-tests-batch-and-exit))

(defun def-eglot-tests ()
@@ -38,6 +39,12 @@
(ert-deftest quicklintjs-is-in-eglot-servers ()
(should (member '(js-mode "quick-lint-js" "--lsp") eglot-server-programs)))))

(defun def-lsp-tests ()
(when (>= emacs-major-version 26)
(require 'lsp-quicklintjs)
(ert-deftest quicklintjs-is-in-lsp-clients ()
(should (gethash 'quick-lint-js lsp-clients)))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Collapse interior whitespace?

Suggested change
(should (gethash 'quick-lint-js lsp-clients)))))
(should (gethash 'quick-lint-js lsp-clients)))))


(defun def-flycheck-tests ()
(require 'flycheck)
(require 'flycheck-ert)