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

Completions list display corrupted #1427

Closed
richardxday opened this issue Nov 13, 2023 · 5 comments
Closed

Completions list display corrupted #1427

richardxday opened this issue Nov 13, 2023 · 5 comments

Comments

@richardxday
Copy link

richardxday commented Nov 13, 2023

Output of the command M-x company-diag

Emacs 29.1 (x86_64-pc-linux-gnu) of 2023-11-13 on nil
Company 0.10.2

company-backends: (company-capf
(company-dabbrev-code company-dabbrev company-ispell)
company-files company-yasnippet company-keywords company-elisp)

Used backend: (company-dabbrev-code company-dabbrev company-ispell)

Major mode: text-mode
Prefix: "candidat"
Completions:
#("candidate" 0 9 (company-backend company-ispell))
#("candidate's" 0 11 (company-backend company-ispell))
#("candidates" 0 10 (company-backend company-ispell))
#("candidature" 0 11 (company-backend company-ispell))
#("candidatures" 0 12 (company-backend company-ispell))

Describe the issue

In Company 20231110.52 from melpa, the list of candidates are not aligned in the popup window.
This effects both GUI and terminal versions of emacs across Windows, Linux and Termux (Android).
It effects all completion backends I've tested (company-ispell and company-capf with lsp-mode).

Steps to reproduce

  1. Create an empty text file with the following in it:
this is a long line
line 2
line 3
line 4
  1. Move to the end of the first line and trigger a completion using company-ispell.

Expected behavior

The list of candidates should appear in an aligned list as a pop-up.

Screenshots

Could only capture as photo of screen.
20231113_201526

Additional context

This only seems to effect instances where the popup windows appears beyond the end of some lines, like the number of spaces to insert between the end of the line and the start of the completion list is wrong.

@dgutov
Copy link
Member

dgutov commented Nov 14, 2023

Hi! I'm trying to reproduce this, but no luck so far.

Including when trying in text-mode, with Emacs 29, and with exact buffer contents like you posted in step 1.

You didn't actually produce a scenario starting from emacs -Q, though: by default, Emacs doesn't show line numbers.

Toggling M-x display-line-numbers-mode didn't help trigger the problem for me, but perhaps there is some other customization in your config (or site-lisp) that affects this?

@richardxday
Copy link
Author

After much experimentation, I can re-create the issue from emacs -Q. It requires the installation of the latest melpa version of company. I have created a minimal .el file to illustrate the issue.

demonstratecompanybug.el:

;; create a simple dictionary file called 'dict.txt' in the current directory for company-ispell
;; it only contains words starting with 'lin' to illustrate the problem!
(find-file "dict.txt")
(with-current-buffer (get-buffer-create "dict.txt")
  (kill-region (point-min) (point-max))
  (insert "line\n")
  (insert "liner\n")
  (insert "liners\n")
  (insert "linear\n")
  (insert "linearization\n")
  (insert "linearisation\n")
  (save-buffer)
  (kill-buffer))

;; add melpa package source
(require 'package)
(customize-set-variable 'package-archives '(("melpa" . "http://melpa.org/packages/")
					    ("gnu" . "http://elpa.gnu.org/packages/")))
(package-refresh-contents)

;; install company
(package-install 'company)

;; configure ispell and company options
(require 'ispell)
(require 'company)
(setq company-ispell-available 'unknown)
(customize-set-variable 'company-backends '(company-ispell))
(customize-set-variable 'company-ispell-dictionary ispell-complete-word-dict)
(customize-set-variable 'display-line-numbers t)
(customize-set-variable 'global-company-mode t)
(customize-set-variable 'global-display-line-numbers-mode t)
(customize-set-variable 'ispell-alternate-dictionary nil)
(customize-set-variable 'ispell-complete-word-dict "dict.txt")
(customize-set-variable 'ispell-dictionary "en")
(customize-set-variable 'ispell-grep-options "-Ei")
(customize-set-variable 'ispell-look-p nil)

;; create buffer with a bunch of lines in it
(with-current-buffer (get-buffer-create "test.txt")
  (pop-to-buffer (current-buffer))
  (company-mode t)
  (display-line-numbers-mode t)
  (insert "this is a long li\n")
  (insert "line2\n")
  (insert "line3\n")
  (insert "line4\n")
  (insert "line5\n")
  (goto-char (point-min))
  (end-of-line))

;; once loaded, simply press 'n' and look at the completions

To run this setup, ensure your existing .emacs.d directory is backed up and run:
rm -fr .emacs.d ; emacs -Q -l demonstratecompanybug.el

After loading you will be presented with a text buffer with the cursor on the end of the first line. At this point, press 'n' to generate 'lin' which company will show the completions for. And they will be misaligned!

The crucial line in the setup seems to be:
(customize-set-variable 'display-line-numbers t)

Removing this fixes the issue!

Thanks,
Richard.

@dgutov
Copy link
Member

dgutov commented Nov 17, 2023

Thanks! It is indeed the clash between the original user option and the mode that was added on top of it. Some built-in functions (like string-pixel-width) don't support this usage either.

I'll see what could be done in Company so that others don't have to fiddle with this too, and maybe send a bug report or two.

For the record, though, you or anyone else don't need to set this variable. Turning on display-line-numbers-mode (or its global version) should be enough.

@richardxday
Copy link
Author

You're welcome. whilst I agree that I shouldn't set global-display-line-numbers-mode and display-line-numbers, there must some weird behaviour because setting display-line-numbers during customization causes the issue but setting it any other time doesn't cause the issue. Also, I thought display-line-numbers was just the buffer local version of global-display-line-numbers-mode but it must be different otherwise we wouldn't be seeing this issue with display-line-numbers but not global-display-line-numbers-mode.

The other thing that might help is that this is a recent change - my customization file (at least the setting of global-display-line-numbers-mode and display-line-numbers`) has been unchanged for months.

So the issue must have been introduced in the last week or two.

Thanks,
Richard.

@dgutov
Copy link
Member

dgutov commented Nov 17, 2023

Also, I thought display-line-numbers was just the buffer local version of global-display-line-numbers-mode but it must be different otherwise we wouldn't be seeing this issue with display-line-numbers but not global-display-line-numbers-mode.

Different, yes: display-line-numbers-mode (global or local) sets the local value of display-line-numbers based on its state and customization options. I'm pretty sure exposing both to the users is not a good idea. Filed as https://debbugs.gnu.org/67248.

The other thing that might help is that this is a recent change - my customization file (at least the setting of global-display-line-numbers-mode and display-line-numbers`) has been unchanged for months.

Indeed: the popup renderer now tries to perform pixel-perfect positioning (see NEWS), and for that I had to employ some new calculation functions.

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