Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make format timeout configurable. #1275

Merged
merged 10 commits into from
Jul 1, 2024
40 changes: 22 additions & 18 deletions lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ settings["use_ssh"] = true
---@type boolean
settings["use_copilot"] = true

-- Set it to false if you want to turn off LSP Inlay Hints
---@type boolean
settings["lsp_inlayhints"] = true

-- Set it to false if there is no need to format on save.
---@type boolean
settings["format_on_save"] = true

-- Set format timeout here (ms)
ayamir marked this conversation as resolved.
Show resolved Hide resolved
---@type number
settings["format_timeout"] = 1000

-- Set it to false if the notification after formatting is annoying.
---@type boolean
settings["format_notify"] = true
Expand All @@ -37,6 +37,24 @@ settings["format_disabled_dirs"] = {
"~/format_disabled_dir",
}

-- Filetypes in this list will skip lsp formatting if rhs is true.
---@type table<string, boolean>
settings["formatter_block_list"] = {
lua = false, -- example
}

-- Servers in this list will skip setting formatting capabilities if rhs is true.
---@type table<string, boolean>
settings["server_formatting_block_list"] = {
lua_ls = true,
tsserver = true,
clangd = true,
}

-- Set it to false if you want to turn off LSP Inlay Hints
---@type boolean
settings["lsp_inlayhints"] = true

-- Set it to false if diagnostics virtual text is annoying.
-- If disabled, you may browse lsp diagnostics using trouble.nvim (press `gt` to toggle it).
---@type boolean
Expand Down Expand Up @@ -85,20 +103,6 @@ settings["background"] = "dark"
---@type string
settings["external_browser"] = "chrome-cli open"

-- Filetypes in this list will skip lsp formatting if rhs is true.
---@type table<string, boolean>
settings["formatter_block_list"] = {
lua = false, -- example
}

-- Servers in this list will skip setting formatting capabilities if rhs is true.
---@type table<string, boolean>
settings["server_formatting_block_list"] = {
lua_ls = true,
tsserver = true,
clangd = true,
}

-- Set the language servers that will be installed during bootstrap here.
-- check the below link for all the supported LSPs:
-- https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/server_configurations
Expand Down
9 changes: 6 additions & 3 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ local format_on_save = settings.format_on_save
local format_notify = settings.format_notify
local format_modifications_only = settings.format_modifications_only
local server_formatting_block_list = settings.server_formatting_block_list
local format_timeout = settings.format_timeout

vim.api.nvim_create_user_command("FormatToggle", function()
M.toggle_format_on_save()
end, {})

local block_list = require("core.settings").formatter_block_list
local block_list = settings.formatter_block_list
vim.api.nvim_create_user_command("FormatterToggleFt", function(opts)
if block_list[opts.args] == nil then
vim.notify(
Expand All @@ -35,7 +36,7 @@ vim.api.nvim_create_user_command("FormatterToggleFt", function(opts)
end, { nargs = 1, complete = "filetype" })

function M.enable_format_on_save(is_configured)
local opts = { pattern = "*", timeout = 1000 }
local opts = { pattern = "*", timeout = format_timeout }
vim.api.nvim_create_augroup("format_on_save", { clear = true })
vim.api.nvim_create_autocmd("BufWritePre", {
group = "format_on_save",
Expand Down Expand Up @@ -156,7 +157,9 @@ function M.format(opts)
{ title = "LSP Formatter Warning" }
)
return
elseif
end

if
format_modifications_only
and require("lsp-format-modifications").format_modifications(client, bufnr).success
then
Expand Down
1 change: 1 addition & 0 deletions lua/modules/configs/completion/null-ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ return function()
log_level = "warn",
update_in_insert = false,
sources = sources,
default_timeout = require("settings").format_timeout,
ayamir marked this conversation as resolved.
Show resolved Hide resolved
})

require("completion.mason-null-ls").setup()
Expand Down