From d63f7899dc975d2c9cb398d5bca44bafd0f6c1ba Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Thu, 21 Jul 2022 00:11:21 +0900 Subject: [PATCH 01/10] replace lsp-mode with lsp-bridge --- modules/fate-company.el | 1 + modules/fate-lsp.el | 119 ++-------------------------------------- 2 files changed, 5 insertions(+), 115 deletions(-) diff --git a/modules/fate-company.el b/modules/fate-company.el index 4a5e90d..c86da10 100644 --- a/modules/fate-company.el +++ b/modules/fate-company.el @@ -25,6 +25,7 @@ ;;; Code: (use-package company + :disabled :hook (after-init . global-company-mode) :bind diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index 8392e1e..18bffe2 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -29,121 +29,10 @@ (require 'fate-flycheck)) -(defun fate-lsp-setup-python () - "Microsoft Python Language Server does not have a syntax checker, setup one for it." - (progn - (require 'lsp-python-ms) - (fate-lsp-deferred) - ;; https://github.com/flycheck/flycheck/issues/1762#issuecomment-626210720 - ;; Do not let lsp hijack flycheck - (setq-local lsp-diagnostics-provider :none) - (setq-local flycheck-checker 'python-flake8))) - -(defun fate-lsp-deferred () - "Defer start of lsp and exclude lsp in specific folders." - (when (and (stringp buffer-file-name) - (not (string-match-p "node_modules" buffer-file-name)) - (not (string-match-p "\\\/run" buffer-file-name))) - (lsp-deferred))) - -(defun fate-lsp-setup-go () - "Use gopls for format and import sorting." - (progn - (require 'lsp) - (fate-lsp-deferred) - (add-hook 'before-save-hook #'lsp-format-buffer nil t) - (add-hook 'before-save-hook #'lsp-organize-imports nil t) - (setq lsp-go-use-gofumpt t))) - -(defun fate-lsp-setup-js () - "Do not start lsp when major mode is qml which derives from `js-mode'." - (unless (member major-mode '(qml-mode)) - (fate-lsp-deferred))) - -(use-package lsp-python-ms - :defer t - :custom - (lsp-python-ms-cache-dir (concat fate-cache-directory ".lsp-python"))) - -(use-package lsp-mode - :diminish lsp-mode - :commands (lsp lsp-deferred) - :hook - ((python-mode . fate-lsp-setup-python) - (go-mode . fate-lsp-setup-go) - (js-mode . fate-lsp-setup-js) - ((sh-mode c-mode c++-mode - html-mode web-mode json-mode - css-mode less-mode sass-mode scss-mode - js2-mode typescript-mode rust-mode - groovy-mode graphql-mode) . fate-lsp-deferred) - (lsp-mode . lsp-headerline-breadcrumb-mode)) - :init - ;; Increase the amount of data which Emacs reads from the process 1mb - ;; default is 4k while some of the language server responses are in 800k - 3M range - (setq read-process-output-max (* 1024 1024)) - (with-eval-after-load 'hydra - (defhydra hydra-lsp (:exit t :hint nil) - " - Buffer^^ Server^^ Symbol -------------------------------------------------------------------------------------- - [_f_] format [_M-r_] restart [_d_] declaration [_i_] implementation [_o_] documentation - [_m_] imenu [_S_] shutdown [_D_] definition [_t_] type [_r_] rename - [_x_] execute action [_M-s_] describe session [_R_] references [_s_] signature" - ("d" lsp-find-declaration) - ("D" lsp-ui-peek-find-definitions) - ("R" lsp-ui-peek-find-references) - ("i" lsp-ui-peek-find-implementation) - ("t" lsp-find-type-definition) - ("s" lsp-signature-help) - ("o" lsp-describe-thing-at-point) - ("r" lsp-rename) - - ("f" lsp-format-buffer) - ("m" lsp-ui-imenu) - ("x" lsp-execute-code-action) - - ("M-s" lsp-describe-session) - ("M-r" lsp-restart-workspace) - ("S" lsp-shutdown-workspace))) - (defun fate-lsp-graphql-activate-p (filename &optional _) - (derived-mode-p 'graphql-mode)) - (advice-add 'lsp-graphql-activate-p :override #'fate-lsp-graphql-activate-p) - :config - ;; same definition as mentioned earlier - (advice-add 'json-parse-string :around - (lambda (orig string &rest rest) - (apply orig (s-replace "\\u0000" "" string) - rest))) - - ;; minor changes: saves excursion and uses search-forward instead of re-search-forward - (advice-add 'json-parse-buffer :around - (lambda (oldfn &rest args) - (save-excursion - (while (search-forward "\\u0000" nil t) - (replace-match "" nil t))) - (apply oldfn args))) - :custom - (lsp-enable-snippet nil "not yet configured") - (lsp-headerline-breadcrumb-segments '(file symbols)) - (lsp-clients-typescript-init-opts '(importModuleSpecifierPreference "relative")) - (lsp-keep-workspace-alive nil "close session when project is closed")) - -(use-package lsp-ui - :defer t - :bind - (:map lsp-ui-mode-map - ([remap xref-find-definitions] . lsp-ui-peek-find-definitions) - ([remap xref-find-references] . lsp-ui-peek-find-references) - ("C-c u" . lsp-ui-imenu)) - :custom - (lsp-ui-sideline-enable nil "Hide sideline") - (lsp-ui-doc-enable nil "Disable lsp doc for now as size is not property handled ") - (lsp-ui-peek-always-show t "Show peek even only one matching")) - -(use-package lsp-treemacs - :after lsp - :commands lsp-treemacs-errors-list) +(use-package lsp-bridge + :straight (:host github + :repo "manateelazycat/lsp-bridge" + :files ("*" (:exclude ".git")))) (provide 'fate-lsp) ;;; fate-lsp.el ends here From 7804d0b8da91ea64758ceea801ca7a4e7721aa1a Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Sun, 7 Aug 2022 21:26:13 +0900 Subject: [PATCH 02/10] enable lsp bridge by default --- modules/fate-lsp.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index 18bffe2..a81b1c3 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -32,7 +32,8 @@ (use-package lsp-bridge :straight (:host github :repo "manateelazycat/lsp-bridge" - :files ("*" (:exclude ".git")))) + :files ("*" (:exclude ".git"))) + :hook (after-init. global-lsp-bridge-mode)) (provide 'fate-lsp) ;;; fate-lsp.el ends here From ec77789810083cdbd074c2f283bdb61cc4f44b7f Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Thu, 11 Aug 2022 11:18:04 +0900 Subject: [PATCH 03/10] fix typo --- modules/fate-lsp.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index a81b1c3..fe01efd 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -33,7 +33,7 @@ :straight (:host github :repo "manateelazycat/lsp-bridge" :files ("*" (:exclude ".git"))) - :hook (after-init. global-lsp-bridge-mode)) + :hook (after-init . global-lsp-bridge-mode)) (provide 'fate-lsp) ;;; fate-lsp.el ends here From 15aefd6ae7138ac785495d4763087818899081ec Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Thu, 18 Aug 2022 10:08:06 +0900 Subject: [PATCH 04/10] hook up hydra for lsp bridge --- modules/fate-lsp.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index fe01efd..79b6bdf 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -33,7 +33,30 @@ :straight (:host github :repo "manateelazycat/lsp-bridge" :files ("*" (:exclude ".git"))) - :hook (after-init . global-lsp-bridge-mode)) + :hook (after-init . global-lsp-bridge-mode) + :custom + (lsp-bridge-signature-function 'eldoc-message) + :bind + (:map lsp-bridge-mode-map + ([remap xref-find-definitions] . lsp-bridge-find-def) + ([remap xref-find-references] . lsp-bridge-find-references)) + :init + (with-eval-after-load 'hydra + (defhydra hydra-lsp (:exit t :hint nil) + " + Action^^ Documentation^^ Server +------------------------------------------------------------------------------------- + [_f_] format [_i_] implementation [_M-r_] restart + [_x_] execute action [_D_] definition [_o_] documentation + [_r_] rename [_R_] references" + ("D" lsp-bridge-find-def) + ("R" lsp-bridge-find-references) + ("i" lsp-bridge-find-impl) + ("o" lsp-bridge-lookup-documentation) + ("r" lsp-bridge-rename) + ("f" lsp-bridge-code-format) + ("x" lsp-bridge-code-action) + ("M-r" lsp-bridge-restart-process)))) (provide 'fate-lsp) ;;; fate-lsp.el ends here From d6305ff526bf1ce6326a92a824280d9e77e47154 Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Mon, 20 Mar 2023 19:15:57 +0900 Subject: [PATCH 05/10] remap view hello-file to popup documentation --- modules/fate-lsp.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index 79b6bdf..18be47d 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -36,10 +36,12 @@ :hook (after-init . global-lsp-bridge-mode) :custom (lsp-bridge-signature-function 'eldoc-message) + (acm-markdown-render-font-height 80) :bind (:map lsp-bridge-mode-map ([remap xref-find-definitions] . lsp-bridge-find-def) - ([remap xref-find-references] . lsp-bridge-find-references)) + ([remap xref-find-references] . lsp-bridge-find-references) + ([remap view-hello-file] . lsp-bridge-popup-documentation)) :init (with-eval-after-load 'hydra (defhydra hydra-lsp (:exit t :hint nil) From 4574d871c49601161102a2acda1bcc48e5b2abb9 Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Mon, 3 Apr 2023 23:29:57 +0900 Subject: [PATCH 06/10] fix custom template --- core/fate-custom-template.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/fate-custom-template.el b/core/fate-custom-template.el index c66b0ac..4ab4d1d 100644 --- a/core/fate-custom-template.el +++ b/core/fate-custom-template.el @@ -34,4 +34,5 @@ ;;; Forge ;; (setq fate/forge-alist '(("git.site.com" "git.site.com/api/v4" "ssh://git@git.site.com" forge-github-repository))) -;;; fate-custom.el ends here +(provide 'custom) +;;; custom.el ends here From 5affb549692c6fafd9a0eb7c790755b591576025 Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Tue, 11 Apr 2023 09:23:50 +0900 Subject: [PATCH 07/10] add lsp diagnostic to hydra --- modules/fate-lsp.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index 18be47d..e7e57c1 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -50,7 +50,7 @@ ------------------------------------------------------------------------------------- [_f_] format [_i_] implementation [_M-r_] restart [_x_] execute action [_D_] definition [_o_] documentation - [_r_] rename [_R_] references" + [_r_] rename [_R_] references [_d_] diagnostic" ("D" lsp-bridge-find-def) ("R" lsp-bridge-find-references) ("i" lsp-bridge-find-impl) @@ -58,6 +58,7 @@ ("r" lsp-bridge-rename) ("f" lsp-bridge-code-format) ("x" lsp-bridge-code-action) + ("d" lsp-bridge-diagnostic-list) ("M-r" lsp-bridge-restart-process)))) (provide 'fate-lsp) From 812571fd551d401660f96de3d830f5ad728e80e4 Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Tue, 11 Apr 2023 10:05:30 +0900 Subject: [PATCH 08/10] add ruff checker and spell checker --- README.md | 31 +++++++++++++++++++++++-------- modules/fate-flycheck.el | 26 +++++++++++++++++++++++++- modules/fate-langs.el | 4 ++++ modules/fate-python.el | 1 - 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e8112e8..12e60f1 100644 --- a/README.md +++ b/README.md @@ -72,14 +72,27 @@ brew install ripgrep sudo apt install fd-find ``` +### enchant + +`enchant` is a library for spell checking + +``` shell +## Ubuntu +sudo apt install libenchant-2-dev pkg-config + +### mac +brew install enchant2 pkg-config +``` + ### Tools configured for Python -| Name | Installation command | Description | -|-----------------|-----------------------------|-------------------------------------------------------------------------------------| -| flake8 | pip install flake8 | Flake8 is a wrapper around PyFlakes, pycodestyle and Ned Batchelder’s McCabe script | -| python-black | pip install black | Black is the uncompromising Python code formatter | -| black-macchiato | pip install black-macchiato | Enable formatting of partial files using black | +| Name | Installation command | Description | +|-----------------|-----------------------------|---------------------------------------------------| +| python-black | pip install black | Black is the uncompromising Python code formatter | +| black-macchiato | pip install black-macchiato | Enable formatting of partial files using black | +| ruff | pip install ruff | Fast Python linter written in rust | + ### Tools configured for Go @@ -90,9 +103,11 @@ sudo apt install fd-find ### Tools configured for JavaScript/JSON -| Name | Installation command | Description | -|----------|----------------------|----------------------------------------------------------| -| prettier | npm i -g prettier | Formater for JavaScript, TypeScript, CSS, JSON, and more | +| Name | Installation command | Description | +|----------------|---------------------------------------|----------------------------------------------------------| +| prettier | npm i -g prettier | Formater for JavaScript, TypeScript, CSS, JSON, and more | +| linter LSP | npm i -g vscode-langservers-extracted | Language server of eslint, HTML, CSS | +| TypeScript LSP | npm i -g typescript-language-server | | ### Tools configured for shell script diff --git a/modules/fate-flycheck.el b/modules/fate-flycheck.el index 67beace..459e9ee 100644 --- a/modules/fate-flycheck.el +++ b/modules/fate-flycheck.el @@ -50,7 +50,31 @@ See URL `https://stedolan.github.io/jq/'." (message) "at line " line ", column " column (zero-or-more not-newline) line-end)) :modes fate-json-mode) - (add-to-list 'flycheck-checkers 'fate-json-jq)) + (add-to-list 'flycheck-checkers 'fate-json-jq) + + (flycheck-define-checker python-ruff + "A Python syntax and style checker using the ruff utility. +To override the path to the ruff executable, set +`flycheck-python-ruff-executable'. +See URL `http://pypi.python.org/pypi/ruff'." + :command ("ruff" + "--format=text" + (eval (when buffer-file-name + (concat "--stdin-filename=" buffer-file-name))) + "-") + :standard-input t + :error-filter (lambda (errors) + (let ((errors (flycheck-sanitize-errors errors))) + (seq-map #'flycheck-flake8-fix-error-level errors))) + :error-patterns + ((warning line-start + (file-name) ":" line ":" (optional column ":") " " + (id (one-or-more (any alpha)) (one-or-more digit)) " " + (message (one-or-more not-newline)) + line-end)) + :modes python-mode) + (add-to-list 'flycheck-checkers 'python-ruff)) + :custom (flycheck-indication-mode 'right-fringe) (flycheck-emacs-lisp-load-path 'inherit) diff --git a/modules/fate-langs.el b/modules/fate-langs.el index 8e1e43b..4fca9df 100644 --- a/modules/fate-langs.el +++ b/modules/fate-langs.el @@ -52,6 +52,10 @@ (setq-local prettier-js-args '("--parser" "markdown"))))) +(use-package jinx + :hook (markdown-mode . jinx-mode) + :bind ([remap ispell-word] . jinx-correct)) + (use-package yaml-mode :mode (("\\.yaml\\'" . yaml-mode) ("\\.yml\\'" . yaml-mode))) diff --git a/modules/fate-python.el b/modules/fate-python.el index ff2bfb9..6a37b00 100644 --- a/modules/fate-python.el +++ b/modules/fate-python.el @@ -51,7 +51,6 @@ Argument ARG is ignored." :hook (python-mode . fate/python-setup-hs-mode)) -;; Format using YAPF ;; Install: ;; pip install black ;; pip install black-macchiato From 9f05af72a535667683bfe7094fd6796f023fcd5d Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Tue, 11 Apr 2023 10:05:56 +0900 Subject: [PATCH 09/10] enable eslint and typescript lsp for ts and tsx --- modules/fate-lsp.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/fate-lsp.el b/modules/fate-lsp.el index e7e57c1..89a5760 100644 --- a/modules/fate-lsp.el +++ b/modules/fate-lsp.el @@ -37,6 +37,8 @@ :custom (lsp-bridge-signature-function 'eldoc-message) (acm-markdown-render-font-height 80) + (lsp-bridge-multi-lang-server-extension-list + '((("ts" "tsx") . "typescript_eslint"))) :bind (:map lsp-bridge-mode-map ([remap xref-find-definitions] . lsp-bridge-find-def) From fc2b6e1d802b2e58f6cf00ef07bf3967519f09a9 Mon Sep 17 00:00:00 2001 From: Binbin Ye Date: Tue, 11 Apr 2023 11:01:57 +0900 Subject: [PATCH 10/10] update guide to install dependencies for lsp-bridge --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 12e60f1..942f563 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ brew install enchant2 pkg-config | Name | Installation command | Description | |------------|--------------------------------------------|-------------------------------------------------------| | shellcheck | apt install shellcheck | A great teacher helping you write better shell script | -| shfmt | go install mvdan.cc/sh/v3/cmd/shfmt@latest | A shell script formater | +| shfmt | go install mvdan.cc/sh/v3/cmd/shfmt@latest | A shell script formatter | ### all-the-icons @@ -170,7 +170,17 @@ Optional configuration, take a look at my [configs](https://github.com/braineo/c ## Install and Update Language Servers -Lsp has a good website documenting usage of [lsp-mode](https://emacs-lsp.github.io/lsp-mode/) + + +Previously [lsp-mode](https://emacs-lsp.github.io/lsp-mode/) was used as LSP client. The configuration now migrates to [lsp-bridge](https://github.com/manateelazycat/lsp-bridge), a client emphasizes performance. It has not covered all the features in lsp-mode, but it is **really** fast. + +``` shell +# install dependencies for lsp-bridge +pip3 install epc orjson sexpdata six +``` + +For each language server, refer to the configuration guide in [lsp-bridge](https://github.com/manateelazycat/lsp-bridge) + ### Language servers implemented in NodeJS @@ -180,8 +190,6 @@ Language servers implemented in NodeJS can obtain directly by doing `lsp-install | --------------------- | -------------------------------------------------------- | | TypeScript/JavaScript | npm i -g typescript-language-server; npm i -g typescript | | JSON | npm i -g vscode-json-languageserver | -| CSS/LessCSS/SASS/SCSS | npm install -g vscode-css-languageserver-bin | -| HTML | npm install -g vscode-html-languageserver-bin | | Dockerfile | npm install -g dockerfile-language-server-nodejs | ### Go