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

Feature Request: export APIs #233

Open
hyangah opened this issue Jun 16, 2020 · 6 comments
Open

Feature Request: export APIs #233

hyangah opened this issue Jun 16, 2020 · 6 comments

Comments

@hyangah
Copy link
Contributor

hyangah commented Jun 16, 2020

activate can surface APIs that can be called by other extension.
Reference: https://code.visualstudio.com/api/references/vscode-api#extensions

We can consider to export information such as

(Feel free to add the wishlist :-))

For example, see the python extension's API.
https://github.com/microsoft/vscode-python/blob/6f770f198cde6df7661a63a7026c1e10e7ae42ba/src/client/api.ts

@hyangah hyangah added this to the Backlog milestone Aug 7, 2020
@hyangah
Copy link
Contributor Author

hyangah commented Sep 10, 2020

Also consider this application: #628

@firelizzard18
Copy link
Contributor

I would like to see getBinPath exported. I am writing extensions that use Go binaries, and I want to respect vscode-go's relevant settings. I can use go.tools.install (command) to install tools, so the remaining piece is getBinPath.

Access to the Go document symbol provider would have solved some issues I had with the Go test explorer. I can call the symbol provider through vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', uri), but I ran into issues with activation, where my extension would be loaded and called before vscode-go had initialized the symbol provider (at least, that's what I think was happening).

@hyangah
Copy link
Contributor Author

hyangah commented Aug 2, 2021

@firelizzard18 I discussed with a team internally. One of the concerns raised is the binary path itself may not be sufficient to run the tools in the same way the Go extension runs. The tools execution environment, flags (including those specified in the settings + flags the extension set) or cwd. For example, we plan to adopt gopls's experimental workspace module setting (or the proposed go.work) which may require the extension to determine the required flag or run commands in a gopls's super module directory outside the workspace. So, if your extension requires to mimic how the go extension would run the go command, I think either we should export all necessary info or let the go extension run the command on behalf of your request. Something like the followings. What do you all think?

  • approach 1: Export all necessary info - similar to python's
export interface ExtensionAPI {
    ...
    settings: {
        /**
         * Returns the execution command corresponding to the specified resource, taking into account
         * any workspace-specific settings for the workspace to which this resource belongs.
         */
        getExecutionCommand(toolName string, resource?: Resource): { binPath: string; flags?: string[]; env?: Object; cwd?: string } | undefined;
    };
};    
  • approach 2: delegate to Go extension
   // run the given tool with the provided args under the same environment the extension uses.
   // TODO: consider to take options and callback like Node.js child_process.exec.
   runTool(toolName string, args?: string[], resource?: resource): ChildProcess | undefined;

Re: extension gets ready -> How about having ready: Promise<void> in the API, that returns a Promise indicating whether this extension is ready?

export interface ExtensionAPI {
   // Promise indicating whether the extension is ready.
  ready: Promise<void>;
}

cc: @suzmue @stamblerre @findleyr @pjweinb @heschi @polinasok

@firelizzard18
Copy link
Contributor

if your extension requires to mimic how the go extension would run the go command

@hyangah I don't have any strict requirements. I have two motivations: 1) I want to meet the user's expectations, and 2) I want to avoid adding code in my extensions for handling Go settings if possible.

I have two current use-cases. One is a custom debugger for scripts (which look like Go, but are executed by an interpreter, not compiled). The other is launching a long-running notebook kernel. In these two cases, I doubt I would get complaints from users if I didn't handle go.work/etc.

I do like the APIs you suggest. I personally prefer getExecutionCommand over runTool, but either would work for my purposes.

How about having ready: Promise in the API, that returns a Promise indicating whether this extension is ready?

👍

@firelizzard18
Copy link
Contributor

@hyangah I updated #1642 to implement approach 1, and I tested it to ensure it works with my use-case. I left out ready because I'm not clear on how that should be implemented. const api = await vscode.extensions.getExtension('golang.go').activate() won't resolve until the (Go) extension's activation function returns.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/336509 mentions this issue: src/goMain: export a small API

gopherbot pushed a commit that referenced this issue Aug 10, 2021
Exports a function for use by other extensions. When I'm creating a
Go-related VSCode extension, being able to reuse this extension's
configuration and certain helper functions would be very useful.
Additionally, users expect Go-related extensions to respect `go.*`
configuration options, and have reported issues when they don't. This
change exports `getBinPath`. With this function, Go-related
extensions don't have to reinvent the wheel when it comes to
installing and configuring Go tools.

Updates #233

Change-Id: I9edf7f87437492182e8562aa107b643ca01a1202
GitHub-Last-Rev: 0171541
GitHub-Pull-Request: #1642
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/336509
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Trust: Suzy Mueller <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants