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

Workspace viewer command visibility #1323

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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