Skip to content

Make sure markdown links execute an ext-host vscode.open command always #154993

Closed

Description

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:

  1. Create abc.md in the root of your workspace. Add a few lines of content to it
  2. Open another md file and open it
  3. 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

Metadata

Assignees

Labels

*dev-questionVS Code Extension Development QuestionmarkdownMarkdown support issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions