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

The incorrect result returned by company-fuzzy. #37

Open
hongyi-zhao opened this issue Apr 4, 2023 · 15 comments
Open

The incorrect result returned by company-fuzzy. #37

hongyi-zhao opened this issue Apr 4, 2023 · 15 comments

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Apr 4, 2023

I use this package with the following configuration:

(use-package flx)
;; ;; https://github.com/jcs-elpa/company-fuzzy
(use-package company-fuzzy
  :hook (company-mode . company-fuzzy-mode)
  :init
  (setq company-fuzzy-sorting-backend 'flx
        company-fuzzy-prefix-on-top nil
        ;; company-fuzzy-trigger-symbols '("." "->" "<" "\"" "'" "@")
	)
  )

Now, I use the self-made english-wordlist to do some test as follows:

$ ug 'iso.*ph' ~/Public/repo/github.com/hongyi-zhao/english-wordlist.git/american-english-exhaustive
anisophyllous
anisophylly
antisophism
antisophist
antisophistic
antisophistication
antisophistry
cardisophistical
diisopropyl fluorophosphate
disodium hydrogen phosphate
disodium phosphate
eisoptrophobia
isocamphor
isocamphoric
isocephalic
isocephalism
isocephalous
isocephaly
isochlorophyll
isochlorophyllin
isodiaphere
isodiapheres
isodimorphic
isodimorphism
isodimorphism's
isodimorphisms
isodimorphous
isoflurophate
isograph
isographic
isographical
isographically
isograph's
isographs
isography
isokeraunographic
isokeraunophonic
isomeromorphism
isometrograph
isomorph
isomorphic
isomorphically
isomorphism
isomorphism's
isomorphisms
isomorphous
isomorph's
isomorphs
isomorphy
isoneph
isonephelic
isophanal
isophane
isophasal
isophenal
isophene
isophenomenal
isophenous
isophone
isophone's
isophones
isophoria
isophorone
isophot
isophotal
isophote
isophote's
isophotes
isophotic line
isophthalic
isophthalic acid
isophthalyl
isophyllia
isophyllous
isophylly
isopodimorphous
isopsephic
isopsephism
isosulphide
isosulphocyanate
isosulphocyanic
isotrimorphic
isotrimorphism
isotrimorphous
misophobia
misosopher
misosophist
misosophy
trisodium phosphate
unisomorphic

But, in Emacs, when I'm typing isoph, only a few completed candidates are listed, as shown below:
image

Any hints for this problem?

See company-mode/company-mode#1380 (comment) for the related discussion.

Regards,
Zhao

@jcs090218
Copy link
Member

What is your value of completion-styles? It seems like the backend is effect by the variable, see https://github.com/company-mode/company-mode/blob/246837b12cbedaac0c9e2b654d97426639e0c778/company-ispell.el#L77.

See https://github.com/jcs-elpa/company-fuzzy#-2-cause-by-completion-styles.

I've tried it and it works! :)

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 4, 2023

Currently, I also have the following configuration for minibuffer completion:

(use-package orderless
  :config
  (setq
   ;; https://github.com/oantolin/orderless#ivy
   ivy-re-builders-alist '((t . orderless-ivy-re-builder))

   ;; Configure a custom style dispatcher (see the Consult wiki)
   ;; orderless-style-dispatchers '(+orderless-dispatch)
   ;; orderless-component-separator #'orderless-escapable-split-on-space

   completion-styles '(orderless)
   completion-category-defaults nil
   completion-category-overrides '((file (styles . (partial-completion)))))

  (defun anchor-first-component (pattern index _total)
    (when (= index 0)
      (cons 'orderless-regexp (concat "^" pattern))))

  (defun with-anchored-first-component (fn &rest args)
    (let ((orderless-style-dispatchers
	   (cons #'anchor-first-component orderless-style-dispatchers)))
      (apply fn args)))

  (advice-add 'company-calculate-candidates
	      :around #'with-anchored-first-component)
  )

So, how should I use your package and orderless at the same time?

On the other hand, I've tried to comment out all the above orderless configuration, and use the following one:

(use-package flx)
;; ;; https://github.com/jcs-elpa/company-fuzzy
(use-package company-fuzzy
  :hook (company-mode . company-fuzzy-mode)
  :init
  (setq company-fuzzy-sorting-backend 'flx
        company-fuzzy-prefix-on-top nil
	completion-styles '(partial-completion)
        company-fuzzy-trigger-symbols '("." "->" "<" "\"" "'" "@")
	)
  )

But I still can't get the desired result:

image
image

@jcs090218
Copy link
Member

Ah, hold on. I guess I was wrong about completion-styles in this case. Proof is:

(let ((completion-styles nil))
  (message "%s" (all-completions "iso" '("isophene" "isophenomenal")))  ; prints (isophene isophenomenal)
  )

So I guess that doesn't effect the result. Hmm...

I will need you to do some tests since I am not able to reproduce this issue from my end.

  1. What happens when you M-x company-ispell directly?
  2. Try to print the candidates out:
(defun company-ispell (command &optional arg &rest ignored)
  "`company-mode' completion backend using Ispell."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-ispell))
    (prefix (when (company-ispell-available)
              (company-grab-word)))
    (candidates
     (let ((words (company-ispell--lookup-words
                   arg
                   (or company-ispell-dictionary ispell-complete-word-dict)))
           (completion-ignore-case t))
       (if (string= arg "")
           ;; Small optimization.
           words
+         (message "? %s" (all-completions arg words))
         ;; Work around issue #284.
         (all-completions arg words))))
    (kind 'text)
    (sorted t)
    (ignore-case 'keep-prefix)))

My best guess is something is "blocking" so it doesn't returns the full list. 🤔

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 4, 2023

I try with C-x C-e or M-x company-ispell to debug all your suggestions as follows:

(let ((completion-styles nil))
  (message "%s" (all-completions "iso" '("isophene" "isophenomenal")))  ; prints (isophene isophenomenal)
  )

image

  1. What happens when you M-x company-ispell directly?
    image

2. Try to print the candidates out:

image

@jcs090218
Copy link
Member

  1. What happens when you M-x company-ispell directly?

Can you try it without company-fuzzy being enabled? :D Want to compare the differences.

  1. Try to print the candidates out:

I want to see what candidate is in used, can you show me the "output" from *Messages* buffer? Thanks! :D

@hongyi-zhao
Copy link
Author

Can you try it without company-fuzzy being enabled? :D Want to compare the differences.

image

I want to see what candidate is in used, can you show me the "output" from *Messages* buffer? Thanks! :D

image

Loading server...done
Iedit default key binding is C-;
[yas] Prepared just-in-time loading of snippets (but no snippets found).
Loading /home/werner/.emacs.d/var/recentf-save.el (source)...done
Cleaning up the recentf list...done (0 removed)
Using default formatter emacs-lisp
For information about GNU Emacs and the GNU system, type C-h C-a.
Wrote /home/werner/.emacs.d/var/recentf-save.el
Package cl is deprecated
Automatic display of crossref information was turned on
Starting new Ispell process /usr/bin/aspell with default dictionary...done
Applying style hooks...
Loading /home/werner/Downloads/TopologicalMaterials/caj/SpaceGroupIrep/2012/.auctex-auto/SpaceGroupIrep.el (source)...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/fontenc.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/color.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/babel.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/english.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/array.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/bm.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/multirow.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/amsmath.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/amstext.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/amsbsy.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/amsopn.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/graphicx.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/pdfpages.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/eso-pic.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/ifthen.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/xcolor.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/textcomp.elc...done
Loading /home/werner/.emacs.d/straight/repos/auctex/style/listings.elc...done
Applying style hooks...done
TabNine server started.
Sorting LaTeX-environment...done
Removing duplicates...done
Beginning of buffer [6 times]

@hongyi-zhao
Copy link
Author

On the other hand, if I only input isop, the following candidates will be triggered:

image

Then, if I further append a h, the results will be narrowed dramatically:

image

@jcs090218
Copy link
Member

I don't think the bug is from this package. We will need to further investigate it, can you try eval the following code and see if it returns anything?

(require 'company-ispell)  ; load before override

;;;###autoload
(defun company-ispell (command &optional arg &rest ignored)
  "`company-mode' completion backend using Ispell."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-ispell))
    (prefix (when (company-ispell-available)
              (company-grab-word)))
    (candidates
     (let ((words '("isophones"  ; manually set the candidates and see what happens.
                    "isophoria"
                    "isophorone"
                    "isophot"
                    "isophotal"
                    "isophote"
                    "isophote's"))
           (completion-ignore-case t))
       (if (string= arg "")
           ;; Small optimization.
           words
         ;; Work around issue #284.
         (all-completions arg words))))
    (kind 'text)
    (sorted t)
    (ignore-case 'keep-prefix)))

It should appear every candidate in the company's popup when you type iso.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 5, 2023

See the following:

image

But isoph will trigger nothing:

image

@jcs090218
Copy link
Member

It seems like it works?! Then there is something wrong with company-ispell--lookup-words. Next thing to try is:

(defun company-ispell (command &optional arg &rest ignored)
  "`company-mode' completion backend using Ispell."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-ispell))
    (prefix (when (company-ispell-available)
              (company-grab-word)))
    (candidates
     (message "arg: %s" arg)  ; print the `arg` value!
     (let ((words (company-ispell--lookup-words
                   arg
                   (or company-ispell-dictionary ispell-complete-word-dict)))
           (completion-ignore-case t))
       (message "reached: %s" words)  ; make sure it goes through this line, print words to see what's the candidates.
       (if (string= arg "")
           ;; Small optimization.
           words
         ;; Work around issue #284.
         (all-completions arg words))))
    (kind 'text)
    (sorted t)
    (ignore-case 'keep-prefix)))

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 5, 2023

Testing code:

(require 'company-ispell)  ; load before override
(defun company-ispell (command &optional arg &rest ignored)
  "`company-mode' completion backend using Ispell."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-ispell))
    (prefix (when (company-ispell-available)
              (company-grab-word)))
    (candidates
     (message "arg: %s" arg)  ; print the `arg` value!
     (let ((words (company-ispell--lookup-words
                   arg
                   (or company-ispell-dictionary ispell-complete-word-dict)))
           (completion-ignore-case t))
       (message "reached: %s" words)  ; make sure it goes through this line, print words to see what's the candidates.
       (if (string= arg "")
           ;; Small optimization.
           words
         ;; Work around issue #284.
         (all-completions arg words))))
    (kind 'text)
    (sorted t)
    (ignore-case 'keep-prefix)))

Results:

image

image

@jcs090218
Copy link
Member

Can you give me the result from the (message "arg: %s" arg) in the *Messages* buffer? Thanks!

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 5, 2023

I'm not sure whether I understand you correctly, but when I try to copy && paste (message "arg: %s" arg) into the *Messages* buffer to evaluate it, the following error occurs:

image

@jcs090218
Copy link
Member

No, I mean after your evaluate the function company-ispell (code above) to override the presented version. And see what's output while typing isop, and the output is in the *Messages* buffer.

@hongyi-zhao
Copy link
Author

See the following:
image
image

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

2 participants