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

virtual text support #241

Merged
merged 25 commits into from
Oct 27, 2024
Merged

virtual text support #241

merged 25 commits into from
Oct 27, 2024

Conversation

dimfeld
Copy link
Contributor

@dimfeld dimfeld commented Oct 6, 2024

This is a port of the virtual text support from codeium.vim.

To enable it, pass virtual_text = { enabled = true } in your setup arguments to the plugin. The README has more details.

Closes #14

@dimfeld dimfeld force-pushed the virtual-text branch 2 times, most recently from 43eefea to f99547e Compare October 7, 2024 00:04
@dimfeld dimfeld marked this pull request as ready for review October 7, 2024 20:13
@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 7, 2024

I think this is ready to go. Been using it today in my development and it's looking good so far

@KyrillGobber
Copy link

Works very well for me, thanks a lot! I hope this gets merged

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 11, 2024

Rebased on latest main

@dro-sh
Copy link

dro-sh commented Oct 14, 2024

@dimfeld I use your fork at my config and have tab use hotkey for apply suggestion. But it is conflict with tab indent and I have next error, then I want to add tab indent where is no suggestion from codeium:

Error executing lua: ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:267: "replace_keycodes" requires "expr"
stack traceback:
        [C]: in function 'nvim_set_keymap'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:267: in function 'set_map'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:185: in function 'solve'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:148: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:147>

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 14, 2024

Could you give more details please? Also that error seems to be coming from cmp which the virtual text doesn't use.

If you just mean that you don't want Tab to be the accept keybinding, check the README on how to change it. The feature to insert a Tab when no completion is showing seems to be working fine for me.

@zenofile
Copy link

This generates a "completion request failed” notification on every keystroke when using the plugin in conjunction with, for example, oil.nvim inside the oil buffer. I need to return early in M.complete to make this usable when the detected filetype is “oil”. It would be helpful to have a config option to specify the filetypes to be ignored.

This indicates special buffers created by some plugins like oil.nvim,
and the LS will return an error.
@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 15, 2024

@zenofile Thanks for the report! I installed oil.nvim and was able to reproduce this, so I made 2 changes:

  1. Detect if the buffer's filename is a URI (like the Oil buffer has a name that looks like oil://home/user) and don't try to do completions in that case. This is actually what was causing the error
  2. Add filetypes to the virtual text config so you can turn it on and off for specific filetypes. The README goes into more detail about how to set this up.

@zenofile
Copy link

Thank you for the quick fix, that works nicely.

However, I think the README.md misses brackets for assigning values to the filetype keys:

require('codeium.virtual_text').setup({
    virtual_text = {
        filetypes = { 
            "python" = true,
            "markdown" = false
        },
        default_filetype_enabled = true
    }
})

@yatinlala
Copy link

yatinlala commented Oct 16, 2024

So happy to see this feature! Thanks for the great work @dimfeld. 🙏

I think there has been a regression in a recent commit. Pressing in insert mode doesn't return me to normal mode. Setting virtual_text = { enabled = false } restores normal functionality.

Minimal conf to reproduce:

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  local out = vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { 'Failed to clone lazy.nvim:\n', 'ErrorMsg' },
      { out, 'WarningMsg' },
      { '\nPress any key to exit...' },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

-- Setup lazy.nvim
require('lazy').setup({
  'dimfeld/codeium.nvim',
  branch = 'virtual-text',
  lazy = false,
  dependencies = {
    'nvim-lua/plenary.nvim',
  },
  opts = {
    enable_cmp_source = false,
    virtual_text = {
      enabled = true,
    },
  },
})

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 16, 2024

@yatinlala which key was affected that doesn’t go back into normal mode? I think GitHub maybe stripped out whatever you wrote there. Esc works fine for me, is there another key you would expect to do that?

@yatinlala
Copy link

Seems like it got stripped — Esc doesn't work for me. I can try and bisect tomorrow to the problem commit.

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 16, 2024

Ok I do see the same issue with that bare config, just not with the one I normally use. Interesting... I'll look into it. Thanks!

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 16, 2024

Ok should be fixed now. Turns out that C-[ is the same keycode as Esc, and I had that set as the default keycode for Clear. So when I fixed a bug that it wasn't setting the Clear keycode properly it started actually mapping Esc to clear.

@saranshsaini
Copy link
Contributor

Thanks for adding this, super cool. Im about ready to merge it in if you think it is done.
The only thing I wanted to bring up is that when your cursor is on an empty line the virtual text shows up the line below it. Would it be an easy fix to put it on the same line as the cursor? Pic attached
image

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 22, 2024

Yeah I think it's all ready to go! So I'm only seeing that extra line in cases where it looks like the Codeium completion is actually trying to insert a newline for formatting purposes. For example here an extra newline makes sense, and when I accept the completion it adds it.

CleanShot 2024-10-21 at 15 42 09@2x

But then if I already have appropriate whitespace then it doesn't, like here:

CleanShot 2024-10-21 at 15 42 30@2x

So I think this is actually coming from Codeium itself. That said, I can try to add something to strip out leading newlines if you think that's not desirable.

@saranshsaini
Copy link
Contributor

If that's the case then all good.
I'll test this on windows soon and then it should be good to merge.

@saranshsaini
Copy link
Contributor

saranshsaini commented Oct 22, 2024

Tested on windows but got an error. I think its because this branch doesnt include the fixes in #248 . Ill approve and when I merge in should be sorted out.

@saranshsaini saranshsaini merged commit a7196bf into Exafunction:main Oct 27, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

feat: inline virtual text suggestion similar to codeium.vim project
6 participants