Exafunction / codeium.el

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

suggetions are visible only with commented lines #82

Closed mcg-cyber closed 3 months ago

mcg-cyber commented 8 months ago

Hi, I read the issues and there similar cases to mine like, I can see the completions only in commented line. Those issues are closed but this bug or feature still exist. Is there any solution for this? Thank you!

I use spacemacs, auto-completions, lsp-mode with company. I tried with corfu, cape and it didn't work, not even with commented line. Below is my config.

;; Codeium config stats ;; we recommend using use-package to organize your init.el (use-package codeium ;; if you use straight ;; :straight '(:type git :host github :repo "Exafunction/codeium.el") ;; otherwise, make sure that the codeium.el file is on load-path

:init
;; use globally
(add-to-list 'completion-at-point-functions #'codeium-completion-at-point)
;; or on a hook
;; (add-hook 'python-mode-hook
;;     (lambda ()
;;         (setq-local completion-at-point-functions '(codeium-completion-at-point))))

;; if you want multiple completion backends, use cape (https://github.com/minad/cape):
;; (add-hook 'python-mode-hook
;;     (lambda ()
;;         (setq-local completion-at-point-functions
;;             (list (cape-super-capf #'codeium-completion-at-point #'lsp-completion-at-point)))))
;; an async company-backend is coming soon!

;; codeium-completion-at-point is autoloaded, but you can
;; optionally set a timer, which might speed up things as the
;; codeium local language server takes ~0.2s to start up
;; (add-hook 'emacs-startup-hook
;;  (lambda () (run-with-timer 0.1 nil #'codeium-init)))

;; :defer t ;; lazy loading, if you want
:config
(setq use-dialog-box nil) ;; do not use popup boxes

;; if you don't want to use customize to save the api-key
(setq codeium/metadata/api_key "--------------------------------------------------------")

;; get codeium status in the modeline
(setq codeium-mode-line-enable
    (lambda (api) (not (memq api '(CancelRequest Heartbeat AcceptCompletion)))))
(add-to-list 'mode-line-format '(:eval (car-safe codeium-mode-line)) t)
;; alternatively for a more extensive mode-line
;; (add-to-list 'mode-line-format '(-50 "" codeium-mode-line) t)

;; use M-x codeium-diagnose to see apis/fields that would be sent to the local language server
(setq codeium-api-enabled
    (lambda (api)
        (memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion))))
;; you can also set a config for a single buffer like this:
;; (add-hook 'python-mode-hook
;;     (lambda ()
;;         (setq-local codeium/editor_options/tab_size 4)))

;; You can overwrite all the codeium configs!
;; for example, we recommend limiting the string sent to codeium for better performance
(defun my-codeium/document/text ()
    (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (min (+ (point) 1000) (point-max))))
;; if you change the text, you should also change the cursor_offset
;; warning: this is measured by UTF-8 encoded bytes
(defun my-codeium/document/cursor_offset ()
    (codeium-utf8-byte-length
        (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (point))))
(setq codeium/document/text 'my-codeium/document/text)
(setq codeium/document/cursor_offset 'my-codeium/document/cursor_offset))
;;;
 ;;;
(use-package company
    :diminish
    :bind (("C-M-i" . company-complete)
            :map company-mode-map
            ("<backtab>" . company-yasnippet))
     :bind (:map company-active-map
                 ("C-n" . company-select-next)
                 ("C-p" . company-select-previous)
                 ("C-s" . company-filter-candidates)
                 ("<tab>" . company-complete-selection))
     :bind (:map company-search-map
           ("C-n" . company-select-next)
           ("C-p" . company-select-previous))
    :hook (after-init . global-company-mode)
    :init
    ;;:config
    (global-company-mode t)
    (setq company-tooltip-align-annotations t
        company-tooltip-limit 12
        company-idle-delay 0.05
        company-echo-delay (if (display-graphic-p) nil 0)
        company-minimum-prefix-length 0
        company-icon-margin 3
        company-require-match nil
        company-dabbrev-ignore-case nil
        company-dabbrev-downcase nil
        ;;; get only preview
        company-frontends '(company-preview-frontend)
        ;;; also get a drop down
        company-frontends '(company-pseudo-tooltip-frontend company-preview-frontend)
        company-global-modes '(not erc-mode message-mode help-mode
                                    gud-mode eshell-mode shell-mode)
        company-backends '((company-capf :with company-yasnippet)
                            ''(company-dabbrev-code company-keywords company-files)
                            company-dabbrev)))
;;;
clintlombard commented 7 months ago

Seeing the same in Doom Emacs. I suspect this isn't working with a language server that's running.

gg-mmill commented 6 months ago
(defun complete-codeium ()
  "Codeium." ; Doc string.
  (interactive)         ; Specify is command.
  (setq completion-at-point-bkp completion-at-point-functions)
  (setq completion-at-point-functions '(codeium-completion-at-point t))
  (call-interactively 'company-complete)
  (setq completion-at-point-functions completion-at-point-bkp)
)

Having the same issue, it seems that configuration to add codeium completion to completion-at-point-functions does not work well - furthermore, I don't want to call codeium for each completion.

Here's a (probably very hacky) function to perform explicit codeium completion (my first elisp interactive function !) You can then bind the function to specific key e.g. (global-set-key (kbd "s-n") 'complete-codeium)

(for some reason, a local override of completion-at-point-functions does not seem to work:

(defun complete-codeium-bis ()
  "Codeium - this does not work ??"
  (interactive)         ; Specify is command.

  (let (
        (completion-at-point-functions '(codeium-completion-at-point t)
        )
        (call-interactively 'company-complete)
        )
  )
  )
jeff-phil commented 4 months ago

@gg-mmill

(for some reason, a local override of completion-at-point-functions does not seem to work:

Should work... here's fixed version:

(defun complete-codeium-bis ()
  (interactive)         ; Specify is command.
  (let ((completion-at-point-functions #'codeium-completion-at-point))
    (call-interactively 'company-complete)))

You had (call-interactively 'company-complete) still in the let binding vs in the body.

mcg-cyber commented 4 months ago

I moved to Corfu from company. Any idea how we can use it with Corfu? Thank you for your suggestions!

jeff-phil commented 4 months ago

Yepper, here you go...

If using corfu, I'd suggest also getting its sibling: cape.

This part matches above, if just wanted to run codeium by itself outside of completion functions. I.e. matches above. It's bound to C-c p c below.

(defun my/cape-codeium (&optional interactive)
  "Allow codeium capf to be run by itself"
  (interactive (list t))
  (when interactive
    ;; if also testing copilot, clear their overlay before showing capf popup
    (when (bound-and-true-p copilot-mode) (copilot-clear-overlay))
    (cape-interactive #'codeium-completion-at-point)))
(keymap-global-set "C-c p c" #'my/cape-codeium)

For full gory effect, this is my setup for corfu, cape and eglot...

This merges codeium, eglot, dabbrev, cape-line all together into one capf:

;; Turn on/off if want to use codeium completions
(defvar my/codeium-is-enabled t)

(defalias 'my/capf-eglot+et-al
  (cape-capf-super
   (cape-capf-silent
    (when (bound-and-true-p my/codeium-is-enabled)
      (cape-capf-properties #'codeium-completion-at-point
                            :annotation-function
                            #'(lambda (_) (propertize "  Codeium"
                                                      'face font-lock-comment-face))
                            :company-kind (lambda (_) 'magic))))
   (cape-capf-buster #'eglot-completion-at-point 'equal)
   (cape-capf-properties #'cape-dabbrev
                         :annotation-function
                         #'(lambda (_) (propertize " Dabbrev"
                                                   'face font-lock-comment-face)))
   ;; if line gets too chatty
   (cape-capf-silent
    (cape-capf-properties #'cape-line
                          :annotation-function
                          #'(lambda (_) (propertize " Line"
                                                    'face font-lock-comment-face))))))

;; eglot, just to validate with just eglot
(defun my/cape-eglot(&optional interactive)
  (interactive (list t))
  (when interactive
    ;; if also testing copilot, clear their overlay before showing capf popup
    (when (bound-and-true-p copilot-mode) (copilot-clear-overlay))
    (cape-capf-buster (cape-interactive #'eglot-completion-at-point) 'equal)))
(keymap-set eglot-mode-map "C-c p g" #'my/cape-eglot)

;; Since merging eglot and others, assign a key binding to test
;; can remove if feel good
(defun my/cape-eglot+et-al(&optional interactive)
  (interactive (list t))
  (when interactive
    ;; if also testing copilot, clear their overlay before showing capf popup
    (when (bound-and-true-p copilot-mode) (copilot-clear-overlay))
    (cape-interactive #'my/capf-eglot+et-al)))
(keymap-set eglot-mode-map "C-c p z" #'my/cape-eglot+et-al)

(defun my/eglot-capf-config()
  (setq-local completion-category-overrides '((file (styles partial-completion)))
              completion-category-defaults nil
              completion-styles '(orderless partial-completion basic)
              ;; add in file first, capf will know when in file mode
              completion-at-point-functions (list #'cape-file #'my/capf-eglot+et-al)))

(add-hook 'eglot-managed-mode-hook #'my/eglot-capf-config)

You can do about the same for elisp, lsp-mode, org-mode, etc. different mode completions. I'll leave that up to you.

Also, cape has a bunch of other completions, like tempel, keywords, emoji's, etc. that could also be combined in like above.

mcg-cyber commented 4 months ago

Awesome! Yeah, actually my setup is with Corfu + Cape but not with Eglot. Thank you so much!

mcg-cyber commented 4 months ago

I just wanted to edit previous post whi is below as not disconnect from the subject. When run codeium install, downloads arm version. I downloaded x64 manually and it seem that works. I need to add as well this line into init.el (add-to-list 'completion-at-point-functuons #'codeium-completion-at-point) this solved the issue. When run codeium init, it doesn't do anything. It supposed to launch the default browser and lead to codeium url. Another one is very slow somehow. I hope this report will help to other users if they face the similar issue. But thank you so much for help and suggestions!

Now that kind of error when run codeium init "Doing vfork: Exec format error: I have API key already in my config. No completions appear. No error in codeium diagnose. Just basic config as it's adviced in readme. I am confused.

jeff-phil commented 4 months ago

Good-o, glad it's working. Probably should close this issue.

mcg-cyber commented 4 months ago

Hi, I reopened this as this is not a bug and related to my first question, Corfu, cape etc. I would like to see the suggestions as inline not in the box. I disabled the view in box feature, now I don't see anything. I am aware of that I could do this with company-frontends variable (setq company-frontends '(company-pseudo-tooltip-unless-just-one-frontend company-preview-frontend). How I can do that with Corfu, Cape, lsp-mode? Could you help please? Thank you!

jeff-phil commented 4 months ago

Since nothing to do with Codeium, you should probably start by looking at Corfu's repo for info and help, googling, etc. 🙂

With that said, I believe what you are looking for is corfu-candidate-overlay: https://code.bsdgeek.org/adam/corfu-candidate-overlay

mcg-cyber commented 4 months ago

It is not codeium bug or faulty , but it is related to codeium . Codeium gives brief instructions to work with company but not with Corfu and Cape . That would be really useful for people if they write into readme how to integrate as many folks use Corfu and Cape . Anyway, thank you so much!

mcg-cyber commented 4 months ago

I close now. Thank you!

mcg-cyber commented 3 months ago

..