diff --git a/lua/sense/helper.lua b/lua/sense/helper.lua index ffff212..c5c68ed 100644 --- a/lua/sense/helper.lua +++ b/lua/sense/helper.lua @@ -24,6 +24,10 @@ function M.get_diags_above(wininfo) end function M.get_diags_below(wininfo) + if wininfo.botline - wininfo.topline + 1 < wininfo.height then + log.debug("buffer bottom is visible in current window, return empty diagnostics") + return {} + end local diagnostics = state.diag_cache[wininfo.bufnr] or {} diagnostics = vim.iter(diagnostics) :filter(function(diag) diff --git a/spec/samples/error_at_bottom.go b/spec/samples/error_at_bottom.go new file mode 100644 index 0000000..2221dad --- /dev/null +++ b/spec/samples/error_at_bottom.go @@ -0,0 +1,35 @@ +package main + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +func main() { + fmt.Println("hi") +} diff --git a/spec/samples/error_at_top.go b/spec/samples/error_at_top.go new file mode 100644 index 0000000..d4665eb --- /dev/null +++ b/spec/samples/error_at_top.go @@ -0,0 +1,35 @@ +package main + +func main() { + fmt.Println("hi") +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/samples/oneline.go b/spec/samples/oneline.go new file mode 100644 index 0000000..e69de29 diff --git a/spec/ui/statuscol_spec.lua b/spec/ui/statuscol_spec.lua index 15b4ad8..edcfc82 100644 --- a/spec/ui/statuscol_spec.lua +++ b/spec/ui/statuscol_spec.lua @@ -118,3 +118,49 @@ describe("UI component - statuscol", function() assert.same(1, #testutils.list_visible_wins()) end) end) + +-- TODO: move out of here and automate it. +local ONELINE_DIAGS = { + { + bufnr = 1, + col = 0, + end_col = 0, + end_lnum = 1, + lnum = 1, + message = "expected ';', found 'EOF'", + namespace = 16, + severity = 1, + source = "syntax", + user_data = { + lsp = { + message = "expected ';', found 'EOF'", + range = { + ["end"] = { + character = 0, + line = 1 + }, + start = { + character = 0, + line = 1 + } + }, + severity = 1, + source = "syntax" + } + } + } +} + +describe("samples/oneline.go", function() + before_each(function() + -- clear all buffers/windows + vim.cmd("silent! %bwipeout") + vim.cmd("silent! wincmd o") + end) + it("when buffer height is smaller than window height", function() + -- open new buffer and set diagnostics + testutils.open_file("spec/samples/oneline.go") + vim.diagnostic.set(TEST_NS, 0, ONELINE_DIAGS) + assert.same(0, #testutils.list_visible_float_wins()) + end) +end)