.emacs.d/elisp/init-lsp.el
2020-01-13 15:14:54 +01:00

115 lines
3.8 KiB
EmacsLisp

;;; init-lsp.el --- -*- lexical-binding: t -*-
;;
;; Filename: init-lsp.el
;; Description: Initialize LSP
;; Author: Mingde (Matthew) Zeng
;; Copyright (C) 2019 Mingde (Matthew) Zeng
;; Created: Fri Mar 15 10:42:09 2019 (-0400)
;; Version: 2.0.0
;; Last-Updated: Thu Dec 26 01:56:25 2019 (-0500)
;; By: Mingde (Matthew) Zeng
;; URL: https://github.com/MatthewZMD/.emacs.d
;; Keywords: M-EMACS .emacs.d lsp
;; Compatibility: emacs-version >= 26.1
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; This initializes lsp-mode and dap-mode
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(eval-when-compile
(require 'init-const))
;; LSPPac
(use-package lsp-mode
:defer t
:commands lsp
:custom
(lsp-auto-guess-root nil)
(lsp-prefer-flymake nil) ; Use flycheck instead of flymake
(lsp-file-watch-threshold 2000)
(read-process-output-max (* 1024 1024))
:bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
:hook ((java-mode python-mode go-mode
js-mode js2-mode typescript-mode web-mode
c-mode c++-mode objc-mode) . lsp))
;; -LSPPac
;; LSPUI
(use-package lsp-ui
:after lsp-mode
:diminish
:commands lsp-ui-mode
:custom-face
(lsp-ui-doc-background ((t (:background nil))))
(lsp-ui-doc-header ((t (:inherit (font-lock-string-face italic)))))
: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-doc-enable t)
(lsp-ui-doc-header t)
(lsp-ui-doc-include-signature t)
(lsp-ui-doc-position 'top)
(lsp-ui-doc-border (face-foreground 'default))
(lsp-ui-sideline-enable nil)
(lsp-ui-sideline-ignore-duplicate t)
(lsp-ui-sideline-show-code-actions nil)
:config
;; Use lsp-ui-doc-webkit only in GUI
(if *sys/gui*
(setq lsp-ui-doc-use-webkit t))
;; WORKAROUND Hide mode-line of the lsp-ui-imenu buffer
;; https://github.com/emacs-lsp/lsp-ui/issues/243
(defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
(setq mode-line-format nil)))
;; -LSPUI
;; DAPPac
(use-package dap-mode
:diminish
:bind
(:map dap-mode-map
(("<f12>" . dap-debug)
("<f8>" . dap-continue)
("<f9>" . dap-next)
("<M-f11>" . dap-step-in)
("C-M-<f11>" . dap-step-out)
("<f7>" . dap-breakpoint-toggle)))
:hook ((after-init . dap-mode)
(dap-mode . dap-ui-mode)
(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) . (lambda () (require 'dap-lldb)))
(php-mode . (lambda () (require 'dap-php)))
(elixir-mode . (lambda () (require 'dap-elixir)))
((js-mode js2-mode typescript-mode) . (lambda () (require 'dap-chrome)))))
;; -DAPPac
(provide 'init-lsp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; init-lsp.el ends here