Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Commit

Permalink
perf(diagnostics): ignore didSave notification if buffer unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Alvarez committed Nov 12, 2021
1 parent a3406ba commit 81bdb29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lua/null-ls/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ M.handler = function(original_params)
s.clear_cache(uri)
end

local params = u.make_params(original_params, methods.map[method])
local bufnr = vim.uri_to_bufnr(uri)

local changedtick = original_params.textDocument.version or api.nvim_buf_get_changedtick(bufnr)

if method == methods.lsp.DID_SAVE and changedtick == last_changedtick[uri] then
u.debug_log("buffer unchanged; ignoring didSave notification")
return
end

local params = u.make_params(original_params, methods.map[method])

last_changedtick[uri] = changedtick

require("null-ls.generators").run_registered({
Expand Down
2 changes: 1 addition & 1 deletion test/spec/diagnostics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("diagnostics", function()
it("should call make_params with params and method", function()
diagnostics.handler(mock_params)

assert.stub(u.make_params).was_called_with(mock_params, methods.internal.DIAGNOSTICS)
assert.stub(u.make_params).was_called_with(mock_params, methods.internal.DIAGNOSTICS_ON_OPEN)
end)

describe("handler", function()
Expand Down

0 comments on commit 81bdb29

Please sign in to comment.