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

Fix 'wrong-type-argument' error with ivy-prescient #119

Merged
merged 2 commits into from
May 1, 2022

Conversation

Hirozy
Copy link
Contributor

@Hirozy Hirozy commented Apr 16, 2022

ivy doesn't convert all variables to string when sorting or calling prescient-remember, so it need to preprocess when work with ivy-prescient.el. if not, a wrong-type-argument error may occur.

ivy-prescient.el Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
ivy-prescient.el Outdated Show resolved Hide resolved
ivy-prescient.el Outdated Show resolved Hide resolved
ivy-prescient.el Outdated Show resolved Hide resolved
@Hirozy
Copy link
Contributor Author

Hirozy commented Apr 18, 2022

With format-all, if more than one formatter is available for a major-mode, such as c++-mode, which has two formatters, clang-format and astyle, the following error will occur when calling the format-all-buffer command.

Debugger entered--Lisp error: (wrong-type-argument sequencep astyle)
  prescient-sort-compare(astyle clang-format)
  ivy-prescient-sort-function((astyle) (clang-format))
  sort(((clang-format)) ivy-prescient-sort-function)
  ivy--reset-state(#s(ivy-state :prompt "Formatter for C++: " :collection ((clang-format) (astyle)) :predicate nil :require-match t :initial-input nil :history nil :preselect nil :keymap nil :update-fn nil :sort t :frame #<frame  *Minibuf-1* 0x154b8ba30> :window #<window 3 on test_lsp.cc> :buffer #<buffer test_lsp.cc> :text nil :action (1 ("o" identity "default") ("i" ivy--action-insert "insert") ("w" ivy--action-copy "copy")) :unwind nil :re-builder orderless-ivy-re-builder :matcher nil :dynamic-collection nil :display-transformer-fn nil :directory "lsp/src/" :caller format-all-buffer :current nil :def nil :ignore t :multi-action nil :extra-props (:caller ivy-completing-read)))
  #<subr ivy-read>("Formatter for C++: " ((clang-format) (astyle)) :predicate nil :require-match t :initial-input nil :preselect nil :def nil :history nil :keymap nil :dynamic-collection nil :extra-props (:caller ivy-completing-read) :caller format-all-buffer :sort t)
  apply(#<subr ivy-read> ("Formatter for C++: " ((clang-format) (astyle)) :predicate nil :require-match t :initial-input nil :preselect nil :def nil :history nil :keymap nil :dynamic-collection nil :extra-props (:caller ivy-completing-read) :caller format-all-buffer :sort t))
  ivy-read("Formatter for C++: " ((clang-format) (astyle)) :predicate nil :require-match t :initial-input nil :preselect nil :def nil :history nil :keymap nil :dynamic-collection nil :extra-props (:caller ivy-completing-read) :caller format-all-buffer)
  ivy-completing-read("Formatter for C++: " ((clang-format) (astyle)) nil t nil nil nil nil)
  format-all--prompt-for-formatter("C++")
  format-all--buffer-or-region(t nil)
  format-all-buffer(t)
  funcall-interactively(format-all-buffer t)
  command-execute(format-all-buffer record)
  counsel-M-x-action("format-all-buffer")
  #f(compiled-function (x) #<bytecode -0x184d58c4805416c0>)("format-all-buffer")
  ivy-call()
  #<subr ivy-read>("M-x " [company-box--max lsp-make-signature-help-options vc-src-responsible-p lsp:omnisharp-run-tests-in-class-request-column tramp-sudoedit-file-name-handler lsp-pwsh-help-completion evil-want-Y-yank-to-eol lsp-watch-kind? python-nav-beginning-of-defun-regexp access-label :maxLength c-electric-lt-gt semantic-c-debug-mode-init-last-mode yas-x-prompt lib-target dired-unmark-all-marks flycheck-mode-line-prefix cl-struct-flycheck-syntax-check-tags haskell-font-lock--put-face-on-type-or-constructor f-ancestor-of? files--splice-dirname-file lsp-perlnavigator eshell-return-exits-minibuffer :EndLineNumber awesome-tab-mode-hook c-make-ml-string-opener-re-function traversed company-box--handle-scroll kmacro-pop-ring1 which-key--stop-timer c-list-found-types flycheck-pug-executable lsp-elixir-suggest-specs xref--push-markers vc-bzr-shelve-menu WatchKind lsp:set-rename-params-uri? lsp-pyls-plugins-flake8-hang-closing lsp-pylsp-plugins-rope-completion-enabled lsp--virtual-buffer lsp-typescript-format-insert-space-after-opening-and-before-closing-nonempty-brackets lsp-lua-hint-enable dash-expand:&JSONResponse? TeX-command-default zoo calcFunc-erfc xref-group angle-bracket-arglist-escape tramp-handle-make-auto-save-file-name puny-encode-digit ...] :predicate #f(compiled-function (sym) #<bytecode -0xd814029039faa09>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x :sort t)
  apply(#<subr ivy-read> ("M-x " [company-box--max lsp-make-signature-help-options vc-src-responsible-p lsp:omnisharp-run-tests-in-class-request-column tramp-sudoedit-file-name-handler lsp-pwsh-help-completion evil-want-Y-yank-to-eol lsp-watch-kind? python-nav-beginning-of-defun-regexp access-label :maxLength c-electric-lt-gt semantic-c-debug-mode-init-last-mode yas-x-prompt lib-target dired-unmark-all-marks flycheck-mode-line-prefix cl-struct-flycheck-syntax-check-tags haskell-font-lock--put-face-on-type-or-constructor f-ancestor-of? files--splice-dirname-file lsp-perlnavigator eshell-return-exits-minibuffer :EndLineNumber awesome-tab-mode-hook c-make-ml-string-opener-re-function traversed company-box--handle-scroll kmacro-pop-ring1 which-key--stop-timer c-list-found-types flycheck-pug-executable lsp-elixir-suggest-specs xref--push-markers vc-bzr-shelve-menu WatchKind lsp:set-rename-params-uri? lsp-pyls-plugins-flake8-hang-closing lsp-pylsp-plugins-rope-completion-enabled lsp--virtual-buffer lsp-typescript-format-insert-space-after-opening-and-before-closing-nonempty-brackets lsp-lua-hint-enable dash-expand:&JSONResponse? TeX-command-default zoo calcFunc-erfc xref-group angle-bracket-arglist-escape tramp-handle-make-auto-save-file-name puny-encode-digit ...] :predicate #f(compiled-function (sym) #<bytecode -0xd814029039faa09>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x :sort t))
  ivy-read("M-x " [company-box--max lsp-make-signature-help-options vc-src-responsible-p lsp:omnisharp-run-tests-in-class-request-column tramp-sudoedit-file-name-handler lsp-pwsh-help-completion evil-want-Y-yank-to-eol lsp-watch-kind? python-nav-beginning-of-defun-regexp access-label :maxLength c-electric-lt-gt semantic-c-debug-mode-init-last-mode yas-x-prompt lib-target dired-unmark-all-marks flycheck-mode-line-prefix cl-struct-flycheck-syntax-check-tags haskell-font-lock--put-face-on-type-or-constructor f-ancestor-of? files--splice-dirname-file lsp-perlnavigator eshell-return-exits-minibuffer :EndLineNumber awesome-tab-mode-hook c-make-ml-string-opener-re-function traversed company-box--handle-scroll kmacro-pop-ring1 which-key--stop-timer c-list-found-types flycheck-pug-executable lsp-elixir-suggest-specs xref--push-markers vc-bzr-shelve-menu WatchKind lsp:set-rename-params-uri? lsp-pyls-plugins-flake8-hang-closing lsp-pylsp-plugins-rope-completion-enabled lsp--virtual-buffer lsp-typescript-format-insert-space-after-opening-and-before-closing-nonempty-brackets lsp-lua-hint-enable dash-expand:&JSONResponse? TeX-command-default zoo calcFunc-erfc xref-group angle-bracket-arglist-escape tramp-handle-make-auto-save-file-name puny-encode-digit ...] :predicate #f(compiled-function (sym) #<bytecode -0xd814029039faa09>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  command-execute(counsel-M-x)

This PR can fix such problems.

@Hirozy Hirozy force-pushed the ivy-fix branch 2 times, most recently from 9af087b to 61daeed Compare April 18, 2022 15:08
Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One more comment

ivy-prescient.el Outdated
element
(cond ((symbolp element) (symbol-name element))
((consp element) (symbol-name (car element)))
((listp element) (car element)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the third case will never trigger, because the only thing that satisfies listp but not consp is nil. So I think this would break the existing case where you have a cons cell whose car is a string, because it would try to take symbol-name of a string?

Copy link
Contributor Author

@Hirozy Hirozy Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment. I've fixed the ivy-prescient--elements-ensure function implementation, which should be the right way. What do you think?

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Looks good, thanks!

@raxod502 raxod502 merged commit d9b30d7 into radian-software:master May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants