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

suggetions are visible only with commented lines #82

Closed
mcg-cyber opened this issue Oct 30, 2023 · 13 comments
Closed

suggetions are visible only with commented lines #82

mcg-cyber opened this issue Oct 30, 2023 · 13 comments

Comments

@mcg-cyber
Copy link

mcg-cyber commented Oct 30, 2023

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
Copy link

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

@gg-mmill
Copy link

gg-mmill commented Dec 19, 2023

(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
Copy link
Contributor

@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
Copy link
Author

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

@jeff-phil
Copy link
Contributor

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
Copy link
Author

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

@mcg-cyber
Copy link
Author

mcg-cyber commented Feb 9, 2024

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
Copy link
Contributor

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

@mcg-cyber
Copy link
Author

mcg-cyber commented Feb 12, 2024

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
Copy link
Contributor

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
Copy link
Author

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 mcg-cyber reopened this Feb 12, 2024
@mcg-cyber
Copy link
Author

I close now. Thank you!

@mcg-cyber
Copy link
Author

..

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

4 participants