syscfg/emacs/module/module-lsp.el

95 lines
2.9 KiB
EmacsLisp

;;; module-lsp.el --- LSP configuration module -*- lexical-binding: t -*-
;;; Commentary:
;; This module sets up lsp-mode with specific configurations for Please build system
;;; Code:
(require 'lsp-mode)
(require 'lsp-ui)
(require 'which-key)
;; LSP Mode core settings
(setq lsp-keymap-prefix "C-c l")
(setq lsp-idle-delay 0.500)
(setq lsp-log-io nil)
(setq lsp-completion-provider :capf)
(setq lsp-prefer-flymake nil)
;; Please build system specific configurations
(setq lsp-file-watch-ignored-directories
'("[/\\\\]\\.git$"
"[/\\\\]\\.hg$"
"[/\\\\]\\.bzr$"
"[/\\\\]_darcs$"
"[/\\\\]\\.svn$"
"[/\\\\]_FOSSIL_$"
"[/\\\\]\\.idea$"
"[/\\\\]\\.ensime_cache$"
"[/\\\\]\\.eunit$"
"[/\\\\]node_modules$"
"[/\\\\]\\.fslckout$"
"[/\\\\]\\.tox$"
"[/\\\\]\\.stack-work$"
"[/\\\\]\\.bloop$"
"[/\\\\]\\.metals$"
"[/\\\\]target$"
"[/\\\\]\\.ccls-cache$"
"[/\\\\]\\.deps$"
"[/\\\\]build-aux$"
"[/\\\\]autom4te.cache$"
"[/\\\\]\\.reference$"
"[/\\\\]plz-out$")) ;; Add plz-out to ignored directories
;; Increase watch threshold for large Please projects
(setq lsp-file-watch-threshold 10000)
;; LSP UI configurations
(setq lsp-ui-doc-enable t)
(setq lsp-ui-doc-show-with-cursor t)
(setq lsp-ui-doc-position 'at-point)
(setq lsp-ui-doc-delay 0.5)
(setq lsp-ui-sideline-enable t)
(setq lsp-ui-sideline-show-diagnostics t)
(setq lsp-ui-sideline-show-hover t)
(setq lsp-ui-sideline-show-code-actions t)
;; Performance optimizations for large projects
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 3 1024 1024)) ;; Increased for larger projects
(setq lsp-response-timeout 20) ;; Increased timeout
(setq lsp-idle-delay 0.500)
;; Decrease the amount of data lsp has to process
(setq lsp-enable-file-watchers t)
(setq lsp-enable-folding nil)
(setq lsp-enable-text-document-color nil)
(setq lsp-enable-on-type-formatting nil)
(setq lsp-enable-links nil)
;; Which-key integration
(with-eval-after-load 'lsp-mode
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))
;; Enable LSP for specific modes
(add-hook 'python-mode-hook #'lsp-deferred)
(add-hook 'c-mode-hook #'lsp-deferred)
(add-hook 'c++-mode-hook #'lsp-deferred)
(add-hook 'rust-mode-hook #'lsp-deferred)
(add-hook 'go-mode-hook #'lsp-deferred)
(add-hook 'js-mode-hook #'lsp-deferred)
(add-hook 'typescript-mode-hook #'lsp-deferred)
;; Format on save (optional)
(add-hook 'before-save-hook #'lsp-format-buffer)
;; Keybindings
(define-key lsp-mode-map (kbd "C-c l f") #'lsp-format-buffer)
(define-key lsp-mode-map (kbd "C-c l r") #'lsp-rename)
(define-key lsp-mode-map (kbd "C-c l a") #'lsp-execute-code-action)
(define-key lsp-mode-map (kbd "C-c l d") #'lsp-find-definition)
(define-key lsp-mode-map (kbd "C-c l R") #'lsp-find-references)
(provide 'module-lsp)
;;; module-lsp.el ends here