golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.78k stars 727 forks source link

New Feature: Copy Go Package Path #3394

Closed xhd2015 closed 1 month ago

xhd2015 commented 1 month ago

Is your feature request related to a problem? Please describe. When working with go code, it is quite common to import packages by path, however I found there were no quick way to do this. I must go to the dir of the package I want to import, copy it's relative path, and concatenate that with the go module path to form a package path. It's just so painful how many times I needed to do this, and it's also too ineffective!

Describe the solution you'd like Add a quick action in vscode-go plugin to copy the go package path with one click.

Describe alternatives you've considered As described above, previously I manually concatenate strings together.

Additional context

I actually have made a vscode plugin that already does this, want to check here if it is generally needed by the community. If so, we may add it to vscode-go.

Step 1: copy

image

Step 2: paste

image

The repository is at https://github.com/xhd2015/VSCode-Ext-Copy-Go-Package-Path .

I'll later propose a PR for reviewing purpose.

Thanks.

hyangah commented 1 month ago

Good to develop and share the extension. I think it's good to have it a separate extension.

Ideally, users shouldn't worry about imports - users just start to use the package, and the language server should be able to auto-import the package (especially those already in the workspace). For example, in the following example, I didn't import counter package yet, but the language server recognizes the package and includes suggestions based on the API of the package. As I accept one of them, the language server provides the extra edit for the import block. This is the workflow we want to support.

Screenshot 2024-05-20 at 10 05 35 AM

We understand that currently some bugs in package imports sometimes prevent this ideal workflow. The gopls team is actively working on fixing and improving the import logic.

xhd2015 commented 1 month ago

Agreed, I'll publish the extension alone. Thansk.