Skip to content

Commit 28f00c7

Browse files
authored
Workspace viewer command visibility (#1323)
* 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
1 parent bb929c4 commit 28f00c7

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

package.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@
326326
"command": "r.workspaceViewer.refreshEntry",
327327
"title": "Manual Refresh",
328328
"icon": "$(refresh)",
329-
"category": "R Workspace Viewer"
329+
"category": "R Workspace Viewer",
330+
"enablement": "rSessionActive"
330331
},
331332
{
332333
"command": "r.workspaceViewer.view",
@@ -338,7 +339,8 @@
338339
"command": "r.workspaceViewer.clear",
339340
"title": "Clear environment",
340341
"icon": "$(clear-all)",
341-
"category": "R Workspace Viewer"
342+
"category": "R Workspace Viewer",
343+
"enablement": "rSessionActive"
342344
},
343345
{
344346
"command": "r.workspaceViewer.remove",
@@ -350,7 +352,8 @@
350352
"command": "r.workspaceViewer.save",
351353
"title": "Save workspace",
352354
"icon": "$(save)",
353-
"category": "R Workspace Viewer"
355+
"category": "R Workspace Viewer",
356+
"enablement": "rSessionActive"
354357
},
355358
{
356359
"command": "r.workspaceViewer.load",
@@ -987,6 +990,20 @@
987990
}
988991
],
989992
"menus": {
993+
"commandPalette": [
994+
{
995+
"command": "r.workspaceViewer.view",
996+
"when": "false"
997+
},
998+
{
999+
"command": "r.workspaceViewer.remove",
1000+
"when": "false"
1001+
},
1002+
{
1003+
"command": "r.workspaceViewer.package.showQuickPick",
1004+
"when": "false"
1005+
}
1006+
],
9901007
"editor/title/run": [
9911008
{
9921009
"when": "editorLangId == r",
@@ -2049,4 +2066,4 @@
20492066
"vsls": "^1.0.4753",
20502067
"winreg": "^1.2.4"
20512068
}
2052-
}
2069+
}

src/rTerminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function deleteTerminal(term: vscode.Terminal): void {
164164
if (config().get<boolean>('sessionWatcher')) {
165165
void term.processId.then((v) => {
166166
if (v) {
167-
cleanupSession(v.toString());
167+
void cleanupSession(v.toString());
168168
}
169169
});
170170
}

src/session.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { commands, StatusBarItem, Uri, ViewColumn, Webview, window, workspace, e
77

88
import { runTextInTerm } from './rTerminal';
99
import { FSWatcher } from 'fs-extra';
10-
import { config, readContent, UriIcon } from './util';
10+
import { config, readContent, setContext, UriIcon } from './util';
1111
import { purgeAddinPickerItems, dispatchRStudioAPICall } from './rstudioapi';
1212

1313
import { IRequest } from './liveShare/shareSession';
@@ -774,17 +774,18 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
774774
sessionStatusBarItem.show();
775775
updateSessionWatcher();
776776
purgeAddinPickerItems();
777+
await setContext('rSessionActive', true);
777778
if (request.plot_url) {
778779
await globalHttpgdManager?.showViewer(request.plot_url);
779780
}
780781
void watchProcess(pid).then((v: string) => {
781-
cleanupSession(v);
782+
void cleanupSession(v);
782783
});
783784
break;
784785
}
785786
case 'detach': {
786787
if (request.pid) {
787-
cleanupSession(request.pid);
788+
await cleanupSession(request.pid);
788789
}
789790
break;
790791
}
@@ -826,7 +827,7 @@ async function updateRequest(sessionStatusBarItem: StatusBarItem) {
826827
}
827828
}
828829

829-
export function cleanupSession(pidArg: string): void {
830+
export async function cleanupSession(pidArg: string): Promise<void> {
830831
if (pid === pidArg) {
831832
if (sessionStatusBarItem) {
832833
sessionStatusBarItem.text = 'R: (not attached)';
@@ -837,6 +838,7 @@ export function cleanupSession(pidArg: string): void {
837838
workspaceData.search = [];
838839
rWorkspace?.refresh();
839840
removeSessionFiles();
841+
await setContext('rSessionActive', false);
840842
}
841843
}
842844

src/workspaceViewer.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,21 @@ export function saveWorkspace(): void {
352352
}
353353

354354
export function loadWorkspace(): void {
355-
if (workspaceData) {
356-
void window.showOpenDialog({
357-
defaultUri: Uri.file(workingDir),
358-
filters: {
359-
'Data': ['RData'],
360-
},
361-
title: 'Load workspace'
362-
}).then(async (uri: Uri[] | undefined) => {
363-
if (uri) {
364-
const savePath = uri[0].fsPath.split(path.sep).join(path.posix.sep);
365-
return runTextInTerm(
366-
`load("${(savePath)}")`
367-
);
368-
}
369-
});
370-
}
355+
const defaultUri = workingDir ? Uri.file(workingDir) : vscode.window.activeTextEditor?.document.uri;
356+
void window.showOpenDialog({
357+
defaultUri: defaultUri,
358+
filters: {
359+
'Data': ['RData'],
360+
},
361+
title: 'Load workspace'
362+
}).then(async (uri: Uri[] | undefined) => {
363+
if (uri) {
364+
const savePath = uri[0].fsPath.split(path.sep).join(path.posix.sep);
365+
return runTextInTerm(
366+
`load("${(savePath)}")`
367+
);
368+
}
369+
});
371370
}
372371

373372
export function viewItem(node: string): void {

0 commit comments

Comments
 (0)