Skip to content
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
37 changes: 19 additions & 18 deletions R/session/vsc.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ inspect_env <- function(env, cache) {
info$slots <- slotNames(obj)
}

if (is.list(obj) && !is.null(dim(obj))) {
if (!is.null(dim(obj))) {
info$dim <- dim(obj)
}
}
Expand All @@ -221,25 +221,26 @@ inspect_env <- function(env, cache) {
dir_session <- file.path(tempdir, "vscode-R")
dir.create(dir_session, showWarnings = FALSE, recursive = TRUE)

removeTaskCallback("vsc.globalenv")
removeTaskCallback("vsc.workspace")
show_globalenv <- isTRUE(getOption("vsc.globalenv", TRUE))
if (show_globalenv) {
globalenv_file <- file.path(dir_session, "globalenv.json")
globalenv_lock_file <- file.path(dir_session, "globalenv.lock")
file.create(globalenv_lock_file, showWarnings = FALSE)

update_globalenv <- function(...) {
tryCatch({
objs <- inspect_env(.GlobalEnv, globalenv_cache)
jsonlite::write_json(objs, globalenv_file, force = TRUE, pretty = FALSE)
cat(get_timestamp(), file = globalenv_lock_file)
}, error = message)
TRUE
}

update_globalenv()
addTaskCallback(update_globalenv, name = "vsc.globalenv")
workspace_file <- file.path(dir_session, "workspace.json")
workspace_lock_file <- file.path(dir_session, "workspace.lock")
file.create(workspace_lock_file, showWarnings = FALSE)

update_workspace <- function(...) {
tryCatch({
data <- list(
search = search()[-1],
loaded_namespaces = loadedNamespaces(),
globalenv = if (show_globalenv) inspect_env(.GlobalEnv, globalenv_cache) else NULL
)
jsonlite::write_json(data, workspace_file, force = TRUE, pretty = FALSE)
cat(get_timestamp(), file = workspace_lock_file)
}, error = message)
TRUE
}
update_workspace()
addTaskCallback(update_workspace, name = "vsc.workspace")

removeTaskCallback("vsc.plot")
use_httpgd <- identical(getOption("vsc.use_httpgd", FALSE), TRUE)
Expand Down
58 changes: 45 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,32 +291,43 @@
{
"command": "r.workspaceViewer.refreshEntry",
"title": "Manual Refresh",
"icon": "$(refresh)"
"icon": "$(refresh)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.view",
"title": "View",
"icon": "$(open-preview)"
"icon": "$(open-preview)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.clear",
"title": "Clear environment",
"icon": "$(clear-all)"
"icon": "$(clear-all)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.remove",
"title": "Remove",
"icon": "$(close)"
"icon": "$(close)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.save",
"title": "Save workspace",
"icon": "$(save)"
"icon": "$(save)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.load",
"title": "Load workspace",
"icon": "$(folder-opened)"
"icon": "$(folder-opened)",
"category": "R Workspace Viewer"
},
{
"command": "r.workspaceViewer.package.showQuickPick",
"title": "Show QuickPick",
"category": "R Workspace Viewer"
},
{
"command": "r.browser.refresh",
Expand All @@ -332,7 +343,8 @@
},
{
"command": "r.showHelp",
"title": "R: Show help"
"title": "Show help",
"category": "R"
},
{
"command": "editor.action.webvieweditor.showFind",
Expand Down Expand Up @@ -544,7 +556,7 @@
},
{
"command": "r.rmarkdown.setKnitDirectory",
"title": "R: Set Knit directory",
"title": "Set Knit directory",
"icon": "$(zap)",
"category": "R Markdown"
},
Expand Down Expand Up @@ -603,113 +615,133 @@
},
{
"command": "r.helpPanel.back",
"title": "R Help Panel: Go Back",
"title": "Go Back",
"category": "R Help Panel",
"enablement": "r.helpPanel.canGoBack",
"icon": "$(arrow-left)"
},
{
"command": "r.helpPanel.forward",
"title": "R Help Panel: Go Forward",
"title": "Go Forward",
"category": "R Help Panel",
"enablement": "r.helpPanel.canGoForward",
"icon": "$(arrow-right)"
},
{
"command": "r.helpPanel.openExternal",
"title": "R Help Panel: Open in external browser",
"title": "Open in external browser",
"category": "R Help Panel",
"icon": "$(link-external)"
},
{
"title": "Search Package Topics",
"category": "R Help Panel",
"command": "r.helpPanel.searchPackage",
"icon": "$(search)"
},
{
"title": "Open Topic in new Panel",
"category": "R Help Panel",
"command": "r.helpPanel.openInNewPanel",
"icon": "$(add)"
},
{
"title": "Clear Cached Files",
"category": "R Help Panel",
"command": "r.helpPanel.clearCache",
"icon": "$(refresh)"
},
{
"title": "Filter Packages",
"category": "R Help Panel",
"command": "r.helpPanel.filterPackages",
"icon": "$(filter)"
},
{
"title": "Remove from favorites",
"category": "R Help Panel",
"command": "r.helpPanel.removeFromFavorites",
"icon": "$(star-full)"
},
{
"title": "Add to favorites",
"category": "R Help Panel",
"command": "r.helpPanel.addToFavorites",
"icon": "$(star-empty)"
},
{
"title": "Show all packages",
"category": "R Help Panel",
"command": "r.helpPanel.showAllPackages",
"icon": "$(star-full)"
},
{
"title": "Show only favorites",
"category": "R Help Panel",
"command": "r.helpPanel.showOnlyFavorites",
"icon": "$(star-empty)"
},
{
"title": "Remove Package",
"category": "R Help Panel",
"command": "r.helpPanel.removePackage",
"icon": "$(trash)"
},
{
"title": "Update Installed Packages",
"category": "R Help Panel",
"command": "r.helpPanel.updateInstalledPackages",
"icon": "$(clone)"
},
{
"title": "Update/reinstall Package",
"category": "R Help Panel",
"command": "r.helpPanel.updatePackage",
"icon": "$(cloud-download)"
},
{
"title": "Install multiple packages",
"category": "R Help Panel",
"command": "r.helpPanel.installPackages",
"icon": "$(expand-all)"
},
{
"title": "Show QuickPick",
"category": "R Help Panel",
"command": "r.helpPanel.showQuickPick",
"icon": "$(zap)"
},
{
"title": "Summarize Identical Topics",
"category": "R Help Panel",
"command": "r.helpPanel.summarizeTopics",
"icon": "$(fold)"
},
{
"title": "Don't Summarize Identical Topics",
"category": "R Help Panel",
"command": "r.helpPanel.unsummarizeTopics",
"icon": "$(unfold)"
},
{
"title": "Open help for selection",
"category": "R",
"category": "R Help Panel",
"command": "r.helpPanel.openForSelection"
},
{
"title": "Open help for path",
"category": "R",
"category": "R Help Panel",
"command": "r.helpPanel.openForPath"
},
{
"command": "r.liveShare.toggle",
"category": "R Live Share",
"title": "Toggle"
},
{
"command": "r.liveShare.retry",
"title": "Retry connection to Live Share service",
"category": "R Live Share",
"icon": "$(refresh)"
},
{
Expand Down
25 changes: 12 additions & 13 deletions src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const roxygenTagCompletionItems = [

export class HoverProvider implements vscode.HoverProvider {
provideHover(document: vscode.TextDocument, position: vscode.Position): vscode.Hover {
if(!session.globalenv){
if(!session.workspaceData.globalenv){
return null;
}

Expand All @@ -48,10 +48,10 @@ export class HoverProvider implements vscode.HoverProvider {
// use juggling check here for both
// null and undefined
// eslint-disable-next-line eqeqeq
if (session.globalenv[text]?.str == null) {
if (session.workspaceData.globalenv[text]?.str == null) {
return null;
}
return new vscode.Hover(`\`\`\`\n${session.globalenv[text]?.str}\n\`\`\``);
return new vscode.Hover(`\`\`\`\n${session.workspaceData.globalenv[text]?.str}\n\`\`\``);
}
}

Expand Down Expand Up @@ -98,8 +98,7 @@ export class StaticCompletionItemProvider implements vscode.CompletionItemProvid
}
}

if (document.lineAt(position).text
.substr(0, 2) === '#\'') {
if (document.lineAt(position).text.startsWith('#\'')) {
return roxygenTagCompletionItems;
}

Expand Down Expand Up @@ -131,8 +130,8 @@ export class LiveCompletionItemProvider implements vscode.CompletionItemProvider
const trigger = completionContext.triggerCharacter;

if (trigger === undefined) {
Object.keys(session.globalenv).forEach((key) => {
const obj = session.globalenv[key];
Object.keys(session.workspaceData.globalenv).forEach((key) => {
const obj = session.workspaceData.globalenv[key];
const item = new vscode.CompletionItem(
key,
obj.type === 'closure' || obj.type === 'builtin'
Expand All @@ -148,7 +147,7 @@ export class LiveCompletionItemProvider implements vscode.CompletionItemProvider
const symbolRange = document.getWordRangeAtPosition(symbolPosition);
const symbol = document.getText(symbolRange);
const doc = new vscode.MarkdownString('Element of `' + symbol + '`');
const obj = session.globalenv[symbol];
const obj = session.workspaceData.globalenv[symbol];
let names: string[];
if (obj !== undefined) {
if (completionContext.triggerCharacter === '$') {
Expand All @@ -159,7 +158,7 @@ export class LiveCompletionItemProvider implements vscode.CompletionItemProvider
}

if (names) {
items.push(...getCompletionItems(names, vscode.CompletionItemKind.Field, '[session]', doc));
items.push(...getCompletionItems(names, vscode.CompletionItemKind.Variable, '[session]', doc));
}
}

Expand Down Expand Up @@ -221,10 +220,10 @@ function getBracketCompletionItems(document: vscode.TextDocument, position: vsco
}

if (!token.isCancellationRequested && symbol !== undefined) {
const obj = session.globalenv[symbol];
const obj = session.workspaceData.globalenv[symbol];
if (obj !== undefined && obj.names !== undefined) {
const doc = new vscode.MarkdownString('Element of `' + symbol + '`');
items.push(...getCompletionItems(obj.names, vscode.CompletionItemKind.Field, '[session]', doc));
items.push(...getCompletionItems(obj.names, vscode.CompletionItemKind.Variable, '[session]', doc));
}
}
return items;
Expand Down Expand Up @@ -266,10 +265,10 @@ function getPipelineCompletionItems(document: vscode.TextDocument, position: vsc
}

if (!token.isCancellationRequested && symbol !== undefined) {
const obj = session.globalenv[symbol];
const obj = session.workspaceData.globalenv[symbol];
if (obj !== undefined && obj.names !== undefined) {
const doc = new vscode.MarkdownString('Element of `' + symbol + '`');
items.push(...getCompletionItems(obj.names, vscode.CompletionItemKind.Field, '[session]', doc));
items.push(...getCompletionItems(obj.names, vscode.CompletionItemKind.Variable, '[session]', doc));
}
}
return items;
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp

// workspace viewer
'r.workspaceViewer.refreshEntry': () => rWorkspace?.refresh(),
'r.workspaceViewer.view': (node: workspaceViewer.WorkspaceItem) => workspaceViewer.viewItem(node.label),
'r.workspaceViewer.remove': (node: workspaceViewer.WorkspaceItem) => workspaceViewer.removeItem(node.label),
'r.workspaceViewer.view': (node: workspaceViewer.GlobalEnvItem) => workspaceViewer.viewItem(node.label),
'r.workspaceViewer.remove': (node: workspaceViewer.GlobalEnvItem) => workspaceViewer.removeItem(node.label),
'r.workspaceViewer.clear': workspaceViewer.clearWorkspace,
'r.workspaceViewer.load': workspaceViewer.loadWorkspace,
'r.workspaceViewer.save': workspaceViewer.saveWorkspace,
Expand Down
Loading