 ;;; tools/lsp/+lsp.el -*- lexical-binding: t; -*-
 
-(defvar +lsp-company-backends (if (featurep! :editor snippets)
-                                  '(:separate company-capf company-yasnippet)
-                                'company-capf)
+(defvar +lsp-company-backends
+  (if (featurep! :editor snippets)
+      '(:separate company-capf company-yasnippet)
+    'company-capf)
   "The backends to prepend to `company-backends' in `lsp-mode' buffers.
 Can be a list of backends; accepts any value `company-backends' accepts.")
 

        "j"   #'lsp-ui-peek--select-next
        "k"   #'lsp-ui-peek--select-prev
        "C-k" #'lsp-ui-peek--select-prev-file
        "C-j" #'lsp-ui-peek--select-next-file)

  (when (featurep! +peek)
    (set-lookup-handlers! 'lsp-ui-mode :async t
      :definition 'lsp-ui-peek-find-definitions
      :implementations 'lsp-ui-peek-find-implementation
      :references 'lsp-ui-peek-find-references)))


(use-package! helm-lsp



(use-package! lsp-ui
  :hook (lsp-mode . lsp-ui-mode)
  :hook (lsp-ui . lsp-ui-sideline-mode)
  :hook (lsp-ui . lsp-ui-doc-mode)
  :config
  ;; For some reason `lsp-ui' doesn't actually use the `lsp-ui-doc-enable' and
  ;; `lsp-ui-sideline-enable' variables, so we fix that.
  (defadvice! +lsp--ui-doc-only-if-enabled-a (&rest _)
    :before-while #'lsp-ui-doc-mode
    lsp-ui-doc-enable)

  (defadvice! +lsp--ui-sideline-only-if-enabled-a (&rest _)
    :before-while 'lsp-ui-sideline-mode
    lsp-ui-sideline-enable)

  (when (featurep! +peek)
    (set-lookup-handlers! 'lsp-ui-mode
      :definition 'lsp-ui-peek-find-definitions
      :implementations 'lsp-ui-peek-find-implementation
      :references 'lsp-ui-peek-find-references))

  (setq lsp-ui-doc-max-height 8
        lsp-ui-doc-max-width 35
        lsp-ui-doc-show-with-mouse nil  ; don't disappear on mouseover
        lsp-ui-doc-position 'at-point
        lsp-ui-sideline-ignore-duplicate t
        ;; Don't show symbol definitions in the sideline. They are pretty noisy,
        ;; and there is a bug preventing Flycheck errors from being shown (the
        ;; errors flash briefly and then disappear).
