You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make sure markdown links execute an ext-host vscode.open command always #154993
I'm trying to use vscode.open with DocumentLinkProvider. At present, only the first argument of vscode.open (the resource) seems to be respected. The other arguments are ignored.
Here's an example extension that demonstrates this issue:
import*asvscodefrom'vscode';exportfunctionactivate(context: vscode.ExtensionContext){// Open `abc.md` from workspace root and select a range in itconstcommandUriWithOptions=vscode.Uri.parse(createCommandUri('vscode.open',vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri,'abc.md'),{selection: newvscode.Range(2,0,5,0),}));// Open `abc.md` from workspace root besides the current fileconstcommandUriWithViewCol=vscode.Uri.parse(createCommandUri('vscode.open',vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri,'abc.md'),vscode.ViewColumn.Beside));// Make sure basic command run on ext host side works//vscode.commands.executeCommand('vscode.open', vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, 'abc.md'), vscode.ViewColumn.Beside);vscode.languages.registerDocumentLinkProvider('markdown',{provideDocumentLinks: (doc)=>{return[newvscode.DocumentLink(newvscode.Range(0,0,100,0),commandUriWithViewCol)];}});}functioncreateCommandUri(command: string, ...args: any[]): string{return`command:${command}?${encodeURIComponent(JSON.stringify(args))}`;}
To repo:
Create abc.md in the root of your workspace. Add a few lines of content to it
Open another md file and open it
Click on the link from the provider
Expected
This should open abc.md besides the current editor
I also tried using _workbench.open directly. That doesn't work well since we don't go through the ext host type conversions. This means that the selection argument in the first example doesn't work since it has the wrong shape
This needs special handling, like done for tree views etc, but that also means extensions cannot (and should not) be able to control the opening details but that the user-gesture (ctrl+click vs normal click) determines the "to the side" behaviour
'vscode.open','_workbench.open','Opens the provided resource in the editor. Can be a text or binary file, or an http(s) URL. If you need more control over the options for opening a text file, use vscode.window.showTextDocument instead.',
[
newApiCommandArgument<URI|string>('uriOrString','Uri-instance or string (only http/https)',v=>URI.isUri(v)||(typeofv==='string'&&matchesSomeScheme(v,Schemas.http,Schemas.https)),v=>v),
newApiCommandArgument<vscode.ViewColumn|typeConverters.TextEditorOpenOptions|undefined,[vscode.ViewColumn?,ITextEditorOptions?]|undefined>('columnOrOptions','Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',
This particular issue seems to be around command links in a document (which I am not aware of how they work). If I understand correctly, these links execute on the renderer and not on the extension host and as such, the additional arguments are not supported:
changed the title [-]`vscode.open` on document link doesn't accept additional arguments[/-][+]Make sure markdown links execute an ext-host `vscode.open` command always[/+]on Sep 7, 2022
Activity
mjbvz commentedon Jul 12, 2022
I believe the root cause is that this ends invoking the renderer version of
vscode.open:vscode/src/vs/workbench/browser/parts/editor/editorCommands.ts
Lines 486 to 495 in 2c036d1
Instead of the one on the extension host that supports all the additional arguments
mjbvz commentedon Jul 12, 2022
I also tried using
_workbench.opendirectly. That doesn't work well since we don't go through the ext host type conversions. This means that theselectionargument in the first example doesn't work since it has the wrong shapejrieken commentedon Jul 13, 2022
This needs special handling, like done for tree views etc, but that also means extensions cannot (and should not) be able to control the opening details but that the user-gesture (ctrl+click vs normal click) determines the "to the side" behaviour
bpasero commentedon Jul 13, 2022
Took me a while to understand. First of all,
vscode.openis clearly supporting an argument to open to the side:vscode/src/vs/workbench/api/common/extHostApiCommands.ts
Lines 381 to 392 in 4404dc6
This particular issue seems to be around command links in a document (which I am not aware of how they work). If I understand correctly, these links execute on the renderer and not on the extension host and as such, the additional arguments are not supported:
vscode/src/vs/workbench/browser/parts/editor/editorCommands.ts
Lines 484 to 495 in 4404dc6
Why can the renderer side not simply allow for the same options?
jrieken commentedon Jul 13, 2022
Because those are API objects and no one transforms them into internal objects
bpasero commentedon Jul 13, 2022
It seems to me that Matt wants to always open to the side, irrespective to the user-gesture?
If so, I believe this is a feature request for document links to:
bpasero commentedon Jul 22, 2022
Let's maybe sync the three of us in August.
1 remaining item
[-]`vscode.open` on document link doesn't accept additional arguments[/-][+]Make sure markdown links execute an ext-host `vscode.open` command always[/+]bpasero commentedon Sep 7, 2022
As discussed, the suggested fix is to call a
vscode.openclone that ensures ext-host side execution and argument conversion.mjbvz commentedon Sep 8, 2022
Fixed by 077f586