fredrikaverpil / neotest-golang

Reliable Neotest adapter for running Go tests in Neovim.
MIT License
57 stars 5 forks source link

Switching from neotest-go to neotest-golang #37

Closed dez11de closed 1 week ago

dez11de commented 2 weeks ago

Hi,

I'm trying to make the switch from neotest-go to neotest-golang.

I've used this configuration:

return {
    "nvim-neotest/neotest",
    dependencies = {
        "nvim-treesitter/nvim-treesitter",
        "nvim-neotest/nvim-nio",
        "nvim-lua/plenary.nvim",
        "antoinemadec/fixcursorhold.nvim",

        -- adapters
        "nvim-neotest/neotest-go",
    },

    config = function()
        ---@diagnostic disable-next-line: missing-fields
        require("neotest").setup({
            adapters = {
                require("neotest-go")({
                    experimental = {
                        test_table = true,
                    },
                    args = { "-count=1", "-timeout=10s" }
                })
            }
        })

        vim.keymap.set('n', '<leader>n',
            ":lua require('neotest').watch.watch(vim.fn.getcwd())<cr>" ..
            ":lua require('neotest').summary.toggle()<cr>",
            { silent = true, desc = "neotest summary" })
    end
}

Which allows me to open a go file, it's testfile, press <Leader>n. This would open the test summary with all tests. When I save go file all the tests are being run. This works perfectly for me.

After finding out about neotest-golang, I've changed my configuration to:

return {
    "nvim-neotest/neotest",
    dependencies = {
        "nvim-treesitter/nvim-treesitter",
        "nvim-neotest/nvim-nio",
        "nvim-lua/plenary.nvim",
        "antoinemadec/FixCursorHold.nvim",

        -- adapters
        "fredrikaverpil/neotest-golang",
    },

    config = function()
        ---@diagnostic disable-next-line: missing-fields
        require("neotest").setup({
            adapters = {
                require("neotest-golang")({
                    go_test_args = {
                        "-v",
                        -- "-race",
                        "-count=1",
                        "-timeout=10s",
                    },
                    dap_go_enabled = false,
                })
            }
        })

        vim.keymap.set('n', '<leader>n',
            ":lua require('neotest').watch.watch(vim.fn.getcwd())<CR>" ..
            ":lua require('neotest').summary.toggle()<CR>",
            { silent = true, desc = "Neotest Summary" })
    end
}

Now, when I open the same .go and it's testfile press <Leader>n I get the following:

No position found with args { "/Users/myname/projects/exorcism/go/election-day",
  filter_path = <function 1>,
  symbol_queries = {
    elixir = <function 2>,
    go = "        ;query\n        ;Captures imported types\n        (qualified_type name: (type_identifier) @symbol)\n        ;Captures package-local and built-in types\n        (type_identifier)@symbol\n        ;Captures imported function calls and variables/constants\n        (selector_expression field: (field_identifier) @symbol)\n        ;Captures package-local functions calls\n        (call_expression f
unction: (identifier) @symbol)\n      ",
    haskell = "        ;query\n        ;explicit import\n        ((import_item [(variable)]) @symbol)\n        ;symbols that may be imported implicitly\n        ((type) @symbol)\n        (qualified_variable (variable) @symbol)\n        (exp_apply (exp_name (variable) @symbol))\n        ((constructor) @symbol)\n        ((operator) @symbol)\n      ",
    java = "        ;query\n        ;captures imported classes\n        (import_declaration\n            (scoped_identifier name: ((identifier) @symbol))\n        )\n      ",
    javascript = '  ;query\n  ;Captures named imports\n  (import_specifier name: (identifier) @symbol)\n  ;Captures default import\n  (import_clause (identifier) @symbol)\n  ;Capture require statements\n  (variable_declarator \n  name: (identifier) @symbol\n  value: (call_expression (identifier) @function  (#eq? @function "require")))\n  ;Capture namespace imports\n  (namespace_import (identifier) @symbol)\n
',
    lua = '        ;query\n        ;Captures module names in require calls\n        (function_call\n          name: ((identifier) @function (#eq? @function "require"))\n          arguments: (arguments (string) @symbol))\n      ',
    python = "        ;query\n        ;Captures imports and modules they're imported from\n        (import_from_statement (_ (identifier) @symbol))\n        (import_statement (_ (identifier) @symbol))\n      ",
    ruby = '        ;query\n        ;rspec - class name\n        (call\n          method: (identifier) @_ (#match? @_ "^(describe|context)")\n          arguments: (argument_list (constant) @symbol )\n        )\n\n        ;rspec - namespaced class name\n        (call\n          method: (identifier)\n          arguments: (argument_list\n            (scope_resolution\n              name: (constant) @symbol))\n
       )\n      ',
    rust = "        ;query\n        ;submodule import\n        (mod_item\n          name: (identifier) @symbol)\n        ;single import\n        (use_declaration\n          argument: (scoped_identifier\n            name: (identifier) @symbol))\n        ;import list\n        (use_declaration\n          argument: (scoped_use_list\n            list: (use_list\n                [(scoped_identifier\n
     path: (identifier)\n                   name: (identifier) @symbol)\n                 ((identifier) @symbol)])))\n        ;wildcard import\n        (use_declaration\n          argument: (scoped_use_list\n            path: (identifier)\n            [(use_list\n              [(scoped_identifier\n                path: (identifier)\n                name: (identifier) @symbol)\n                ((identifier) @
symbol)\n              ])]))\n      ",
    tsx = '  ;query\n  ;Captures named imports\n  (import_specifier name: (identifier) @symbol)\n  ;Captures default import\n  (import_clause (identifier) @symbol)\n  ;Capture require statements\n  (variable_declarator \n  name: (identifier) @symbol\n  value: (call_expression (identifier) @function  (#eq? @function "require")))\n  ;Capture namespace imports\n  (namespace_import (identifier) @symbol)\n',
    typescript = '  ;query\n  ;Captures named imports\n  (import_specifier name: (identifier) @symbol)\n  ;Captures default import\n  (import_clause (identifier) @symbol)\n  ;Capture require statements\n  (variable_declarator \n  name: (identifier) @symbol\n  value: (call_expression (identifier) @function  (#eq? @function "require")))\n  ;Capture namespace imports\n  (namespace_import (identifier) @symbol)\n
'
  }
}
Press ENTER or type command to continue

And the neotest summary split says: No tests found

What would I need to change to get neotest-golang working?

fredrikaverpil commented 2 weeks ago

Strange, not sure what's wrong on your end. Do you have an up to date Neotest version? Perhaps try another go project / repo? You can try this one, the neotest-golang one, and you should see Go tests appearing.

dez11de commented 2 weeks ago

Everything is up-to-date. Same thing happens in other repo's. If I run :lua require('neotest').summary.toggle(), the summary split opens saying No tests found. When I run :Lua require('neotest').watch.watch(vim.fn.cwd()) I get all the errors listed above.

fredrikaverpil commented 2 weeks ago

Do you see something suspicious from the Neotest logs?

require("neotest.logging"):set_level(vim.log.levels.DEBUG)

local logfile = require("neotest.logging"):get_filename()
vim.notify(logfile) -- print the path to the log file
dez11de commented 2 weeks ago

Logfile stays completely empty...

fredrikaverpil commented 2 weeks ago

I can see a bunch of other languages there in the error message. Do you have another adapter installed that could be interfering?

Can you try to disable any other adapters?

I would uninstall (hit x in lazy.nvim for example) and reinstall Neotest and Treesitter too.

It's somewhat strange that the term "No position found with args" doesn't exist in either Neotest or Treesitter source code. I just searched here from GitHub mobile.

dez11de commented 2 weeks ago

The (other) languages that are visible in the error message, seem to come from the neotest default configuration judging from :help neotest.setup

I have no other adapters installed whatsoever. I've removed the ~/.local/state/nvim and /?./local/share/nvim dirs (I am on a Mac) and reinstalled everything from scratch. Doesn't make a difference.

FWIW if I start neotest with neotest-go adapter and open the test summary this shows up in the logfile:

DEBUG | 2024-06-20T23:51:01Z+0200 | ...al/share/nvim/lazy/neotest/lua/neotest/lib/file/init.lua:225 | Path separator: /
DEBUG | 2024-06-20T23:51:11Z+0200 | ...al/share/nvim/lazy/neotest/lua/neotest/lib/file/init.lua:225 | Path separator: /