diff --git a/package-lock.json b/package-lock.json index f0000ecd3..065a80560 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,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", @@ -79,7 +79,7 @@ "webpack-cli": "^4.5.0" }, "engines": { - "vscode": "^1.63.0" + "vscode": "^1.65.2" } }, "node_modules/@babel/code-frame": { @@ -1529,9 +1529,9 @@ "integrity": "sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg==" }, "node_modules/@types/vscode": { - "version": "1.61.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.61.0.tgz", - "integrity": "sha512-9k5Nwq45hkRwdfCFY+eKXeQQSbPoA114mF7U/4uJXRBJeGIO7MuJdhF1PnaDN+lllL9iKGQtd6FFXShBXMNaFg==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", + "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "dev": true }, "node_modules/@types/yargs": { @@ -12976,9 +12976,9 @@ "integrity": "sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg==" }, "@types/vscode": { - "version": "1.61.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.61.0.tgz", - "integrity": "sha512-9k5Nwq45hkRwdfCFY+eKXeQQSbPoA114mF7U/4uJXRBJeGIO7MuJdhF1PnaDN+lllL9iKGQtd6FFXShBXMNaFg==", + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.65.0.tgz", + "integrity": "sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==", "dev": true }, "@types/yargs": { diff --git a/package.json b/package.json index ee5e0c8ba..8e777bfea 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "license": "MIT", "engines": { - "vscode": "^1.63.0" + "vscode": "^1.65.2" }, "categories": [ "Programming Languages", @@ -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", diff --git a/src/evaluate.ts b/src/evaluate.ts index 605262974..779c98a3d 100644 --- a/src/evaluate.ts +++ b/src/evaluate.ts @@ -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'; @@ -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, @@ -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, diff --git a/src/extension.ts b/src/extension.ts index eb3d2428a..69ca688d6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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'; @@ -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, diff --git a/src/providers/inlayhints.ts b/src/providers/inlayhints.ts new file mode 100644 index 000000000..508602e5e --- /dev/null +++ b/src/providers/inlayhints.ts @@ -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 { + //private readonly _onDidChangeInlayHints = new vscode.EventEmitter(); + public readonly emitter = new vscode.EventEmitter(); + 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); +}