go icon indicating copy to clipboard operation
go copied to clipboard

x/tools/gopls: automatically include open packages in the workspace

Open findleyr opened this issue 1 year ago • 1 comments

Noticed indirectly via #53933: when packages are outside of the workspace, autocompletion stops working because it operates on packages in "TypeCheckWorkspace" mode, which means it does have function bodies for packages outside of the workspace.

That's not wrong, but we should automatically include any open packages in the workspace.

For the most part it should "just work" to adjust our workspace package algorithm, we just need to be sure to recompute workspace packages (snapshot.computeWorkspacePackages) following any didOpen or didClose event.

This is low-hanging fruit, as particularly with #53880 it could significantly improve the user experience with go.work files when opening a package outside the workspace: some functionality will still work, and the user will be alerted that other functionality will be degraded.

findleyr avatar Aug 04 '22 16:08 findleyr

While working on an unrelated test, I realized that the heuristic is not quite right: we should not "include all packages containing open files" in the workspace, but rather "ensure that PackagesForFile(x) for all open files x is included in the workspace". The reason for this is actually subtle: if we reinitialize the view, we may not ask for PackagesForFile for files that aren't included in the workspace, so there is a chicken-and-egg problem.

findleyr avatar Aug 05 '22 19:08 findleyr

Since this isn't critical for v0.12, moving to v0.13.

findleyr avatar May 03 '23 18:05 findleyr

Redundant with zero-config.

findleyr avatar Nov 15 '23 19:11 findleyr