Interface CompletionMatcher

All Known Implementing Classes:
CompletionMatcherImpl

public interface CompletionMatcher
Interface for matching and filtering completion candidates.

The CompletionMatcher is responsible for determining which completion candidates should be presented to the user based on what they've typed so far. It implements the logic for matching candidates against the input, handling case sensitivity, typo tolerance, and other matching strategies.

This interface allows for different matching algorithms to be used, such as:

  • Prefix matching - candidates that start with the input text
  • Substring matching - candidates that contain the input text
  • Fuzzy matching - candidates that approximately match the input text
  • Camel case matching - matching based on camel case patterns

The default implementation is CompletionMatcherImpl.

See Also:
  • Method Details

    • compile

      void compile(Map<LineReader.Option,Boolean> options, boolean prefix, CompletingParsedLine line, boolean caseInsensitive, int errors, String originalGroupName)
      Initializes the matcher with the current completion context.

      This method is called before any matching operations to set up the matcher with the current completion context, including the line being completed, reader options, and other parameters that affect how matching should be performed.

      The matcher uses this information to compile its internal matching functions that will be used to filter candidates.

      Parameters:
      options - LineReader options that may affect matching behavior
      prefix - true if invoked by complete-prefix or expand-or-complete-prefix widget
      line - the parsed line within which completion has been requested
      caseInsensitive - true if completion should be case insensitive
      errors - number of typo errors accepted in matching (for fuzzy matching)
      originalGroupName - value of the LineReader variable original-group-name
    • matches

      List<Candidate> matches(List<Candidate> candidates)
      Filters the provided candidates based on the current matching criteria.

      This method applies the matching algorithm to the list of candidates and returns only those that match the current input according to the configured matching rules. The returned list may be sorted based on match quality.

      Parameters:
      candidates - the list of candidates to filter
      Returns:
      a list of candidates that match the current input
    • exactMatch

      Candidate exactMatch()
      Returns a candidate that exactly matches the current input, if any.

      An exact match typically means the candidate's value is identical to what the user has typed, possibly ignoring case depending on the matcher configuration. This is used to determine if the completion should be accepted immediately without showing a list of options.

      Returns:
      a candidate that exactly matches the current input, or null if no exact match is found
    • getCommonPrefix

      String getCommonPrefix()
      Returns the longest common prefix shared by all matched candidates.

      This is used to implement tab completion behavior where pressing tab will automatically complete as much of the input as can be unambiguously determined from the available candidates.

      Returns:
      the longest common prefix of all matched candidates, or an empty string if none