Skip to content

Commit

Permalink
Merge pull request #1911 from posit-dev/feature/help-and-vignette-links
Browse files Browse the repository at this point in the history
Support help and vignette links
  • Loading branch information
jmcphers authored Nov 30, 2023
2 parents e49a80c + d1514f9 commit a04096d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion extensions/positron-r/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
},
"positron": {
"binaryDependencies": {
"ark": "0.1.28"
"ark": "0.1.29"
}
}
}
60 changes: 49 additions & 11 deletions extensions/positron-r/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,20 @@ export class RRuntime implements positron.LanguageRuntime, vscode.Disposable {

// Dispatch the open.
switch (resource.scheme) {
// Run code.
case 'x-r-run':
console.log('********************************************************************');
console.log(`R runtime should run resource "${resource.path}"`);
console.log('********************************************************************');
return Promise.resolve(true);

// Open help resource.
case 'x-r-help':
console.log('********************************************************************');
console.log(`R runtime should open help resource "${resource.path}"`);
console.log('********************************************************************');
this.showHelpTopic(resource.path);
return Promise.resolve(true);

// Open vignette resource.
case 'x-r-vignette':
this.showVignetteTopic(resource.path);
return Promise.resolve(true);

// Run code.
case 'x-r-run':
console.log('********************************************************************');
console.log(`R runtime should open vignette resource "${resource.path}"`);
console.log(`R runtime should run resource "${resource.path}"`);
console.log('********************************************************************');
return Promise.resolve(true);

Expand Down Expand Up @@ -402,6 +398,48 @@ export class RRuntime implements positron.LanguageRuntime, vscode.Disposable {
}
}
}

/**
* Shows a help topic in the Positron help viewer.
*
* @param topic The help topic to show.
*/
private async showHelpTopic(topic: string): Promise<void> {
try {
// showHelpTopic returns a logical value indicating whether the
// topic was found. If it wasn't, we'll show an error message.
const result = await this.callMethod('showHelpTopic', topic);
if (!result) {
vscode.window.showWarningMessage(
`The requested help topic '${topic}' was not found.`);
}
} catch (err) {
const runtimeError = err as positron.RuntimeMethodError;
vscode.window.showErrorMessage(
`Error showing help topic '${topic}': ${runtimeError.message} ` +
`(${runtimeError.code})`);
}
}

/**
* Shows a vignette topic in the Positron help viewer.
*
* @param topic The vignette topic to show.
*/
private async showVignetteTopic(topic: string): Promise<void> {
try {
const result = await this.callMethod('showVignetteTopic', topic);
if (!result) {
vscode.window.showWarningMessage(
`The requested vignette topic '${topic}' was not found.`);
}
} catch (err) {
const runtimeError = err as positron.RuntimeMethodError;
vscode.window.showErrorMessage(
`Error showing vignette topic '${topic}': ${runtimeError.message} ` +
`(${runtimeError.code})`);
}
}
}

export function createJupyterKernelExtra(): JupyterKernelExtra {
Expand Down

0 comments on commit a04096d

Please sign in to comment.