Skip to content

Commit

Permalink
feat: when no results show origin document
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmu committed Apr 25, 2024
1 parent 3bcd14d commit dfd176d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/periscope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,10 @@ export const periscope = () => {
return;
} else if (code === 127) {
const msg = `PERISCOPE: Ripgrep exited with code ${code} (Ripgrep not found. Please install ripgrep)`;
vscode.window.showErrorMessage(msg );
vscode.window.showErrorMessage(msg);
} else if (code === 1) {
console.log(`PERISCOPE: Ripgrep exited with code ${code} (no results found)`);
if(!config.showPreviousResultsWhenNoMatches) {
// hide the previous results if no results found
qp.items = [];
}
handleNoResultsFound();
} else if (code === 2) {
console.error(`PERISCOPE: Ripgrep exited with code ${code} (error during search operation)`);
} else {
Expand All @@ -314,6 +311,25 @@ export const periscope = () => {
});
}

function handleNoResultsFound() {
if (config.showPreviousResultsWhenNoMatches) {
return;
}

// hide the previous results if no results found
qp.items = [];
// no peek preview available, show the origin document instead
showPreviewOfOriginDocument();
}

function showPreviewOfOriginDocument() {
if (!previousActiveEditor) {return;}
vscode.window.showTextDocument(previousActiveEditor.document, {
preserveFocus: true,
preview: true
});
}

function checkKillProcess() {
spawnRegistry.forEach(spawnProcess => {
spawnProcess.stdout.destroy();
Expand Down

0 comments on commit dfd176d

Please sign in to comment.