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

SuperBo/lsp-ai.nvim #155

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

SuperBo/lsp-ai.nvim #155

wants to merge 1 commit into from

Conversation

fredrikaverpil
Copy link
Owner

@fredrikaverpil fredrikaverpil commented Jun 17, 2024

This aims to add LSP-AI for a local code assistant for work projects, where I cannot use e.g. GitHub Copilot.

Initial errors

Currently, some LSP configuration problems to iron out when e.g. opening a .go file:

   Warn  09:10:41 notify.warn Client lsp_ai quit with exit code 1 and signal 0. Check log for errors: /Users/fredrik/.local/state/fredrik/lsp.log
   Error  09:10:41 msg_show.lua_error Error executing vim.schedule lua callback: ....10.0/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:185: Invalid buffer id: 18
stack traceback:
	[C]: in function 'nvim_buf_attach'
	....10.0/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:185: in function 'new'
	....10.0/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:612: in function 'start'
	.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:959: in function <.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:957>
   Error  09:10:42 msg_show.emsg LSP[gopls]: Error SERVER_REQUEST_HANDLER_ERROR: ".../Cellar/neovim/0.10.0/share/nvim/runtime/lua/vim/lsp.lua:310: Invalid buffer id: 18"
   Error  09:10:42 msg_show.lua_error Error executing vim.schedule lua callback: ....10.0/share/nvim/runtime/lua/vim/lsp/_changetracking.lua:154: Invalid buffer id: 19
stack traceback:
	[C]: in function 'nvim_buf_get_name'
	....10.0/share/nvim/runtime/lua/vim/lsp/_changetracking.lua:154: in function 'init'
	.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:907: in function '_text_document_did_open_handler'
	.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:942: in function '_on_attach'
	.../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:615: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

LSP log

/Users/fredrik/.local/state/fredrik/lsp.log:

[START][2024-06-17 09:20:27] LSP logging initiated
[ERROR][2024-06-17 09:20:27] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/fredrik/.local/bin/lsp-ai"	"stderr"	"thread '<unnamed>' panicked at /Users/fredrik/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lsp-server-0.7.6/src/stdio.rs:28:37:\nreceiver was dropped, failed to send a message: \"SendError(..)\"\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"
[ERROR][2024-06-17 09:20:27] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/fredrik/.local/bin/lsp-ai"	"stderr"	"Error: "
[ERROR][2024-06-17 09:20:27] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/fredrik/.local/bin/lsp-ai"	"stderr"	"missing field `repository`\n"
[ERROR][2024-06-17 09:20:27] ...m/lsp/client.lua:972	"LSP[gopls]"	"on_error"	{  code = "SERVER_REQUEST_HANDLER_ERROR",  err = ".../Cellar/neovim/0.10.0/share/nvim/runtime/lua/vim/lsp.lua:310: Invalid buffer id: 18"}
[ERROR][2024-06-17 09:20:27] ...lsp/handlers.lua:623	"2024/06/17 09:20:27 failed to register for file watching notifications: .../Cellar/neovim/0.10.0/share/nvim/runtime/lua/vim/lsp.lua:310: Invalid buffer id: 18\n"
[ERROR][2024-06-17 09:20:28] .../vim/lsp/rpc.lua:770	"rpc"	"/Users/fredrik/.local/share/fredrik/mason/bin/bash-language-server"	"stderr"	"(node:75018) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n(Use `node --trace-deprecation ...` to show where the warning was created)\n"
[WARN][2024-06-17 09:20:28] ...lsp/handlers.lua:625	"07:20:28.125 WARNING ⛔️ Environment variable configuration is being deprecated, please use workspace configuration. The following environment variables were used: shfmt"
[WARN][2024-06-17 09:20:28] ...lsp/handlers.lua:135	"The language server copilot triggers a registerCapability handler for workspace/didChangeWorkspaceFolders despite dynamicRegistration set to false. Report upstream, this warning is harmless"

Related configs

@SuperBo
Copy link

SuperBo commented Jun 17, 2024

Hi @fredrikaverpil, lsp-ai tell this [ERROR][2024-06-17 09:20:27] .../vim/lsp/rpc.lua:770 "rpc" "/Users/fredrik/.local/bin/lsp-ai" "stderr" "missing field repository\n".

  • Did you install lsp-ai with llama_cpp support? cargo install lsp-ai -F llama_cpp.
  • Did you download model file? If not, download it from here https://huggingface.co/Qwen/CodeQwen1.5-7B-Chat-GGUF/tree/main. Then change your filepath in config corresponding to local model. (Change file_path = "/opt/model/codeqwen-1_5-7b-chat-q4_k_m.gguf" to real path on your computer).

@fredrikaverpil
Copy link
Owner Author

fredrikaverpil commented Jun 17, 2024

@SuperBo thank you, that was helpful. I now get this:

   Error  14:35:15 notify.error [LSP-AI] n_kv_req > n_ctx, the required kv cache size is not big enough
        either reduce max_new_tokens or increase n_ctx

I've tried playing around with the values for n_ctx and max_new_tokens but I still keep seeing this error. Any ideas?

EDIT: by commenting out n_ctx, it now works! 🎉

@SuperBo
Copy link

SuperBo commented Jun 17, 2024

@fredrikaverpil, you need to increase n_ctx and decrease max_new_tokens :3

@fredrikaverpil
Copy link
Owner Author

Very nice @SuperBo it works 😄 🎉

It looks like it's a chat model. Do you know if I can make this more into a GitHub Copilot-style assistant by picking a different model, like a completion model?

@SuperBo
Copy link

SuperBo commented Jun 17, 2024

You need to tweak your prompt. https://github.com/SilasMarvin/lsp-ai/wiki/Prompting. And put it in generation.parameters.messages. You can try to play around with other model :D.

@fredrikaverpil
Copy link
Owner Author

Awesome, thank you so much - will play around with this now that I have it working later tonight 😄

Really nice work putting together this Neovim plugin! 👏 🥳

@SuperBo
Copy link

SuperBo commented Jun 17, 2024

@fredrikaverpil, thank your for testing. The code is still in beta phase and lacking support for inline completion, I will try to add it later when I have more free time.

Feel free to raise issue in https://github.com/SuperBo/lsp-ai.nvim if you found bug. Thank you again!

@fredrikaverpil
Copy link
Owner Author

@SuperBo sure! 😄
The only thing I can come to think of right now would be that it would be nice to be able to configure the keymap to accept the code generated. Do you want me to open up an issue about that, or is it already configurable?

@SuperBo
Copy link

SuperBo commented Jun 17, 2024

@fredrikaverpil, for now it is hard coded to Esc and Enter :3, please raise issue for it :D

@fredrikaverpil fredrikaverpil force-pushed the lsp-ai branch 2 times, most recently from 094ae78 to badd457 Compare June 17, 2024 18:36
@fredrikaverpil fredrikaverpil force-pushed the main branch 3 times, most recently from 0c5db43 to 147baca Compare July 6, 2024 08:31
@fredrikaverpil fredrikaverpil changed the title Add LSP-AI for local code assistant SuperBo/lsp-ai.nvim Jul 15, 2024
@fredrikaverpil fredrikaverpil force-pushed the main branch 3 times, most recently from 0753cd6 to 0c1af40 Compare September 28, 2024 15:48
@fredrikaverpil fredrikaverpil force-pushed the main branch 3 times, most recently from 7e71cc4 to 91213fc Compare October 3, 2024 20:45
@fredrikaverpil fredrikaverpil force-pushed the main branch 2 times, most recently from f0124ac to a067d4c Compare October 13, 2024 09:52
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.

2 participants