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

Switch R package development support to commands #772

Merged
merged 9 commits into from
Jun 25, 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
108 changes: 89 additions & 19 deletions extensions/positron-r/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@
"title": "%r.command.createNewFile.title%",
"shortTitle": "%r.menu.createNewFile.title%"
},
{
"command": "r.packageLoad",
"category": "R",
"title": "%r.command.packageLoad.title%",
"shortTitle": "%r.menu.packageLoad.title%"
},
{
"command": "r.packageBuild",
"category": "R",
"title": "%r.command.packageBuild.title%",
"shortTitle": "%r.menu.packageBuild.title%"
},
{
"command": "r.packageInstall",
"category": "R",
"title": "%r.command.packageInstall.title%",
"shortTitle": "%r.menu.packageInstall.title%"
},
{
"command": "r.packageTest",
"category": "R",
"title": "%r.command.packageTest.title%",
"shortTitle": "%r.menu.packageTest.title%"
},
{
"command": "r.packageCheck",
"category": "R",
"title": "%r.command.packageCheck.title%",
"shortTitle": "%r.menu.packageCheck.title%"
},
{
"command": "r.packageDocument",
"category": "R",
"title": "%r.command.packageDocument.title%",
"shortTitle": "%r.menu.packageDocument.title%"
},
{
"command": "r.sourceCurrentFile",
"category": "R",
Expand Down Expand Up @@ -104,6 +140,38 @@
"path": "./syntaxes/r.tmGrammar.gen.json"
}
],
"keybindings" : [
{
"command": "r.packageLoad",
"key": "ctrl+shift+l",
"mac": "cmd+shift+l",
"when": "isRPackage"
},
{
"command": "r.packageBuild",
"key": "ctrl+shift+b",
"mac": "cmd+shift+b",
"when": "isRPackage"
},
{
"command": "r.packageTest",
"key": "ctrl+shift+t",
"mac": "cmd+shift+t",
"when": "isRPackage"
},
{
"command": "r.packageCheck",
"key": "ctrl+shift+e",
"mac": "cmd+shift+e",
"when": "isRPackage"
},
{
"command": "r.packageDocument",
"key": "ctrl+shift+d",
"mac": "cmd+shift+d",
"when": "isRPackage"
}
],
"menus": {
"commandPalette": [
{
Expand All @@ -112,6 +180,26 @@
"icon": "$(play)",
"title": "%r.command.sourceCurrentFile.title%",
"when": "editorLangId == r"
},
{
"category": "R",
"command": "r.packageLoad",
"when": "isRPackage"
},
{
"category": "R",
"command": "r.packageBuild",
"when": "isRPackage"
},
{
"category": "R",
"command": "r.packageTest",
"when": "isRPackage"
},
{
"category": "R",
"command": "r.packageCheck",
"when": "isRPackage"
}
],
"file/newFile": [
Expand All @@ -138,25 +226,7 @@
"when": "resourceLangId == r && !isInDiffEditor"
}
]
},
"taskDefinitions": [
{
"type": "rPackageBuild",
"when": "isRPackage"
},
{
"type": "rPackageLoad",
"when": "isRPackage"
},
{
"type": "rPackageTest",
"when": "isRPackage"
},
{
"type": "rPackageCheck",
"when": "isRPackage"
}
]
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
Expand Down
6 changes: 6 additions & 0 deletions extensions/positron-r/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"r.command.sourceCurrentFile.title": "Source R File",
"r.command.setKernelPath.title": "Set Kernel Path",
"r.command.createNewFile.title": "New R File",
"r.command.packageLoad.title": "Load R Package",
"r.command.packageBuild.title": "Build R Package",
"r.command.packageInstall.title": "Install R Package",
"r.command.packageTest.title": "Test R Package",
"r.command.packageCheck.title": "Check R Package",
"r.command.packageDocument.title": "Document R Package",
"r.menu.createNewFile.title": "R File",
"r.configuration.title": "Positron R Language Pack",
"r.configuration.kernelPath.description": "Path on disk to the ARK kernel executable; use this to override the default (embedded) kernel.",
Expand Down
48 changes: 47 additions & 1 deletion extensions/positron-r/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import * as positron from 'positron';

import { adaptJupyterKernel } from './kernel';

export function registerCommands(context: vscode.ExtensionContext) {
export async function registerCommands(context: vscode.ExtensionContext) {

const isRPackage = await detectRPackage();
vscode.commands.executeCommand('setContext', 'isRPackage', isRPackage);

context.subscriptions.push(
// Command used to register the ARK kernel with the Jupyter Adapter
// extension. Typically run only once to set up the kernel.
Expand Down Expand Up @@ -43,6 +47,31 @@ export function registerCommands(context: vscode.ExtensionContext) {
});
}),

// Commands for package development tooling
vscode.commands.registerCommand('r.packageLoad', () => {
positron.runtime.executeCode('r', 'devtools::load_all()', true);
}),

vscode.commands.registerCommand('r.packageBuild', () => {
positron.runtime.executeCode('r', 'devtools::build()', true);
}),

vscode.commands.registerCommand('r.packageInstall', () => {
positron.runtime.executeCode('r', 'devtools::install()', true);
}),

vscode.commands.registerCommand('r.packageTest', () => {
positron.runtime.executeCode('r', 'devtools::test()', true);
}),

vscode.commands.registerCommand('r.packageCheck', () => {
positron.runtime.executeCode('r', 'devtools::check()', true);
}),

vscode.commands.registerCommand('r.packageDocument', () => {
positron.runtime.executeCode('r', 'devtools::document()', true);
}),

// Command used to source the current file
vscode.commands.registerCommand('r.sourceCurrentFile', async () => {
// Get the active text editor
Expand Down Expand Up @@ -84,3 +113,20 @@ export function registerCommands(context: vscode.ExtensionContext) {
}),
);
}

async function detectRPackage(): Promise<boolean> {
if (vscode.workspace.workspaceFolders !== undefined) {
const folderUri = vscode.workspace.workspaceFolders[0].uri;
const fileUri = vscode.Uri.joinPath(folderUri, 'DESCRIPTION');
try {
const bytes = await vscode.workspace.fs.readFile(fileUri);
const descriptionText = Buffer.from(bytes).toString('utf8');
const descriptionLines = descriptionText.split(/(\r?\n)/);
const descStartsWithPackage = descriptionLines[0].startsWith('Package:');
const typeLines = descriptionLines.filter(line => line.startsWith('Type:'));
const typeIsPackage = typeLines.length === 0 || typeLines[0].includes('Package');
return descStartsWithPackage && typeIsPackage;
} catch { }
}
return false;
}
4 changes: 0 additions & 4 deletions extensions/positron-r/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as vscode from 'vscode';
import { registerCommands } from './commands';
import { adaptJupyterKernel } from './kernel';
import { initializeLogging, trace, traceOutputChannel } from './logging';
import { providePackageTasks } from './tasks';

function activateKernel(context: vscode.ExtensionContext) {

Expand Down Expand Up @@ -60,8 +59,5 @@ export function activate(context: vscode.ExtensionContext) {
// Register commands.
registerCommands(context);

// Provide tasks.
providePackageTasks(context);

}

70 changes: 0 additions & 70 deletions extensions/positron-r/src/tasks.ts

This file was deleted.