-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Allow extensions to intercept and handle terminal links #91606
Comments
Proposal: // Modeled after UriHandler
export namespace window {
export function registerTerminalLinkHandler(handler: TerminalLinkHandler): Disposable;
}
export interface TerminalLinkHandler {
/**
* @return true when the link was handled (and should not be considered by
* other providers including the default), false when the link was not handled.
*/
handleLink(terminal: Terminal, link: string): ProviderResult<boolean>;
} |
It might be useful to allow the provider to return |
@connor4312 that could just as easily be accomplished with the current proposal too with |
Oh, good point. Works for me then. |
What kind of links are those and how are they generated? If you have control over the latter you could just generate a command-link (for a command that you own). Can we have a end to end sample? |
The use case I want it for is allowing js-debug to automatically debug links printed in the terminal. For instance, say you have a brand new In js-debug I might implement it something like this: const handledProtocols = new Set(['http', 'https', 'file']);
vscode.window.registerTerminalLinkHandler({
handleUri(terminal, link) {
// Only handle links from debug terminals
if (!isDebugTerminal(terminal)) {
return false;
}
// Only handle http/https/file links
const url = new URL(link);
if (!handledProtocols.has(url.protocol)) {
return false;
}
// For those links, launch them in a debuggable Chrome browser.
const userDefaults = vscode.workspace.getConfiguration('debug.javascript.defaultLinkConfig');
vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], {
...chromeLaunchConfigDefaults,
...userDefaults,
url: link,
});
return true;
}
}); |
@jrieken the how they are generated part was going to be handled by this API #91290, this proposal is splitting out the handling part such that extensions do not need to bother with link parsing and instead just handle/act upon the links if they want. Also I notice I used handleUri as the callback, I've updated this as it could be any arbitrary string (eg. "filename", "./folder/file", or something else contributed by the eventual #91290 API. |
Notes from api sync:
|
For language features we actually have LIFO because you can force yourself coming after a particular extension by defining a dependency. Alternatively, and in combination with the protection dialog you could show a picker-like UX that allows me to select the extension. This is what we do for formatting. |
For the initial proposed API I am leaving off the link protection mechanism as it seems pretty awkward to do, for example if 2 extensions registered link handlers, when you click a link a dialog would show for each asking whether to allow that extension to consider this link, only after which it would trigger. I've also added a 3 second window to allow extensions to handle it before logging an error and triggering the default handler. |
Let's leave this open and drag it along the API discussion |
Created test plan item for March, moving this to April for finalization. |
I've moved this back to proposed as I feel we may regret this after link providers #91290 come out. Link providers definitely handle a link, which lets us give a nice label to the link (internal and from extensions): However, link handlers may handle a particular link, so we cannot label it and ctrl+clicking may not accurately do what the hover says anymore. The one downside of going link providers only would be that extensions need to create their own link matchers probably via regex, and as such could miss cases. This isn't much of an issue for localhost links, but detecting file names for example is very complex and a link provider couldn't possible say they will definitely be able to handle something like that. |
Perhaps the next incarnation of this will just allow to override the default handling of folders/files/web links by providing a uri handler? We could then also have multiple actions in the hover as suggested in #91290 (comment) |
I plan on removing this in this iteration. I believe js-debug was the only consumer which has since moved onto link providers. |
Splitting out the handle part of this: #91290
This proposal will let js-debug for example handle and cancel bubbling of the handler, live share could handle it and not cancel.
The text was updated successfully, but these errors were encountered: