-
Contributing guidelines
Module(s)mini.deps QuestionWhile using Mini.Deps, I've been trying to get LSPs lazy loaded properly to shave ~20ms of startup time but I am having a weird issue. Take lua_ls for example. When a file is opened from within neovim (using :e or mini.pick for example), lua_ls attaches just fine. But when opening the file from the cli, it does not attach, i.e. "nvim myfile.lua" will not trigger the attach autocommand. What is the proper solution to this set up? I know lazy loading LSPs should be possible. Here is the lsp snippet of my config. My overall init.lua is minimal, I only use lazydev and nvim-lspconfig and I install the LSPs myself (yes they're both available on path). --------- LANGUAGE SERVER -------------
later(function()
add('neovim/nvim-lspconfig')
add('folke/lazydev.nvim')
require('lazydev').setup({})
local lspconfig = require('lspconfig')
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('custom-lsp-attach', { clear = false }),
callback = function(event)
local opts = { buffer = event.buf }
map('n', 'K', vim.lsp.buf.hover, opts)
map('n', 'gd', vim.lsp.buf.definition, opts)
map('n', 'gD', vim.lsp.buf.declaration, opts)
map('n', 'gi', vim.lsp.buf.implementation, opts)
map('n', 'gs', vim.lsp.buf.signature_help, opts)
map('n', 'gr', vim.lsp.buf.references, opts)
map('n', '<F4>', vim.lsp.buf.code_action, opts)
end,
})
lspconfig.lua_ls.setup({
settings = { Lua = { format = { enable = false } } },
})
lspconfig.ruff.setup({})
end) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I use this in my config. ...
later(lsp) -- inside function lsp all "lsp related plugins" are added and configured
if Util.opened_with_arguments() then
later(function() -- The lsp does not attach when directly opening a file:
local ft = vim.bo.filetype
if ft and ft ~= "oil" then
vim.api.nvim_exec_autocmds("FileType", {
modeline = false,
pattern = vim.bo.filetype,
})
end
end)
end
... ... and have been saving those 20ms multiple times a day for a year now...) |
Beta Was this translation helpful? Give feedback.
-
I rarely encounter this as I tend to open bare -- Load now if started like `nvim -- file` and later if `nvim`
local now_if_args = vim.fn.argc(-1) > 0 and now or later
now_if_args(function()
-- LSP and tree-sitter related plugin setup
...
end) If you don't use any dashboard-like plugin (which I'd still suggest trying, it feels like a cleaner experience and setup), then indeed forcing LSP and tree-sitter loading via manually forcing |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help @abeldekat and @echasnovski. I ended up just adding |
Beta Was this translation helpful? Give feedback.
Thanks for your help @abeldekat and @echasnovski.
I ended up just adding
vim.cmd('LspStart')
to the end of my later(..) function and it seems to have solved it. I did actually find myself leaning more towards opening nvim first then navigating to the file, so maybe it's not a big deal after all. I've been enjoying mini.starter, I like the fact that it shows recently opened files! I hope the shada bug I see on windows gets fixed soon so I don't have to delete my shada file and reset my starter dashboard all the time.