[lsp] Sync lsp layer with latest lsp mode functionality
- provide keybindings for the new lsp-mode functionality - use lsp-treemacs and helm-lsp for errors and workspace symbols
This commit is contained in:
parent
03e6bc0691
commit
5e256d2506
|
@ -1488,7 +1488,7 @@ Other:
|
|||
=wrong-number-of-arguments= error when jabber receives a new notification
|
||||
(thanks to Aleksei Fedotov)
|
||||
**** Java
|
||||
- Added support for multiple backends. Supported backends are: =megahnada=,
|
||||
- Added support for multiple backends. Supported backends are: =meghanada=,
|
||||
=eclim= and =ensime=. The default backend is =meghanada=.
|
||||
- Key bindings:
|
||||
- ~SPC m e e~ is now to fix error around point. Use ~SPC e~ prefix to navigate
|
||||
|
@ -1568,6 +1568,18 @@ Other:
|
|||
- Replace lsp-capabilities keybinding with lsp-describe-session
|
||||
(thanks to Bryan Tan)
|
||||
- Added lsp-prefer-flymake variable (thanks to Juuso Valkeejärvi)
|
||||
- Added =lsp-treemacs=
|
||||
- ~SPC m t g e~ to show error list
|
||||
- Fixed missing shorcuts for =lsp-mode=
|
||||
- ~SPC m F r~ to remove workspace folder
|
||||
- ~SPC m F a~ to add workspace folder
|
||||
- ~SPC m F r~ to switch workspace folder
|
||||
- ~SPC m b s~ to shutdown current workspace
|
||||
- ~SPC m T l~ to toggle lenses
|
||||
- ~SPC m = r~ to format region
|
||||
- Added package =helm-lsp=
|
||||
- ~SPC m g s~ to find symbol in current project
|
||||
- ~SPC m g S~ to find symbol in all projects
|
||||
**** Markdown
|
||||
- New layer variable =markdown-mmm-auto-modes= which is a list of language names
|
||||
or lists of language and mode names that are supported in source blocks, you
|
||||
|
|
|
@ -77,6 +77,7 @@ The key bindings are grouped under the following prefixes:
|
|||
| ~SPC m =~ | format | Source formatting |
|
||||
| ~SPC m g~ | goto | Source navigation |
|
||||
| ~SPC m G~ | peek | Source navigation (lsp-ui-peek overlay) |
|
||||
| ~SPC m F~ | folder | Add/remove folders from workspace |
|
||||
| ~SPC m h~ | help | Help |
|
||||
| ~SPC m b~ | lsp/backend | Catchall. Restart LSP backend, other implementation-specific functionality |
|
||||
| ~SPC m r~ | refactor | What it says on the tin |
|
||||
|
@ -84,10 +85,10 @@ The key bindings are grouped under the following prefixes:
|
|||
|
||||
Some navigation key bindings (i.e. ~SPC m g~ / ~SPC m G~) use an additional level of grouping:
|
||||
|
||||
| prefix | name | functional area |
|
||||
|-----------------+------------------+----------------------------------------------------------|
|
||||
| ~SPC m <g/G> h~ | hierarchy | Heirarchy (i.e. call/inheritance hierarchy etc. ) |
|
||||
| ~SPC m <g/G> m~ | member hierarchy | Class/namespace members (functions, nested classes, vars |
|
||||
| prefix | name | functional area |
|
||||
|-----------------+------------------+-----------------------------------------------------------|
|
||||
| ~SPC m <g/G> h~ | hierarchy | Hierarchy (i.e. call/inheritance hierarchy etc. ) |
|
||||
| ~SPC m <g/G> m~ | member hierarchy | Class/namespace members (functions, nested classes, vars) |
|
||||
|
||||
** Core key bindings
|
||||
The lsp minor mode bindings are:
|
||||
|
@ -95,18 +96,20 @@ The lsp minor mode bindings are:
|
|||
| binding | function |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| ~SPC m = b~ | format buffer (lsp) |
|
||||
| ~SPC m = r~ | format region (lsp) |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| ~SPC m g t~ | goto type-definition (lsp) |
|
||||
| ~SPC m g k~ | goto viewport word (avy) (See Note 1) |
|
||||
| ~SPC m g K~ | goto viewport symbol (avy) (See Note 1) |
|
||||
| ~SPC m g e~ | browse flycheck errors |
|
||||
| ~SPC m g e~ | browse flycheck errors (lsp-treemacs) |
|
||||
| ~SPC m g M~ | browse file symbols (lsp-ui-imenu) |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| Note | /Replaced by the lsp-ui-peek equivalents when ~lsp-navigation~ == ='peek=/ |
|
||||
| ~SPC m g i~ | find implementations (lsp) |
|
||||
| ~SPC m g d~ | find definitions (xref/lsp) |
|
||||
| ~SPC m g r~ | find references (xref/lsp) |
|
||||
| ~SPC m g s~ | find-workspace-symbol (lsp-ui) |
|
||||
| ~SPC m g s~ | find symbol in project (helm-lsp) |
|
||||
| ~SPC m g S~ | find symbol in all projects (helm-lsp) |
|
||||
| ~SPC m g p~ | goto previous (xref-pop-marker-stack) |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| Note | /Omitted when ~lsp-navigation~ == ='peek= or ='simple=/ |
|
||||
|
@ -117,9 +120,11 @@ The lsp minor mode bindings are:
|
|||
| ~SPC m G s~ | find-workspace-symbol (lsp-ui-peek) |
|
||||
| ~SPC m G p~ | goto previous (lsp-ui-peek stack - see Note 2) |
|
||||
| ~SPC m G n~ | goto next (lsp-ui-peek stack - see Note 2) |
|
||||
| ~SPC m G E~ | browse flycheck errors (lsp-ui) |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| ~SPC m h h~ | describe thing at point |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| ~SPC m b s~ | lsp-shutdown-workspace |
|
||||
| ~SPC m b r~ | lsp-restart-workspace |
|
||||
| ~SPC m b a~ | execute code action |
|
||||
| ~SPC m b d~ | lsp-describe-session |
|
||||
|
@ -131,6 +136,11 @@ The lsp minor mode bindings are:
|
|||
| ~SPC m T s~ | toggle symbol info overlay |
|
||||
| ~SPC m T S~ | toggle symbol info overlay symbol name |
|
||||
| ~SPC m T I~ | toggle symbol info overlay duplicates |
|
||||
| ~SPC m T l~ | toggle lenses |
|
||||
|-------------+--------------------------------------------------------------------------------|
|
||||
| ~SPC m F r~ | Remove workspace folder |
|
||||
| ~SPC m F a~ | Add workspace folder |
|
||||
| ~SPC m F s~ | Switch workspace folder |
|
||||
|
||||
Note 1: Your language server may not distinguish between the word and symbol variants of this binding.
|
||||
Note 2: There is a window local jump list dedicated to cross references.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"Set jump handler for LSP with the given MODE."
|
||||
(dolist (m modes)
|
||||
(add-to-list (intern (format "spacemacs-jump-handlers-%S" m))
|
||||
'(lsp-ui-peek-find-definitions :async t))))
|
||||
'(lsp-ui-peek-find-definitions :async t))))
|
||||
|
||||
(defun fix-lsp-company-prefix ()
|
||||
"fix lsp-javascript company prefix
|
||||
|
@ -22,8 +22,8 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
(defun lsp-prefix-company-transformer (candidates)
|
||||
(let ((completion-ignore-case t))
|
||||
(if (and (car candidates)
|
||||
(get-text-property 0 'lsp-completion-prefix (car candidates)))
|
||||
(all-completions (company-grab-symbol) candidates)
|
||||
(get-text-property 0 'lsp-completion-prefix (car candidates)))
|
||||
(all-completions (company-grab-symbol) candidates)
|
||||
candidates)))
|
||||
(make-local-variable 'company-transformers)
|
||||
(add-to-list 'company-transformers 'lsp-prefix-company-transformer))
|
||||
|
@ -34,40 +34,48 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
('simple (spacemacs//lsp-bind-simple-navigation-functions "g"))
|
||||
('peek (spacemacs//lsp-bind-peek-navigation-functions "g"))
|
||||
('both
|
||||
(spacemacs//lsp-bind-simple-navigation-functions "g")
|
||||
(spacemacs//lsp-bind-peek-navigation-functions "G")))
|
||||
(spacemacs//lsp-bind-simple-navigation-functions "g")
|
||||
(spacemacs//lsp-bind-peek-navigation-functions "G")))
|
||||
|
||||
(spacemacs/set-leader-keys-for-minor-mode 'lsp-mode
|
||||
;;format
|
||||
;; format
|
||||
"=b" #'lsp-format-buffer
|
||||
;;goto
|
||||
"=r" #'lsp-format-region
|
||||
;; goto
|
||||
"gt" #'lsp-find-type-definition
|
||||
"gk" #'spacemacs/lsp-avy-goto-word
|
||||
"gK" #'spacemacs/lsp-avy-goto-symbol
|
||||
"ge" #'lsp-ui-flycheck-list
|
||||
"gM" #'lsp-ui-imenu
|
||||
;;help
|
||||
;; help
|
||||
"hh" #'lsp-describe-thing-at-point
|
||||
;;jump
|
||||
;;backend
|
||||
;; jump
|
||||
;; backend
|
||||
"ba" #'lsp-execute-code-action
|
||||
"bd" #'lsp-describe-session
|
||||
"br" #'lsp-restart-workspace
|
||||
;;refactor
|
||||
"bs" #'lsp-shutdown-workspace
|
||||
;; refactor
|
||||
"rr" #'lsp-rename
|
||||
;;toggles
|
||||
;; toggles
|
||||
"Td" #'lsp-ui-doc-mode
|
||||
"Ts" #'lsp-ui-sideline-mode
|
||||
"TF" #'spacemacs/lsp-ui-doc-func
|
||||
"TS" #'spacemacs/lsp-ui-sideline-symb
|
||||
"TI" #'spacemacs/lsp-ui-sideline-ignore-duplicate))
|
||||
"TI" #'spacemacs/lsp-ui-sideline-ignore-duplicate
|
||||
"Tl" #'lsp-lens-mode
|
||||
;; folders
|
||||
"Fs" #'lsp-workspace-folders-switch
|
||||
"Fr" #'lsp-workspace-folders-remove
|
||||
"Fa" #'lsp-workspace-folders-add))
|
||||
|
||||
(defun spacemacs//lsp-bind-simple-navigation-functions (prefix-char)
|
||||
(spacemacs/set-leader-keys-for-minor-mode 'lsp-mode
|
||||
(concat prefix-char "i") #'lsp-find-implementation
|
||||
(concat prefix-char "d") #'xref-find-definitions
|
||||
(concat prefix-char "r") #'xref-find-references
|
||||
(concat prefix-char "s") #'lsp-ui-find-workspace-symbol
|
||||
(concat prefix-char "e") #'lsp-treemacs-errors-list
|
||||
(concat prefix-char "s") #'helm-lsp-workspace-symbol
|
||||
(concat prefix-char "S") #'helm-lsp-global-workspace-symbol
|
||||
(concat prefix-char "p") #'xref-pop-marker-stack))
|
||||
|
||||
(defun spacemacs//lsp-bind-peek-navigation-functions (prefix-char)
|
||||
|
@ -77,6 +85,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
(concat prefix-char "r") #'lsp-ui-peek-find-references
|
||||
(concat prefix-char "s") #'lsp-ui-peek-find-workspace-symbol
|
||||
(concat prefix-char "p") #'lsp-ui-peek-jump-backward
|
||||
(concat prefix-char "e") #'lsp-ui-flycheck-list
|
||||
(concat prefix-char "n") #'lsp-ui-peek-jump-forward))
|
||||
|
||||
(defun spacemacs//lsp-declare-prefixes-for-mode (mode)
|
||||
|
@ -88,6 +97,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
(spacemacs/declare-prefix-for-mode mode "mT" "toggle")
|
||||
(spacemacs/declare-prefix-for-mode mode "mg" "goto")
|
||||
(spacemacs/declare-prefix-for-mode mode "mG" "peek")
|
||||
(spacemacs/declare-prefix-for-mode mode "mF" "folder")
|
||||
(dolist (prefix '("mg" "mG"))
|
||||
(spacemacs/declare-prefix-for-mode mode (concat prefix "h") "hierarchy")
|
||||
(spacemacs/declare-prefix-for-mode mode (concat prefix "m") "members")))
|
||||
|
@ -115,7 +125,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
(while key
|
||||
(define-key keymap (kbd key) def)
|
||||
(setq key (pop bindings)
|
||||
def (pop bindings))))
|
||||
def (pop bindings))))
|
||||
|
||||
;; These functions facilitate extension of the navigation-mode keybindings in derived layers
|
||||
;; See c/c++ layer for a usage example
|
||||
|
@ -124,12 +134,12 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
|
||||
(defun spacemacs//lsp-define-custom-extension (layer-name nav-mode kind request &optional extra)
|
||||
(let ((lsp-extension-fn (if (equal nav-mode "find")
|
||||
'lsp-find-locations
|
||||
'lsp-find-locations
|
||||
'lsp-ui-peek-find-custom))
|
||||
(extension-name (spacemacs//lsp-get-extension-name layer-name nav-mode kind))
|
||||
(extension-descriptor (format (concat nav-mode " %s") (symbol-name kind))))
|
||||
(extension-name (spacemacs//lsp-get-extension-name layer-name nav-mode kind))
|
||||
(extension-descriptor (format (concat nav-mode " %s") (symbol-name kind))))
|
||||
(if extra
|
||||
(defalias extension-name `(lambda () ,extension-descriptor (interactive) (funcall ',lsp-extension-fn ,request ',extra)))
|
||||
(defalias extension-name `(lambda () ,extension-descriptor (interactive) (funcall ',lsp-extension-fn ,request ',extra)))
|
||||
(defalias extension-name `(lambda () ,extension-descriptor (interactive) (funcall ',lsp-extension-fn ,request))))))
|
||||
|
||||
(defun spacemacs/lsp-define-extensions (layer-name kind request &optional extra)
|
||||
|
@ -137,7 +147,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
|
|||
The function names will be <layer-name>/find-<kind> and <layer-name>/peek-<kind>, respectively."
|
||||
(dolist (nav-mode '("find" "peek"))
|
||||
(if extra
|
||||
(spacemacs//lsp-define-custom-extension layer-name nav-mode kind request extra)
|
||||
(spacemacs//lsp-define-custom-extension layer-name nav-mode kind request extra)
|
||||
(spacemacs//lsp-define-custom-extension layer-name nav-mode kind request))))
|
||||
|
||||
(defun spacemacs//lsp-bind-extensions (mode layer-name key kind)
|
||||
|
@ -171,38 +181,38 @@ a find extension defined using `lsp-define-extensions'"
|
|||
(defun spacemacs//lsp-avy-document-symbol (all)
|
||||
(interactive)
|
||||
(let ((line 0) (col 0) (w (selected-window))
|
||||
(ccls (and (memq major-mode '(c-mode c++-mode objc-mode)) (eq c-c++-backend 'lsp-ccls)))
|
||||
(start-line (1- (line-number-at-pos (window-start))))
|
||||
(end-line (1- (line-number-at-pos (window-end))))
|
||||
ranges point0 point1
|
||||
candidates)
|
||||
(ccls (and (memq major-mode '(c-mode c++-mode objc-mode)) (eq c-c++-backend 'lsp-ccls)))
|
||||
(start-line (1- (line-number-at-pos (window-start))))
|
||||
(end-line (1- (line-number-at-pos (window-end))))
|
||||
ranges point0 point1
|
||||
candidates)
|
||||
(save-excursion
|
||||
(goto-char 1)
|
||||
(cl-loop for loc in
|
||||
(lsp--send-request (lsp--make-request
|
||||
"textDocument/documentSymbol"
|
||||
`(:textDocument ,(lsp--text-document-identifier)
|
||||
:all ,(if all t :json-false)
|
||||
:startLine ,start-line :endLine ,end-line)))
|
||||
for range = (if ccls loc (->> loc (gethash "location") (gethash "range")))
|
||||
for range_start = (gethash "start" range)
|
||||
for range_end = (gethash "end" range)
|
||||
for l0 = (gethash "line" range_start)
|
||||
for c0 = (gethash "character" range_start)
|
||||
for l1 = (gethash "line" range_end)
|
||||
for c1 = (gethash "character" range_end)
|
||||
while (<= l0 end-line)
|
||||
when (>= l0 start-line)
|
||||
do
|
||||
(forward-line (- l0 line))
|
||||
(forward-char c0)
|
||||
(setq point0 (point))
|
||||
(forward-line (- l1 l0))
|
||||
(forward-char c1)
|
||||
(setq point1 (point))
|
||||
(setq line l1 col c1)
|
||||
(push `((,point0 . ,point1) . ,w) candidates)))
|
||||
(lsp--send-request (lsp--make-request
|
||||
"textDocument/documentSymbol"
|
||||
`(:textDocument ,(lsp--text-document-identifier)
|
||||
:all ,(if all t :json-false)
|
||||
:startLine ,start-line :endLine ,end-line)))
|
||||
for range = (if ccls loc (->> loc (gethash "location") (gethash "range")))
|
||||
for range_start = (gethash "start" range)
|
||||
for range_end = (gethash "end" range)
|
||||
for l0 = (gethash "line" range_start)
|
||||
for c0 = (gethash "character" range_start)
|
||||
for l1 = (gethash "line" range_end)
|
||||
for c1 = (gethash "character" range_end)
|
||||
while (<= l0 end-line)
|
||||
when (>= l0 start-line)
|
||||
do
|
||||
(forward-line (- l0 line))
|
||||
(forward-char c0)
|
||||
(setq point0 (point))
|
||||
(forward-line (- l1 l0))
|
||||
(forward-char c1)
|
||||
(setq point1 (point))
|
||||
(setq line l1 col c1)
|
||||
(push `((,point0 . ,point1) . ,w) candidates)))
|
||||
;; (require 'avy)
|
||||
(avy-with avy-document-symbol
|
||||
(avy--process candidates
|
||||
(avy--style-fn avy-style)))))
|
||||
(avy--style-fn avy-style)))))
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
(defconst lsp-packages
|
||||
'(
|
||||
lsp-mode
|
||||
lsp-ui
|
||||
(company-lsp :requires company)
|
||||
))
|
||||
lsp-mode
|
||||
lsp-ui
|
||||
(company-lsp :requires company)
|
||||
helm-lsp
|
||||
lsp-treemacs
|
||||
))
|
||||
|
||||
(defun lsp/init-lsp-mode ()
|
||||
(use-package lsp-mode
|
||||
|
@ -48,3 +50,9 @@
|
|||
|
||||
(defun lsp/init-company-lsp ()
|
||||
(use-package company-lsp :defer t))
|
||||
|
||||
(defun lsp/init-helm-lsp ()
|
||||
(use-package helm-lsp :defer t))
|
||||
|
||||
(defun lsp/init-lsp-treemacs ()
|
||||
(use-package lsp-treemacs :defer t))
|
||||
|
|
Loading…
Reference in a new issue