Skip to content

Commit

Permalink
Add basic REPL History search
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkam2 committed Apr 27, 2024
1 parent 859f162 commit fcf8060
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,12 @@
"enablement": "calva:connected",
"category": "Calva"
},
{
"command": "calva.searchReplHistory",
"title": "Search REPL History",
"enablement": "calva:connected && calva:outputWindowActive && calva:replHistoryCommandsActive",
"category": "Calva"
},
{
"command": "calva.showPreviousReplHistoryEntry",
"title": "Show Previous REPL History Entry",
Expand Down Expand Up @@ -2748,6 +2754,11 @@
"key": "ctrl+alt+c ctrl+alt+space",
"when": "calva:keybindingsEnabled && editorLangId == clojure && calva:connected && !calva:outputWindowActive"
},
{
"command": "calva.searchReplHistory",
"key": "alt+shift+r",
"when": "calva:keybindingsEnabled && editorLangId == clojure && calva:connected && calva:outputWindowActive"
},
{
"command": "calva.showPreviousReplHistoryEntry",
"key": "alt+up",
Expand Down Expand Up @@ -3069,6 +3080,10 @@
"command": "calva.debug.instrument",
"when": "editorLangId == clojure"
},
{
"command": "calva.searchReplHistory",
"when": "calva:connected && calva:outputWindowActive"
},
{
"command": "calva.showPreviousReplHistoryEntry",
"when": "calva:connected && calva:outputWindowActive"
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ async function activate(context: vscode.ExtensionContext) {
showFileForOutputWindowNS: () => {
return outputWindow.revealDocForCurrentNS(false);
},
searchReplHistory: replHistory.searchReplHistory,
showNextReplHistoryEntry: replHistory.showNextReplHistoryEntry,
showOutputWindow: () => outputWindow.revealResultsDoc(false),
showOutputChannel: output.showOutputChannel,
Expand Down
17 changes: 17 additions & 0 deletions src/repl-window/repl-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,26 @@ function showNextReplHistoryEntry(): void {
}
}

function searchReplHistory(): void {
const editor = util.getActiveTextEditor();
const history = getHistory(getSessionType());
vscode.window.showInputBox({
prompt: 'Enter search term for REPL history',
validateInput: (text) => {
const entry = history.filter((entry) => entry.includes(text)).pop();
if (entry !== undefined) {
showReplHistoryEntry(prependNewline(entry), editor);
return undefined;
}
return 'No matching entry found in REPL history';
},
});
}

export {
addToHistory,
addToReplHistory,
searchReplHistory,
showPreviousReplHistoryEntry,
showNextReplHistoryEntry,
resetState,
Expand Down

0 comments on commit fcf8060

Please sign in to comment.