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

Migrate configuration from lsp-mode to lsp-bridge #12

Merged
merged 10 commits into from
Apr 11, 2023
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -101,7 +116,7 @@ sudo apt install fd-find
| 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
Expand Down Expand Up @@ -155,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

Expand All @@ -165,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
Expand Down
3 changes: 2 additions & 1 deletion core/fate-custom-template.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
;;; Forge
;; (setq fate/forge-alist '(("git.site.com" "git.site.com/api/v4" "ssh://[email protected]" forge-github-repository)))

;;; fate-custom.el ends here
(provide 'custom)
;;; custom.el ends here
1 change: 1 addition & 0 deletions modules/fate-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
;;; Code:

(use-package company
:disabled
:hook
(after-init . global-company-mode)
:bind
Expand Down
26 changes: 25 additions & 1 deletion modules/fate-flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions modules/fate-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
136 changes: 27 additions & 109 deletions modules/fate-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,121 +29,39 @@
(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
(use-package lsp-bridge
:straight (:host github
:repo "manateelazycat/lsp-bridge"
:files ("*" (:exclude ".git")))
:hook (after-init . global-lsp-bridge-mode)
: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))
(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)
([remap xref-find-references] . lsp-bridge-find-references)
([remap view-hello-file] . lsp-bridge-popup-documentation))
: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
Action^^ Documentation^^ Server
-------------------------------------------------------------------------------------
[_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)
[_f_] format [_i_] implementation [_M-r_] restart
[_x_] execute action [_D_] definition [_o_] documentation
[_r_] rename [_R_] references [_d_] diagnostic"
("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)
("d" lsp-bridge-diagnostic-list)
("M-r" lsp-bridge-restart-process))))

(provide 'fate-lsp)
;;; fate-lsp.el ends here
1 change: 0 additions & 1 deletion modules/fate-python.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down