From b916371f828a3a4cbd64d0f3b5560ea384512092 Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 29 Oct 2023 12:38:28 +0100 Subject: [PATCH] Handling errors during tests. --- after/plugin/snippy.lua | 11 ++++++++++ after/plugin/treesitter.lua | 44 ++++++++++++++++++------------------- lua/myworkflow/go-tests.lua | 20 ++++++++++++++++- lua/myworkflow/packer.lua | 6 ++++- 4 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 after/plugin/snippy.lua diff --git a/after/plugin/snippy.lua b/after/plugin/snippy.lua new file mode 100644 index 0000000..251ed62 --- /dev/null +++ b/after/plugin/snippy.lua @@ -0,0 +1,11 @@ +require('snippy').setup({ + mappings = { + is = { + [''] = 'expand_or_advance', + [''] = 'previous', + }, + nx = { + ['x'] = 'cut_text', + }, + }, +}) diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua index d03eb2a..d6c7741 100644 --- a/after/plugin/treesitter.lua +++ b/after/plugin/treesitter.lua @@ -1,27 +1,27 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "go", "rust", "toml", "c", "lua", "vim", "vimdoc", "query" }, +require 'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "go", "rust", "toml", "c", "lua", "vim", "vimdoc", "query" }, - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, - highlight = { - enable = true, + highlight = { + enable = true, - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, - ident = { enable = true }, - rainbow = { - enable = true, - extended_mode = true, - max_file_lines = nil, - } + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + ident = { enable = true }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = nil, + } } diff --git a/lua/myworkflow/go-tests.lua b/lua/myworkflow/go-tests.lua index fd513de..dc4fab7 100644 --- a/lua/myworkflow/go-tests.lua +++ b/lua/myworkflow/go-tests.lua @@ -23,6 +23,12 @@ local test_function_query_string = [[ ) ]] +local t_run_query_string = [[ +( + +) +]] + local find_test_line = function(go_bufnr, name) local formatted = string.format(test_function_query_string, name) local query = vim.treesitter.query.parse("go", formatted) @@ -66,11 +72,17 @@ vim.api.nvim_create_user_command('GoClearTestMarks', function() vim.api.nvim_buf_clear_namespace(currbuf, ns, 0, -1) end, {}) +local errored = false function M.goRunTests() -- TODO: replace jobstart/jobwait with system() local id = vim.fn.jobstart({ "go", "test", "./...", "-json" }, { stdout_buffered = true, on_stdout = function(_, data) + if errored == true then + errored = false + return + end + if not data then return end @@ -91,7 +103,13 @@ function M.goRunTests() ::continue:: end end, - on_exit = function() + on_stderr = function(_, data) + for _, value in pairs(data) do + if value and value ~= "" then + errored = true + print('Error while running tests: ', value) + end + end end }) vim.fn.jobwait({ id }) diff --git a/lua/myworkflow/packer.lua b/lua/myworkflow/packer.lua index a5e36a2..73ee4b5 100644 --- a/lua/myworkflow/packer.lua +++ b/lua/myworkflow/packer.lua @@ -11,7 +11,11 @@ return require('packer').startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' + + -- undotree use 'mbbill/undotree' + + -- treesitter use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' }) -- Colors @@ -39,7 +43,7 @@ return require('packer').startup(function(use) use 'hrsh7th/cmp-cmdline' use 'hrsh7th/nvim-cmp' - -- Snippets (not really sure what this is for) + -- Snippets use 'dcampos/nvim-snippy' use 'dcampos/cmp-snippy'