doomemacs icon indicating copy to clipboard operation
doomemacs copied to clipboard

Latex completion suggestion on whitespace

Open qcfu-bu opened this issue 2 years ago • 5 comments

What did you expect to happen?

After pressing the spacebar, I expect a simple whitespace character typed to the file, nothing more, nothing less.

What actually happened?

After pressing the spacebar, a whitespace character is typed to the file, but a long list of suggestions appear. This happens on every spacebar press and is extrememly annoying. image

Describe your attempts to resolve the issue

I am using doom's latex module with +lsp option and texlab as the backend. After disabling +lsp and using plain auctex, there is no issue, but the completion that auctex provides is not as rich as +lsp. I've tested the texlab extension in vscode, it does not exhibit this issue.

Steps to reproduce

  1. Enable latex in init.el with +lsp option.
  2. Open any .tex file
  3. Type a space

System Information

https://pastebin.com/wJX57wpn

qcfu-bu avatar Aug 21 '22 02:08 qcfu-bu

What is the value of company-minimum-prefix-length? You can use SPC h v company-minimum-prefix-length RET to check it. If it is zero try setting it to a non-zero value.

aikrahguzar avatar Aug 21 '22 14:08 aikrahguzar

What is the value of company-minimum-prefix-length? You can use SPC h v company-minimum-prefix-length RET to check it. If it is zero try setting it to a non-zero value.

The variable company-minimum-prefix-length is set to 2.

qcfu-bu avatar Aug 22 '22 00:08 qcfu-bu

The variable company-minimum-prefix-length is set to 2.

Sorry can't help you too much as I don't use a latex lsp but does the popup go away if you disable company via M-x company-mode RET?

aikrahguzar avatar Aug 22 '22 14:08 aikrahguzar

The variable company-minimum-prefix-length is set to 2.

Sorry can't help you too much as I don't use a latex lsp but does the popup go away if you disable company via M-x company-mode RET?

Yes, the popup goes away after disabling company-mode. But this also eliminates the good completions.

qcfu-bu avatar Aug 23 '22 16:08 qcfu-bu

After some digging around, it seems to be the new yas-snippets integration is interferring with the latex completion and not texlab itself. This issue does not seem to exist for other markup languages like markdown, org, etc. Not sure why company-yassnippets gets triggered by a simple whitespace.

qcfu-bu avatar Aug 30 '22 01:08 qcfu-bu

I am having the same issue. As a temporary fix is it possible to get company to not suggest snippets in latex mode?

tbdcit avatar Feb 21 '23 16:02 tbdcit

I did not find the correct way to set the company backends per mode, but you can define yourself a function. Then just execute that in every latex buffer. Ping me if you find a better way to set company-backends for only tex buffers.

(defun fix-latex-company ()
        (interactive)
        (setq-local company-backends '(company-reftex-labels company-reftex-citations (+latex-symbols-company-backend company-auctex-macros company-auctex-environments) (:separate company-dabbrev company-yasnippet company-ispell))))

fabian-thomas avatar Feb 21 '23 18:02 fabian-thomas

One method worked for me was to switch the lsp integration from lsp-mode to eglot.

qcfu-bu avatar Feb 21 '23 18:02 qcfu-bu

Perhaps with is a separate bug, but evaluating

(set-company-backend! 'latex-mode '(company-capf company-dabbrev company-yasnippet))

has no effect.

tbdcit avatar Feb 26 '23 18:02 tbdcit

One method worked for me was to switch the lsp integration from lsp-mode to eglot.

Do you have working configuration for texlab + eglot? I have not worked out how to setup the commands textDocument/build and textDocument/forwardSearch which I rely on heavily.

tbdcit avatar Feb 26 '23 19:02 tbdcit

One method worked for me was to switch the lsp integration from lsp-mode to eglot.

Do you have working configuration for texlab + eglot? I have not worked out how to setup the commands textDocument/build and textDocument/forwardSearch which I rely on heavily.

This is what I have for setting eglot to use texlab.

(add-to-list 'eglot-server-programs '((tex-mode bibtex-mode) . ("texlab")))

I'm not sure what textDocument/build and textDocument/forwardSearch do. Can you post a link documenting them?

qcfu-bu avatar Feb 26 '23 20:02 qcfu-bu

textDocument/build and textDocument/forwardSearch are custom messages which can be sent to the language server to compile the tex file and to perform forward search with synctex. I rely on the textDocument/build as it integrates very well with tectonic for compiling tex to pdf, unlike the build methods provided by auctex which I have not managed to get to work.

More information about these "custom messages", including how the client should implement them: https://github.com/latex-lsp/texlab/wiki/LSP-Internals#custom-messages, https://github.com/latex-lsp/texlab/wiki/Previewing

Another useful source is how the lsp-latex package implements these commands.

https://github.com/ROCKTAKEY/lsp-latex/blob/9200ad19c416b3945d62683dd606917d8a1b3fee/lsp-latex.el#L792-L817

https://github.com/ROCKTAKEY/lsp-latex/blob/9200ad19c416b3945d62683dd606917d8a1b3fee/lsp-latex.el#L823-L887

tbdcit avatar Mar 06 '23 11:03 tbdcit

I think this is a bug of company and it has been fixed by the upstream. Unpinning company solves this problem.

;; Adding this to DOOMDIR/packages.el
(unpin! (:completion company))

lizhuohua avatar Nov 14 '23 03:11 lizhuohua