Closed henry-hsieh closed 2 years ago
For per project level virtualenv paths with pylsp I did the following:
local jedi_env = function(env)
return {
pylsp = {
plugins = {
jedi = {
environment = env,
},
},
},
}
end
lspconfig.pylsp.setup({
on_init = function(client)
local path = client.workspace_folders[1].name
if path == '/home/foo/src/project1' then
client.config.settings = jedi_env('/home/foo/.local/pipx/venvs/pyinfra')
elseif path == '/home/foo/src/project2' then
client.config.settings = jedi_env('./venv')
end
client.notify('workspace/didChangeConfiguration')
return true
end,
})
I recently realized that Neovim has a built-in function for converting JSON to Lua table. All you need to do is parsing setting files at root directory and assign to LSP settings.
The example is in my pull request of svlangserver. Check the on_init
function at line 38.
For per project level virtualenv paths with pylsp I did the following:
local jedi_env = function(env) return { pylsp = { plugins = { jedi = { environment = env, }, }, }, } end lspconfig.pylsp.setup({ on_init = function(client) local path = client.workspace_folders[1].name if path == '/home/foo/src/project1' then client.config.settings = jedi_env('/home/foo/.local/pipx/venvs/pyinfra') elseif path == '/home/foo/src/project2' then client.config.settings = jedi_env('./venv') end client.notify('workspace/didChangeConfiguration') return true end, })
I updated the project local settings in Wiki page. I think that your method should be default method for project local settings because replacement of exrc
is detecting path in personal vimrc.
nlsp-settings.nvim provides project local settings likes coc.nvim for lspconfig. Therefore, my custom json loader can be replaced by it.
Language server
No response
Requested feature
I'm aware of there is a Wiki page for project local settings. It uses
set exrc
that Neovim will execute the .nvimrc or .exrc of the current directory. However, theset exrc
is not secure. Moreover, the option is not usable at latest release version of Neovim (0.7.0).Coc uses .vim/coc-settings.json as local configuration file instead of using script. I thought that other LSP clients use configuration files, too. It's more secure by parsing configuration file.
Other clients which have this feature
coc.nvim