Skip to content

Commit

Permalink
Workspace viewer command visibility (#1323)
Browse files Browse the repository at this point in the history
* Enablement changes, load anytime

- Save, Clear, and Refresh are disabled when there is no attached terminal
- Load can be used at any time to attach a terminal + load data easily
- View and Remove are no longer shown in the command palette

* Update session.ts

* Update package.json

* Fix lint
  • Loading branch information
ElianHugh authored Mar 6, 2023
1 parent bb929c4 commit 28f00c7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
25 changes: 21 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
"command": "r.workspaceViewer.refreshEntry",
"title": "Manual Refresh",
"icon": "$(refresh)",
"category": "R Workspace Viewer"
"category": "R Workspace Viewer",
"enablement": "rSessionActive"
},
{
"command": "r.workspaceViewer.view",
Expand All @@ -338,7 +339,8 @@
"command": "r.workspaceViewer.clear",
"title": "Clear environment",
"icon": "$(clear-all)",
"category": "R Workspace Viewer"
"category": "R Workspace Viewer",
"enablement": "rSessionActive"
},
{
"command": "r.workspaceViewer.remove",
Expand All @@ -350,7 +352,8 @@
"command": "r.workspaceViewer.save",
"title": "Save workspace",
"icon": "$(save)",
"category": "R Workspace Viewer"
"category": "R Workspace Viewer",
"enablement": "rSessionActive"
},
{
"command": "r.workspaceViewer.load",
Expand Down Expand Up @@ -987,6 +990,20 @@
}
],
"menus": {
"commandPalette": [
{
"command": "r.workspaceViewer.view",
"when": "false"
},
{
"command": "r.workspaceViewer.remove",
"when": "false"
},
{
"command": "r.workspaceViewer.package.showQuickPick",
"when": "false"
}
],
"editor/title/run": [
{
"when": "editorLangId == r",
Expand Down Expand Up @@ -2049,4 +2066,4 @@
"vsls": "^1.0.4753",
"winreg": "^1.2.4"
}
}
}
2 changes: 1 addition & 1 deletion src/rTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function deleteTerminal(term: vscode.Terminal): void {
if (config().get<boolean>('sessionWatcher')) {
void term.processId.then((v) => {
if (v) {
cleanupSession(v.toString());
void cleanupSession(v.toString());
}
});
}
Expand Down
10 changes: 6 additions & 4 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { commands, StatusBarItem, Uri, ViewColumn, Webview, window, workspace, e

import { runTextInTerm } from './rTerminal';
import { FSWatcher } from 'fs-extra';
import { config, readContent, UriIcon } from './util';
import { config, readContent, setContext, UriIcon } from './util';
import { purgeAddinPickerItems, dispatchRStudioAPICall } from './rstudioapi';

import { IRequest } from './liveShare/shareSession';
Expand Down Expand Up @@ -774,17 +774,18 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
sessionStatusBarItem.show();
updateSessionWatcher();
purgeAddinPickerItems();
await setContext('rSessionActive', true);
if (request.plot_url) {
await globalHttpgdManager?.showViewer(request.plot_url);
}
void watchProcess(pid).then((v: string) => {
cleanupSession(v);
void cleanupSession(v);
});
break;
}
case 'detach': {
if (request.pid) {
cleanupSession(request.pid);
await cleanupSession(request.pid);
}
break;
}
Expand Down Expand Up @@ -826,7 +827,7 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
}
}

export function cleanupSession(pidArg: string): void {
export async function cleanupSession(pidArg: string): Promise<void> {
if (pid === pidArg) {
if (sessionStatusBarItem) {
sessionStatusBarItem.text = 'R: (not attached)';
Expand All @@ -837,6 +838,7 @@ export function cleanupSession(pidArg: string): void {
workspaceData.search = [];
rWorkspace?.refresh();
removeSessionFiles();
await setContext('rSessionActive', false);
}
}

Expand Down
31 changes: 15 additions & 16 deletions src/workspaceViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,21 @@ export function saveWorkspace(): void {
}

export function loadWorkspace(): void {
if (workspaceData) {
void window.showOpenDialog({
defaultUri: Uri.file(workingDir),
filters: {
'Data': ['RData'],
},
title: 'Load workspace'
}).then(async (uri: Uri[] | undefined) => {
if (uri) {
const savePath = uri[0].fsPath.split(path.sep).join(path.posix.sep);
return runTextInTerm(
`load("${(savePath)}")`
);
}
});
}
const defaultUri = workingDir ? Uri.file(workingDir) : vscode.window.activeTextEditor?.document.uri;
void window.showOpenDialog({
defaultUri: defaultUri,
filters: {
'Data': ['RData'],
},
title: 'Load workspace'
}).then(async (uri: Uri[] | undefined) => {
if (uri) {
const savePath = uri[0].fsPath.split(path.sep).join(path.posix.sep);
return runTextInTerm(
`load("${(savePath)}")`
);
}
});
}

export function viewItem(node: string): void {
Expand Down

0 comments on commit 28f00c7

Please sign in to comment.