Exafunction / codeium.vim

Free, ultrafast Copilot alternative for Vim and Neovim
https://codeium.com
MIT License
3.69k stars 125 forks source link

Chat integration #317

Closed vphantom closed 4 months ago

vphantom commented 4 months ago

Starting point for chat integration: enabling the server.

To test the chat, I fired up Vim on any file and then tailed /tmp/.../6/codeium/manager/server_output/language_server_stderr_... to find the WS and HTTP ports (even though the log incorrectly claims HTTPS for the latter). I then formulated the URL by hand based on my own Vim and language server versions: http://127.0.0.1:.../api_key=...&web_server_url=ws://127.0.0.1:...&extension_name=vim&extension_version=1.6.28&ide_name=vim&ide_version=9.0&locale=en

The resulting web page recognizes my identity and that I'm a Teams account, it works 100% well if I click the examples, but I cannot write my own questions. Hitting ENTER does the same as SHIFT-ENTER (newline) and hitting CTRL-ENTER does nothing. JS console shows nothing.

I'd like to get over this hurdle before continuing with this work, to make sure it's not an insurmountable problem.

Once this problem is resolved, I intend to figure out how to get the two port numbers from within Vim itself, so I can contribute a command which, like your :Codeium Auth, would launch the default browser, but with this chat URL with the current language server.

CLAassistant commented 4 months ago

CLA assistant check
All committers have signed the CLA.

vphantom commented 4 months ago

There is now a proper codeium#Chat() function ready for use. The only problem is the bug described above in the language server itself. Once we can hit "ENTER" as far as I know this will be done.

vphantom commented 4 months ago

I can now interact with chat. However despite being a Teams level (recognized as such), I cannot convince the chat to refer to anything in actual files. I even opened a specific file in a buffer in the same editor and asked it about the return value of a function, and it said it didn't have access to the file. When asked if it had access to it, it said yes. We went around in circles. 😬

So we're getting closer, but still not quite there. I even tried enabling the language server's search/index features but @function: never finds anything and the chat, even with CTRL+Enter, doesn't seem to be aware of anything at all in our codebase. I also referred to a function in the open file by name, but when I asked it how it would rewrite it with a simple change, it output something completely unrelated based on the name alone.

Note: I experimentally called codeium#server#Request('AddTrackedWorkspace', {"workspace":"/home/..my.work.dir../"}) and it did trigger a bit of CPU activity for 2-3 seconds, but still nothing with @ and no sign that chat has my context.

fortenforge commented 4 months ago

What language were you trying this with? Can you share some screenshots?

vphantom commented 4 months ago

Sorry I was out yesterday. Yes I can create screenshots, but it would help if I had a bit of guidance from you as to the kind of things to try, as I'm new to Codeium. Especially, how to manually ask the same kinds of things which your in-editor shortcuts seem to do so you can see if I get what you'd expect.

I have mostly Perl and OCaml projects with some JS/CSS sprinkled in, and my test was in the Perl one. I asked for things like describing or rewriting a specific function from a specific file and it just guessed something from the function's name alone. The @ pop-up has no content in the Functions or Classes submenus, and the Repos is your own 10-15 sample repos, no mention of mine (that part may be expected?) I even had the Perl file in question open in my editor and my cursor near the function, still no dice.

Today, interestingly, I do get "Read 78 context items" with CTRL+Enter. Nothing in Functions/Classes still though. I guess the context selection algorithm simply didn't pick up what I was trying to do, or maybe Perl support is still experimental? I can live with that, I just want to make sure I'm getting everything I should be out of Codeium. 😉

codeium_at_nothing

codeium_timediff_unknown

fortenforge commented 4 months ago

We should be able to do @ mentions with Perl—we recently added support for it. Tell you what... let's just merge this and then I can take a look myself.

This PR should still be useful on its own as it enables chat.

fortenforge commented 4 months ago

(Can you modify the PR to add the arguments you mentioned?)

vphantom commented 4 months ago

Sure thing! I'll clean things up a bit and submit the missing tweaks later today. I'm still fiddling with finding the current workspace directory "the Vim way" for that RPC call.

vphantom commented 4 months ago

Here it is. Now the strange thing is, I get contexts from my code base regardless of if I use Enter vs CTRL+Enter. (Although still nothing for the @ pop-up.) Again, I'm a novice, and clearly I still don't know what to expect from Codeium chat. 😬

This commit only looks for a project root hint once at the first chat launch, when workspace tracking is activated. This could be made fancier eventually for users who juggle multiple projects in a single Vim session. Hints are in a global variable to make them user-configurable.

Launch chat in browser with :call codeium#Chat() (or setting a mapping for it).

Once we confirm that the chat is behaving as expected, I'll contribute an addition to README.md to let users know how to fire up the chat and how to use custom project root hints.

fortenforge commented 4 months ago

Basically even if you hit Enter we do try to detect if your question would be better served with context, and if we think so we will fetch context items even if you didn't explicitly request it.

It sounds like everything is working correctly except for the @'s. Let's get this merged! Please add the README documentation and we should be good to go.

vphantom commented 4 months ago

I also took the opportunity to do some minor cleanup of whitespace in the README, as suggested by my Markdown editor (https://github.com/marktext/marktext). I kept these in a separate commit in case you'd rather not include them.

vphantom commented 4 months ago

Is there a reference of special syntax or preferred wordings we should be using, for example to prompt for refactors, document generation, etc. or to refer to specific bits of code? I assume @ will address the latter once we get it working, but for the former a primer on how best to interact with Chat to get constructive results would be very handy.

fortenforge commented 4 months ago

there is no special syntax—just state what you want as clearly as you can and you should get a reasonable response.

vphantom commented 4 months ago

there is no special syntax—just state what you want as clearly as you can and you should get a reasonable response.

I still suspect I'm missing something, because for example when you use in-editor shortcuts to refactor, the resulting prompts include references to code sections which are highlighted in a way that hints to me that some special syntax is at play:

codeium_refactor_example

Also when I paste code as part of a question it's a bit garbled, so I suspect there might be a way to quote code better, perhaps with backticks?

I tried snooping in the source code of your VS extension but I couldn't find where you formulate those prompts. Should I take this discussion to Discord, perhaps, if you think this PR is done? Ultimately I think I'm looking for a document which doesn't exist yet but which would greatly benefit your users to show what kind of prompts are possible, how to quote code snippets cleanly, how to refer to specific bits of code as the above screenshot, etc. I also still am not sure if my @ problem is my fault or a problem with the language server's indexing.

marceldev89 commented 4 months ago

It kinda, sorta, works for me with st (C code) and a personal python project after calling the codeium#server#Request("AddTrackedWorkspace", {"workspace": "..."}) function. For my python project even the @function: and @class: works but doesn't for the C code base. Seems like it's a bit limited for now (I am on the free plan, which might have something to do with it?). Screenshot 2024-02-27 at 18-20-22 Codeium Chat

vphantom commented 4 months ago

Surprising that you got two different results from asking about xloadfont() twice in a row. Did you maybe hit Enter the first time and CTRL+Enter the second time?

marceldev89 commented 4 months ago

Surprising that you got two different results from asking about xloadfont() twice in a row. Did you maybe hit Enter the first time and CTRL+Enter the second time?

Ah yes, forgot to mention that but yes you're correct. First with Enter, second with Ctrl+Enter.

vphantom commented 3 months ago

@fortenforge Someone found a typo (a letter should be uppercase, still works on my version of Vim but not theirs). Do I commit the fix here or start a new PR? (I don't use GitHub PRs often, still a rookie.)

pqn commented 3 months ago

@vphantom you'll need a new PR since this one has already merged.

ajkdrag commented 3 months ago

When i open up Vim and type :call codeium#Chat() nothing happens. It just says Unknown function codeium#Chat

vphantom commented 3 months ago

When i open up Vim and type :call codeium#Chat() nothing happens. It just says Unknown function codeium#Chat

It doesn't look like your extension is installed. Either that or your version isn't up to date.

LeonardoMor commented 2 months ago

In light of this you might be able to get the chat inside NeoVim itself. The only thing is that you would need to have a browser