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

revealFileInOS invoked programatically does not do anything #232522

Closed
Splines opened this issue Oct 29, 2024 · 3 comments
Closed

revealFileInOS invoked programatically does not do anything #232522

Splines opened this issue Oct 29, 2024 · 3 comments
Assignees
Labels
*dev-question VS Code Extension Development Question

Comments

@Splines
Copy link

Splines commented Oct 29, 2024

  • Does this issue occur when all extensions are disabled?: Yes
  • VS Code Version: 1.95.0, commit 912bb68
  • OS Version: Windows 10, Version 22H2. Running VSCode inside WSL2 Ubuntu 22.04.5 LTS

Description

Invoking revealFileInOS programatically via a VSCode Extension doesn't do anything (does not even error). Manually invoking this command via the command palette works.

I'd love to invoke this command programatically to provide a command allowing users of our extension to open the extension's log file in their explorer/finder/whatever and then just drag-and-drop this file into a new GitHub issue (instead of pasting the contents in the issue, making it hard to read).

Steps to reproduce

Inside the activate function of a VSCode Extension:

vscode.commands.registerCommand('manim-notebook.openLogFileTest', async () => {
	const myFilePath= vscode.Uri.joinPath(<some-paths-joined-together>);
	await vscode.commands.executeCommand('revealFileInOS', myFilePath); // also tested with myFilePath.fsPath
});

This is inspired by what the built-in TypeScript Language Server does here:

try {
await vscode.commands.executeCommand('revealFileInOS', this.serverState.server.tsServerLog.uri);
return true;
} catch {
vscode.window.showWarningMessage(vscode.l10n.t("Could not open TS Server log file"));
return false;
}

I can verify that myFilePath has a reference to a valid file as expected by executing this beforehand:

const doc = await vscode.workspace.openTextDocument(myFilePath);
await window.showTextDocument(doc);

This correctly opens myFilePath in the editor and shows its contents.

Related issues

await vscode.commands.executeCommand('workbench.view.explorer');
@Splines Splines changed the title revealFileInOS invoked programatically does not do anything revealFileInOS invoked programatically does not do anything Oct 29, 2024
@Splines
Copy link
Author

Splines commented Oct 29, 2024

Note this was already a problem in the prior release 1.94. I've just updated to 1.95 and it's still a problem there.

Copy link

We have a great extension developer community over on GitHub discussions and Slack where extension authors help each other. This is a great place for you to ask questions and find support.

Happy Coding!

@vs-code-engineering vs-code-engineering bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
@Splines
Copy link
Author

Splines commented Oct 30, 2024

Thanks for pointing me to the discussions, I didn't know these existed. If anyone from the Internet stumbles upon this issue in some years, here's what I now came up with to resolve this issue. The problem was that the revealFileInOS command is not working on a WSL remote. Instead, we use the remote-wsl.revealInExplorer command that I found about in this discussion.

/**
 * Opens a file in the OS file explorer.
 * 
 * @param uri The URI of the file to reveal.
 */
async function revealFileInOS(uri: vscode.Uri) {
	if (vscode.env.remoteName === 'wsl') {
		await vscode.commands.executeCommand('remote-wsl.revealInExplorer', uri);
	} else {
		await vscode.commands.executeCommand('revealFileInOS', uri);
	}
}

Then call it like this:

try {
	await revealFileInOS(logFilePath);
} catch (error: any) {
	window.showErrorMessage(`Could not open log file in the`
		+ ` OS file explorer: ${error?.message}`);
}

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*dev-question VS Code Extension Development Question
Projects
None yet
Development

No branches or pull requests

4 participants