Skip to content

Instantly share code, notes, and snippets.

@holgerschurig
Last active November 3, 2019 16:18
Show Gist options
  • Save holgerschurig/3817f10540079792e8c225b8d26e59a5 to your computer and use it in GitHub Desktop.
Save holgerschurig/3817f10540079792e8c225b8d26e59a5 to your computer and use it in GitHub Desktop.
my lsp / clang configuration
;;; Package: lsp-mode - language server protocol
(use-package lsp-mode
:straight t
:diminish lsp-mode ;; I can see if it is active in the menu!
:commands (lsp lsp-deferred)
:hook ((c-mode . lsp-deferred)
(c++-mode . lsp-deferred))
:bind (:map lsp-mode-map
("C-c o" . lsp-describe-thing-at-point)
("C-c f" . lsp-format-region)
("C-c a" . lsp-execute-code-action)
("C-c h" . lsp-document-highlight)
("C-c n" . lsp-rename)
;; ("M-." . lsp-find-definition)
)
:init
;; (add-hook 'hack-local-variables-hook
;; (lambda () (when (derived-mode-p 'c++-mode) (lsp-deferred))))
:config
(require 'yasnippet)
(setq lsp-auto-guess-root t) ; Detect project root
;;(setq lsp-enable-snippet nil) ; no yasnipped for now
(setq lsp-prefer-flymake nil) ; Use lsp-ui if present
(setq lsp-eldoc-render-all nil) ; this is now rendered via lsp-ui
(setq lsp-enable-symbol-highlighting nil) ; don't highlight the current symbol
(setq lsp-document-sync-method 'incremental)
(setq lsp-keep-workspace-alive nil)
(setq lsp-session-file (locate-user-emacs-file "tmp/lsp-session-v1"))
;; face for "hightlight referenced"
(set-face-attribute 'lsp-face-highlight-textual nil
:background "#666" :foreground "#ffffff")
(set-face-attribute 'lsp-face-highlight-read nil
:background "#666" :foreground "#ffffff" :underline nil)
(set-face-attribute 'lsp-face-highlight-write nil
:background "#666" :foreground "#ffffff")
;; fixup the menu
(define-key lsp-mode-menu [menu-bar lsp] nil)
(easy-menu-remove-item lsp-mode-menu nil "Add folder to workspace")
(easy-menu-remove-item lsp-mode-menu nil "Remove folder from workspace")
(easy-menu-remove-item lsp-mode-menu nil "Switch to another workspace folder")
;; not supported by clangd
(easy-menu-remove-item lsp-mode-menu nil "Find implementations of symbol under point")
(easy-menu-remove-item lsp-mode-menu nil "Find type definitions of symbol under point")
;; no need to display this menu entry when the function is disabled
(unless lsp-log-io
(easy-menu-remove-item lsp-mode-menu nil "View IO logs for workspace")))
;;; Package: lsp-clients - use clangd
(use-package lsp-clients
:defer t
:defines (lsp-clients-clangd-args)
:init
;; prevent this from being loaded :-)
(provide 'lsp-pyls)
(provide 'lsp-rust)
(provide 'lsp-solargraph)
(provide 'lsp-vetur)
(provide 'lsp-intelephense)
(provide 'lsp-css)
(provide 'lsp-xml)
(provide 'lsp-go)
(provide 'lsp-clojure)
(provide 'lsp-dart)
(provide 'lsp-elm)
(provide 'lsp-metals)
(provide 'lsp-fsharp)
(provide 'lsp-erlang)
:config
(setq lsp-clients-clangd-executable "/usr/bin/clangd-10")
;; maybe set this from .dir-locals?
(setq lsp-clients-clangd-args `("-j=2"
"--background-index"
"--clang-tidy"
"--completion-style=bundled"
"--header-insertion=iwyu"
"--suggest-missing-includes"
"--log=error"
,(concat "--compile-commands-dir=" (file-truename (locate-dominating-file "." ".git")) "build")
)))
;;; Package: lsp-ui - show error and documentation in a nice way
(use-package lsp-ui
:straight t
:commands lsp-ui-mode
:bind (:map lsp-ui-mode-map
([remap xref-find-definitions] . lsp-ui-peek-find-definitions)
([remap xref-find-references] . lsp-ui-peek-find-references)
("M-g i" . lsp-ui-imenu)
)
:config
(setq lsp-ui-doc-enable nil)
(setq lsp-ui-doc-delay 0.5)
(setq lsp-ui-doc-include-signature t)
;; (setq lsp-ui-doc-border (face-foreground 'default))
;; (setq lsp-eldoc-enable-hover t)
(setq lsp-ui-sideline-ignore-duplicate t)
;; (setq lsp-ui-sideline-show-hover nil)
;; (setq lsp-ui-sideline-show-diagnostics t)
;; (add-to-list 'lsp-ui-doc-frame-parameters '(right-fringe . 8))
(easy-menu-define-key lsp-mode-menu "M-." (cons "Find definition" #'lsp-ui-peek-find-definitions)
"Find definitions of symbol")
(easy-menu-define-key lsp-mode-menu "M-?" (cons "Find references" #'lsp-ui-peek-find-references)
"Find definitions of symbol")
(easy-menu-remove-item lsp-mode-menu nil "Find definitions of symbol")
;; these two aren't supported by clangd
(easy-menu-remove-item lsp-mode-menu nil "Find implementations of symbol under point")
(easy-menu-remove-item lsp-mode-menu nil "Find references to symbol under point"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment