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: add ability to alter lsp file operation timeout #317

Merged
merged 9 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ require("oil").setup({
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
-- Set to "unmodified" to only save unmodified buffers
lsp_rename_autosave = false,
-- The amount of time LSP waits for file operation before it errors
lsp_file_operation_timeout_ms = 1000,
-- 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",
Expand Down
2 changes: 2 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ CONFIG *oil-confi
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
-- Set to "unmodified" to only save unmodified buffers
lsp_rename_autosave = false,
-- The amount of time LSP waits for file operation before it errors
lsp_file_operation_timeout_ms = 1000,
-- 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",
Expand Down
4 changes: 4 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ local default_config = {
-- Set to true to autosave buffers that are updated with LSP willRenameFiles
-- Set to "unmodified" to only save unmodified buffers
lsp_rename_autosave = false,

-- The amount of time LSP waits for file operation before it errors
lsp_file_operation_timeout_ms = 1000,

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're adding another option related to LSP file operations (and we may want more in the future), let's nest this under another table

lsp_file_methods = {
  timeout_ms = 1000
}

We'll also want to move lsp_rename_autosave into that table with a backwards compatibility shim and deprecation message, but I can do that after this PR.

Would also recommend rewording the comment to something like "Time to wait for LSP file operations to complete before skipping" to make it clear that we're waiting on the LSP, and that the consequences of a timeout are only that it gets skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @stevearc, I tried to do all of the above. Let me know if there is anything else I need to change. Thank you!

-- 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",
Expand Down
7 changes: 4 additions & 3 deletions lua/oil/lsp/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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_operation_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)),
Expand Down
4 changes: 2 additions & 2 deletions lua/oil/lsp/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ local function will_file_operation(method, capability_name, files, options)
end, matching_files),
}
---@diagnostic disable-next-line: invisible
local result, err = client.request_sync(method, params, options.timeout_ms or 1000, 0)
local result, err = client.request_sync(method, params, options.timeout_ms, 0)
if result and result.result then
if options.apply_edits ~= false then
vim.lsp.util.apply_workspace_edit(result.result, client.offset_encoding)
Expand Down Expand Up @@ -260,7 +260,7 @@ function M.will_rename_files(files, options)
}
local result, err =
---@diagnostic disable-next-line: invisible
client.request_sync(ms.workspace_willRenameFiles, params, options.timeout_ms or 1000, 0)
client.request_sync(ms.workspace_willRenameFiles, params, options.timeout_ms, 0)
if result and result.result then
if options.apply_edits ~= false then
vim.lsp.util.apply_workspace_edit(result.result, client.offset_encoding)
Expand Down