]> git.eshelyaron.com Git - emacs.git/commitdiff
Add simple support for workspacefolders
authorFelicián Németh <felician.nemeth@gmail.com>
Sun, 20 Mar 2022 08:50:15 +0000 (09:50 +0100)
committerFelicián Németh <felician.nemeth@gmail.com>
Sun, 20 Mar 2022 16:53:21 +0000 (17:53 +0100)
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

index 3bd2d844c8a3cd784bcd0bd7e89be37b05c32676..daf6c3e23769148fbe87f94f967158fff4812d71 100644 (file)
@@ -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