Skip to content

Commit

Permalink
perf: speedup nvim loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Apr 17, 2024
1 parent 9aa5d1a commit 2f5950c
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 177 deletions.
1 change: 1 addition & 0 deletions root/.config/nvim/.project.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let g:nvim_lsp_autostart = {'lua_ls': v:true}
176 changes: 96 additions & 80 deletions root/.config/nvim/lua/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,97 +42,107 @@ end

local function setup_lsp(on_attach, capabilities)
local lspconfig = require('lspconfig')
lspconfig.clangd.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = vim.g.clangd_cmd,
}
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()

lspconfig.lua_ls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
format = {
enable = true,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "tab",
indent_size = "2",
if vim.fn.get(vim.g.nvim_lsp_autostart, 'clangd', false) then
lspconfig.clangd.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = vim.g.clangd_cmd,
}
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
end
if vim.fn.get(vim.g.nvim_lsp_autostart, 'lua_ls', false) then
lspconfig.lua_ls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
format = {
enable = true,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "tab",
indent_size = "2",
}
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { 'vim' },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
completion = {
callSnippet = "Replace"
}
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { 'vim' },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
completion = {
callSnippet = "Replace"
}
},
},
}

lspconfig.texlab.setup {
autostart = vim.fn.get(vim.g.nvim_lsp_autostart, 'texlab', false),
on_attach = on_attach,
capabilities = capabilities,
settings = {
texlab = {
latexFormatter = 'latexindent',
latexindent = {
['local'] = os.getenv("HOME") .. '/vimrc/root/latexindent.yaml', -- local is a reserved keyword
modifyLineBreaks = false,
}
end
if vim.fn.get(vim.g.nvim_lsp_autostart, 'texlab', false) then
lspconfig.texlab.setup {
autostart = true,
on_attach = on_attach,
capabilities = capabilities,
settings = {
texlab = {
latexFormatter = 'latexindent',
latexindent = {
['local'] = os.getenv("HOME") .. '/vimrc/root/latexindent.yaml', -- local is a reserved keyword
modifyLineBreaks = false,
},
bibtexFormatter = 'texlab',
formatterLineLength = 80,
},
bibtexFormatter = 'texlab',
formatterLineLength = 80,
},
}
}
}
end

-- ltex-ls.nvim似乎也不支持add to dictionary命令,建议使用coc.nvim
lspconfig.ltex.setup {
autostart = vim.fn.get(vim.g.nvim_lsp_autostart, 'ltex', false),
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "bib", "tex", "latex" },
settings = {
ltex = {
language = "en-US",
},
if vim.fn.get(vim.g.nvim_lsp_autostart, 'ltex', false) then
-- ltex-ls.nvim似乎也不支持add to dictionary命令,建议使用coc.nvim
lspconfig.ltex.setup {
autostart = true,
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "bib", "tex", "latex" },
settings = {
ltex = {
language = "en-US",
},
}
}
}
end

-- marksman and markdown_oxide are both markdown language servers, choose one of them
lspconfig.marksman.setup {
autostart = vim.fn.get(vim.g.nvim_lsp_autostart, 'marksman', false),
on_attach = on_attach,
capabilities = capabilities,
}
lspconfig.markdown_oxide.setup {
autostart = vim.fn.get(vim.g.nvim_lsp_autostart, 'markdown_oxide', false),
on_attach = on_attach,
capabilities = capabilities,
root_dir = lspconfig.util.root_pattern('.moxide.toml', '.git'),
}
if vim.fn.get(vim.g.nvim_lsp_autostart, 'marksman', false) then
-- marksman and markdown_oxide are both markdown language servers, choose one of them
lspconfig.marksman.setup {
autostart = true,
on_attach = on_attach,
capabilities = capabilities,
}
end
if vim.fn.get(vim.g.nvim_lsp_autostart, 'markdown_oxide', false) then
lspconfig.markdown_oxide.setup {
autostart = true,
on_attach = on_attach,
capabilities = capabilities,
root_dir = lspconfig.util.root_pattern('.moxide.toml', '.git'),
}
end

-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#jsonls
-- npm i -g vscode-langservers-extracted
local other_servers = { 'jsonls', 'pyright', 'typst_lsp' }
local other_servers = { 'jsonls', 'pyright', 'typst_lsp', 'gopls' }
for _, lsp in ipairs(other_servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
Expand Down Expand Up @@ -231,6 +241,12 @@ function M.lspconfig()
})
end,
})
vim.api.nvim_create_user_command('OutgoingCalls', function(_)
vim.lsp.buf.outgoing_calls()
end, { nargs = 0 })
vim.api.nvim_create_user_command('IncomingCalls', function(_)
vim.lsp.buf.incoming_calls()
end, { nargs = 0 })
end

return M
85 changes: 0 additions & 85 deletions root/.config/nvim/lua/lsp/lsp_progress.lua

This file was deleted.

81 changes: 80 additions & 1 deletion root/.config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,91 @@ if vim.g.vimrc_lsp == 'nvim-lsp' then
},
{
"linrongbin16/lsp-progress.nvim",
config = require("lsp.lsp_progress").lsp_progress,
opts = {
-- Spinning icons.
spinner = { "", "", "", "", "", "", "", "" },
-- Spinning update time in milliseconds.
spin_update_time = 200,
-- Last message cached decay time in milliseconds.
--
-- Message could be really fast(appear and disappear in an
-- instant) that user cannot even see it, thus we cache the last message
-- for a while for user view.
decay = 1000,
-- User event name.
event = "LspProgressStatusUpdated",
-- Event update time limit in milliseconds.
--
-- Sometimes progress handler could emit many events in an instant, while
-- refreshing statusline cause too heavy synchronized IO, so we limit the
-- event rate to reduce this cost.
event_update_time_limit = 125,
--- Max progress string length, by default -1 is unlimit.
max_size = -1,
-- Format series message.
--
-- By default it looks like: `formatting isort (100%) - done`.
--
-- @param title Message title.
-- @param message Message body.
-- @param percentage Progress in percentage numbers: [0%-100%].
-- @param done Indicate if this message is the last one in progress.
-- @return A nil|string|table value. The returned value will be
-- passed to function `client_format` as one of the
-- `series_messages` array, or ignored if return nil.
series_format = function(title, message, percentage, done)
local builder = {}
local has_title = false
local has_message = false
if title and title ~= "" then
table.insert(builder, title)
has_title = true
end
if message and message ~= "" then
table.insert(builder, message)
has_message = true
end
if percentage and (has_title or has_message) then
table.insert(builder, string.format("(%.0f%%%%)", percentage))
end
if done and (has_title or has_message) then
table.insert(builder, "- done")
end
return table.concat(builder, " ")
end,
-- Format client message.
client_format = function(client_name, spinner, series_messages)
return #series_messages > 0
and ("[" .. client_name .. "] " .. spinner .. " " .. table.concat(
series_messages,
", "
))
or nil
end,
-- Format (final) message.
format = function(client_messages)
local sign = " LSP" -- nf-fa-gear \uf013
return #client_messages > 0
and (sign .. " " .. table.concat(client_messages, " "))
or sign
end,
--- Enable debug.
debug = false,
--- Print log to console(command line).
console_log = true,
--- Print log to file.
file_log = false,
-- Log file to write, work with `file_log=true`.
-- For Windows: `$env:USERPROFILE\AppData\Local\nvim-data\lsp-progress.log`.
-- For *NIX: `~/.local/share/nvim/lsp-progress.log`.
file_log_name = "lsp-progress.log",
}
},
{
-- IMPORTANT: make sure to setup neodev BEFORE lspconfig
"folke/neodev.nvim",
opts = {},
ft = { 'lua' },
priority = 501
},
{
Expand Down
Loading

0 comments on commit 2f5950c

Please sign in to comment.