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
+113 -185
View File
@@ -1,7 +1,7 @@
return {
'mason-org/mason-lspconfig.nvim',
dependencies = {
{ 'neovim/nvim-lspconfig', },
{ 'neovim/nvim-lspconfig' },
{
'mason-org/mason.nvim',
opts = {
@@ -9,19 +9,19 @@ return {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = ""
}
}
package_uninstalled = "",
},
},
},
},
{
'hrsh7th/nvim-cmp',
event = { 'InsertEnter', 'CmdlineEnter' },
config = function()
local cmp = require'cmp'
local lspkind = require'lspkind'
local cmp = require 'cmp'
local lspkind = require 'lspkind'
local cmp_select = { behavior = cmp.SelectBehavior.Select }
local luasnip = require'luasnip'
local luasnip = require 'luasnip'
cmp.setup({
snippet = {
expand = function(args)
@@ -35,47 +35,21 @@ return {
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, {
{ name = 'buffer' },
{ name = 'luasnip_choice' },
{ name = 'copilot' },
{ name = 'supermaven' },
{ name = 'nvim_lsp_document_symbol' },
{ name = 'nvim_lsp_signature_help' },
{ 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 = 'buffer', keyword_length = 4 },
{ name = 'path' },
{ name = 'dotenv' },
{ name = 'render-markdown' },
{ name = 'emoji' },
}),
formatting = {
format = lspkind.cmp_format({
mode = 'symbol',
maxwidth = {
menu = 50,
abbr = 50,
},
symbol_map = {
Supermaven = '',
Copilot = '',
},
maxwidth = { menu = 50, abbr = 50 },
symbol_map = { Copilot = '' },
ellipsis_char = '...',
show_labelDetails = true,
before = function(entry, vim_item)
before = function(_, vim_item)
return vim_item
end,
}),
@@ -84,33 +58,11 @@ return {
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<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(),
}),
--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',
@@ -121,13 +73,21 @@ return {
{ name = 'git' },
}, {
{ name = 'buffer' },
}),
})
cmp.setup.filetype({ 'json', 'jsonc' }, {
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'npm' },
}, {
{ name = 'buffer', keyword_length = 4 },
}),
})
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' },
}
},
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
@@ -136,59 +96,47 @@ return {
}, {
{ name = 'cmdline' },
}),
matching = { disallow_symbol_nonprefix_matching = false }
matching = { disallow_symbol_nonprefix_matching = false },
})
end,
},
{ 'hrsh7th/cmp-nvim-lsp' },
{ '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-copilot' },
{
'zbirenbaum/copilot-cmp',
config = function ()
require'copilot_cmp'.setup()
end
config = function()
require 'copilot_cmp'.setup()
end,
},
{ 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-emoji' },
{ 'chrisgrieser/cmp-nerdfont' },
{ 'jcha0713/cmp-tw2css' },
{ 'SergioRibera/cmp-dotenv' },
{ 'saadparwaiz1/cmp_luasnip' },
{ 'onsails/lspkind.nvim' },
{ 'rafamadriz/friendly-snippets' },
{
'L3MON4D3/cmp-luasnip-choice',
config = function()
require'cmp_luasnip_choice'.setup()
end,
},
{
'petertriho/cmp-git',
config = function()
require'cmp_git'.setup({})
end
},
{
'j-hui/fidget.nvim',
config = function()
require'fidget'.setup({})
require 'cmp_git'.setup({})
end,
},
{
'David-Kunz/cmp-npm',
config = function()
require'cmp-npm'.setup({})
end
require 'cmp-npm'.setup({})
end,
},
{
'j-hui/fidget.nvim',
config = function()
require 'fidget'.setup({})
end,
},
{
'stevearc/conform.nvim',
config = function()
require'conform'.setup({
require 'conform'.setup({
formatters_by_ft = {
cs = { 'csharpier', 'lsp' },
javascript = { 'prettierd', 'prettier' },
@@ -210,7 +158,7 @@ return {
local end_line = vim.fn.line("'>")
range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } }
end
require'conform'.format({
require 'conform'.format({
async = true,
lsp_fallback = true,
range = range,
@@ -221,97 +169,41 @@ return {
{
'<leader>fk',
':Format<CR>',
mode = {'n', 'v'},
mode = { 'n', 'v' },
silent = true,
desc = "Format with conform"
}
}
desc = "Format with conform",
},
},
},
{
'L3MON4D3/LuaSnip',
version = 'v2.*',
build = 'make install_jsregexp'
build = 'make install_jsregexp',
},
--{ 'github/copilot.vim' },
{
"zbirenbaum/copilot.lua",
requires = {
'copilotlsp-nvim/copilot-lsp',
},
'zbirenbaum/copilot.lua',
cmd = 'Copilot',
event = 'InsertEnter',
config = function()
require'copilot'.setup({
--copilot_model = "",
--nes = {
--enabled = true,
--keymap = {
--accept_and_goto = '<leader>,',
--accept = false,
--dismiss = 'Esc',
--},
--},
require 'copilot'.setup({
-- Disable native ghost text so copilot-cmp can manage suggestions instead
suggestion = { enabled = false },
panel = { enabled = false },
})
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' },
{
'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',
event = 'InsertEnter',
config = true
config = true,
},
{
'windwp/nvim-ts-autotag',
config = function()
require'nvim-ts-autotag'.setup({})
require 'nvim-ts-autotag'.setup({})
end,
},
--{
--"garyhurtz/cmp_kitty",
--dependencies = {
--{ "hrsh7th/nvim-cmp" },
--},
--init = function()
--require('cmp_kitty'):setup()
--end
--},
{ 'hrsh7th/cmp-cmdline' },
},
config = function()
@@ -325,23 +217,22 @@ return {
prefix = '',
},
})
require'mason'.setup({})
local cmp = require'cmp'
local cmp_lsp = require'cmp_nvim_lsp'
local lspconfig = require'lspconfig'
require 'mason'.setup({})
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_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("menu_opened", function()
cmp.event:on('menu_opened', function()
vim.b.copilot_suggestion_hidden = true
end)
cmp.event:on("menu_closed", function()
cmp.event:on('menu_closed', function()
vim.b.copilot_suggestion_hidden = false
end)
require 'mason-lspconfig'.setup({
@@ -378,18 +269,18 @@ return {
'svelte',
'tailwindcss',
'tinymist',
'ts_ls',
'vtsls',
'yamlls',
},
handlers = {
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities
capabilities = capabilities,
})
end,
zls = function()
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 = {
zls = {
enable_inlay_hints = true,
@@ -401,39 +292,76 @@ return {
vim.g.zig_fmt_parse_errors = 0
vim.g.zig_fmt_autosave = 0
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({
capabilities = capabilities,
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
},
diagnostics = {
globals = { 'vim' },
},
runtime = { version = 'LuaJIT' },
diagnostics = { globals = { 'vim' } },
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false,
-- These are the key settings to prevent the infinite processing
maxPreload = 100000,
preloadFileSize = 10000,
},
telemetry = {
enable = false,
},
telemetry = { enable = false },
format = {
enable = true,
defaultConfig = {
indent_style = "space",
indent_size = "2",
indent_style = 'space',
indent_size = '2',
},
},
},
},
})
end,
}
},
})
end,
}