Closed
Description
openedon Jul 12, 2022
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 * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
// Open `abc.md` from workspace root and select a range in it
const commandUriWithOptions = vscode.Uri.parse(
createCommandUri('vscode.open', vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, 'abc.md'), {
selection: new vscode.Range(2, 0, 5, 0),
})
);
// Open `abc.md` from workspace root besides the current file
const commandUriWithViewCol = 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 [
new vscode.DocumentLink(new vscode.Range(0, 0, 100, 0), commandUriWithViewCol)
];
}
});
}
function createCommandUri(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
Actual
abc.md
is opened in the same view column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment