2020-05-01 11:01:11 +02:00
|
|
|
;;; tools/lsp/autoload/lsp-mode.el -*- lexical-binding: t; -*-
|
2022-08-12 20:29:19 +02:00
|
|
|
;;;###if (not (modulep! +eglot))
|
2019-02-21 16:08:27 -05:00
|
|
|
|
2020-04-02 00:56:01 -04:00
|
|
|
;;;###autodef
|
|
|
|
(defun set-lsp-priority! (client priority)
|
|
|
|
"Change the PRIORITY of lsp CLIENT."
|
|
|
|
(require 'lsp-mode)
|
|
|
|
(if-let (client (gethash client lsp-clients))
|
2020-05-09 01:37:40 -04:00
|
|
|
(setf (lsp--client-priority client)
|
2020-04-02 00:56:01 -04:00
|
|
|
priority)
|
|
|
|
(error "No LSP client named %S" client)))
|
|
|
|
|
2020-02-24 14:59:14 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun +lsp/uninstall-server (dir)
|
|
|
|
"Delete a LSP server from `lsp-server-install-dir'."
|
|
|
|
(interactive
|
|
|
|
(list (read-directory-name "Uninstall LSP server: " lsp-server-install-dir nil t)))
|
|
|
|
(unless (file-directory-p dir)
|
|
|
|
(user-error "Couldn't find %S directory" dir))
|
|
|
|
(delete-directory dir 'recursive)
|
|
|
|
(message "Uninstalled %S" (file-name-nondirectory dir)))
|
2020-04-02 00:56:01 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +lsp/switch-client (client)
|
|
|
|
"Switch to another LSP server."
|
|
|
|
(interactive
|
|
|
|
(progn
|
|
|
|
(require 'lsp-mode)
|
|
|
|
(list (completing-read
|
|
|
|
"Select server: "
|
2022-01-03 18:02:29 +01:00
|
|
|
(or (mapcar #'lsp--client-server-id (lsp--filter-clients (-andfn #'lsp--supports-buffer?
|
2021-07-24 19:28:07 -03:00
|
|
|
#'lsp--server-binary-present?)))
|
2020-04-02 00:56:01 -04:00
|
|
|
(user-error "No available LSP clients for %S" major-mode))))))
|
|
|
|
(require 'lsp-mode)
|
|
|
|
(let* ((client (if (symbolp client) client (intern client)))
|
|
|
|
(match (car (lsp--filter-clients (lambda (c) (eq (lsp--client-server-id c) client)))))
|
|
|
|
(workspaces (lsp-workspaces)))
|
|
|
|
(unless match
|
|
|
|
(user-error "Couldn't find an LSP client named %S" client))
|
|
|
|
(let ((old-priority (lsp--client-priority match)))
|
|
|
|
(setf (lsp--client-priority match) 9999)
|
|
|
|
(unwind-protect
|
|
|
|
(if workspaces
|
|
|
|
(lsp-workspace-restart
|
|
|
|
(if (cdr workspaces)
|
|
|
|
(lsp--completing-read "Select server: "
|
|
|
|
workspaces
|
|
|
|
'lsp--workspace-print
|
|
|
|
nil t)
|
|
|
|
(car workspaces)))
|
|
|
|
(lsp-mode +1))
|
2021-07-24 19:28:07 -03:00
|
|
|
(add-transient-hook! 'lsp-after-initialize-hook
|
|
|
|
(setf (lsp--client-priority match) old-priority))))))
|
2021-03-27 21:41:15 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +lsp-lookup-definition-handler ()
|
|
|
|
"Find definition of the symbol at point using LSP."
|
|
|
|
(interactive)
|
|
|
|
(when-let (loc (lsp-request "textDocument/definition"
|
|
|
|
(lsp--text-document-position-params)))
|
|
|
|
(lsp-show-xrefs (lsp--locations-to-xref-items loc) nil nil)
|
2021-06-04 01:30:34 -04:00
|
|
|
'deferred))
|
2021-03-27 21:41:15 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +lsp-lookup-references-handler (&optional include-declaration)
|
|
|
|
"Find project-wide references of the symbol at point using LSP."
|
|
|
|
(interactive "P")
|
|
|
|
(when-let
|
|
|
|
(loc (lsp-request "textDocument/references"
|
|
|
|
(append (lsp--text-document-position-params)
|
|
|
|
(list
|
|
|
|
:context `(:includeDeclaration
|
|
|
|
,(lsp-json-bool include-declaration))))))
|
|
|
|
(lsp-show-xrefs (lsp--locations-to-xref-items loc) nil t)
|
2021-06-04 01:30:34 -04:00
|
|
|
'deferred))
|