Skip to content

Commit

Permalink
feat: add healthcheck (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Jul 13, 2024
1 parent 86bb540 commit 2e34efd
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 23 deletions.
59 changes: 59 additions & 0 deletions .github/DISCUSSION_TEMPLATE/configuration.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ return {
}
```

You can run `:checkhealth neotest-golang` to review common issues.

## ⚙️ Configuration

| Argument | Default value | Description |
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions lua/neotest-golang/health.lua
Original file line number Diff line number Diff line change
@@ -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
39 changes: 16 additions & 23 deletions lua/neotest-golang/lib/find.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand All @@ -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

Expand Down

0 comments on commit 2e34efd

Please sign in to comment.