Exafunction / codeium.el

Free, ultrafast Copilot alternative for Emacs
https://www.codeium.com
MIT License
412 stars 13 forks source link

Not seeing suggestion in `C++` (lsp + company) #20

Closed apmanol closed 1 year ago

apmanol commented 1 year ago

Hello all,

trying to play around with this awesome software, bad it doesn't work in C++ mode with lsp enabled.

A snippet of the .emacs can be found https://gist.github.com/apmanol/6ab0bb12174d3f1fc9b7b2ff1e4fa909 it's a setup with lsp + company + company lsp.

The server seems to work as it seems in the logs and in the diagnose but autocomplete doesn't work. Furthermore, without lsp mode i.e. scratch, I can see suggestions and server communication.

completion-at-point-functions is a variable defined in ‘minibuffer.el’.

Its value is
(codeium-completion-at-point tags-completion-at-point-function)

Probably, I miss something, but I can't find out anything.

thanks for any tips.

Alan-Chen99 commented 1 year ago

whats the value of completion-at-point-functions local to the buffer you are completing in? If you instead see lsp completions, then you need to manually reorder the priorities (probably on your mode hook). If you want to see both I recommend cape-super-capf

Edit: I meant "completion-at-point-functions" instead of "codeium-completion-at-point"

akhil3417 commented 1 year ago

a better way would be to prepend codeium-completion-at-point to current value of completion-at-point-functions and call it manually in buffers you want codeium completion , different modes have different buffer local values for completion , if you are trying to add a hook add an delay of few seconds so that its setup correctly after the default mode hooks have been setup.

(defun add-codeium-completion ()
  (interactive)
  (setq completion-at-point-functions
        (cons 'codeium-completion-at-point
              completion-at-point-functions))
  (setq-local company-frontends
              '(company-pseudo-tooltip-frontend
                company-preview-frontend))
  (setq company-minimum-prefix-length 0))

(defun remove-codeium-completion ()
  (interactive)
  (setq completion-at-point-functions
        (delete 'codeium-completion-at-point
                completion-at-point-functions))
  (setq company-frontends
        '(company-box-frontend company-preview-frontend))
  (setq company-minimum-prefix-length 2))

for adding delay you can use :

    (add-hook 'python-mode-hook
                (lambda)
                (run-with-timer 2 nil
                                (lambda()
                                  (add-hook 'post-command-hook
                                    #'add-codeium-completion))))

Alan-Chen99 commented 1 year ago

While what @akhil3417 have is fine, you probably want something much less aggressive, like

(add-hook 'python-mode-hook
    (let ((buf (current-buffer)))
        (run-with-timer 2 nil
            (lambda ()
                (with-current-buffer buf
                    (add-codeium-completion))))))

You would otherwise have a very hard time of turning codeium off.

Alan-Chen99 commented 1 year ago

Also, if you don't have any other deferred things, you shouldn't need the timer.

apmanol commented 1 year ago

whats the value of completion-at-point-functions local to the buffer you are completing in? If you instead see lsp completions, then you need to manually reorder the priorities (probably on your mode hook). If you want to see both I recommend cape-super-capf

Edit: I meant "completion-at-point-functions" instead of "codeium-completion-at-point"


Its value is
(lsp-completion-at-point codeium-completion-at-point tags-completion-at-point-function)
Local in buffer xxx.cpp```
apmanol commented 1 year ago

I removed the company-lsp because it isn't supported anymore, from lsp-mode and now codeium is autocompleting only the comments in the code! That is some progress.

apmanol commented 1 year ago

I replaced the company with corfu and cape + capf and things are much better now.

Would you like to leave the bug open, since the setup with the company didn't go very smoothly?

fortenforge commented 1 year ago

Closing this since your issue is resolved. I created a new issue to track the particular problem you had with company.