Skip to content

Commit

Permalink
feat: make format timeout configurable (#1275)
Browse files Browse the repository at this point in the history
* feat&refactor: make format timeout configurable, refactor format-related
options.

* chore(settings): set `format_modifications_only` to `false` to prevent possible ci issues

Signed-off-by: Charles Chiu <charleschiu@hey.com>

* fix: set timeout for null-ls considering range format capability.

this commit also revert the settings structure b/c we can refactor it in
another PR.

* fixup: fix ci.

* fix: remove redundant notification.

* fixup: fix notify logic and CI.

* fixup: merge judgements.

Co-authored-by: jint_lzxy_ <50296129+Jint-lzxy@users.noreply.github.com>
Signed-off-by: Mohu <miracle_l@bupt.edu.cn>

* fixup: remove redundant judge.

* docs: more accurate comment note.

Co-authored-by: jint_lzxy_ <50296129+Jint-lzxy@users.noreply.github.com>
Signed-off-by: ayamir <miracle_l@bupt.edu.cn>

* fix: wrong require source.

Co-authored-by: jint_lzxy_ <50296129+Jint-lzxy@users.noreply.github.com>
Signed-off-by: ayamir <miracle_l@bupt.edu.cn>

---------

Signed-off-by: Charles Chiu <charleschiu@hey.com>
Signed-off-by: Mohu <miracle_l@bupt.edu.cn>
Signed-off-by: ayamir <miracle_l@bupt.edu.cn>
Co-authored-by: Charles Chiu <charleschiu@hey.com>
Co-authored-by: jint_lzxy_ <50296129+Jint-lzxy@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent f0369f5 commit 8f30bae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
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 (in ms).
---@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("core.settings").format_timeout,
})

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

0 comments on commit 8f30bae

Please sign in to comment.