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

Explore inlay hints for REPL results #1594

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"license": "MIT",
"engines": {
"vscode": "^1.63.0"
"vscode": "^1.65.2"
},
"categories": [
"Programming Languages",
Expand Down Expand Up @@ -2652,7 +2652,7 @@
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.167",
"@types/mocha": "^9.0.0",
"@types/vscode": "^1.45.0",
"@types/vscode": "^1.65.0",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"chai": "^4.2.0",
Expand Down
12 changes: 11 additions & 1 deletion src/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import * as state from './state';
import annotations from './providers/annotations';
import * as inlayhints from './providers/inlayhints';
import * as path from 'path';
import * as util from './utilities';
import { NReplSession, NReplEvaluation } from './nrepl';
Expand Down Expand Up @@ -151,6 +152,14 @@ async function evaluateCode(
);
}
if (!outputWindow.isResultsDoc(editor.document)) {
inlayhints.registerResult(
editor,
editor.document,
new vscode.Range(selection.end, selection.end),
//selection,
//resultLocation.range,
value
);
annotations.decorateSelection(
value,
selection,
Expand All @@ -159,7 +168,8 @@ async function evaluateCode(
resultLocation,
annotations.AnnotationStatus.SUCCESS
);
if (!options.comment) {
// hide decoration results for this exploration
if (false && !options.comment) {
annotations.decorateResults(
value,
false,
Expand Down
8 changes: 8 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import JarContentProvider from './providers/content';
import HoverProvider from './providers/hover';
import * as definition from './providers/definition';
import { CalvaSignatureHelpProvider } from './providers/signature';
import { TheInlayHintsProvider } from './providers/inlayhints';
import testRunner from './testRunner';
import annotations from './providers/annotations';
import select from './select';
Expand Down Expand Up @@ -612,6 +613,13 @@ async function activate(context: vscode.ExtensionContext) {
new HoverProvider()
)
);
context.subscriptions.push(
vscode.languages.registerInlayHintsProvider(
config.documentSelector,
TheInlayHintsProvider

)
);
context.subscriptions.push(
vscode.languages.registerDefinitionProvider(
config.documentSelector,
Expand Down
73 changes: 73 additions & 0 deletions src/providers/inlayhints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as vscode from 'vscode';


let THE_RESULTS = {};

function newHint(position, replResults: string) {
let lines = replResults.split(/\r?\n/);
let label = new vscode.InlayHintLabelPart(lines[0])
// the tooltip doesn't show
label.tooltip = replResults;
// .location implies that the hover will be related to the
// an actual symbol at the location, so I think
// this approach won't work for REPL results
label.location = position;
// la
// label.command = {
// title: "Go to output window",
// command: "calva.showOutputWindow"
// };
let copyLabel = new vscode.InlayHintLabelPart("(copy)")
// this doesn't appear to be executing
copyLabel.command = {
title: "Copy to Clipboard",
command: "calva.copyLastResults"};
let space = new vscode.InlayHintLabelPart(" ");
let hint = new vscode.InlayHint(position,
[label, space, copyLabel],
vscode.InlayHintKind.Parameter
);
return hint;
}

export class InlayHintsProvider implements vscode.InlayHintsProvider<vscode.InlayHint> {
//private readonly _onDidChangeInlayHints = new vscode.EventEmitter<void>();
public readonly emitter = new vscode.EventEmitter<void>();
public readonly onDidChangeInlayHints = this.emitter.event;
provideInlayHints(document, hintRange: vscode.Range, token) {
let docResults = THE_RESULTS[document.uri.toString()] || [];
let hints = [];
for (let {range, value} of docResults) {
if (hintRange.contains(range.end)) {
hints.push(newHint(range.end, value.toString()));
}
}
return hints;
}


}

export var TheInlayHintsProvider = new InlayHintsProvider();


export function registerResult(editor: vscode.TextEditor, document: vscode.TextDocument, range: vscode.Range, value: any) {
let k = document.uri.toString();
let docResults = THE_RESULTS[k] || [];
THE_RESULTS[k] = docResults;
docResults.push({range: range, value: value});
let firstLine = document.lineAt(0);
let lastLine = document.lineAt(document.lineCount - 1);
let textRange = new vscode.Range(firstLine.range.start, lastLine.range.end);
// show hints immediately
TheInlayHintsProvider.emitter.fire();
// try to show hints even more immediately (doesn't seem to have an effect)
vscode.commands.executeCommand(
"vscode.executeInlayHintProvider", document.uri,
textRange);

// editor.edit((editBuilder) => {
// }, {undoStopAfter: false, undoStopBefore: false}
// );
console.log("REGISTERED RESULT", document.uri.toString(), range.start, range.end, value);
}