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

Ability to add dependencies in go.mod to search #2080

Closed
thedadams opened this issue Feb 22, 2022 · 2 comments
Closed

Ability to add dependencies in go.mod to search #2080

thedadams opened this issue Feb 22, 2022 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@thedadams
Copy link

Is your feature request related to a problem? Please describe.
When running a program and trying to find a particular log message, I often use the "search everywhere" functionality to find the log message. This is problematic when this log message comes from a dependency of my program. The search functionality will not find the log message.

Similarly, it is not easy to open a file in a dependent package. It would be great to user cmd-p (or ctrl-p) to open the file dialog and be able to open files in dependent packages.

Describe the solution you'd like
I would like the vscode-go extension to somehow add the dependent files to search and the file opening dialog.

Describe alternatives you've considered
I understand that this may not be possible without scanning all dependencies on startup and holding them in memory (which may not even be possible). I also understand that the functionality I am looking for may not be possible with the vscode-go extension.

I will also add that there is a work-around here: to have a vendor file that contains all the dependencies of my program, but this would mean having multiple copies of the files on my hard driver (potentially one copy for every repo where a dependency exists) and would need to be manually updated every time a dependency changes.

Additional context
This may not be a constructive comment, but Goland handles this very nicely. This functionality is probably the only reason I used Goland over VSCode and vscode-go.

@gopherbot gopherbot added this to the Untriaged milestone Feb 22, 2022
@hyangah
Copy link
Contributor

hyangah commented Mar 1, 2022

@thedadams Do you mean VSCode's default search feature by the "search everywhere" functionality?
AFAIK this functionality is provided by VSCode itself and I don't see an API through which extensions can influence the scope of searched/indexed files.

Note: Our extension provides the symbol search feature and the results include all the third-party dependencies and standard libraries even when they are outside of the workspace). That's different from VSCode's pure text search or file name search.

However, I think you can still achieve what you want:

Most of all, keep in mind the source code of the third-party dependency is in the module cache (either your ${GOPATH}/pkg/mod or ${GOMOD} directories, or the local folder as specified in the replace-directive in your go.mod file). You need to help VS Code search those directories.

  • Option 1: You can use "Advanced search options" to include the directories. The 'files to include' accepts absolute paths too. Note that if you have a module cache shared by multiple projects, the module cache may contain libraries downloaded for other projects, so the results may look noisy.

  • Option 2: Configure your Go environment to create the dedicated module cache inside your workspace. For example,
    "go.toolsEnvVars": { "GOMODCACHE": "${workspaceRoot}/modcache" } will create the module cache in the modcache directory of the project root. The files and directories in the module cache will appear in your file explorer as well. You may want to configure gopls, VSCode's file search, and maybe .gitignore and other dot files to exclude some files in the GOMODCACHE directory. This will prevent sharing of the module cache among projects though and result in multiple copies of libraries in your computer. Also, if you update the dependency changes, the search results may include stale dependencies (like Option 1).

If that does not meet your need, I recommend opening an issue in the VS Code project issue tracker. If VS Code allows extensions to contribute to the search/index space, we are happy to implement the info provider.


In my test set up for Option2, I configured:

 "go.toolsEnvVars": {
     "GOMODCACHE": "${workspaceRoot}/modcache"
 },
 "gopls": {
     "build.directoryFilters": [
         "-modcache/cache",
     ]
 },
 "files.exclude": {
     "modcache/cache/**": true,
 },
 "files.watcherExclude": {
     "**/.git/objects/**": true,
     "**/.git/subtree-cache/**": true,
     "modcache/**": true,
 }

and in .gitignore, configured not to include modcache.

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 4, 2022
@gopherbot
Copy link
Collaborator

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants