I'm the developer for the vscode extension.
When the debugger activated, I opened a specific file in the right column editor to show the other related file for the current debug file using the below command.
vscode.commands.executeCommand('vscode.open', vscode.Uri.file('/main.c.dbgasm'), 2);
Now I want to close it. But I have no idea to close the right column editor. There are some close editor commands but they do not fit my needs which shown below.
workbench.action.closeActiveEditor
workbench.action.closeAllEditors
workbench.action.closeAllGroups
workbench.action.closeEditorsInGroup
workbench.action.closeOtherEditors
workbench.action.closeUnmodifiedEditors
Can anyone have idea about it?
You can use the window.tabGroups.close()
method.
// the 'all' array is 0-based, so this is the second editor group
const sourceGroup = vscode.window.tabGroups.all[1];
// this would get the first tab in the second editor group
// if you don't know where in the editor group the file you want to close is
// you can filter the tabs by label,url or path, see below
const myTab = sourceGroup.tabs[0];
await vscode.window.tabGroups.close(myTab, false);
To filter the tabs in an editor group by their path, try this:
const sourceGroup = vscode.window.tabGroups.all[0]; // 'all' array is 0-based
// note small "c" to match how Uri.fsPath looks
const myPath = "c:\\Users\\Mark\\OneDrive\\Test Bed\\howdy.js";
const foundTab = sourceGroup.tabs.filter(tab =>
(tab.input instanceof vscode.TabInputText) && (tab.input.uri.fsPath === myPath)
);
// close() takes an array or a single tab
if (foundTab?.length === 1) await vscode.window.tabGroups.close(foundTab, false);