Skip to content

Commit

Permalink
Implement help preview for local package(s) (#1259)
Browse files Browse the repository at this point in the history
* Implement help preview for local package

* Remove debugging file write

* Check if linked files exist

* Use custom open file command

* Add 00Index preview

* Add DESCRIPTION preview

* Add warning message for failing links

* Refactoring

* Hide openExternal command for previews

* Allow multiple R-file references

* Tweak regex

* Handle line breaks in R file list

* Tweak Index preview

* Optionally exclude preview-aliases from getAllAliases
  • Loading branch information
ManuelHentschel authored Nov 23, 2022
1 parent b3e107e commit 73d2fbb
Show file tree
Hide file tree
Showing 12 changed files with 1,003 additions and 168 deletions.
38 changes: 38 additions & 0 deletions html/help/00Index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>
<%= packageTitle %>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
</head>

<body>
<div class="container">
<h1>
<%= packageTitle %>
</h1>
<hr />
<h2>Documentation for package &lsquo;<%= packageName %> &rsquo; version <%= packageVersion %>
</h2>

<ul>
<li><a href="../DESCRIPTION">DESCRIPTION file</a>.</li>
</ul>

<h2>Help Pages</h2>

<table width="100%">
<% topics.forEach((topic)=> { %>
<tr>
<td style="width: 25%;"><a href="<%= topic.href %>"><%= topic.name %></a></td>
<td><%= topic.title %></td>
</tr>
<% }) %>
</table>
</div>
</body>

</html>
22 changes: 21 additions & 1 deletion html/help/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ a ~ div.header {
display: none;
}

/* Styling for preview info box */
.previewInfo {
position: relative;
left: -20px;
width: calc(100% + 40px);
background-color: var(--vscode-list-inactiveSelectionBackground);
box-sizing: border-box;
text-align: center;

padding-top: 0.5em;
padding-bottom: 0.5em;
padding-left: calc(0.5em + 20px);
padding-right: calc(0.5em + 20px);
/* margin-top: 1.5em; */
margin-bottom: 1em;

font-family: var(--vscode-editor-font-family);
font-size: var(--vscode-editor-font-size);
}

/* Styling for clickable code sections */
pre, code {
font-family: var(--vscode-editor-font-family);
Expand All @@ -40,7 +60,7 @@ pre, code {
.preHoverPointer .preDiv:hover {
cursor: pointer;
}
.preClickable pre:hover {
.preClickable .preCodeExample:hover {
background-color: var(--vscode-list-hoverBackground);
}

Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@
"command": "r.helpPanel.openExternal",
"title": "Open in external browser",
"category": "R Help Panel",
"enablement": "r.helpPanel.canOpenExternal",
"icon": "$(link-external)"
},
{
Expand Down Expand Up @@ -1496,6 +1497,14 @@
],
"default": "None"
},
"r.helpPanel.previewLocalPackages": {
"type": "array",
"items": {
"type": "string"
},
"default": ["."],
"markdownDescription": "Which local directories to try for local help pages previewer. Set to `[]` to disable."
},
"r.helpPanel.rpath": {
"type": "string",
"default": "",
Expand Down
4 changes: 2 additions & 2 deletions src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class HelpLinkHoverProvider implements vscode.HoverProvider {
const token = document.getText(wordRange);
const aliases = await globalRHelp?.getMatchingAliases(token) || [];
const mds = aliases.map(a => {
const cmdText = `${a.package}::${a.name}`;
const args = [`/library/${a.package}/html/${a.alias}.html`];
const cmdText = `${a.package}::${a.alias}`;
const args = [`/library/${a.package}/html/${a.name}.html`];
const encodedArgs = encodeURIComponent(JSON.stringify(args));
const cmd = 'command:r.helpPanel.openForPath';
const cmdUri = vscode.Uri.parse(`${cmd}?${encodedArgs}`);
Expand Down
Loading

0 comments on commit 73d2fbb

Please sign in to comment.