Skip to content

Commit fb88cc6

Browse files
authored
Prefer buffer's major mode for rendering strings. (#4322)
Currently, when multiple major modes exist and are available for a language (e.g., c-mode and c-ts-mode), the major mode used to render strings is determined by the ordering of these modes within `lsp-language-id-configuration'. This ordering doesn't necessarily reflect the preference of the user. This change alters this behavior by preferring to render strings, whose language matches that of the current buffer, with the same major mode as the buffer. When the string's language is different from the buffer, the behavior falls back to selecting the first major mode matching the language from `lsp-language-id-configuration'.
1 parent b2e5438 commit fb88cc6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lsp-mode.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5516,10 +5516,11 @@ In addition, each can have property:
55165516
"Render STR using `major-mode' corresponding to LANGUAGE.
55175517
When language is nil render as markup if `markdown-mode' is loaded."
55185518
(setq str (s-replace "\r" "" (or str "")))
5519-
(if-let ((mode (-some (-lambda ((mode . lang))
5520-
(when (and (equal lang language) (functionp mode))
5521-
mode))
5522-
lsp-language-id-configuration)))
5519+
(if-let* ((modes (-keep (-lambda ((mode . lang))
5520+
(when (and (equal lang language) (functionp mode))
5521+
mode))
5522+
lsp-language-id-configuration))
5523+
(mode (car (or (member major-mode modes) modes))))
55235524
(lsp--fontlock-with-mode str mode)
55245525
str))
55255526

0 commit comments

Comments
 (0)