Update neovim lsp config to work better with monorepo

This commit is contained in:
2026-04-14 20:04:12 -04:00
parent cfc2b82c06
commit 065b7747cf
+121 -193
View File
@@ -1,7 +1,7 @@
return { return {
'mason-org/mason-lspconfig.nvim', 'mason-org/mason-lspconfig.nvim',
dependencies = { dependencies = {
{ 'neovim/nvim-lspconfig', }, { 'neovim/nvim-lspconfig' },
{ {
'mason-org/mason.nvim', 'mason-org/mason.nvim',
opts = { opts = {
@@ -9,19 +9,19 @@ return {
icons = { icons = {
package_installed = "", package_installed = "",
package_pending = "", package_pending = "",
package_uninstalled = "" package_uninstalled = "",
} },
} },
}, },
}, },
{ {
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
event = { 'InsertEnter', 'CmdlineEnter' }, event = { 'InsertEnter', 'CmdlineEnter' },
config = function() config = function()
local cmp = require'cmp' local cmp = require 'cmp'
local lspkind = require'lspkind' local lspkind = require 'lspkind'
local cmp_select = { behavior = cmp.SelectBehavior.Select } local cmp_select = { behavior = cmp.SelectBehavior.Select }
local luasnip = require'luasnip' local luasnip = require 'luasnip'
cmp.setup({ cmp.setup({
snippet = { snippet = {
expand = function(args) expand = function(args)
@@ -35,47 +35,21 @@ return {
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'luasnip' }, { name = 'luasnip' },
}, {
{ name = 'buffer' },
{ name = 'luasnip_choice' },
{ name = 'copilot' }, { name = 'copilot' },
{ name = 'supermaven' }, }, {
{ name = 'nvim_lsp_document_symbol' }, { name = 'buffer', keyword_length = 4 },
{ name = 'nvim_lsp_signature_help' }, { name = 'path' },
{ name = 'nvim_lua' },
{ name = 'nerdfont' },
{
name = 'path',
option = {
pathMappings = {
['@'] = '${folder}/src',
['/'] = '${folder}/public/',
['~'] = '${folder}/src',
-- ['/images'] = '${folder}/src/images',
-- ['/components'] = '${folder}/src/components',
},
},
},
{ name = 'emoji' },
{ name = 'npm' },
{ name = 'cmp-tw2css' },
{ name = 'dotenv' }, { name = 'dotenv' },
{ name = 'render-markdown' }, { name = 'emoji' },
}), }),
formatting = { formatting = {
format = lspkind.cmp_format({ format = lspkind.cmp_format({
mode = 'symbol', mode = 'symbol',
maxwidth = { maxwidth = { menu = 50, abbr = 50 },
menu = 50, symbol_map = { Copilot = '' },
abbr = 50,
},
symbol_map = {
Supermaven = '',
Copilot = '',
},
ellipsis_char = '...', ellipsis_char = '...',
show_labelDetails = true, show_labelDetails = true,
before = function(entry, vim_item) before = function(_, vim_item)
return vim_item return vim_item
end, end,
}), }),
@@ -84,33 +58,11 @@ return {
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select), ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select), ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<C-y>'] = cmp.mapping.confirm({ select = true }), ['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(), ['<C-e>'] = cmp.mapping.abort(),
}), }),
--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, preselect = cmp.PreselectMode.Item,
completion = { completion = {
completeopt = 'menu,menuone,noinsert', completeopt = 'menu,menuone,noinsert',
@@ -121,13 +73,21 @@ return {
{ name = 'git' }, { name = 'git' },
}, { }, {
{ name = 'buffer' }, { name = 'buffer' },
}) }),
})
cmp.setup.filetype({ 'json', 'jsonc' }, {
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'npm' },
}, {
{ name = 'buffer', keyword_length = 4 },
}),
}) })
cmp.setup.cmdline({ '/', '?' }, { cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = { sources = {
{ name = 'buffer' }, { name = 'buffer' },
} },
}) })
cmp.setup.cmdline(':', { cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
@@ -136,59 +96,47 @@ return {
}, { }, {
{ name = 'cmdline' }, { name = 'cmdline' },
}), }),
matching = { disallow_symbol_nonprefix_matching = false } matching = { disallow_symbol_nonprefix_matching = false },
}) })
end, end,
}, },
{ 'hrsh7th/cmp-nvim-lsp' }, { 'hrsh7th/cmp-nvim-lsp' },
{ 'nvim-lua/plenary.nvim' }, { 'nvim-lua/plenary.nvim' },
{ 'hrsh7th/cmp-nvim-lsp-document-symbol' },
{ 'hrsh7th/cmp-nvim-lua' },
{ 'hrsh7th/cmp-nvim-lsp-signature-help' },
{ 'hrsh7th/cmp-path' }, { 'hrsh7th/cmp-path' },
--{ 'hrsh7th/cmp-copilot' },
{ {
'zbirenbaum/copilot-cmp', 'zbirenbaum/copilot-cmp',
config = function () config = function()
require'copilot_cmp'.setup() require 'copilot_cmp'.setup()
end end,
}, },
{ 'hrsh7th/cmp-buffer' }, { 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-emoji' }, { 'hrsh7th/cmp-emoji' },
{ 'chrisgrieser/cmp-nerdfont' },
{ 'jcha0713/cmp-tw2css' },
{ 'SergioRibera/cmp-dotenv' }, { 'SergioRibera/cmp-dotenv' },
{ 'saadparwaiz1/cmp_luasnip' }, { 'saadparwaiz1/cmp_luasnip' },
{ 'onsails/lspkind.nvim' }, { 'onsails/lspkind.nvim' },
{ 'rafamadriz/friendly-snippets' }, { 'rafamadriz/friendly-snippets' },
{
'L3MON4D3/cmp-luasnip-choice',
config = function()
require'cmp_luasnip_choice'.setup()
end,
},
{ {
'petertriho/cmp-git', 'petertriho/cmp-git',
config = function() config = function()
require'cmp_git'.setup({}) require 'cmp_git'.setup({})
end
},
{
'j-hui/fidget.nvim',
config = function()
require'fidget'.setup({})
end, end,
}, },
{ {
'David-Kunz/cmp-npm', 'David-Kunz/cmp-npm',
config = function() config = function()
require'cmp-npm'.setup({}) require 'cmp-npm'.setup({})
end end,
},
{
'j-hui/fidget.nvim',
config = function()
require 'fidget'.setup({})
end,
}, },
{ {
'stevearc/conform.nvim', 'stevearc/conform.nvim',
config = function() config = function()
require'conform'.setup({ require 'conform'.setup({
formatters_by_ft = { formatters_by_ft = {
cs = { 'csharpier', 'lsp' }, cs = { 'csharpier', 'lsp' },
javascript = { 'prettierd', 'prettier' }, javascript = { 'prettierd', 'prettier' },
@@ -208,110 +156,54 @@ return {
if args.count ~= -1 then if args.count ~= -1 then
local start_line = vim.fn.line("'<") local start_line = vim.fn.line("'<")
local end_line = vim.fn.line("'>") local end_line = vim.fn.line("'>")
range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } } range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } }
end end
require'conform'.format({ require 'conform'.format({
async = true, async = true,
lsp_fallback = true, lsp_fallback = true,
range = range, range = range,
}) })
end, { range = true, desc = "Format current buffer or range" }) end, { range = true, desc = "Format current buffer or range" })
end, end,
keys = { keys = {
{ {
'<leader>fk', '<leader>fk',
':Format<CR>', ':Format<CR>',
mode = {'n', 'v'}, mode = { 'n', 'v' },
silent = true, silent = true,
desc = "Format with conform" desc = "Format with conform",
} },
} },
}, },
{ {
'L3MON4D3/LuaSnip', 'L3MON4D3/LuaSnip',
version = 'v2.*', version = 'v2.*',
build = 'make install_jsregexp' build = 'make install_jsregexp',
}, },
--{ 'github/copilot.vim' },
{ {
"zbirenbaum/copilot.lua", 'zbirenbaum/copilot.lua',
requires = {
'copilotlsp-nvim/copilot-lsp',
},
cmd = 'Copilot', cmd = 'Copilot',
event = 'InsertEnter', event = 'InsertEnter',
config = function() config = function()
require'copilot'.setup({ require 'copilot'.setup({
--copilot_model = "", -- Disable native ghost text so copilot-cmp can manage suggestions instead
--nes = { suggestion = { enabled = false },
--enabled = true, panel = { enabled = false },
--keymap = {
--accept_and_goto = '<leader>,',
--accept = false,
--dismiss = 'Esc',
--},
--},
}) })
end, end,
}, },
--{
--"copilotlsp-nvim/copilot-lsp",
--init = function()
--vim.g.copilot_nes_debounce = 500
--vim.lsp.enable("copilot_ls")
--vim.keymap.set("n", "<tab>", function()
--local bufnr = vim.api.nvim_get_current_buf()
--local state = vim.b[bufnr].nes_state
--if state then
---- Try to jump to the start of the suggestion edit.
---- If already at the start, then apply the pending suggestion and jump to the end of the edit.
--local _ = require("copilot-lsp.nes").walk_cursor_start_edit()
--or (
--require("copilot-lsp.nes").apply_pending_nes()
--and require("copilot-lsp.nes").walk_cursor_end_edit()
--)
--return nil
--else
---- Resolving the terminal's inability to distinguish between `TAB` and `<C-i>` in normal mode
--return "<C-i>"
--end
--end, { desc = "Accept Copilot NES suggestion", expr = true })
--end,
--},
{ 'AndreM222/copilot-lualine' }, { 'AndreM222/copilot-lualine' },
{
'supermaven-inc/supermaven-nvim',
config = function()
require'supermaven-nvim'.setup({
keymaps = {
accept_suggestion = '<Tab>',
clear_suggestion = '<C-]>',
accept_word = '<C-.>',
},
disable_inline_completion = true,
})
end,
},
{ {
'windwp/nvim-autopairs', 'windwp/nvim-autopairs',
event = 'InsertEnter', event = 'InsertEnter',
config = true config = true,
}, },
{ {
'windwp/nvim-ts-autotag', 'windwp/nvim-ts-autotag',
config = function() config = function()
require'nvim-ts-autotag'.setup({}) require 'nvim-ts-autotag'.setup({})
end, end,
}, },
--{
--"garyhurtz/cmp_kitty",
--dependencies = {
--{ "hrsh7th/nvim-cmp" },
--},
--init = function()
--require('cmp_kitty'):setup()
--end
--},
{ 'hrsh7th/cmp-cmdline' }, { 'hrsh7th/cmp-cmdline' },
}, },
config = function() config = function()
@@ -325,23 +217,22 @@ return {
prefix = '', prefix = '',
}, },
}) })
require'mason'.setup({}) require 'mason'.setup({})
local cmp = require'cmp' local cmp = require 'cmp'
local cmp_lsp = require'cmp_nvim_lsp' local cmp_lsp = require 'cmp_nvim_lsp'
local lspconfig = require'lspconfig' local lspconfig = require 'lspconfig'
local capabilities = vim.tbl_deep_extend( local capabilities = vim.tbl_deep_extend(
'force', 'force',
{}, {},
vim.lsp.protocol.make_client_capabilities(), vim.lsp.protocol.make_client_capabilities(),
cmp_lsp.default_capabilities() cmp_lsp.default_capabilities()
) )
local cmp_autopairs = require'nvim-autopairs.completion.cmp' local cmp_autopairs = require 'nvim-autopairs.completion.cmp'
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done())
cmp.event:on("menu_opened", function() cmp.event:on('menu_opened', function()
vim.b.copilot_suggestion_hidden = true vim.b.copilot_suggestion_hidden = true
end) end)
cmp.event:on('menu_closed', function()
cmp.event:on("menu_closed", function()
vim.b.copilot_suggestion_hidden = false vim.b.copilot_suggestion_hidden = false
end) end)
require 'mason-lspconfig'.setup({ require 'mason-lspconfig'.setup({
@@ -378,18 +269,18 @@ return {
'svelte', 'svelte',
'tailwindcss', 'tailwindcss',
'tinymist', 'tinymist',
'ts_ls', 'vtsls',
'yamlls', 'yamlls',
}, },
handlers = { handlers = {
function(server_name) function(server_name)
lspconfig[server_name].setup({ lspconfig[server_name].setup({
capabilities = capabilities capabilities = capabilities,
}) })
end, end,
zls = function() zls = function()
lspconfig.zls.setup({ lspconfig.zls.setup({
root_dir = lspconfig.util.root_pattern(".git", "build.zig", "zls.json"), root_dir = lspconfig.util.root_pattern('.git', 'build.zig', 'zls.json'),
settings = { settings = {
zls = { zls = {
enable_inlay_hints = true, enable_inlay_hints = true,
@@ -401,39 +292,76 @@ return {
vim.g.zig_fmt_parse_errors = 0 vim.g.zig_fmt_parse_errors = 0
vim.g.zig_fmt_autosave = 0 vim.g.zig_fmt_autosave = 0
end, end,
["lua_ls"] = function() ['vtsls'] = function()
lspconfig.vtsls.setup({
capabilities = capabilities,
root_dir = lspconfig.util.root_pattern('turbo.json', 'pnpm-workspace.yaml', '.git'),
settings = {
vtsls = {
autoUseWorkspaceTsdk = true,
experimental = {
completion = {
enableServerSideFuzzyMatch = true,
},
},
},
typescript = {
updateImportsOnFileMove = { enabled = 'always' },
suggest = { completeFunctionCalls = true },
preferences = {
importModuleSpecifier = 'non-relative',
includePackageJsonAutoImports = 'auto',
},
inlayHints = {
parameterNames = { enabled = 'literals' },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
},
},
javascript = {
updateImportsOnFileMove = { enabled = 'always' },
suggest = { completeFunctionCalls = true },
inlayHints = {
parameterNames = { enabled = 'literals' },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
},
},
},
})
end,
['lua_ls'] = function()
lspconfig.lua_ls.setup({ lspconfig.lua_ls.setup({
capabilities = capabilities, capabilities = capabilities,
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = { version = 'LuaJIT' },
version = 'LuaJIT', diagnostics = { globals = { 'vim' } },
},
diagnostics = {
globals = { 'vim' },
},
workspace = { workspace = {
library = vim.api.nvim_get_runtime_file("", true), library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false, checkThirdParty = false,
-- These are the key settings to prevent the infinite processing
maxPreload = 100000, maxPreload = 100000,
preloadFileSize = 10000, preloadFileSize = 10000,
}, },
telemetry = { telemetry = { enable = false },
enable = false,
},
format = { format = {
enable = true, enable = true,
defaultConfig = { defaultConfig = {
indent_style = "space", indent_style = 'space',
indent_size = "2", indent_size = '2',
}, },
}, },
}, },
}, },
}) })
end, end,
} },
}) })
end, end,
} }