Uploaded image for project: 'Aesh'
  1. Aesh
  2. AESH-477

CompletionHandler re-sorts custom Completion implementation candidates list

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.7
    • 1.8
    • None
    • None

      I am using a custom Completion<CompleteOperation> implementation, which provides a list of valid completions for my use case.

      The completion list is populated like this:

                      possibleCompletions = Files.list(currentPath).filter(isOnlyDirectories ? isDirectory() : path -> true)
                              .filter(isHiddenFile(incompleteFilename).negate())
                              .filter(startsWithIncompleteFilename(incompleteFilename))
                              .map(Path::getFileName)
                              .map(Path::toString)
                              .map(filename -> Files.isDirectory(currentPath.resolve(filename)) ? filename + File.separator : filename)
                              .sorted(Comparator.comparing(String::toLowerCase))
                              .collect(Collectors.toList());
      

      which results in the results and ordering I want. However, this code:

      CompletionHandler.java Line 209-220:

          private void displayCompletions(List<TerminalString> completions, Buffer buffer,
                                          InputProcessor inputProcessor) {
              Collections.sort(completions);
      
              inputProcessor.buffer().writeOut(Config.CR);
              inputProcessor.buffer().writeOut(Parser.formatDisplayListTerminalString(completions,
                      inputProcessor.buffer().size().getHeight(), inputProcessor.buffer().size().getWidth()));
      
              buffer.setIsPromptDisplayed(false);
              buffer.invalidateCursorLocation();
              inputProcessor.buffer().drawLine();
          }
      

      calls

      Collections.sort(completions);
      

      which re-sorts my provided list and changes the order completions are listed in.

      I debated putting this under a bug or a feature-request / enhancement, sorry if I've put it into the wrong category

      It would be nice to either

      1. have the code assume that completions are being provided in a sorted order that is appropriate for the given completion
      2. provide a way to disable the sorting that occurs in the displayCompletions() method

      I'd be willing to help with a PR on this too!

              spederse@redhat.com Stale Pedersen
              thauser_jira Thomas Hauser (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: