Skip to content

Commit

Permalink
fix: quick pick item show all
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmu committed Mar 6, 2023
1 parent c02510a commit e113b22
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/periscope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const periscope = () => {
function register() {
console.log('Periscope instantiated');
activeEditor = vscode.window.activeTextEditor;
// @see https://code.visualstudio.com/api/references/vscode-api#QuickPick
quickPick = vscode.window.createQuickPick();

quickPick.placeholder = 'Enter a search query';
Expand Down Expand Up @@ -93,26 +94,26 @@ export const periscope = () => {
return;
}
if (code === 0 && searchResultLines.length) {
quickPick.items = searchResultLines
.map(searchResult => {
// break the filename via regext ':line:col:'
const [filePath, linePos, colPos, fileContents] =
searchResult.split(':');

// if all data is not available then remove the item
if (!filePath || !linePos || !colPos || !fileContents) {
return false;
}

return createResultItem(
filePath,
fileContents,
parseInt(linePos),
parseInt(colPos),
searchResult
);
})
.filter(Boolean) as QuickPickItemCustom[];
quickPick.items = searchResultLines.map(searchResult => {
// break the filename via regext ':line:col:'
const [filePath, linePos, colPos, ...textResult] =
searchResult.split(':');
const fileContents = textResult.join(':');

// if all data is not available then remove the item
if (!filePath || !linePos || !colPos || !fileContents) {
return false;
}

return createResultItem(
filePath,
fileContents,
parseInt(linePos),
parseInt(colPos),
searchResult
);
}).filter(Boolean) as QuickPickItemCustom[];

} else if (code === 127) {
vscode.window.showErrorMessage(
`Periscope: Exited with code ${code}, ripgrep not found.`
Expand Down Expand Up @@ -235,8 +236,8 @@ export const periscope = () => {
const folders = filePath.split(path.sep);

// abbreviate path if too long
if (folders.length > 2) {
folders.splice(0, folders.length - 2);
if (folders.length > 4) {
folders.splice(0, folders.length - 4);
folders.unshift('...');
}

Expand All @@ -248,8 +249,10 @@ export const periscope = () => {
colPos,
rawResult: rawResult ?? '',
},
description: `${folders.join(path.sep)}`,
// detail: `${folders.join(path.sep)}`,
// description: `${folders.join(path.sep)}`,
detail: `${folders.join(path.sep)}`,
// ! required to support regex, otherwise quick pick will automatically remove results that don't have an exact match
alwaysShow: true,
};
}

Expand Down

0 comments on commit e113b22

Please sign in to comment.