Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Feature Request: Open Package in new window #1928

Closed
davidwkeith opened this issue Sep 13, 2018 · 11 comments
Closed

Feature Request: Open Package in new window #1928

davidwkeith opened this issue Sep 13, 2018 · 11 comments

Comments

@davidwkeith
Copy link

Similar to the URL detection in VSCode's terminal, when hovering over a supported import string (eg "github.com/google/uuid") the string would become underlined with a tool tip to "Cmd + click open source" (or appropriate OS modifier key)

When clicked it would open the source import path. This could be new window, or just navigating to the source in the file tree view, depending on the project root.

Extra cool would be an option to open the appropriate web page (but that can get complicated if it is not a top level package in a repo)

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 18, 2018

Is the expectation to see the contents of the package?

Currently, when your cursor is on one of the packages in the import block, you can run Go: Browse Packages. That will open all the files in the package for you to navigate to.

You can also run Go: Add Package to Workspace at this point to open the package as another root in the explorer.

@davidwkeith
Copy link
Author

Those are great, but neither does quiet what I hoped.

  • Go: Browser Packages: Does not auto jump to the currently package, still need to search, then browsing the files inside the package is not great.
  • Go: Add Package to Workspace: The package is already in the workspace, I get "Could not find package…"

Ultimately the command would be Go: Open Package in File Tree that would open vendor/github.com/google/uuid in the file tree, and maybe load uuid.go from that directory in the editor (or README if it were super advanced)

Closest command I have found is "Go to Definition" contextual menu, which works on package contents, but not the package name itself.

@ramya-rao-a
Copy link
Contributor

Go: Browser Packages: Does not auto jump to the currently package, still need to search, then browsing the files inside the package is not great.

Keeping the cursor on the package in the import block and then calling Go: Browse Packages does indeed open the drop down with package files. If the package was already open in the workspace, and you selected one of the files from the drop down, the file explorer would automatically show the file that was opened.

@axetroy
Copy link

axetroy commented Oct 3, 2018

I have been expecting this feature for a long long time, but it has never been implemented.

In fact goLand integrates this function very well.

This is worth learning and reference.

those great feature in goLand:

1. Tree View for External Libries

2018-10-03 10 48 28

2. command-click to navigate to the import's source

2018-10-03 10 50 46

It is undeniable that goLand is a commercial software and does have a lot to learn.

I also hope to use these features in vscode.

@ramya-rao-a
Copy link
Contributor

@davidwkeith

Go: Add Package to Workspace: The package is already in the workspace, I get "Could not find package…"

Can you elaborate on this? Was the package under the main folder that you had already opened in VS Code? Or were you in a multi-root workspace set up and the package was one of the top level folders already opened?

@davidwkeith , @axetroy

Cmd-click is reserved for the Go to definition feature in VS Code.
Extensions are supposed to provide one or more locations (file path + position in the file) for each symbol that has been Cmd-clicked, which VS Code then opens in a new tab.

Similar to the URL detection in VSCode's terminal, when hovering over a supported import string (eg "github.com/google/uuid") the string would become underlined with a tool tip to "Cmd + click open source" (or appropriate OS modifier key)
When clicked it would open the source import path. This could be new window, or just navigating to the source in the file tree view, depending on the project root.

I still believe Go: Add Package to Workspace command is the right thing to do when you want to open the package under the cursor in the file explorer. Please let me know if this doesn't work for you.

To open the package in a new window, we can definitely support a new command called say Go: Open Package in new Window

PRs are welcome if anyone wants to give this a try

Code Pointers:

  • Build and Debug extension
  • Refer to addImportToWorkspace which implements the Go: Add Package to Workspace command. You will be sharing a lot of code from here.
  • To finally register the command, you need to add it to the package.json and goMain.ts file. Again use the Go: Add Package to Workspace command as a reference
  • To actually open the folder, see below
let uri = Uri.file('/some/path/to/folder');
vscode.commands.executeCommand('vscode.openFolder', uri);

@axetroy
Copy link

axetroy commented Dec 31, 2018

After a few months, can someone achieve this feature?

Because of this feature, I had to use Goland.

But I really like VS Code. This is really regrettable.

@ramya-rao-a ramya-rao-a changed the title Feature Request: command-click to navigate to the import's source Feature Request: Open Package in new window Jan 29, 2019
@stamblerre
Copy link
Contributor

gopls supports this feature, and it will offer a list of files to jump to after CL 210321 is submitted. @ramya-rao-a: Is that sufficient for us to close this issue?

@ramya-rao-a
Copy link
Contributor

Looks like the upstream code has been merged.

@stamblerre, Can you explain how this feature will work? We can close the issue after that

@stamblerre
Copy link
Contributor

Screen Shot 2020-03-16 at 12 32 41 PM

Now, clicking go to definition on an import line gives you a list of files to choose from. This achieves #2 in @axetroy's request. I'm not sure if that's sufficient here, but it may be.

2. command-click to navigate to the import's source

2018-10-03 10 50 46

@ramya-rao-a
Copy link
Contributor

Now, clicking go to definition on an import line gives you a list of files to choose from.

This was already available via the Go: Browse Packages cmd when invoked after keeping the cursor on the import line

I believe the ask is more towards the ability to open the folder to the package in the file explorer. If the package is not already part of the current workspace, then perhaps adding it to the workspace

@ramya-rao-a
Copy link
Contributor

When clicked it would open the source import path. This could be new window, or just navigating to the source in the file tree view, depending on the project root.
Extra cool would be an option to open the appropriate web page (but that can get complicated if it is not a top level package in a repo)

The original ask has been addressed by the use of language server i.e navigating to the source path and the web page

Go: Add Package to Workspace can be used to add the package to the workspace.

To open the package in a new folder is not a feature we will be investing anytime soon, but can be implemented independent of this package in a separate extension.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants