(use-package eglot
  :commands (eglot eglot-ensure)
  :bind (:map eglot-mode-map
              ;; M-.
              ;; ([remap xref-find-definitions] . lsp-ui-peek-find-definitions)
              ;; M-?
              ;; ([remap xref-find-references] . lsp-ui-peek-find-references)
              ("C-c C-a" . eglot-code-actions)
              )
  :hook (
         (eglot-managed-mode . (lambda ()
                                 (when (eglot-managed-p)
                                   (corfu-mode +1)
                                   )
                                 ))
         )
  :config
  ;; Increase garbage collection threshold for performance (default 800000)
  (setq gc-cons-threshold 100000000)

  ;; Increase amount of data read from processes, default 4k
  (when (>= emacs-major-version 27)
    (setq read-process-output-max (* 1024 1024)) ;; 1mb
    )

  (set-face-attribute 'eglot-highlight-symbol-face nil :background "#0291a1" :foreground "black")
  (set-face-attribute 'eglot-mode-line nil :inherit 'mode-line :bold nil)

  (use-package consult-eglot
    :bind (
           :map eglot-mode-map
           ;; C-M-.
           ([remap xref-find-apropos] . #'consult-eglot-symbols)
           )
    )
  :custom
  (eglot-autoshutdown t "Shut down server when last buffer is killed.")
  (eglot-sync-connect 0 "Don't block on language server starting.")
  )

(provide 'common-lsp)
