Skip to content

Instantly share code, notes, and snippets.

@tuulos
Last active August 7, 2024 04:12
Show Gist options
  • Save tuulos/f513eaec896724f9d9a6bdaaf45dc0b4 to your computer and use it in GitHub Desktop.
Save tuulos/f513eaec896724f9d9a6bdaaf45dc0b4 to your computer and use it in GitHub Desktop.
async function openFile(uri) {
const options = {
preview: false,
viewColumn: vscode.ViewColumn.One,
};
const workspaceFolder = getWorkspaceUri();
const docURI = vscode.Uri.joinPath(workspaceFolder, uri.path);
const files = await vscode.workspace.textDocuments.filter(doc => doc.fileName === docURI.fsPath);
if (files.length === 0) {
// no active file, open it and return
//const doc = await vscode.workspace.openTextDocument(docURI);
console.log("open", docURI);
await vscode.commands.executeCommand("vscode.openWith", vscode.Uri.file(docURI.fsPath), 'jupyter-notebook');
// indow.showTextDocument(doc, options);
return;
}
// if we have the window open and it is not active just show it
for await (const doc of files) {
if (vscode.window.activeTextEditor?.document.fileName !== doc.fileName) {
await vscode.commands.executeCommand("vscode.openWith", vscode.Uri.file(docURI.fsPath), 'jupyter-notebook');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment