-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: support single file mode #34160
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
Comments
I sometimes write small one-off programs for simple jobs or to experiment, for which this would be very handy. |
I think that the following relates to this issue, but apologies if it doesn't. In my app (a work-in-progress Go editor) I would like to be able to initialise gopls without a workspace. Then add a workspace when a project window is opened. Add another workspace if another project is opened, and so on. And when a project window is closed, remove the workspace folder from the list of folders Currently I cannot take this approach because if I send an I intend on working around this for now by making a special case for the first project to open, and initialising gopls at that point with a single workspace. And if another project is opened, add a workspace with a A couple of questions around this.
|
I've done some more reading, and I think that I was getting confused between multiple workspaces and multi-folder workspaces. If I understand correctly, a single language server (gopls) instance only supports a single workspace. And that workspace may support multiple folders. Although currently gopls only supports a workspace with at least one folder. Launching multiple vscode instances and looking for gopls processes appears to confirm this. So I'm going to keep it simple in my application, and launch a separate gopls instance for each of my open workspaces. That means that support for single file mode probably won't be of interest to me. (I think that #34111 looks like what I'm really after.) |
What about this: In the case of a single file mode, we expect a gopls user to send We grab these options from here: If we have an absolute path to a if singleFile != "" {
s.pendingFolders = []protocol.WorkspaceFolder{{
URI: "file://" + singleFile,
Name: path.Base(singleFile),
}}
} For the VSCode, we would need to update I tried it for myself and it seems to be working fine. There are some problems with locations that contain a lot of unrelated folders and files (like If this plan seems right, I can send a CL that implements it. :) |
Sorry for not replying earlier, @quasilyte. Thanks for thinking about this, but I'm hoping that we can avoid having an extra setting for this mode. We will be doing work on managing multiple module roots for Also commenting here as a reminder: We should remember to try to handle the case described in #37875 (comment). |
Change https://golang.org/cl/240099 mentions this issue: |
When the user opens an individual file in their editor, we don't offer any language features. This is because we don't know the module root. Should we have some hack just to support this mode? We could run
go env GOMOD
and assume that is the root (if that is empty, the directory of the file could be the root).Note that this will be particularly difficult, as we won't be able to initialize any views until we receive a
textDocument/didOpen
for the specific file.The text was updated successfully, but these errors were encountered: