Skip to content

Commit

Permalink
feat: support for passing rg parameters directly when search term is …
Browse files Browse the repository at this point in the history
…enclosed by quotation marks
  • Loading branch information
joshmu committed Aug 17, 2024
1 parent b4aeb42 commit ea125af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ For optimal performance, ensure that the VSCode configuration _Editor: Enable Pr

- **Search with Regex**: Use regex in your search query to find specific patterns in your codebase.
- **Selected Text Search**: Highlight text in the editor and invoke `periscope.search` to have it automatically used as the initial query.
- **Utilise `rgQueryParams`**: Create shortcuts for common ripgrep search queries via regex matching against your current query. This provides a way to map your query to ripgrep parameters via capture groups in the regex.
- **Raw Queries**: Enclosing your `search_term` in quotes will allow additional ripgrep parameters to be passed through. eg: `"foobar" -t js` will search for `foobar` in js files.
- **Utilise `rgQueryParams`**: Create shortcuts for common ripgrep search queries via regex matching against your current query. This provides a way to map your query to ripgrep parameters via capture groups in the regex for faster lookups.

## Configuration

Expand Down
14 changes: 13 additions & 1 deletion src/lib/ripgrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ function getRgCommand(value: string, extraFlags?: string[]) {
...excludes,
];

return `"${rgPath}" "${value}" ${rgFlags.join(' ')}`;
const normalizedQuery = handleSearchTermWithAdditionalRgParams(value);

return `"${rgPath}" ${normalizedQuery} ${rgFlags.join(' ')}`;
}

/**
* Support for passing raw ripgrep queries by detection of a search_term within quotes within the input query
* if found we can assume the rest of the query are additional ripgrep parameters
*/
function handleSearchTermWithAdditionalRgParams(query: string): string {
const valueWithinQuotes = /".*?"/.exec(query);
if (valueWithinQuotes) return query;
return `"${query}"`;
}

export function rgSearch(value: string, rgExtraFlags?: string[]) {
Expand Down

0 comments on commit ea125af

Please sign in to comment.