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

Make the extension extensible by third-parties #75

Open
fcollonval opened this issue Apr 28, 2022 · 0 comments
Open

Make the extension extensible by third-parties #75

fcollonval opened this issue Apr 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@fcollonval
Copy link
Member

fcollonval commented Apr 28, 2022

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>;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant