Expand your neovim sense with small UI components
0

Configure Feed

Select the types of activity you want to include in your feed.

test: add first test case that matters

+97 -41
+2 -2
lua/sense/ui/init.lua
··· 24 24 function M.update(wininfo) 25 25 virtual.top:render(wininfo) 26 26 virtual.bot:render(wininfo) 27 - statuscol.top:render(wininfo) 27 + -- statuscol.top:render(wininfo) 28 28 end 29 29 30 30 function M.close(wininfo) 31 31 virtual.top:close(wininfo) 32 32 virtual.bot:close(wininfo) 33 - statuscol.top:close(wininfo) 33 + -- statuscol.top:close(wininfo) 34 34 end 35 35 36 36 return M
+1
lua/sense/ui/statuscol.lua
··· 73 73 } 74 74 end 75 75 76 + -- FIXME: don't render anything when textoff is 0 76 77 M.top = gen_statuscol("top_statuscol", function (wininfo, height) 77 78 return { 78 79 relative = "win",
+29 -21
spec/minimal_init.lua
··· 7 7 vim.cmd("runtime! filetype.lua") 8 8 vim.cmd("runtime! plugin/**/*.{vim,lua}") 9 9 10 - local servers = { 11 - gopls = { 12 - name = "gopls", 13 - cmd = { "gopls" }, 14 - root_dir = vim.fs.root(0, { "go.work", "go.mod", "gotmpl", ".git" }), 15 - filetypes = { "go", "gomod", "gowork", "gotmpl" }, 16 - }, 17 - } 18 - local group = vim.api.nvim_create_augroup("UserLspStart", { clear = true }) 19 - vim.api.nvim_create_autocmd("filetype", { 20 - group = group, 21 - pattern = servers.gopls.filetypes, 22 - callback = function(ev) 23 - vim.lsp.start(servers.gopls, { 24 - bufnr = ev.buf, 25 - reuse_client = function() 26 - return true 27 - end, 28 - }) 29 - end, 30 - }) 10 + vim.notify("minimal_init") 11 + 12 + local M = {} 13 + 14 + function M.init_lsp() 15 + local servers = { 16 + gopls = { 17 + name = "gopls", 18 + cmd = { "gopls" }, 19 + root_dir = vim.fs.root(0, { "go.work", "go.mod", "gotmpl", ".git" }), 20 + filetypes = { "go", "gomod", "gowork", "gotmpl" }, 21 + }, 22 + } 23 + local group = vim.api.nvim_create_augroup("UserLspStart", { clear = true }) 24 + vim.api.nvim_create_autocmd("filetype", { 25 + group = group, 26 + pattern = servers.gopls.filetypes, 27 + callback = function(ev) 28 + vim.lsp.start(servers.gopls, { 29 + bufnr = ev.buf, 30 + reuse_client = function() 31 + return true 32 + end, 33 + }) 34 + end, 35 + }) 36 + end 37 + 38 + return M
+65 -18
spec/ui/virtual_spec.lua
··· 1 1 ---@module 'luassert' 2 2 3 3 require("spec.minimal_init") 4 - local nio = require("nio") 5 4 local ui = require("sense.ui") 6 5 7 - describe("Test", function() 8 - it("small test", function() 9 - assert.same(3, 1 + 2) 6 + ---@diagnostic disable-next-line: duplicate-set-field 7 + -- require("sense.log").debug = function (...) 8 + -- vim.print(...) 9 + -- end 10 + 11 + -- describe("Test", function() 12 + -- it("small test", function() 13 + -- assert.same(3, 1 + 2) 14 + -- end) 15 + -- nio.tests.it("goplsssss", function () 16 + -- vim.cmd.edit("spec/example.go") 17 + -- local buf = vim.api.nvim_get_current_buf() 18 + -- assert.same("go", vim.bo[buf].filetype) 19 + -- -- HACK: this is clearly not good way to wait until LspAttach event 20 + -- nio.sleep(500) 21 + -- local client = vim.lsp.get_clients({ bufnr = buf })[1] 22 + -- assert.not_nil(client) 23 + -- assert.same("gopls", client.name) 24 + -- end) 25 + -- it("open virtual window", function() 26 + -- end) 27 + -- end) 28 + 29 + local test_ns = vim.api.nvim_create_namespace("sense.test") 30 + local diags = { 31 + { 32 + code = "UndeclaredName", 33 + col = 4, 34 + end_col = 7, 35 + end_lnum = 3, 36 + lnum = 3, 37 + message = "undefined: fmt", 38 + severity = 1, 39 + source = "compiler", 40 + user_data = { 41 + lsp = { 42 + code = "UndeclaredName", 43 + codeDescription = { 44 + href = "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName", 45 + }, 46 + }, 47 + }, 48 + }, 49 + } 50 + describe("UI component - virtual", function() 51 + local function count_win() 52 + return #vim.api.nvim_list_wins() 53 + end 54 + it("assert vim window size", function() 55 + assert.same(vim.o.columns, 80) 56 + assert.same(vim.o.lines, 24) 10 57 end) 11 - nio.tests.it("goplsssss", function () 58 + it("open virtual window", function() 12 59 vim.cmd.edit("spec/example.go") 13 - local buf = vim.api.nvim_get_current_buf() 14 - assert.same("go", vim.bo[buf].filetype) 15 - -- HACK: this is clearly not good way to wait until LspAttach event 16 - nio.sleep(500) 17 - local client = vim.lsp.get_clients({ bufnr = buf })[1] 18 - assert.not_nil(client) 19 - assert.same("gopls", client.name) 20 - end) 21 - it("open virtual window", function() 22 - end) 23 - end) 60 + vim.diagnostic.set(test_ns, 0, diags) 61 + -- split window vertically 62 + vim.cmd.wincmd("v") 63 + assert.same(2, count_win()) 64 + 65 + -- go to bottom to show virtual UI pointing top 66 + vim.cmd.normal("G") 67 + ui.update(vim.fn.getwininfo()[1]) 68 + assert.same(3, count_win()) 24 69 25 - describe("UI", function () 26 - nio.tests.it("open virtual window", function() 70 + -- close the new split window 71 + vim.cmd.wincmd("q") 72 + -- window count should be 1 here 73 + assert.same(1, count_win()) 27 74 end) 28 75 end)