Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple support for workspaceFolders #893

Closed
wants to merge 1 commit into from

Conversation

nemethf
Copy link
Collaborator

@nemethf nemethf commented Mar 20, 2022

Fixes #890.

I haven't tested the workspace/workspaceFolders request, because I don't know any servers that sends this. But this part of the PR is quite trivial.


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.

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.
@joaotavora
Copy link
Owner

Read it, looks rather perfect. :) Two questions

  1. Man that uniquify thing is tricky indeed. Doesn't this make some "garbage" dired buffers behind the user's back? Even in the common case, it opens the main root right? Shouldn't we clean up? I know it's more boring code, but still...

  2. If rootURI and rootPath are deprecated, is it ok to provide both wsfolders and these other two at the same time?

@joaotavora
Copy link
Owner

Also aren't there some server capability checks in order?

@nemethf
Copy link
Collaborator Author

nemethf commented Mar 20, 2022

1. Man that uniquify thing is tricky indeed. Doesn't this make some "garbage" dired buffers behind the user's back? Even in the common case, it opens the main root right? Shouldn't we clean up? I know it's more boring code, but still...

Yes, garbage buffers are left behind. Should I make an attempt to clean them? Personally I think it's not a problem.

2. If rootURI and rootPath are deprecated, is it ok to provide both wsfolders and these other two at the same time?

I think so. The client doesn't know whether the server supports workspace-folders before receiving the server-capabilities.

Also aren't there some server capability checks in order?

Can you elaborate?

@joaotavora
Copy link
Owner

Yes, garbage buffers are left behind. Should I make an attempt to clean them?

I don't think the normal user would like a surprising dired buffer to appear as a result of M-x eglot. Thinking about this, I would err on the side of simplicity, don't care about uniquified folder names, and just use file-name-base for getting the name.
Else, you must use find-buffer-visiting to check which ones are already open beforehand, then use cl-intersection to find the ones you have to kill in an unwind-protect unwind block.

I think my simplistic suggestion where in some (presumably edge) cases we get duplicate names is much better. The server itself can always disambiguate them with the URI, right? Does the spec suggest otherwise?

I think so. The client doesn't know whether the server supports workspace-folders before receiving the server-capabilities.

Also aren't there some server capability checks in order?
Can you elaborate?

No need. You just answered in the previous line :-) There are no server caps to check because we don't have the list yet. So that part is fine.

@nemethf
Copy link
Collaborator Author

nemethf commented Mar 20, 2022

I would err on the side of simplicity, don't care about uniquified folder names, and just use file-name-base for getting the name.

I'm OK with file-name-base, but how about abbreviate-file-name instead?

(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))))))

I think my simplistic suggestion where in some (presumably edge) cases we get duplicate names is much better. The server itself can always disambiguate them with the URI, right? Does the spec suggest otherwise?

The specification mentions just this: "The name of the workspace folder. Used to refer to this workspace folder in the user interface." So I think the servers do not care; in some notifications they might refer to a workspace by its name, and the user should recognize the name.

@joaotavora
Copy link
Owner

I don't know what abbreviate-file-name does, but it sure sounds promising, so yes, go ahead :-)

@nemethf nemethf closed this in 9eb9353 Mar 20, 2022
@joaotavora
Copy link
Owner

Can you add this to the NEWS.md file too. I think it's reasonably relevant. Sorry I forgot to mention that :-)

@nemethf
Copy link
Collaborator Author

nemethf commented Mar 21, 2022

Can you add this to the NEWS.md file too.
done

bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 18, 2022
Close joaotavora/eglot#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.
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
Close joaotavora/eglot#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.
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
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.

#893: joaotavora/eglot#893
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 12, 2022
Close joaotavora/eglot#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.
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 20, 2022
Close joaotavora/eglot#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants