confi-emacs-actual/configs/base-lsp.el
kj a7045d3b30 Mixed changes.
- Rename org-config.el to base-org.el.
- Enable lsp by default.
- Improve lsp.
- Add citre package (ctags IDE).
- Add ripgrep search.
- Add pomidor  (pomodoro timer).
- Move keybinding for improve load time (some are deleted or changed).
- Add C-x C-r keybinding for recent files.
- And more...
2022-06-01 09:18:06 -04:00

107 lines
3.9 KiB
EmacsLisp

;;; base-lsp.el --- Languaje server protocol. -*- lexical-binding: t -*-
;; Author: kj <webmaster@outcontrol.net>
;; URL: https://git.kj2.me/kj/confi-emacs-actual
;;; Commentary:
;;; Code:
;; Performace tuning
;; @see https://emacs-lsp.github.io/lsp-mode/page/performance/
(setq read-process-output-max (* 1024 1024)) ;; 1MB
(setenv "LSP_USE_PLISTS" "true")
(use-package lsp-mode
:defer t
:straight t
:diminish
:commands (lsp-enable-which-key-integration
lsp-format-buffer
lsp-organize-imports
lsp-install-server)
:hook ((prog-mode . (lambda ()
(unless (derived-mode-p 'emacs-lisp-mode 'lisp-mode 'makefile-mode)
(lsp-deferred))))
(markdown-mode . lsp-deferred)
(lsp-mode . lsp-enable-which-key-integration))
:custom
(lsp-headerline-breadcrumb-enable nil)
:init (setq lsp-keymap-prefix "C-c l"
lsp-keep-workspace-alive nil
lsp-signature-auto-activate nil
lsp-modeline-code-actions-enable nil
lsp-modeline-diagnostics-enable nil
lsp-modeline-workspace-status-enable nil
lsp-headerline-breadcrumb-enable nil
lsp-enable-file-watchers nil
lsp-enable-folding nil
lsp-enable-symbol-highlighting nil
lsp-enable-text-document-color nil
lsp-enable-indentation nil
lsp-enable-on-type-formatting nil)
:config
(with-no-warnings
;; Disable `lsp-mode' in `git-timemachine-mode'
(defun my-lsp--init-if-visible (fn &rest args)
(unless (bound-and-true-p git-timemachine-mode)
(apply fn args)))
(advice-add #'lsp--init-if-visible :around #'my-lsp--init-if-visible)
;; Enable `lsp-mode' in sh/bash/zsh
(defun my-lsp-bash-check-sh-shell (&rest _)
(and (eq major-mode 'sh-mode)
(memq sh-shell '(sh bash zsh))))
(advice-add #'lsp-bash-check-sh-shell :override #'my-lsp-bash-check-sh-shell)
;; Only display icons in GUI
(defun my-lsp-icons-get-symbol-kind (fn &rest args)
(and (icon-displayable-p) (apply fn args)))
(advice-add #'lsp-icons-get-by-symbol-kind :around #'my-lsp-icons-get-symbol-kind)
(defun my-lsp-icons-get-by-file-ext (fn &rest args)
(and (icon-displayable-p) (apply fn args)))
(advice-add #'lsp-icons-get-by-file-ext :around #'my-lsp-icons-get-by-file-ext)
(defun my-lsp-icons-all-the-icons-material-icon (icon-name face fallback &optional feature)
(if (and (icon-displayable-p)
(lsp-icons--enabled-for-feature feature))
(all-the-icons-material icon-name
:face face)
(propertize fallback 'face face)))
(advice-add #'lsp-icons-all-the-icons-material-icon
:override #'my-lsp-icons-all-the-icons-material-icon))
)
;; Interface para lsp
(use-package lsp-ui
:defer t
:straight t
:bind (("<f1>" . lsp-ui-doc-glance))
:hook (lsp-mode . lsp-ui-mode)
:init
(setq lsp-ui-sideline-show-diagnostics nil
lsp-ui-sideline-ignore-duplicate t
lsp-ui-doc-delay 0.1
lsp-ui-imenu-colors `(,(face-foreground 'font-lock-keyword-face)
,(face-foreground 'font-lock-string-face)
,(face-foreground 'font-lock-constant-face)
,(face-foreground 'font-lock-variable-name-face)))
;; Set correct color to borders
(defun my-lsp-ui-doc-set-border ()
"Set the border color of lsp doc."
(setq lsp-ui-doc-border
(if (facep 'posframe-border)
(face-background 'posframe-border nil t)
(face-foreground 'shadow nil t))))
(my-lsp-ui-doc-set-border)
(add-hook 'after-load-theme-hook #'my-lsp-ui-doc-set-border t)
)
(provide 'base-lsp)
;;; base-lsp.el ends here