search-replace
search-replace copied to clipboard
Make the extension extensible by third-parties
Is your feature request related to a problem? Please describe.
Currently the extension is not extensible on the following subject:
- The search engine - hard coded
ripgrep
usage on the backend - The file opener and replacer - hard coded
FileEditor
to highlight and/or replace search matches from ripgrep.
Describe the solution you'd like
It would be good to allow third-parties to register plugin to alleviate those limitations.
An API candidate is the following:
interface ISearchReplaceProvider {
/**
* Initialize the provider with the search parameters
* @returns Additional exclude filters to be set on ripgrep search or null to skip calling ripgrep.
*/
preprocess: (all search parameters) => string[] | null;
/**
* Update/Extend the matches from ripgrep search
* This could add file matches for excluded files in the preprocessor phase
* or add a customized `displayAndReplace` callback on file matches
*/
postprocess: (filematches: IFileMatch[]) => IFileMatch[];
}
interface ISearchReplaceRegistry {
/**
* Add a provider
* Options
* rank: Rank of the provider (default order of registration)
*/
add: (provider: ISearchReplaceProvider, options?: {rank: number}) => void;
}
/**
* Interface to represent matches in a file
*/
export interface IFileMatch {
/**
* path of file
*/
path: string;
/**
* all matches within that file
*/
matches: IMatch[];
/**
* Open and optionally replace matches in a file
* ### Notes
* If replace is false, only open the file and highlight to the first match
* The replace action should be undoable
* @param path File path
* @param matches Matches within the file
* @param replace Whether to replace or not
* @returns the widget opened
*/
displayAndReplace?: (path: string, matches?: SearchReplace.IMatch[], replace = false) => Promise<Widget>;
}