Skip to content

Commit 9eb9353

Browse files
committed
Add simple support for workspaceFolders
Close #893. Clients can support workspaceFolders since LSP 3.6. rootUri and rootPath are deprecated. Dynamic changes in folders are not supported, i.e., this patch does not implement workspace/didChangeWorkspaceFolders. * eglot.el (eglot-client-capabilities): Add capability `workspaceFolders'. (eglot-workspace-folders): New cl-defgeneric. (eglot--connect): Add workspaceFolders to initializeParams. (eglot-handle-request workspace/workspaceFolders): New cl-defmethod.
1 parent f775187 commit 9eb9353

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

eglot.el

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ treated as in `eglot-dbind'."
654654
`(:dynamicRegistration
655655
,(if (eglot--trampish-p s) :json-false t))
656656
:symbol `(:dynamicRegistration :json-false)
657-
:configuration t)
657+
:configuration t
658+
:workspaceFolders t)
658659
:textDocument
659660
(list
660661
:synchronization (list
@@ -719,6 +720,15 @@ treated as in `eglot-dbind'."
719720
#'car eglot--tag-faces)])))
720721
:experimental eglot--{})))
721722

723+
(cl-defgeneric eglot-workspace-folders (server)
724+
"Return workspaceFolders for SERVER."
725+
(let ((project (eglot--project server)))
726+
(vconcat
727+
(mapcar (lambda (dir)
728+
(list :uri (eglot--path-to-uri dir)
729+
:name (abbreviate-file-name dir)))
730+
`(,(project-root project) ,@(project-external-roots project))))))
731+
722732
(defclass eglot-lsp-server (jsonrpc-process-connection)
723733
((project-nickname
724734
:documentation "Short nickname for the associated project."
@@ -1164,7 +1174,8 @@ This docstring appeases checkdoc, that's all."
11641174
:rootUri (eglot--path-to-uri default-directory)
11651175
:initializationOptions (eglot-initialization-options
11661176
server)
1167-
:capabilities (eglot-client-capabilities server))
1177+
:capabilities (eglot-client-capabilities server)
1178+
:workspaceFolders (eglot-workspace-folders server))
11681179
:success-fn
11691180
(eglot--lambda ((InitializeResult) capabilities serverInfo)
11701181
(unless cancelled
@@ -1924,6 +1935,11 @@ THINGS are either registrations or unregisterations (sic)."
19241935
"Handle server request workspace/applyEdit."
19251936
(eglot--apply-workspace-edit edit eglot-confirm-server-initiated-edits))
19261937

1938+
(cl-defmethod eglot-handle-request
1939+
(server (_method (eql workspace/workspaceFolders)))
1940+
"Handle server request workspace/workspaceFolders."
1941+
(eglot-workspace-folders server))
1942+
19271943
(defun eglot--TextDocumentIdentifier ()
19281944
"Compute TextDocumentIdentifier object for current buffer."
19291945
`(:uri ,(eglot--path-to-uri (or buffer-file-name

0 commit comments

Comments
 (0)