Commit 9c8ec1d
authored
fix(lsp-mode): tolerate buffers whose major mode has no language spec (#2193)
* fix(lsp-mode): tolerate buffers whose major mode has no language spec
get-language-spec asserted the per-symbol property was a spec
instance, but its callers (buffer-language-spec, etc.) already use
when-let against the result -- they expect nil for modes that should
not activate LSP. The assertion crashed the editor command loop
whenever a buffer's major mode lacked a registered spec.
This is reachable in normal use. clojure-repl-mode (and similar
listener-style modes) inherits from clojure-mode, which registers a
spec. The parent activation fires *clojure-mode-hook* ->
enable-lsp-mode, which starts an async workspace connect. By the
time the workspace's :then callback fires text-document/did-open,
the buffer's major mode has switched to clojure-repl-mode (no spec)
and get-language-spec crashed. Even if the open was skipped, the
buffer kept lsp-mode's before-change hook, so the next keystroke
hit text-document/did-change -> find-workspace nil -> error.
Push the guard down to where it belongs -- the LSP request
functions themselves -- so every callsite stays a single,
unconditional invocation:
- get-language-spec returns nil for unregistered modes, matching
the when-let contract its callers already assume.
- find-workspace returns nil silently when language-id is nil,
regardless of :errorp. A nil language-id means the buffer is
not an LSP buffer -- not a runtime failure.
- text-document/did-open, did-change, did-save, and did-close all
wrap their request body in (when-let (workspace
(buffer-workspace buffer nil)) ...), so a buffer that has no
workspace (no spec, or workspace not yet connected) becomes a
silent no-op instead of crashing on workspace-client nil.
LSP remains fully functional for any buffer whose major mode is
registered; non-LSP buffers (REPL transcripts, etc.) become no-ops
on the relevant hooks.
* test(lsp-mode): cover spec/workspace nil-tolerant lookups
Two deftests guard the regressions the previous commit fixed:
- get-language-spec returns nil for an unregistered mode (the path
that previously asserted and crashed the editor command loop the
first time a REPL-style buffer interacted with lsp-mode).
- find-workspace returns nil for a nil language-id even with
:errorp t (the default path that previously signaled
"The NIL workspace is not found." on the next keystroke).
Verified both fail when the source fix is reverted.1 parent 8919e53 commit 9c8ec1d
4 files changed
Lines changed: 89 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
238 | 243 | | |
239 | 244 | | |
240 | 245 | | |
| |||
613 | 618 | | |
614 | 619 | | |
615 | 620 | | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
621 | 627 | | |
622 | 628 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
632 | 639 | | |
633 | 640 | | |
634 | 641 | | |
| |||
644 | 651 | | |
645 | 652 | | |
646 | 653 | | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
654 | 662 | | |
655 | 663 | | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
661 | 670 | | |
662 | 671 | | |
663 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | | - | |
52 | | - | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments