Skip to content

Commit

Permalink
Add simple support for workspaceFolders
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nemethf committed Mar 20, 2022
1 parent f775187 commit 9eb9353
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ treated as in `eglot-dbind'."
`(:dynamicRegistration
,(if (eglot--trampish-p s) :json-false t))
:symbol `(:dynamicRegistration :json-false)
:configuration t)
:configuration t
:workspaceFolders t)
:textDocument
(list
:synchronization (list
Expand Down Expand Up @@ -719,6 +720,15 @@ treated as in `eglot-dbind'."
#'car eglot--tag-faces)])))
:experimental eglot--{})))

(cl-defgeneric eglot-workspace-folders (server)
"Return workspaceFolders for SERVER."
(let ((project (eglot--project server)))
(vconcat
(mapcar (lambda (dir)
(list :uri (eglot--path-to-uri dir)
:name (abbreviate-file-name dir)))
`(,(project-root project) ,@(project-external-roots project))))))

(defclass eglot-lsp-server (jsonrpc-process-connection)
((project-nickname
:documentation "Short nickname for the associated project."
Expand Down Expand Up @@ -1164,7 +1174,8 @@ This docstring appeases checkdoc, that's all."
:rootUri (eglot--path-to-uri default-directory)
:initializationOptions (eglot-initialization-options
server)
:capabilities (eglot-client-capabilities server))
:capabilities (eglot-client-capabilities server)
:workspaceFolders (eglot-workspace-folders server))
:success-fn
(eglot--lambda ((InitializeResult) capabilities serverInfo)
(unless cancelled
Expand Down Expand Up @@ -1924,6 +1935,11 @@ THINGS are either registrations or unregisterations (sic)."
"Handle server request workspace/applyEdit."
(eglot--apply-workspace-edit edit eglot-confirm-server-initiated-edits))

(cl-defmethod eglot-handle-request
(server (_method (eql workspace/workspaceFolders)))
"Handle server request workspace/workspaceFolders."
(eglot-workspace-folders server))

(defun eglot--TextDocumentIdentifier ()
"Compute TextDocumentIdentifier object for current buffer."
`(:uri ,(eglot--path-to-uri (or buffer-file-name
Expand Down

0 comments on commit 9eb9353

Please sign in to comment.