Files
sunhat/configs/dotfiles/nvim/lua/plugins/lsp.lua
2025-08-15 16:37:31 -05:00

252 lines
6.8 KiB
Lua

vim.pack.add({
{ src = 'https://github.com/mason-org/mason.nvim' },
{ src = 'https://github.com/neovim/nvim-lspconfig' },
{ src = 'https://github.com/mason-org/mason-lspconfig.nvim' },
{ src = 'https://github.com/hrsh7th/nvim-cmp' },
{ src = 'https://github.com/hrsh7th/cmp-nvim-lsp' },
{ src = 'https://github.com/nvim-lua/plenary.nvim' },
{ src = 'https://github.com/hrsh7th/cmp-nvim-lsp-document-symbol' },
{ src = 'https://github.com/hrsh7th/cmp-nvim-lua' },
{ src = 'https://github.com/hrsh7th/cmp-path' },
{ src = 'https://github.com/hrsh7th/cmp-buffer' },
{ src = 'https://github.com/hrsh7th/cmp-emoji' },
{ src = 'https://github.com/chrisgrieser/cmp-nerdfont' },
{ src = 'https://github.com/jcha0713/cmp-tw2css' },
{ src = 'https://github.com/SergioRibera/cmp-dotenv' },
{ src = 'https://github.com/saadparwaiz1/cmp_luasnip' },
{ src = 'https://github.com/onsails/lspkind.nvim' },
{ src = 'https://github.com/rafamadriz/friendly-snippets' },
{ src = 'https://github.com/j-hui/fidget.nvim' },
{ src = 'https://github.com/David-Kunz/cmp-npm' },
{ src = 'https://github.com/stevearc/conform.nvim' },
{
src = 'https://github.com/L3MON4D3/LuaSnip',
version = vim.version.range('2')
},
{ src = 'https://github.com/supermaven-inc/supermaven-nvim' },
{ src = 'https://github.com/garyhurtz/cmp_kitty' },
{ src = 'https://github.com/windwp/nvim-autopairs' },
{ src = 'https://github.com/windwp/nvim-ts-autotag' },
--{ src = 'https://github.com/hrsh7th/cmp-cmdline' },
--{ src = 'https://github.com/chrisgrieser/cmp-yanky' },
})
local cmp = require 'cmp'
local cmp_lsp = require 'cmp_nvim_lsp'
local lspconfig = require 'lspconfig'
local capabilities = vim.tbl_deep_extend(
'force',
{},
vim.lsp.protocol.make_client_capabilities(),
cmp_lsp.default_capabilities()
)
local cmp_select = { behavior = cmp.SelectBehavior.Select }
local lspkind = require 'lspkind'
local cmp_autopairs = require'nvim-autopairs.completion.cmp'
require 'mason'.setup({})
require 'mason-lspconfig'.setup({
handlers = {
function(server_name)
require 'lspconfig'[server_name].setup({
capabilities = capabilities
})
end,
zls = function()
lspconfig.zls.setup({
root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"),
settings = {
zls = {
enable_inlay_hints = true,
enable_snippets = true,
warn_style = true,
},
},
})
vim.g.zig_fmt_parse_errors = 0
vim.g.zig_fmt_autosave = 0
end,
["lua_ls"] = function()
lspconfig.lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
format = {
enable = true,
defaultConfig = {
indent_style = "space",
indent_size = "2",
},
},
},
},
})
end,
}
})
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'supermaven' },
--{ name = 'luasnip', keyword_length = 2 },
--{ name = 'buffer', keyword_length = 3 },
--{ name = 'supermaven', keyword_length = 2 },
{
name = 'path',
option = {
pathMappings = {
['@'] = '${folder}/src',
['/'] = '${folder}/src/public',
['/components'] = '${folder}/src/components',
},
trailing_slash = true,
},
},
{ name = 'nvim_lsp_document_symbol' },
{ name = 'nvim_lsp_signature_health' },
{ name = 'nvim_lua' },
{ name = 'nerdfont' },
{ name = 'emoji' },
{ name = 'npm' },
{ name = 'cmp-tw2css' },
{ name = 'dotenv' },
{ name = 'kitty' },
{ name = 'render-markdown' },
{ name = 'cmdline' },
--{ name = 'cmp_yanky' },
},
formatting = {
format = lspkind.cmp_format({
mode = 'symbol',
maxwidth = {
menu = 50,
abbr = 50,
},
symbol_map = {
Supermaven = '',
},
ellipsis_char = '...',
show_labelDetails = true,
before = function(entry, vim_item)
return vim_item
end,
}),
},
mapping = cmp.mapping.preset.insert({
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
if cmp.get_selected_entry() then
cmp.confirm({ select = false })
else
cmp.select_next_item()
end
else
fallback()
end
end, { 'i', 's' }),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(),
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
}),
preselect = cmp.PreselectMode.Item,
completion = {
completeopt = 'menu,menuone,noinsert',
},
})
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
require 'cmp_kitty':setup({})
require 'cmp-npm'.setup({})
require 'supermaven-nvim'.setup({
disable_inline_completion = true,
})
require 'conform'.setup({
formatters_by_ft = {
cs = { 'csharpier', 'lsp' },
javascript = { 'prettierd', 'prettier' },
javascriptreact = { 'prettierd', 'prettier' },
typescript = { 'prettierd', 'prettier' },
typescriptreact = { 'prettierd', 'prettier' },
json = { 'prettierd', 'prettier' },
html = { 'prettierd', 'prettier' },
css = { 'prettierd', 'prettier' },
lua = { 'stylua' },
},
})
require 'fidget'.setup({})
require 'nvim-autopairs'.setup({})
require 'nvim-ts-autotag'.setup({})
--cmp.setup.cmdline('/', {
--mapping = cmp.mapping.preset.cmdline(),
--sources = {
--{ name = 'buffer' }
--}
--})
--cmp.setup.cmdline(':', {
--mapping = cmp.mapping.preset.cmdline(),
--sources = cmp.config.sources({
--{ name = 'path' }
--}, {
--{
--name = 'cmdline',
--}
--})
--})
vim.lsp.enable({
'asm_lsp',
'bashls',
'cmake',
'cssls',
'css_variables',
'cssmodules_ls',
'docker_compose_language_service',
'dockerls',
'eslint',
'gopls',
'gradle_ls',
'graphql',
'html',
'htmx',
'intelephense',
'jsonls',
'kotlin_lsp',
'lua_ls',
'markdown_oxide',
'nginx_language_server',
'prismals',
'pyright',
'rust-analyzer',
'sqlls',
'svelte_language_server',
'tailwindcss',
'ts_ls',
'tinymist',
'yamlls',
})
vim.diagnostic.config({
float = {
focusable = false,
style = "minimal",
border = "rounded",
source = true,
header = "",
prefix = "",
},
})