@@ -2218,27 +2218,34 @@ WORKSPACE is the workspace that contains the diagnostics."
2218
2218
2219
2219
2220
2220
;; keybindings
2221
+ (defvar lsp--binding-descriptions nil
2222
+ "List of key binding/short description pair.")
2221
2223
2222
- (defmacro lsp-define-conditional-key (keymap key def cond &rest bindings)
2224
+ (defmacro lsp-define-conditional-key (keymap key def desc cond &rest bindings)
2223
2225
"In KEYMAP, define key sequence KEY as DEF conditionally.
2224
2226
This is like `define-key', except the definition disappears
2225
2227
whenever COND evaluates to nil.
2226
- BINDINGS is a list of (key def cond)."
2228
+ DESC is the short-description for the binding.
2229
+ BINDINGS is a list of (key def desc cond)."
2227
2230
(declare (indent defun)
2228
- (debug (form form form form &rest sexp)))
2229
- (->> (cl-list* key def cond bindings)
2230
- (-partition 3)
2231
- (-map (-lambda ((key def cond))
2232
- `(define-key ,keymap ,key
2233
- '(menu-item
2234
- ,(format "maybe-%s" def)
2235
- ,def
2236
- :filter (lambda (item)
2237
- (when (with-current-buffer (or (when (buffer-live-p lsp--describe-buffer)
2238
- lsp--describe-buffer)
2239
- (current-buffer))
2240
- ,cond)
2241
- item))))))
2231
+ (debug (form form form form form &rest sexp)))
2232
+ (->> (cl-list* key def desc cond bindings)
2233
+ (-partition 4)
2234
+ (-mapcat (-lambda ((key def desc cond))
2235
+ `((define-key ,keymap ,key
2236
+ '(menu-item
2237
+ ,(format "maybe-%s" def)
2238
+ ,def
2239
+ :filter
2240
+ (lambda (item)
2241
+ (when (with-current-buffer (or (when (buffer-live-p lsp--describe-buffer)
2242
+ lsp--describe-buffer)
2243
+ (current-buffer))
2244
+ ,cond)
2245
+ item))))
2246
+ (when (stringp ,key)
2247
+ (setq lsp--binding-descriptions
2248
+ (nconc lsp--binding-descriptions '(,key ,desc)))))))
2242
2249
macroexp-progn))
2243
2250
2244
2251
(defvar lsp--describe-buffer nil)
@@ -2261,70 +2268,76 @@ BINDINGS is a list of (key def cond)."
2261
2268
(-doto (make-sparse-keymap)
2262
2269
(lsp-define-conditional-key
2263
2270
;; sessions
2264
- "sr " lsp-workspace-restart (lsp-workspaces)
2265
- "ss " lsp t
2266
- "sq" lsp-workspace-shutdown (lsp-workspaces)
2267
- "sd " lsp-describe-session t
2268
- "sD " lsp-disconnect (lsp-workspaces)
2271
+ "sD " lsp-disconnect "disconnect" (lsp-workspaces)
2272
+ "sd " lsp-describe-session "describe session" t
2273
+ "sq" lsp-workspace-shutdown "shutdown server" (lsp-workspaces)
2274
+ "sr " lsp-workspace-restart "restart server" (lsp-workspaces)
2275
+ "ss " lsp "start server" t
2269
2276
2270
2277
;; formatting
2271
- "==" lsp-format-buffer (or (lsp-feature? "textDocument/rangeFormatting")
2272
- (lsp-feature? "textDocument/formatting"))
2273
- "=r" lsp-format-region (lsp-feature? "textDocument/rangeFormatting")
2278
+ "==" lsp-format-buffer "format buffer" (or (lsp-feature? "textDocument/rangeFormatting")
2279
+ (lsp-feature? "textDocument/formatting"))
2280
+ "=r" lsp-format-region "format region" (lsp-feature? "textDocument/rangeFormatting")
2274
2281
2275
2282
;; folders
2276
- "Fa" lsp-workspace-folders-add t
2277
- "Fr " lsp-workspace-folders -remove t
2278
- "Fb " lsp-workspace-blacklist -remove t
2283
+ "Fa" lsp-workspace-folders-add "add folder" t
2284
+ "Fb " lsp-workspace-blacklist -remove "un-blacklist folder" t
2285
+ "Fr " lsp-workspace-folders -remove "remove folder" t
2279
2286
2280
2287
;; toggles
2281
- "Tl" lsp-lens-mode (lsp-feature? "textDocument/codeLens")
2282
- "TL" lsp-toggle-trace-io t
2283
- "Th" lsp-toggle-symbol-highlight (lsp-feature? "textDocument/documentHighlight")
2284
- "Tb" lsp-headerline-breadcrumb-mode (lsp-feature? "textDocument/documentSymbol")
2285
- "Ta" lsp-modeline-code-actions-mode (lsp-feature? "textDocument/codeAction")
2286
- "TD" lsp-modeline-diagnostics-mode (lsp-feature? "textDocument/publishDiagnostics")
2287
- "TS" lsp-ui-sideline-mode (featurep 'lsp-ui-sideline)
2288
- "Td" lsp-ui-doc-mode (featurep 'lsp-ui-doc)
2289
- "Ts" lsp-toggle-signature-auto-activate (lsp-feature? "textDocument/signatureHelp")
2290
- "Tf" lsp-toggle-on-type-formatting (lsp-feature? "textDocument/onTypeFormatting")
2291
- "TT" lsp-treemacs-sync-mode (featurep 'lsp-treemacs)
2288
+ "TD" lsp-modeline-diagnostics-mode "toggle modeline diagnostics" (lsp-feature?
2289
+ "textDocument/publishDiagnostics")
2290
+ "TL" lsp-toggle-trace-io "toggle log io" t
2291
+ "TS" lsp-ui-sideline-mode "toggle sideline" (featurep 'lsp-ui-sideline)
2292
+ "TT" lsp-treemacs-sync-mode "toggle treemacs integration" (featurep 'lsp-treemacs)
2293
+ "Ta" lsp-modeline-code-actions-mode "toggle modeline code actions" (lsp-feature?
2294
+ "textDocument/codeAction")
2295
+ "Tb" lsp-headerline-breadcrumb-mode "toggle breadcrumb" (lsp-feature?
2296
+ "textDocument/documentSymbol")
2297
+ "Td" lsp-ui-doc-mode "toggle documentation popup" (featurep 'lsp-ui-doc)
2298
+ "Tf" lsp-toggle-on-type-formatting "toggle on type formatting" (lsp-feature?
2299
+ "textDocument/onTypeFormatting")
2300
+ "Th" lsp-toggle-symbol-highlight "toggle highlighting" (lsp-feature? "textDocument/documentHighlight")
2301
+ "Tl" lsp-lens-mode "toggle lenses" (lsp-feature? "textDocument/codeLens")
2302
+ "Ts" lsp-toggle-signature-auto-activate "toggle signature" (lsp-feature? "textDocument/signatureHelp")
2292
2303
2293
2304
;; goto
2294
- "gg" lsp -find-definition (lsp-feature? "textDocument/definition ")
2295
- "gr " lsp-find-references (lsp-feature? "textDocument/references ")
2296
- "gi " lsp-find-implementation (lsp-feature? "textDocument/implementation" )
2297
- "gt " lsp-find-type- definition (lsp-feature? "textDocument/typeDefinition ")
2298
- "gd " lsp-find-declaration ( lsp-feature? "textDocument/declaration ")
2299
- "gh" lsp-treemacs-call-hierarchy (and (lsp-feature? "callHierarchy/incomingCalls" )
2300
- (fboundp ' lsp-treemacs-call-hierarchy) )
2301
- "ga" xref -find-apropos (lsp-feature? "workspace/symbol ")
2302
- "ge " lsp-treemacs-errors-list (fboundp ' lsp-treemacs-errors-list )
2305
+ "ga" xref -find-apropos "find symbol in workspace" (lsp-feature? "workspace/symbol ")
2306
+ "gd " lsp-find-declaration "find declarations" (lsp-feature? "textDocument/declaration ")
2307
+ "ge " lsp-treemacs-errors-list "show errors" (fboundp 'lsp-treemacs-errors-list )
2308
+ "gg " lsp-find-definition "find definitions" (lsp-feature? "textDocument/definition ")
2309
+ "gh " lsp-treemacs-call-hierarchy "call hierarchy" (and ( lsp-feature? "callHierarchy/incomingCalls ")
2310
+ (fboundp ' lsp-treemacs-call-hierarchy) )
2311
+ "gi" lsp-find-implementation "find implementations" ( lsp-feature? "textDocument/implementation" )
2312
+ "gr" lsp -find-references "find references" (lsp-feature? "textDocument/references ")
2313
+ "gt " lsp-find-type-definition "find type definition" ( lsp-feature? "textDocument/typeDefinition" )
2303
2314
2304
2315
;; help
2305
- "hh " lsp-describe-thing-at-point ( lsp-feature? "textDocument/hover" )
2306
- "hs" lsp-signature-activate (lsp-feature? "textDocument/signatureHelp" )
2307
- "hg " lsp-ui-doc-glance (and (featurep ' lsp-ui-doc )
2308
- (lsp-feature? "textDocument/hover") )
2316
+ "hg " lsp-ui-doc-glance "glance symbol" (and (featurep ' lsp-ui-doc )
2317
+ (lsp-feature? "textDocument/hover") )
2318
+ "hh " lsp-describe-thing-at-point "describe symbol at point" ( lsp-feature? "textDocument/hover" )
2319
+ "hs" lsp-signature-activate "signature help" (lsp-feature? "textDocument/signatureHelp" )
2309
2320
2310
2321
;; refactoring
2311
- "rr " lsp-rename (lsp-feature? "textDocument/rename ")
2312
- "ro " lsp-organize-imports (lsp-feature? "textDocument/codeAction ")
2322
+ "ro " lsp-organize-imports "organize imports" (lsp-feature? "textDocument/codeAction ")
2323
+ "rr " lsp-rename "rename" (lsp-feature? "textDocument/rename ")
2313
2324
2314
2325
;; actions
2315
- "aa" lsp-execute-code-action (lsp-feature? "textDocument/codeAction")
2316
- "al " lsp-avy-lens (and (bound-and-true-p lsp-lens-mode) (featurep 'avy) )
2317
- "ah " lsp-document-highlight ( lsp-feature? "textDocument/documentHighlight" )
2326
+ "aa" lsp-execute-code-action "code actions" (lsp-feature? "textDocument/codeAction")
2327
+ "ah " lsp-document-highlight "highlight symbol" ( lsp-feature? "textDocument/documentHighlight" )
2328
+ "al " lsp-avy-lens "lens" (and (bound-and-true-p lsp-lens-mode) (featurep 'avy) )
2318
2329
2319
2330
;; peeks
2320
- "Gg" lsp-ui-peek-find-definitions (and (lsp-feature? "textDocument/definition")
2321
- (fboundp 'lsp-ui-peek-find-definitions))
2322
- "Gr" lsp-ui-peek-find-references (and (fboundp 'lsp-ui-peek-find-references)
2323
- (lsp-feature? "textDocument/references"))
2324
- "Gi" lsp-ui-peek-find-implementation (and (fboundp 'lsp-ui-peek-find-implementation)
2325
- (lsp-feature? "textDocument/implementation"))
2326
- "Gs" lsp-ui-peek-find-workspace-symbol (and (fboundp 'lsp-ui-peek-find-workspace-symbol)
2327
- (lsp-feature? "workspace/symbol")))))
2331
+ "Gg" lsp-ui-peek-find-definitions "peek definitions" (and (lsp-feature? "textDocument/definition")
2332
+ (fboundp 'lsp-ui-peek-find-definitions))
2333
+ "Gi" lsp-ui-peek-find-implementation "peek implementations" (and
2334
+ (fboundp 'lsp-ui-peek-find-implementation)
2335
+ (lsp-feature? "textDocument/implementation"))
2336
+ "Gr" lsp-ui-peek-find-references "peek references" (and (fboundp 'lsp-ui-peek-find-references)
2337
+ (lsp-feature? "textDocument/references"))
2338
+ "Gs" lsp-ui-peek-find-workspace-symbol "peek workspace symbol" (and (fboundp
2339
+ 'lsp-ui-peek-find-workspace-symbol)
2340
+ (lsp-feature? "workspace/symbol")))))
2328
2341
2329
2342
2330
2343
;; which-key integration
@@ -2341,65 +2354,18 @@ active `major-mode', or for all major modes when ALL-MODES is t."
2341
2354
(apply
2342
2355
#'which-key-fn
2343
2356
(lsp--prepend-prefix
2344
- (list
2345
- "" "lsp"
2346
- "s" "sessions"
2347
- "s s" "start server"
2348
- "s r" "restart server"
2349
- "s q" "shutdown server"
2350
- "s d" "describe session"
2351
- "s D" "disconnect"
2352
-
2353
- "F" "folders"
2354
- "F a" "add folder"
2355
- "F r" "remove folder"
2356
- "F b" "un-blacklist folder"
2357
-
2358
- "=" "formatting"
2359
- "= r" "format region"
2360
- "= =" "format buffer"
2361
-
2362
- "T" "toggle"
2363
- "T l" "toggle lenses"
2364
- "T h" "toggle highlighting"
2365
- "T L" "toggle log io"
2366
- "T s" "toggle signature"
2367
- "T a" "toggle modeline code actions"
2368
- "T S" "toggle sideline"
2369
- "T d" "toggle documentation popup"
2370
- "T p" "toggle signature help"
2371
- "T f" "toggle on type formatting"
2372
- "T T" "toggle treemacs integration"
2373
-
2374
- "g" "goto"
2375
- "g g" "find definitions"
2376
- "g r" "find references"
2377
- "g i" "find implementations"
2378
- "g d" "find declarations"
2379
- "g t" "find type definition"
2380
- "g h" "call hierarchy"
2381
- "g a" "find symbol in workspace"
2382
- "g A" "find symbol in all workspaces"
2383
- "g e" "show errors"
2384
-
2385
- "h" "help"
2386
- "h h" "describe symbol at point"
2387
- "h s" "signature help"
2388
-
2389
- "r" "refactor"
2390
- "r r" "rename"
2391
- "r o" "organize imports"
2392
-
2393
- "a" "code actions"
2394
- "a a" "code actions"
2395
- "a l" "lens"
2396
- "a h" "highlight symbol"
2397
-
2398
- "G" "peek"
2399
- "G g" "peek definitions"
2400
- "G r" "peek references"
2401
- "G i" "peek implementations"
2402
- "G s" "peek workspace symbol")))))
2357
+ (nconc
2358
+ '("" "lsp"
2359
+ "s" "sessions"
2360
+ "F" "folders"
2361
+ "=" "formatting"
2362
+ "T" "toggle"
2363
+ "g" "goto"
2364
+ "h" "help"
2365
+ "r" "refactor"
2366
+ "a" "code actions"
2367
+ "G" "peek")
2368
+ lsp--binding-descriptions)))))
2403
2369
2404
2370
2405
2371
;; Globbing syntax
0 commit comments