feat(lsp): add pyright support
This commit is contained in:
parent
6bb5f2b68a
commit
34e827fd05
4 changed files with 30 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
-- DEFAULT USER SETTINGS
|
||||||
local ok, user_config = pcall(require, 'cosmic.config.config')
|
local ok, user_config = pcall(require, 'cosmic.config.config')
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
|
@ -16,6 +17,7 @@ local default_config = {
|
||||||
jsonls = {
|
jsonls = {
|
||||||
format = false,
|
format = false,
|
||||||
},
|
},
|
||||||
|
pyright = true,
|
||||||
sumneko_lua = {
|
sumneko_lua = {
|
||||||
format = false,
|
format = false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,6 +57,6 @@ end
|
||||||
|
|
||||||
M.autostart = true
|
M.autostart = true
|
||||||
|
|
||||||
M.single_file_mode = true
|
M.single_file_support = true
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -58,6 +58,8 @@ lsp_installer.on_server_ready(function(server)
|
||||||
opts = u.merge(opts, require('cosmic.lsp.providers.tsserver'))
|
opts = u.merge(opts, require('cosmic.lsp.providers.tsserver'))
|
||||||
elseif server.name == 'jsonls' then
|
elseif server.name == 'jsonls' then
|
||||||
opts = u.merge(opts, require('cosmic.lsp.providers.jsonls'))
|
opts = u.merge(opts, require('cosmic.lsp.providers.jsonls'))
|
||||||
|
elseif server.name == 'pyright' then
|
||||||
|
opts = u.merge(opts, require('cosmic.lsp.providers.pyright'))
|
||||||
elseif server.name == 'sumneko_lua' then
|
elseif server.name == 'sumneko_lua' then
|
||||||
opts = u.merge(opts, require('cosmic.lsp.providers.sumneko_lua'))
|
opts = u.merge(opts, require('cosmic.lsp.providers.sumneko_lua'))
|
||||||
end
|
end
|
||||||
|
|
25
lua/cosmic/lsp/providers/pyright.lua
Normal file
25
lua/cosmic/lsp/providers/pyright.lua
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
local path = require('lspconfig/util').path
|
||||||
|
|
||||||
|
local function get_python_path(workspace)
|
||||||
|
-- Use activated virtualenv.
|
||||||
|
if vim.env.VIRTUAL_ENV then
|
||||||
|
return path.join(vim.env.VIRTUAL_ENV, 'bin', 'python')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Find and use virtualenv in workspace directory.
|
||||||
|
for _, pattern in ipairs({ '*', '.*' }) do
|
||||||
|
local match = vim.fn.glob(path.join(workspace, pattern, 'pyvenv.cfg'))
|
||||||
|
if match ~= '' then
|
||||||
|
return path.join(path.dirname(match), 'bin', 'python')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fallback to system Python.
|
||||||
|
return exepath('python3') or exepath('python') or 'python'
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
before_init = function(_, config)
|
||||||
|
config.settings.python.pythonPath = get_python_path(config.root_dir)
|
||||||
|
end,
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue