2022-11-19 04:33:22 +01:00
|
|
|
;;; init-lsp.el --- Languaje server protocol. -*- lexical-binding: t -*-
|
2022-06-01 15:18:06 +02:00
|
|
|
|
|
|
|
;; Author: kj <webmaster@outcontrol.net>
|
|
|
|
;; URL: https://git.kj2.me/kj/confi-emacs-actual
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2023-04-14 18:39:19 +02:00
|
|
|
;; Este archivo es lo misma idea que "init-eglot",
|
|
|
|
;; pero en este caso cambiamos lsp-mode en lugar
|
|
|
|
;; de Eglot.
|
|
|
|
;;
|
|
|
|
;; Desde que Emacs trae integrado Eglot, he dejado
|
|
|
|
;; de usarlo y es probable que en un futuro sea
|
|
|
|
;; eliminado totalmente.
|
|
|
|
|
2022-06-01 15:18:06 +02:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;; Performace tuning
|
|
|
|
;; @see https://emacs-lsp.github.io/lsp-mode/page/performance/
|
2022-06-07 09:09:10 +02:00
|
|
|
(setq read-process-output-max (* 1024 (* 3 1024))) ;; 3MB
|
2022-06-01 15:18:06 +02:00
|
|
|
(setenv "LSP_USE_PLISTS" "true")
|
|
|
|
|
|
|
|
(use-package lsp-mode
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:diminish
|
|
|
|
:commands (lsp-enable-which-key-integration
|
2022-06-07 09:36:36 +02:00
|
|
|
lsp-format-buffer
|
|
|
|
lsp-organize-imports
|
|
|
|
lsp-install-server)
|
2022-06-27 22:02:41 +02:00
|
|
|
:hook ((prog-mode . (lambda ()
|
2022-11-19 19:16:29 +01:00
|
|
|
(unless (derived-mode-p 'emacs-lisp-mode 'lisp-mode 'makefile-mode 'sql-mode)
|
2022-06-27 22:02:41 +02:00
|
|
|
(lsp-deferred))))
|
2022-06-30 02:52:39 +02:00
|
|
|
(html-mode . lsp-deferred)
|
2022-06-27 22:02:41 +02:00
|
|
|
(markdown-mode . lsp-deferred)
|
2022-06-01 15:18:06 +02:00
|
|
|
(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
|
2022-07-12 22:38:53 +02:00
|
|
|
lsp-enable-links nil
|
2022-06-01 15:18:06 +02:00
|
|
|
lsp-enable-symbol-highlighting nil
|
2022-07-12 22:38:53 +02:00
|
|
|
lsp-enable-semantic-highlighting nil
|
|
|
|
cls-sem-highlight-method nil
|
2022-06-01 15:18:06 +02:00
|
|
|
lsp-enable-text-document-color nil
|
2022-06-19 19:41:32 +02:00
|
|
|
lsp-lens-enable nil
|
2022-06-27 22:02:41 +02:00
|
|
|
lsp-auto-guess-root t
|
2022-06-01 15:18:06 +02:00
|
|
|
|
2022-06-09 09:53:28 +02:00
|
|
|
lsp-log-io nil
|
2022-06-27 22:02:41 +02:00
|
|
|
lsp-idle-delay 0.5
|
|
|
|
lsp-diagnostic-package :none ; Evitar que lsp conecte con flycheck para evitar que se congele
|
2022-06-09 09:53:28 +02:00
|
|
|
|
2022-06-01 15:18:06 +02:00
|
|
|
lsp-enable-indentation nil
|
|
|
|
lsp-enable-on-type-formatting nil)
|
2022-06-07 09:36:36 +02:00
|
|
|
:config
|
|
|
|
(with-no-warnings
|
2022-06-30 02:52:39 +02:00
|
|
|
;; Remove php extension on form lsp
|
|
|
|
(setq lsp-language-id-configuration
|
2022-08-11 18:16:02 +02:00
|
|
|
(remove '(".*\\.php$" . "php") lsp-language-id-configuration))
|
2022-08-18 22:48:25 +02:00
|
|
|
(add-to-list 'lsp-language-id-configuration '(web-mode . "html"))
|
2022-06-30 02:52:39 +02:00
|
|
|
|
2022-06-07 09:36:36 +02:00
|
|
|
;; 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))
|
2022-06-01 15:18:06 +02:00
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Interface para lsp
|
|
|
|
(use-package lsp-ui
|
|
|
|
:defer t
|
|
|
|
:straight t
|
2022-06-06 23:11:28 +02:00
|
|
|
:bind (:map lsp-mode-map
|
2022-06-07 09:36:36 +02:00
|
|
|
("<f1>" . lsp-ui-doc-glance))
|
2022-06-01 15:18:06 +02:00
|
|
|
:hook (lsp-mode . lsp-ui-mode)
|
|
|
|
|
|
|
|
:init
|
2022-06-09 09:53:28 +02:00
|
|
|
(setq lsp-ui-sideline-show-code-actions nil
|
|
|
|
lsp-ui-sideline-show-symbol nil
|
|
|
|
lsp-ui-sideline-show-hover nil
|
|
|
|
lsp-ui-sideline-delay 0.5)
|
2022-06-01 15:18:06 +02:00
|
|
|
(setq lsp-ui-sideline-show-diagnostics nil
|
|
|
|
lsp-ui-sideline-ignore-duplicate t
|
2022-06-06 23:11:28 +02:00
|
|
|
lsp-ui-doc-show-with-cursor nil
|
|
|
|
lsp-ui-doc-show-with-mouse nil
|
|
|
|
lsp-ui-doc-position 'at-point
|
2022-06-01 15:18:06 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
|
2022-06-07 09:36:36 +02:00
|
|
|
;; Integración con ivy
|
|
|
|
(use-package lsp-ivy
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:after lsp-mode
|
|
|
|
:bind (:map lsp-mode-map
|
|
|
|
([remap xref-find-apropos] . lsp-ivy-workspace-symbol)
|
|
|
|
("C-s-." . lsp-ivy-global-workspace-symbol))
|
|
|
|
:config
|
|
|
|
(with-no-warnings
|
|
|
|
(when (icon-displayable-p)
|
|
|
|
(defvar lsp-ivy-symbol-kind-icons
|
|
|
|
`(,(all-the-icons-material "find_in_page" :height 0.9 :v-adjust -0.15) ; Unknown - 0
|
|
|
|
,(all-the-icons-faicon "file-o" :height 0.9 :v-adjust -0.02) ; File - 1
|
|
|
|
,(all-the-icons-material "view_module" :height 0.9 :v-adjust -0.15 :face 'all-the-icons-lblue) ; Module - 2
|
|
|
|
,(all-the-icons-material "view_module" :height 0.95 :v-adjust -0.15 :face 'all-the-icons-lblue) ; Namespace - 3
|
|
|
|
,(all-the-icons-octicon "package" :height 0.9 :v-adjust -0.15) ; Package - 4
|
|
|
|
,(all-the-icons-material "settings_input_component" :height 0.9 :v-adjust -0.15 :face 'all-the-icons-orange) ; Class - 5
|
|
|
|
,(all-the-icons-faicon "cube" :height 0.9 :v-adjust -0.02 :face 'all-the-icons-purple) ; Method - 6
|
|
|
|
,(all-the-icons-faicon "wrench" :height 0.8 :v-adjust -0.02) ; Property - 7
|
|
|
|
,(all-the-icons-octicon "tag" :height 0.95 :v-adjust 0 :face 'all-the-icons-lblue) ; Field - 8
|
|
|
|
,(all-the-icons-faicon "cube" :height 0.9 :v-adjust -0.02 :face 'all-the-icons-lpurple) ; Constructor - 9
|
|
|
|
,(all-the-icons-material "storage" :height 0.9 :v-adjust -0.15 :face 'all-the-icons-orange) ; Enum - 10
|
|
|
|
,(all-the-icons-material "share" :height 0.9 :v-adjust -0.15 :face 'all-the-icons-lblue) ; Interface - 11
|
|
|
|
,(all-the-icons-faicon "cube" :height 0.9 :v-adjust -0.02 :face 'all-the-icons-purple) ; Function - 12
|
|
|
|
,(all-the-icons-octicon "tag" :height 0.95 :v-adjust 0 :face 'all-the-icons-lblue) ; Variable - 13
|
|
|
|
,(all-the-icons-faicon "cube" :height 0.9 :v-adjust -0.02 :face 'all-the-icons-purple) ; Constant - 14
|
|
|
|
,(all-the-icons-faicon "text-width" :height 0.9 :v-adjust -0.02) ; String - 15
|
|
|
|
,(all-the-icons-material "format_list_numbered" :height 0.95 :v-adjust -0.15) ; Number - 16
|
|
|
|
,(all-the-icons-octicon "tag" :height 0.9 :v-adjust 0.0 :face 'all-the-icons-lblue) ; Boolean - 17
|
|
|
|
,(all-the-icons-material "view_array" :height 0.95 :v-adjust -0.15) ; Array - 18
|
|
|
|
,(all-the-icons-octicon "tag" :height 0.9 :v-adjust 0.0 :face 'all-the-icons-blue) ; Object - 19
|
|
|
|
,(all-the-icons-faicon "key" :height 0.9 :v-adjust -0.02) ; Key - 20
|
|
|
|
,(all-the-icons-octicon "tag" :height 0.9 :v-adjust 0.0) ; Null - 21
|
|
|
|
,(all-the-icons-material "format_align_right" :height 0.95 :v-adjust -0.15 :face 'all-the-icons-lblue) ; EnumMember - 22
|
|
|
|
,(all-the-icons-material "settings_input_component" :height 0.9 :v-adjust -0.15 :face 'all-the-icons-orange) ; Struct - 23
|
|
|
|
,(all-the-icons-octicon "zap" :height 0.9 :v-adjust 0 :face 'all-the-icons-orange) ; Event - 24
|
|
|
|
,(all-the-icons-material "control_point" :height 0.9 :v-adjust -0.15) ; Operator - 25
|
|
|
|
,(all-the-icons-faicon "arrows" :height 0.9 :v-adjust -0.02) ; TypeParameter - 26
|
|
|
|
))
|
|
|
|
|
|
|
|
(lsp-defun my-lsp-ivy--format-symbol-match
|
|
|
|
((sym &as &SymbolInformation :kind :location (&Location :uri))
|
|
|
|
project-root)
|
|
|
|
"Convert the match returned by `lsp-mode` into a candidate string."
|
|
|
|
(let* ((sanitized-kind (if (< kind (length lsp-ivy-symbol-kind-icons)) kind 0))
|
|
|
|
(type (elt lsp-ivy-symbol-kind-icons sanitized-kind))
|
|
|
|
(typestr (if lsp-ivy-show-symbol-kind (format "%s " type) ""))
|
|
|
|
(pathstr (if lsp-ivy-show-symbol-filename
|
|
|
|
(propertize (format " · %s" (file-relative-name (lsp--uri-to-path uri) project-root))
|
|
|
|
'face font-lock-comment-face)
|
|
|
|
"")))
|
|
|
|
(concat typestr (lsp-render-symbol-information sym ".") pathstr)))
|
|
|
|
(advice-add #'lsp-ivy--format-symbol-match :override #'my-lsp-ivy--format-symbol-match))))
|
|
|
|
|
|
|
|
;; Debug
|
|
|
|
(use-package dap-mode
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:defines dap-python-executable
|
|
|
|
:functions dap-hydra/nil
|
|
|
|
:diminish
|
|
|
|
:bind (:map lsp-mode-map
|
|
|
|
("<f5>" . dap-debug)
|
|
|
|
("M-<f5>" . dap-hydra))
|
|
|
|
:hook ((after-init . dap-auto-configure-mode)
|
|
|
|
(dap-stopped . (lambda (_args) (dap-hydra)))
|
|
|
|
(dap-terminated . (lambda (_args) (dap-hydra/nil)))
|
|
|
|
|
|
|
|
(python-mode . (lambda () (require 'dap-python)))
|
|
|
|
(ruby-mode . (lambda () (require 'dap-ruby)))
|
|
|
|
(go-mode . (lambda () (require 'dap-go)))
|
|
|
|
(java-mode . (lambda () (require 'dap-java)))
|
|
|
|
((c-mode c++-mode objc-mode swift-mode) . (lambda () (require 'dap-lldb)))
|
|
|
|
(php-mode . (lambda () (require 'dap-php)))
|
|
|
|
(elixir-mode . (lambda () (require 'dap-elixir)))
|
|
|
|
((js-mode js2-mode) . (lambda () (require 'dap-chrome)))
|
|
|
|
(powershell-mode . (lambda () (require 'dap-pwsh))))
|
|
|
|
:init
|
|
|
|
(setq dap-auto-configure-features '(sessions locals breakpoints expressions controls))
|
|
|
|
(when (executable-find "python3")
|
|
|
|
(setq dap-python-executable "python3")))
|
|
|
|
|
|
|
|
;; Python debug
|
|
|
|
(use-package lsp-pyright
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:preface
|
|
|
|
;; Use yapf to format
|
|
|
|
(defun lsp-pyright-format-buffer ()
|
|
|
|
(interactive)
|
|
|
|
(when (and (executable-find "yapf") buffer-file-name)
|
|
|
|
(call-process "yapf" nil nil nil "-i" buffer-file-name)))
|
|
|
|
:hook (python-mode . (lambda ()
|
|
|
|
(require 'lsp-pyright)
|
|
|
|
(add-hook 'after-save-hook #'lsp-pyright-format-buffer t t)))
|
|
|
|
:init (when (executable-find "python3")
|
|
|
|
(setq lsp-pyright-python-executable-cmd "python3")))
|
|
|
|
|
|
|
|
;; Java LSP
|
|
|
|
(use-package lsp-java
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:hook (java-mode . (lambda () (require 'lsp-java))))
|
|
|
|
|
2022-11-19 03:56:57 +01:00
|
|
|
;; `lsp-mode' and `treemacs' integration
|
|
|
|
(use-package lsp-treemacs
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:after lsp-mode
|
|
|
|
:bind (:map lsp-mode-map
|
|
|
|
("C-<f8>" . lsp-treemacs-errors-list)
|
|
|
|
("M-<f8>" . lsp-treemacs-symbols)
|
|
|
|
("s-<f8>" . lsp-treemacs-java-deps-list))
|
|
|
|
:init (lsp-treemacs-sync-mode 1)
|
|
|
|
:config
|
|
|
|
(with-eval-after-load 'ace-window
|
|
|
|
(when (boundp 'aw-ignored-buffers)
|
|
|
|
(push 'lsp-treemacs-symbols-mode aw-ignored-buffers)
|
|
|
|
(push 'lsp-treemacs-java-deps-mode aw-ignored-buffers))))
|
2022-06-07 09:36:36 +02:00
|
|
|
|
2022-11-23 00:34:06 +01:00
|
|
|
|
|
|
|
;; Revisar sintaxis en vivo
|
|
|
|
(use-package flycheck
|
|
|
|
;; :diminish flycheck-mode
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:hook (prog-mode . (lambda ()
|
|
|
|
(unless (derived-mode-p 'makefile-mode 'js-mode)
|
|
|
|
(flycheck-mode))))
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Mostrar los errores de flycheck en un pop up
|
|
|
|
(use-package flycheck-popup-tip
|
|
|
|
:defer t
|
|
|
|
:straight t
|
|
|
|
:hook (flycheck-mode . flycheck-popup-tip-mode))
|
|
|
|
|
2022-11-19 04:33:22 +01:00
|
|
|
(provide 'init-lsp)
|
|
|
|
;;; init-lsp.el ends here
|