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

Add a hover to results annotation w/ full results #336

Merged
merged 2 commits into from
Sep 22, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes to Calva.

## [Unreleased]
- [Escape HTML in stdout and stderr in REPL window](https://github.com/BetterThanTomorrow/calva/issues/321)
- [Add hover to inline result display, containing the full results](https://github.com/BetterThanTomorrow/calva/pull/336)

## [2.0.39] - 20.09.2019
- [Revert disconnecting and jacking out on closing of REPL window](https://github.com/BetterThanTomorrow/calva/issues/326)
Expand Down
11 changes: 6 additions & 5 deletions calva/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ async function evaluateSelection(document = {}, options = {}) {
chan.appendLine("Evaluated as comment.")
} else {
annotations.decorateSelection(codeSelection, editor, annotations.AnnotationStatus.SUCCESS);
if (!pprint)
annotations.decorateResults(' => ' + value.replace(/\n/gm, " ") + " ", false, codeSelection, editor);
annotations.decorateResults(value, false, codeSelection, editor);
}

if (out.length > 0) {
Expand All @@ -94,8 +93,8 @@ async function evaluateSelection(document = {}, options = {}) {
}

annotations.decorateSelection(codeSelection, editor, annotations.AnnotationStatus.ERROR);
const annotation = err.join();
annotations.decorateResults(' => ' + annotation.replace(/\n/gm, " ") + " ", true, codeSelection, editor);
const annotation = err.join("\n");
annotations.decorateResults(annotation, true, codeSelection, editor);
}
}
} else
Expand Down Expand Up @@ -167,8 +166,10 @@ async function copyLastResultCommand() {
let client = replWindow ? replWindow.session : util.getSession(util.getFileType(util.getDocument({})));

let value = await client.eval("*1").value;
if (value !== null)
if (value !== null) {
vscode.env.clipboard.writeText(value);
vscode.window.showInformationMessage("Results copied to the clipboard.");
}
else
chan.appendLine("Nothing to copy");
}
Expand Down
18 changes: 13 additions & 5 deletions calva/providers/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,34 @@ const evalResultsDecorationType = vscode.window.createTextEditorDecorationType({
textDecoration: 'none',
fontWeight: 'normal',
fontStyle: 'normal',
},
width: "250px",
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedOpen
});

function evaluated(contentText, hasError) {

//<a href="#" data-href="command:gitlens.showQuickCommitDetails?%7B%22sha%22%3A%22ec09a1477b748da5d0d59b6e9f1eaff031aca4e2%22%7D" title="Show Commit Details"><code>ec09a14</code></a>

function evaluated(contentText, hoverText, hasError) {
const commandUri = vscode.Uri.parse("command:calva.copyLastResults"),
commandMd = `[Copy](${commandUri} "Copy results to the clipboard")`;
let hoverMessage = new vscode.MarkdownString(commandMd + '\n```clojure\n' + hoverText + '\n```');
hoverMessage.isTrusted = true;
return {
hoverMessage: hasError ? hoverText : hoverMessage,
renderOptions: {
before: {
contentText: contentText,
overflow: "hidden"
},
light: {
before: {
color: hasError ? 'rgb(255, 127, 127)' : 'black',
backgroundColor: 'white',
},
},
dark: {
before: {
color: hasError ? 'rgb(255, 175, 175)' : 'white',
backgroundColor: 'black',
}
},
},
Expand Down Expand Up @@ -99,7 +107,7 @@ function decorateResults(resultString, hasError, codeSelection: vscode.Range, ed
let uri = editor.document.uri,
key = uri + ':resultDecorationRanges',
decorationRanges = state.deref().get(key) || [],
decoration = evaluated(resultString, hasError);
decoration = evaluated(` => ${resultString} `, resultString, hasError);
decorationRanges = _.filter(decorationRanges, (o) => { return !o.codeRange.intersection(codeSelection) });
decoration["codeRange"] = codeSelection;
decoration["range"] = new vscode.Selection(codeSelection.end, codeSelection.end);
Expand Down