"Return logical Eglot server for current buffer, nil if none."
(setq eglot--cached-server
(or eglot--cached-server
- (cl-find major-mode
- (gethash (eglot--current-project) eglot--servers-by-project)
- :key #'eglot--major-modes
- :test #'memq)
+ (cl-find-if #'eglot--languageId
+ (gethash (eglot--current-project)
+ eglot--servers-by-project))
(and eglot-extend-to-xref
buffer-file-name
(gethash (expand-file-name buffer-file-name)
(append (eglot--TextDocumentIdentifier)
`(:version ,eglot--versioned-identifier)))
+(cl-defun eglot--languageId (&optional (server (eglot--current-server-or-lose)))
+ "Compute LSP \\='languageId\\=' string for current buffer.
+Doubles as an predicate telling if SERVER can manage current
+buffer."
+ (cl-loop for (mode . languageid) in
+ (eglot--languages server)
+ when (provided-mode-derived-p major-mode mode)
+ return languageid))
+
(defun eglot--TextDocumentItem ()
"Compute TextDocumentItem object for current buffer."
(append
(eglot--VersionedTextDocumentIdentifier)
- (list :languageId
- (alist-get major-mode (eglot--languages (eglot--current-server-or-lose)))
+ (list :languageId (eglot--languageId)
:text
(eglot--widening
(buffer-substring-no-properties (point-min) (point-max))))))