Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ settings["search_backend"] = "telescope"
---@type boolean
settings["lsp_inlayhints"] = false

-- Set to true to enable python experimental LSPs, e.g. `ty`, `pyrefly`.
-- NOTE: By setting the option to true, must set one of the following LSPs in `python_experimental_lsp_deps`,
-- else it won't work alone, and the default `pylsp` LSP will be used.
-- NOTE: By setting this to false, the default `pylsp` LSP will be installed and used.
---@type boolean
settings["use_python_experimental_lsp"] = false

-- Python Experimental LSPs to install during bootstrap.
-- NOTE: As these LSPs are experimental, they may not be stable or fully functional.
-- NOTE: Both these LSPs don't support formatting, so `ruff` is installed for linting and formatting by default.
---@type string[]
settings["python_experimental_lsp_deps"] = {
-- "pyrefly", -- LSP from facebook
-- "ty", -- LSP from astral
}

-- LSPs to install during bootstrap.
-- Full lsit: https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/configs
---@type string[]
Expand All @@ -118,7 +134,6 @@ settings["lsp_deps"] = {
"html",
"jsonls",
"lua_ls",
"pylsp",
"gopls",
}

Expand Down
26 changes: 26 additions & 0 deletions lua/modules/configs/completion/mason-lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ M.setup = function()
local diagnostics_virtual_lines = require("core.settings").diagnostics_virtual_lines
local diagnostics_level = require("core.settings").diagnostics_level
local lsp_deps = require("core.settings").lsp_deps
local use_python_experimental_lsp = require("core.settings").use_python_experimental_lsp
local python_experimental_lsp_deps = require("core.settings").python_experimental_lsp_deps

require("lspconfig.ui.windows").default_options.border = "rounded"
require("modules.utils").load_plugin("mason-lspconfig", {
Expand Down Expand Up @@ -91,6 +93,30 @@ please REMOVE your LSP configuration (rust_analyzer.lua) from the `servers` dire
end
end

--- the LSP for python should be set up differently depend on the value of `use_python_experimental_lsp`.
--- If both `use_python_experimental_lsp` and `python_experimental_lsp_deps` are set,
--- we'll use the experimental LSP with the specified dependencies.
--- Otherwise, default `pylsp` will be used.
if use_python_experimental_lsp then
if not python_experimental_lsp_deps or #python_experimental_lsp_deps == 0 then
vim.notify(
[[
If you want to use the experimental Python LSP,
please set `python_experimental_lsp_deps` in your settings.
Fallback to default `pylsp` now.]],
vim.log.levels.WARN,
{ title = "nvim-lspconfig" }
)
else
mason_lsp_handler("pylsp")
end
else
for _, exp_py_lsp in ipairs(python_experimental_lsp_deps) do
mason_lsp_handler(exp_py_lsp)
end
mason_lsp_handler("ruff") -- for linting and formatting as the exp LSPs do not support it
end

for _, lsp in ipairs(lsp_deps) do
mason_lsp_handler(lsp)
end
Expand Down