Skip to content

Commit

Permalink
Reinstall hover results and remove peek
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
PEZ committed Apr 18, 2021
1 parent 1533152 commit cb6f42f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
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.
- [Paredit backspace should delete non-bracket parts of the opening token](https://github.com/BetterThanTomorrow/calva/issues/1122)
- [Use `shift+tab` for the ”Infer parens from indentation” command](https://github.com/BetterThanTomorrow/calva/issues/1126)
- Fix: [Inline evaluation results can show up in the wrong editor](https://github.com/BetterThanTomorrow/calva/issues/1120)
- [Bring back results in hovers](https://github.com/BetterThanTomorrow/calva/issues/736)

## [2.0.188] - 2021-04-16
- Fix: [Getting Started REPL failing on Windows when username has spaces (on some machines)](https://github.com/BetterThanTomorrow/calva/issues/1085)
Expand Down
15 changes: 0 additions & 15 deletions docs/site/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ If you have typed some text after the prompt before you start traversing up the

You can clear the repl history by running the command "Clear REPL History" from the command palette.

## Peek at Results

On smaller screens (or just depending on your taste) you might not have the output window visible side-by-side with your code, but rather in a tab in the same editor group.

Then your immediate feedback will be the inline display, which is limited to the first line of the results. All is not lost, however, you can peek at the full results using VS Code's command **Peek Definition**. Calva adds a definition pointer ”in” to the evaluated code in the output window.

![Peek at results](images/howto/output/peek-last-result.gif)

(On Mac the default keyboard shortcut for the peek command is `alt+f12`.)

In the demo gif we utilize two things about this peek widget:

1. It stays open until you close it. So you can keep evaluating different versions of your form and see the results get printed.
2. The widget displays a ”full” Calva editor, so you can use Paredit to conveniently select forms.

## Stack Traces

When an evaluation produces an error, the output window will automatically print the the error message. If there is a stack trace associated with the error, this can now be printed on demand using the **Calva: Print Last Stacktrace to the Output Window** command. The output window will also have a Codelense button below the error message that will print the stack trace..
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('calva.runAllTests', testRunner.runAllTestsCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.rerunTests', testRunner.rerunTestsCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.clearInlineResults', annotations.clearEvaluationDecorations));
context.subscriptions.push(vscode.commands.registerCommand('calva.copyAnnotationHoverText', annotations.copyHoverTextCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.copyLastResults', eval.copyLastResultCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.requireREPLUtilities', eval.requireREPLUtilitiesCommand));
context.subscriptions.push(vscode.commands.registerCommand('calva.refresh', refresh.refresh));
Expand Down Expand Up @@ -222,7 +223,6 @@ async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.languages.registerHoverProvider(config.documentSelector, new HoverProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(config.documentSelector, new definition.ClojureDefinitionProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(config.documentSelector, new definition.StackTraceDefinitionProvider()));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(config.documentSelector, new definition.ResultsDefinitionProvider()));
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(config.documentSelector, new CalvaSignatureHelpProvider(), ' ', ' '));


Expand Down
12 changes: 9 additions & 3 deletions src/providers/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ function decorateSelection(resultString: string, codeSelection: vscode.Selection
decorationRanges = _.filter(decorationRanges, (o) => { return !o.range.intersection(codeSelection) });
decoration["range"] = codeSelection;
if (status != AnnotationStatus.PENDING && status != AnnotationStatus.REPL_WINDOW) {
const commandUri = `command:calva.showOutputWindow`,
commandMd = `[Open Results Window](${commandUri} "Open the results window")`;
let hoverMessage = new vscode.MarkdownString(commandMd);
const copyCommandUri = `command:calva.copyAnnotationHoverText?${encodeURIComponent(JSON.stringify([{ text: resultString }]))}`,
copyCommandMd = `[Copy](${copyCommandUri} "Copy results to the clipboard")`;
const openWindowCommandUri = `command:calva.showOutputWindow`,
openWindowCommandMd = `[Open Output Window](${openWindowCommandUri} "Open the output window")`;
const hoverMessage = new vscode.MarkdownString(`${copyCommandMd} | ${openWindowCommandMd}\n` + '```clojure\n' + resultString + '\n```');
hoverMessage.isTrusted = true;
decoration["hoverMessage"] = status == AnnotationStatus.ERROR ? resultString : hoverMessage;
}
Expand Down Expand Up @@ -169,10 +171,14 @@ function onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
}
}

function copyHoverTextCommand(args: { [x: string]: string; }) {
vscode.env.clipboard.writeText(args["text"]);
}
export default {
AnnotationStatus,
clearEvaluationDecorations,
clearAllEvaluationDecorations,
copyHoverTextCommand,
decorateResults,
decorateSelection,
onDidChangeTextDocument,
Expand Down
12 changes: 1 addition & 11 deletions src/providers/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,4 @@ export class StackTraceDefinitionProvider implements vscode.DefinitionProvider {
return new vscode.Location(entry.uri, pos);
}
}
}

export class ResultsDefinitionProvider implements vscode.DefinitionProvider {
state: any;
constructor() {
this.state = state;
}
async provideDefinition(document, position, token) {
return annotations.getResultsLocation(position);
}
}
}

0 comments on commit cb6f42f

Please sign in to comment.