From a38ce8b28fef2f50263d827aedb3394b795dac56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felici=C3=A1n=20N=C3=A9meth?= Date: Sun, 20 Mar 2022 09:50:15 +0100 Subject: [PATCH] Add simple support for workspacefolders Close https://github.com/joaotavora/eglot/issues/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. --- lisp/progmodes/eglot.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3bd2d844c8a..daf6c3e2376 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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 @@ -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." @@ -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 @@ -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 -- 2.39.5