Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Adding custom libraries #17

Closed
ranjithshegde opened this issue Jul 11, 2021 · 11 comments
Closed

Adding custom libraries #17

ranjithshegde opened this issue Jul 11, 2021 · 11 comments

Comments

@ranjithshegde
Copy link

ranjithshegde commented Jul 11, 2021

This might be the noobest question in git issues history, but I cant for the life of me figure out how to add libraries apart from the default.

For example, before using lua-dev I had something like this in "regular" sumneko, and it worked correctly.

settings = {
                Lua = {
                    runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
                    diagnostics = {globals = {"vim", "pd"}},
                    workspace = {
                        library = {
                            [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                            [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
                            ["/usr/lib/pd/extra/pdlua"] = true,
                            ["/some/other/libraries"] = true,
                        }
                    }
                }
            }

I have tried adding the same in libraries = {} section like this

 local luadev =
         require("lua-dev").setup(
         {
             libraries = {
                 ["/usr/lib/pd/extra/pdlua"] = true,
             },
             lspconfig = {
                 on_attach = custom_attach,

and I have also tried in the same's lspconfig like this

settings = {
                  Lua = {
                         runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
                         diagnostics = {globals = {"vim", "pd"}},
                         workspace = {
                             library = {
                                 ["/usr/lib/pd/extra/pdlua"] = true
                             }
                         }
                     }
                 }

But with either setup, the libraries wont get picked up. I dont get any lsp features like hover, autocompletion, nothing at all.

I am sure there is a an exceedingly simple answer to this, which once you point out I will feel too stupid to show my face on github again.
Can you please help?

@ranjithshegde
Copy link
Author

@folke
I just tried your gist article which preceded this plugin. Putting the desired paths in that setup's add("/usr/lib/pd/extra/pdlua")
works perfectly
Is there anything that I am doing syntactically wrong in what in my previous post

@folke
Copy link
Owner

folke commented Jul 12, 2021

Update to the latest version and do something like:

local lspconfig = require('lspconfig')

local luadev = require("lua-dev").setup({
  -- add any options here, or leave empty to use the default settings
  -- lspconfig = {
  --   cmd = {"lua-language-server"}
  -- },
})

table.insert(luadev.settings.Lua.workspace.library, "/usr/lib/pd/extra/pdlua")

lspconfig.sumneko_lua.setup(luadev)

@ranjithshegde
Copy link
Author

Thanks for your response and the qucik change! appreciate it

I get the following error

E5100: Cannot convert given lua table: table should either have a sequence of positive integer keys or contain only string keys
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:399: error converting argument 1

@folke
Copy link
Owner

folke commented Jul 12, 2021

Sorry, should be:

luadev.settings.Lua.workspace.library["/usr/lib/pd/extra/pdlua"] = true

Either way, please just check the docs for lua-language server. You can change whatever you want on the condig returned by lua-dev.

@ranjithshegde
Copy link
Author

Thanks. That works.

Either way, please just check the docs for lua-language server. You can change whatever you want on the condig returned by lua-dev.

Only recently setting up sumneko. Still learning. Thank you for your help and patience.

@mehalter
Copy link

Is there a way to do this with the current state of Neodev? It would be great if there was an option in the setup function to add more library folders to include when setting up the library. Not sure if there is a way to do it with the override function. I can see that I can modify the setup options there like enable/disable the library or plugins, but is there a way to add a specific folder to the workspace library list?

@folke
Copy link
Owner

folke commented Jan 22, 2023

You should just add any custom libraries to the settings for lspconfig. No need to change anything in Neodev for that

@mehalter
Copy link

Thanks for the quick reply, I am doing that currently but I am wondering if neodev provides an easy way to only add the library when neodev is active. Since it's a folder in my Neovim runtime path but it's not getting access to variables defined in my ~/.config/nvim folder

@mehalter
Copy link

I'm not sure if Neodev should be giving access to these things automatically when it sets up the lbrary runtime path. I can see the folder in my runtime path and Neodev is correctly enabling the runtime so I can get auto complete for vim types as well as plugins, but it's not properly adding the other folders in the runtime path as part of the library. So I can't get auto complete for the other variables that I have defined in other runtime path folders. So in this case I want it to automatically add runtime path folders to the workspace library and only when neodev has detected that it should be enabled. So adding it to my global lspconfig settings for sumneko_lua isn't really an appropriate place since it's only related to my neovim configuration files/folders

Sorry I'm continuing this on this issue, I just didn't want to open a new issue if it was related to this one and decrease clutter on the repo. It seems like if it's not supposed to be automatically detected, I would want to be able to add it to the override function to include my config folder and other runtime path folders.

@mehalter
Copy link

I have ~/.config/separate_folder in my RTP and investigating the workspace settings that are set with vim.lsp.get_active_client() I see that it's correctly adding the neodev stable types, my user/share/nvim/runtime/lua and ~/.config/separate_folder/lua but it's not adding ~/.config/nvim/lua which is still in my RTP and should be getting checked

workspace = {                                                                                                           
  checkThirdParty = false,                                                                                              
  ignoreDir = { "types/nightly", "lua" },                                                                               
  library = { "/home/micah/.local/share/nvim/lazy/neodev.nvim/types/stable", "/usr/share/nvim/runtime/lua", "/home/micah
/.config/separate_folder/lua" }                                                                                                         
}                                                                                                                       

@folke
Copy link
Owner

folke commented Jan 22, 2023

The config folder is never added to the workspace outside of the config folder, since in most cases (like when developing a plugin) that's not wanted.

If you still need that for a certain folder, then just add it only for that project.

You could use a luarc.json file in that folder, to add in your config as a workspace folder.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants