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 basic REPL History search #2540

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
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({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be this dangling promise that causes the linter to complain. I think the solution is to return the promise, because otherwise systems like Joyride and runCommands can't wait for the command to finish, which limits its usefulness.

Suggested change
vscode.window.showInputBox({
return 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