feat: use lazy-lsp
This commit is contained in:
parent
5445335c0e
commit
5f0399e356
2 changed files with 35 additions and 172 deletions
|
|
@ -335,55 +335,26 @@ require("lazy").setup({
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
{ -- LSP Configuration & Plugins
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"dundalek/lazy-lsp.nvim",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
-- Automatically install LSPs and related tools to stdpath for neovim
|
"neovim/nvim-lspconfig",
|
||||||
"williamboman/mason.nvim",
|
{ "VonHeikemen/lsp-zero.nvim", branch = "v3.x" },
|
||||||
"williamboman/mason-lspconfig.nvim",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
"hrsh7th/nvim-cmp",
|
||||||
|
|
||||||
-- Useful status updates for LSP.
|
|
||||||
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
|
||||||
{ "j-hui/fidget.nvim", opts = {} },
|
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Brief Aside: **What is LSP?**
|
local lsp_zero = require("lsp-zero")
|
||||||
--
|
|
||||||
-- LSP is an acronym you've probably heard, but might not understand what it is.
|
|
||||||
--
|
|
||||||
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
|
|
||||||
-- and language tooling communicate in a standardized fashion.
|
|
||||||
--
|
|
||||||
-- In general, you have a "server" which is some tool built to understand a particular
|
|
||||||
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc). These Language Servers
|
|
||||||
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
|
|
||||||
-- processes that communicate with some "client" - in this case, Neovim!
|
|
||||||
--
|
|
||||||
-- LSP provides Neovim with features like:
|
|
||||||
-- - Go to definition
|
|
||||||
-- - Find references
|
|
||||||
-- - Autocompletion
|
|
||||||
-- - Symbol Search
|
|
||||||
-- - and more!
|
|
||||||
--
|
|
||||||
-- Thus, Language Servers are external tools that must be installed separately from
|
|
||||||
-- Neovim. This is where `mason` and related plugins come into play.
|
|
||||||
--
|
|
||||||
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully
|
|
||||||
-- and elegantly composed help section, :help lsp-vs-treesitter
|
|
||||||
|
|
||||||
-- First, enable neodev. This is helpful for auto-configuring the Lua LSP
|
|
||||||
-- to understand your Neovim environment
|
|
||||||
require("neodev").setup()
|
require("neodev").setup()
|
||||||
|
|
||||||
-- makes #f100b2 purple ish
|
|
||||||
require("colorizer").setup()
|
require("colorizer").setup()
|
||||||
|
|
||||||
-- This function gets run when an LSP connects to a particular buffer.
|
lsp_zero.on_attach(function(client, bufnr)
|
||||||
-- That is to say, every time a new file is opened that is associated with
|
lsp_zero.default_keymaps({
|
||||||
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
|
buffer = bufnr,
|
||||||
-- function will be executed to configure the current buffer
|
preserve_mappings = false,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }),
|
group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }),
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
|
|
@ -462,108 +433,17 @@ require("lazy").setup({
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- LSP servers and clients are able to communicate to each other what features they support.
|
require("lazy-lsp").setup({
|
||||||
-- By default, Neovim doesn't support everything that is in the LSP Specification.
|
configs = {
|
||||||
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
|
|
||||||
-- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
||||||
capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())
|
|
||||||
|
|
||||||
-- Enable the following language servers
|
|
||||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
|
||||||
--
|
|
||||||
-- Add any additional override configuration in the following tables. Available keys are:
|
|
||||||
-- - cmd (table): Override the default command used to start the server
|
|
||||||
-- - filetypes (table): Override the default list of associated filetypes for the server
|
|
||||||
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
|
||||||
-- - settings (table): Override the default settings passed when initializing the server.
|
|
||||||
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
|
||||||
local servers = {
|
|
||||||
-- TODO: see if there is a fun way to make these added and installed per project
|
|
||||||
clangd = {},
|
|
||||||
gopls = {},
|
|
||||||
pyright = {},
|
|
||||||
html = { filetypes = { "html", "twig", "hbs" } },
|
|
||||||
templ = { filetypes = { "templ" } },
|
|
||||||
nil_ls = {
|
|
||||||
settings = {
|
|
||||||
["nil"] = {
|
|
||||||
formatting = {
|
|
||||||
command = { "nixpkgs-fmt" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ocamllsp = {},
|
|
||||||
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
|
|
||||||
--
|
|
||||||
-- Some languages (like typescript) have entire language plugins that can be useful:
|
|
||||||
-- https://github.com/pmizio/typescript-tools.nvim
|
|
||||||
--
|
|
||||||
-- But for many setups, the LSP (`tsserver`) will work just fine
|
|
||||||
-- tsserver = {},
|
|
||||||
--
|
|
||||||
|
|
||||||
htmx = {
|
|
||||||
filetypes = { "html" },
|
|
||||||
},
|
|
||||||
|
|
||||||
lua_ls = {
|
lua_ls = {
|
||||||
-- cmd = {...},
|
|
||||||
-- filetypes { ...},
|
|
||||||
-- capabilities = {},
|
|
||||||
settings = {
|
settings = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = { version = "LuaJIT" },
|
diagnostics = {
|
||||||
workspace = {
|
global = { "vim" },
|
||||||
checkThirdParty = false,
|
},
|
||||||
-- Tells lua_ls where to find all the Lua files that you have loaded
|
|
||||||
-- for your neovim configuration.
|
|
||||||
library = {
|
|
||||||
"${3rd}/luv/library",
|
|
||||||
unpack(vim.api.nvim_get_runtime_file("", true)),
|
|
||||||
},
|
|
||||||
-- If lua_ls is really slow on your computer, you can try this instead:
|
|
||||||
-- library = { vim.env.VIMRUNTIME },
|
|
||||||
},
|
|
||||||
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
|
|
||||||
-- diagnostics = { disable = { 'missing-fields' } },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
-- Ensure the servers and tools above are installed
|
|
||||||
-- To check the current status of installed tools and/or manually install
|
|
||||||
-- other tools, you can run
|
|
||||||
-- :Mason
|
|
||||||
--
|
|
||||||
-- You can press `g?` for help in this menu
|
|
||||||
require("mason").setup()
|
|
||||||
|
|
||||||
-- You can add other tools here that you want Mason to install
|
|
||||||
-- for you, so that they are available from within Neovim.
|
|
||||||
local ensure_installed = vim.tbl_keys(servers or {})
|
|
||||||
vim.list_extend(ensure_installed, {
|
|
||||||
"stylua", -- Used to format lua code
|
|
||||||
"black", -- Used to format python code
|
|
||||||
})
|
|
||||||
require("mason-tool-installer").setup({ ensure_installed = ensure_installed })
|
|
||||||
|
|
||||||
require("mason-lspconfig").setup({
|
|
||||||
handlers = {
|
|
||||||
function(server_name)
|
|
||||||
local server = servers[server_name] or {}
|
|
||||||
require("lspconfig")[server_name].setup({
|
|
||||||
cmd = server.cmd,
|
|
||||||
settings = server.settings,
|
|
||||||
filetypes = server.filetypes,
|
|
||||||
-- This handles overriding only values explicitly passed
|
|
||||||
-- by the server configuration above. Useful when disabling
|
|
||||||
-- certain features of an LSP (for example, turning off formatting for tsserver)
|
|
||||||
capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}),
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@
|
||||||
programs.neovim =
|
programs.neovim =
|
||||||
{
|
{
|
||||||
enable = true;
|
enable = true;
|
||||||
extraPackages = with pkgs; lib.mkMerge [
|
extraPackages = with pkgs; [
|
||||||
[
|
|
||||||
ripgrep
|
ripgrep
|
||||||
luarocks
|
luarocks
|
||||||
gnumake
|
gnumake
|
||||||
|
|
@ -17,22 +16,6 @@
|
||||||
nixpkgs-fmt
|
nixpkgs-fmt
|
||||||
tree-sitter
|
tree-sitter
|
||||||
fd
|
fd
|
||||||
]
|
|
||||||
(lib.mkIf config.modules.apps.neovim.enableLanguages [
|
|
||||||
cargo
|
|
||||||
gcc
|
|
||||||
go
|
|
||||||
jdk22
|
|
||||||
luaPackages.lua
|
|
||||||
nodejs
|
|
||||||
php83Packages.composer
|
|
||||||
php83
|
|
||||||
opam
|
|
||||||
(python3.withPackages (python-pkgs: [
|
|
||||||
python-pkgs.pip
|
|
||||||
python-pkgs.black
|
|
||||||
]))
|
|
||||||
])
|
|
||||||
];
|
];
|
||||||
defaultEditor = true;
|
defaultEditor = true;
|
||||||
viAlias = true;
|
viAlias = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue