From 29a06fcc906f57894c1bc768219ba590e03d1121 Mon Sep 17 00:00:00 2001 From: TheNordicMule <42049019+TheNordicMule@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:02:42 -0600 Subject: [PATCH] feat: add ability to alter lsp file operation timeout (#317) * feat: add ability to alter lsp file operation timeout * change default * fix table * add missing * move inside table * remove duplicate * reuse default * change message * refactor: rename autosave config option --------- Co-authored-by: Steven Arcangeli --- README.md | 10 +++++++--- doc/oil.txt | 10 +++++++--- lua/oil/config.lua | 19 ++++++++++++++++--- lua/oil/lsp/helpers.lua | 9 +++++---- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c329196..1f4bd18 100644 --- a/README.md +++ b/README.md @@ -163,9 +163,13 @@ require("oil").setup({ -- You can set the delay to false to disable cleanup entirely -- Note that the cleanup process only starts when none of the oil buffers are currently displayed cleanup_delay_ms = 2000, - -- Set to true to autosave buffers that are updated with LSP willRenameFiles - -- Set to "unmodified" to only save unmodified buffers - lsp_rename_autosave = false, + lsp_file_methods = { + -- Time to wait for LSP file operations to complete before skipping + timeout_ms = 1000, + -- Set to true to autosave buffers that are updated with LSP willRenameFiles + -- Set to "unmodified" to only save unmodified buffers + autosave_changes = false, + }, -- Constrain the cursor to the editable parts of the oil buffer -- Set to `false` to disable, or "name" to keep it on the file names constrain_cursor = "editable", diff --git a/doc/oil.txt b/doc/oil.txt index 24ff83e..9e6eec3 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -54,9 +54,13 @@ CONFIG *oil-confi -- You can set the delay to false to disable cleanup entirely -- Note that the cleanup process only starts when none of the oil buffers are currently displayed cleanup_delay_ms = 2000, - -- Set to true to autosave buffers that are updated with LSP willRenameFiles - -- Set to "unmodified" to only save unmodified buffers - lsp_rename_autosave = false, + lsp_file_methods = { + -- Time to wait for LSP file operations to complete before skipping + timeout_ms = 1000, + -- Set to true to autosave buffers that are updated with LSP willRenameFiles + -- Set to "unmodified" to only save unmodified buffers + autosave_changes = false, + }, -- Constrain the cursor to the editable parts of the oil buffer -- Set to `false` to disable, or "name" to keep it on the file names constrain_cursor = "editable", diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 5026f78..8753903 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -37,9 +37,13 @@ local default_config = { -- You can set the delay to false to disable cleanup entirely -- Note that the cleanup process only starts when none of the oil buffers are currently displayed cleanup_delay_ms = 2000, - -- Set to true to autosave buffers that are updated with LSP willRenameFiles - -- Set to "unmodified" to only save unmodified buffers - lsp_rename_autosave = false, + lsp_file_methods = { + -- Time to wait for LSP file operations to complete before skipping + timeout_ms = 1000, + -- Set to true to autosave buffers that are updated with LSP willRenameFiles + -- Set to "unmodified" to only save unmodified buffers + autosave_changes = false, + }, -- Constrain the cursor to the editable parts of the oil buffer -- Set to `false` to disable, or "name" to keep it on the file names constrain_cursor = "editable", @@ -172,6 +176,15 @@ M.setup = function(opts) new_conf.keymaps = opts.keymaps or {} end + if new_conf.lsp_rename_autosave ~= nil then + new_conf.lsp_file_methods.autosave_changes = new_conf.lsp_rename_autosave + new_conf.lsp_rename_autosave = nil + vim.notify_once( + "oil config value lsp_rename_autosave has moved to lsp_file_methods.autosave_changes.\nCompatibility will be removed on 2024-09-01.", + vim.log.levels.WARN + ) + end + for k, v in pairs(new_conf) do M[k] = v end diff --git a/lua/oil/lsp/helpers.lua b/lua/oil/lsp/helpers.lua index e0a1451..89c5469 100644 --- a/lua/oil/lsp/helpers.lua +++ b/lua/oil/lsp/helpers.lua @@ -68,9 +68,10 @@ M.will_perform_file_operations = function(actions) end end end - accum(workspace.will_create_files(creates)) - accum(workspace.will_delete_files(deletes)) - accum(workspace.will_rename_files(moves)) + local timeout_ms = config.lsp_file_methods.timeout_ms + accum(workspace.will_create_files(creates, { timeout_ms = timeout_ms })) + accum(workspace.will_delete_files(deletes, { timeout_ms = timeout_ms })) + accum(workspace.will_rename_files(moves, { timeout_ms = timeout_ms })) if final_err then vim.notify( string.format("[lsp] file operation error: %s", vim.inspect(final_err)), @@ -83,7 +84,7 @@ M.will_perform_file_operations = function(actions) workspace.did_delete_files(deletes) workspace.did_rename_files(moves) - local autosave = config.lsp_rename_autosave + local autosave = config.lsp_file_methods.autosave_changes if autosave == false then return end