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

Order of company candidates is lost #26

Open
ag91 opened this issue Jun 30, 2024 · 0 comments
Open

Order of company candidates is lost #26

ag91 opened this issue Jun 30, 2024 · 0 comments

Comments

@ag91
Copy link

ag91 commented Jun 30, 2024

Hey, thanks for maintaining this repo.

I wonder how this wasn't raised before, but helm-company stores company-candidates strings in a hash-table.
Elisp hash tables are unordered, so (hash-table-keys helm-company-display-candidates-hash) applies a random order to the list of completions.

I finally managed to find the issue today and this is my fix:

    (defvar my/sorted-candidates-display-str nil)

    (defun helm-company--make-display-candidate-hash (candidates)
      (let ((hash (make-hash-table :test 'equal :size 1000)))
        (setq my/sorted-candidates-display-str nil)
        (cl-loop for candidate in candidates
                 for annot = (helm-company--get-annotations candidate)
                 for display-str = (helm-company--make-display-string candidate annot)
                 for key = (substring-no-properties display-str)
                 do (progn
                      (add-to-list 'my/sorted-candidates-display-str display-str 'append)
                      (puthash key (cons display-str candidate) hash)))
        hash))

    (defun helm-company-get-display-strings ()
      (let ((sort (null helm--in-fuzzy))
            (display-strs my/sorted-candidates-display-str))
        (if sort
            (sort display-strs #'helm-generic-sort-fn)
          display-strs)))
    )

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant