-
Notifications
You must be signed in to change notification settings - Fork 76
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
Neovim Plugin and nvim-lspconfig integration #2
Comments
Hey @Nold360 . We were just having this discussion on Reddit yesterday and will hopefully have some example configurations in the repository and make a pr into Here is an answer provided by Microbzz on reddit:
You can swap out the value of There is still an open discussion around getting ghost text working and potentially shipping our own neovim plugin for automatic inline completion. |
For those of you who want a very rough pow you can use this snippet. This will use local lsp_ai_config = {
-- Uncomment if using nvim-cmp
-- capabilities = require('cmp_nvim_lsp').default_capabilities(),
cmd = { 'lsp-ai' },
root_dir = vim.loop.cwd(),
init_options = {
memory = {
file_store = {}
},
models = {
model1 = {
type = "open_ai",
chat_endpoint = "https://api.openai.com/v1/chat/completions",
model = "gpt-4-1106-preview",
auth_token_env_var_name = "OPENAI_API_KEY",
}
},
completion = {
model = "model1",
parameters = {
max_context = 2048,
max_new_tokens = 128,
messages = {
{
role = "system",
content = "You are a chat completion system like GitHub Copilot. You will be given a context and a code snippet. You should generate a response that is a continuation of the context and code snippet."
},
{
role = "user",
content = "Context: {CONTEXT} - Code: {CODE}"
}
}
}
}
},
}
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
callback = function() vim.lsp.start(lsp_ai_config) end,
})
-- Register key shortcut
vim.keymap.set(
"n",
"<leader>co",
function()
print("Loading completion...")
local x = vim.lsp.util.make_position_params(0)
local y = vim.lsp.util.make_text_document_params(0)
local combined = vim.tbl_extend("force", x, y)
local result = vim.lsp.buf_request_sync(
0,
"textDocument/completion",
combined,
10000
)
print(vim.inspect(result))
end,
{
noremap = true,
}
) I'd definitely wish a ghost-like text, just like copilot.vim does it. I'm not too familiar with LSPs, but #5 could be related to this |
Thank you for sharing this! To integrate fully with Neovim and provide good inline completion with ghost text I think we will need to write our own plugin. Write now it will pretty much mimic the functionality of copilot.vim but have more support for different backends for completion. This will change as we add new supported features to LSP-AI that we want Neovim to take advantage of like chatting with your code and semantic search over your code base. If anyone sees this and is interested in writing a Neovim plugin, feel free to do it! I'm happy to help however I can. Our VS Code plugin is a really good place to start for the kind of functionality it should provide: https://github.com/SilasMarvin/lsp-ai/blob/main/editors/vscode/src/index.ts |
@Robzz we'd love to see how you did that! :) |
I'll be opening a draft PR in a bit. I would not recommend merging it until the default config is integrated in Edit: PR up, see #17 |
This is awesome! One thing I'm still unsure of is how to handle default configs. Right now if a user passes empty We could absolutely provide a default on the server for For the VS Code plugin, I thought that making OpenAI with gpt-4o the default in the plugin settings would be a reasonable choice, but it honestly wasn't my favorite as it still requires users to set an We want to make it as easy as possible for everyone to get started using LSP-AI but I think it requires they make some initial decision on at least what backend they want to use which brings me back to being unsure on how to implement any default config. |
... and ...
I think this is the best case for a default config. It's much more likely that a user will expose an |
I think you are probably right here. I do think they shouldn't be defaults on the server, they should be defaults for the config / plugin to send to the server. I don't want to have defaults for the server that might expose users codebases to third parties. |
Agree'd. I think ideally the LSP part and LSP/IDE glue should have sensible defaults, but the backend/model config should probably be left for the user to pick. So as far as I can tell, that leaves only the |
Yes we can make the Or maybe I am misunderstanding what is standard for nvim-lspconfig and its ok to provide a default that doesn't full work without the user providing more parameters? |
This I really don't know, maybe there are similar cases among the supported LSP servers in nvim-lspconfig, I haven't seen any but I only glanced over it and it's a long list. I haven't seen any AI LSP servers in there either since HuggingFace have gone the way of writing their own plugin instead for |
Got it. I'll ask in the matrix server. We could do the same thing llm-ls does and just fork the llm-ls neovim plugin. This would provide a better user experience for completions. I know eventually we do want our own plugin. We could also have both? |
For "ghost text" I am working on features for supermaven-nvim and we use something like this: I didn't implement this feature so I am not gonna say I completely get it but when creating the local augroup = vim.api.nvim_create_augroup("lsp-ai", { clear = true })
local ns_id = vim.api.nvim_create_namespace("lsp-ai")
local opts = {
id = 1,
hl_mode = "combine",
}
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
group = augroup,
callback = function() vim.lsp.start(lsp_ai_config) end,
})
-- Register key shortcut
vim.keymap.set(
"n",
"<leader>co",
function()
print("Loading completion...")
local x = vim.lsp.util.make_position_params(0)
local y = vim.lsp.util.make_text_document_params(0)
local combined = vim.tbl_extend("force", x, y)
local result = vim.lsp.buf_request_sync(
0,
"textDocument/completion",
combined,
10000
)
print(vim.inspect(result))
vim.api.nvim_buf_set_extmark(0, ns_id, vim.fn.line(".") - 1, vim.fn.col(".") - 1, opts)
end,
{
noremap = true,
}
) Warning Not sure this works as expected for ghost text or how the |
Ok great!
Yes, in my understanding it's not unusual in the nvim ecosystem to have an additional plugin for language server specific features while keeping the minimal config in the lspconfig plugin, it's even the official recommendation. |
Thanks for sharing! |
Got it that makes sense. I'll ask around about defaults in the matrix probably tomorrow. Would you want to head up our neovim plugin? I'm thinking for now we just fork llm-ls, edit the configuration options to match the options I have for our VS Code plugin, and then just have it perform inline completion with ghost text. |
I asked on the Matrix, they recommended discussing it on their GitHub. I suggest we create a PR that requires the user to provide defaults and have a discussion about it in that PR. |
I'm not sure how long term I can commit to it, but sure I'm happy to at least help it take it off the ground.
Alright I'll send them the PR hopefully tomorrow to get the discussion going. |
This is awesome thank you! |
Hi @SilasMarvin, @Robzz, what is you guys final decision. If you decided to start a dedicated plugin, I'm happy to help (FYI, I'm developing another Neovim plugin https://github.com/SuperBo/fugit2.nvim). |
We definitely want to have a dedicated plugin, if you want to get started on it that would be awesome! We have one for VS Code that should be a good reference: https://github.com/SilasMarvin/lsp-ai/tree/main/editors/vscode Here is an overview on the wiki about it: https://github.com/SilasMarvin/lsp-ai/wiki/Plugins You could also fork: https://github.com/huggingface/llm.nvim and use it as a base. I'm happy to give more input if you want, just let me know! |
@SilasMarvin, ok. Will start working on it tomorrow. Are you ok with name |
That is a great name for it I love it! Let me know how it goes excited to see it! |
@SuperBo @SilasMarvin I created this template repo for Neovim plugins, it has It also has It also has more utilities but that is more of a personal opinion on why you should use something like |
@AlejandroSuero, Thank you for good template, can I cherry pick your selene and stylua config? For testing, I prefer native busted + nlua setup. I also need to add neorocks formula also. So I will start an empty repo first without any template. Hope that don't bother you! |
@SuperBo for the Cherry pick what you want, is free to use. I haven't got to try |
@AlejandroSuero, you can see the sample setup here https://github.com/SuperBo/fugit2.nvim. I decided to fork from https://github.com/huggingface/llm.nvim. I saw some of your pullrequest (huggingface/llm.nvim#98, huggingface/llm.nvim#97) there. Could I merge it into my fork :D? |
@SuperBo yeah, go for it. I will be checking out your git plugin tomorrow and also get a look for the testing setup. |
Screen.Recording.2024-06-16.at.22.51.00.movFirst update guys, we now can ask AI for whole file code completion. |
That is awesome!!! I love it. This is really exciting stuff! |
Can anyone help me to test this Example config lazy config can be like this: {
'SuperBo/lsp-ai.nvim',
opts = {
-- autostart = false,
server = {
memory = {
file_store = {},
},
models = {
model1 = {
type="llama_cpp",
file_path="/opt/model/codeqwen-1_5-7b-chat-q4_k_m.gguf",
n_ctx=512,
-- ctx_size= 512,
n_gpu_layers= 500,
}
}
},
generation = {
model = "model1",
parameters = {
max_tokens=256,
max_context=1024,
messages = {
{
role="system",
content="You are a programming completion tool. Replace <CURSOR> with the correct code."
},
{
role = "user",
content = "{CODE}"
}
}
}
}
},
dependencies = { 'neovim/nvim-lspconfig' },
} Command to ask LSP-AI is |
I had to do these modifications: {
- dir ='SuperBo/lsp-ai.nvim',
+ "SuperBo/lsp-ai.nvim",
opts = {
-- autostart = false,
server = {
memory = {
file_store = {},
},
models = {
model1 = {
type="llama_cpp",
file_path="/opt/model/codeqwen-1_5-7b-chat-q4_k_m.gguf",
n_ctx=512,
-- ctx_size= 512,
n_gpu_layers= 500,
}
}
},
generation = {
model = "model1",
parameters = {
max_tokens=256,
max_context=1024,
messages = {
{
role="system",
content="You are a programming completion tool. Replace <CURSOR> with the correct code."
},
{
role = "user",
content = "{CODE}"
}
}
}
}
},
dependencies = { 'neovim/nvim-lspconfig' },
+ config = function(_, opts)
+ require("lsp_ai").setup(opts)
+ end,
} But I can't run
|
@fredrikaverpil, what language are you testing (python, go, ...). I've just hard code these support file types: Do you have lsp-ai compiled with llama_cpp? You can test with openai if you have OPENAI key. You don't need to add config to |
This comment was marked as resolved.
This comment was marked as resolved.
Following up on this thread. Been talking in the Discord a little bit about our Neovim integration and would love to get you in there @SuperBo Link is in the README |
@SilasMarvin, sorry, I've been quite busy since last week. I will have more free time this weekend. See you in discord. |
Hi,
I really would love to test this with neovim, but i have no idea how to setup a custom LSP. Maybe using
nvim-lspconfig
The text was updated successfully, but these errors were encountered: