From 2e34efdee206bc9830cd387e3f26e4531fb1e19a Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 13 Jul 2024 15:30:46 +0200 Subject: [PATCH] feat: add healthcheck (#123) --- .github/DISCUSSION_TEMPLATE/configuration.yml | 59 +++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 3 + README.md | 6 ++ lua/neotest-golang/health.lua | 42 +++++++++++++ lua/neotest-golang/lib/find.lua | 39 +++++------- 5 files changed, 126 insertions(+), 23 deletions(-) create mode 100644 .github/DISCUSSION_TEMPLATE/configuration.yml create mode 100644 lua/neotest-golang/health.lua diff --git a/.github/DISCUSSION_TEMPLATE/configuration.yml b/.github/DISCUSSION_TEMPLATE/configuration.yml new file mode 100644 index 00000000..34af7f37 --- /dev/null +++ b/.github/DISCUSSION_TEMPLATE/configuration.yml @@ -0,0 +1,59 @@ +name: Configuration +description: Get help with configuration issues. +title: "configuration: " +labels: [configuration] +body: + - type: markdown + attributes: + value: | + To best be able to help you with your configuration-related issue, please fill out the below form. + - type: checkboxes + attributes: + label: Did you check docs and existing issues? + description: Make sure you checked all of the below before submitting an issue. + options: + - label: I have read the [documentation](https://github.com/fredrikaverpil/neotest-golang/blob/main/README.md). + required: true + - label: I have searched the existing [discussions](https://github.com/fredrikaverpil/neotest-golang/discussions). + required: true + - label: I have updated to the latest version of Neotest. + required: true + - label: I have updated to the latest version of neotest-golang. + required: true + - type: input + attributes: + label: "Neovim version (nvim -v)" + placeholder: "0.10.0 commit db1b0ee3b30f" + validations: + required: true + - type: input + attributes: + label: "Operating system/version" + placeholder: "MacOS 14.5" + validations: + required: true + - type: textarea + attributes: + label: Output from `:checkhealth neotest-golang` + description: Please provide the output. + validations: + required: true + - type: textarea + attributes: + label: Your Neotest and neotest-golang Lua setup + description: Please provide valid Lua code, describing how you load and configure the neotest-golang adapter. + render: Lua + placeholder: | + return { + -- your setup here + } + validations: + required: true + - type: textarea + attributes: + label: Describe the problem + description: | + A clear and concise description of what the problem is. + Please include any related errors you see in Neovim (e.g. in `:messages`) and attach any screenshots. + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 7395f6b0..bc590dba 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,8 @@ blank_issues_enabled: false contact_links: + - name: Configuration issue + url: https://github.com/fredrikaverpil/neotest-golang/discussions/categories/configuration + about: Get help setting up neotest-golang. - name: Ask a question or start a discussion url: https://github.com/fredrikaverpil/neotest-golang/discussions about: Use Github discussions instead. diff --git a/README.md b/README.md index 63e0d326..c0e32230 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ return { } ``` +You can run `:checkhealth neotest-golang` to review common issues. + ## ⚙️ Configuration | Argument | Default value | Description | @@ -301,6 +303,10 @@ return { ## ⛑️ Tips & troubleshooting +### Issues with setting up the adapter + +You can run `:checkhealth neotest-golang` to review common issues. + ### Neotest is slowing down Neovim Neotest, out of the box with default settings, can appear very slow in large diff --git a/lua/neotest-golang/health.lua b/lua/neotest-golang/health.lua new file mode 100644 index 00000000..ea06e9fb --- /dev/null +++ b/lua/neotest-golang/health.lua @@ -0,0 +1,42 @@ +local start = vim.health.start or vim.health.report_start +local ok = vim.health.ok or vim.health.report_ok +local warn = vim.health.warn or vim.health.report_warn +local error = vim.health.error or vim.health.report_error +local info = vim.health.info or vim.health.report_info + +local options = require("neotest-golang.options") +local lib = require("neotest-golang.lib") + +local M = {} + +function M.check() + M.go_binary_on_path() + M.go_mod_found() +end + +function M.go_binary_on_path() + local go = vim.fn.executable("go") + if go == 1 then + ok("Go binary found on PATH: " .. vim.fn.exepath("go")) + else + warn("Go binary not found on PATH") + end +end + +function M.go_mod_found() + local go_mod_filepath = nil + local filepaths = lib.find.go_test_filepaths(vim.fn.getcwd()) + for _, filepath in ipairs(filepaths) do + local start_path = vim.fn.fnamemodify(filepath, ":h") + go_mod_filepath = lib.find.file_upwards("go.mod", start_path) + if go_mod_filepath ~= nil then + ok("Found go.mod file for " .. filepath .. " in " .. go_mod_filepath) + break + end + end + if go_mod_filepath == nil then + warn("No go.mod file found") + end +end + +return M diff --git a/lua/neotest-golang/lib/find.lua b/lua/neotest-golang/lib/find.lua index 050fe82f..f759a570 100644 --- a/lua/neotest-golang/lib/find.lua +++ b/lua/neotest-golang/lib/find.lua @@ -1,6 +1,8 @@ --- Helpers around filepaths. -local plenary_scan = require("plenary.scandir") +local scandir = require("plenary.scandir") + +local convert = require("neotest-golang.lib.convert") local M = {} @@ -9,41 +11,32 @@ local M = {} --- @param start_path string --- @return string | nil function M.file_upwards(filename, start_path) - local scan = require("plenary.scandir") local found_filepath = nil while start_path ~= vim.fn.expand("$HOME") do - local files = scan.scan_dir( - start_path, - { search_pattern = filename, hidden = true, depth = 1 } - ) + local files = scandir.scan_dir(start_path, { + search_pattern = convert.to_lua_pattern(filename), + depth = 1, + add_dirs = false, + }) if #files > 0 then found_filepath = files[1] - break + return found_filepath end - start_path = vim.fn.fnamemodify(start_path, ":h") -- go up one directory end if found_filepath == nil then - -- check if filename exists in the current directory - local files = scan.scan_dir( - start_path, - { search_pattern = filename, hidden = true, depth = 1 } - ) - if #files > 0 then - found_filepath = files[1] - end + -- go up one directory and try again + start_path = vim.fn.fnamemodify(start_path, ":h") + return M.file_upwards(filename, start_path) end - - return found_filepath end -- Get all *_test.go files in a directory recursively. function M.go_test_filepaths(folderpath) - local files = plenary_scan.scan_dir(folderpath, { - search_pattern = "_test%.go$", - depth = math.huge, - add_dirs = false, - }) + local files = scandir.scan_dir( + folderpath, + { search_pattern = "_test%.go$", add_dirs = false } + ) return files end