Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Doing gF inside neotest-output floating window opens the file in same float #387

Open
lawrence-laz opened this issue Apr 11, 2024 · 1 comment
Assignees

Comments

@lawrence-laz
Copy link
Contributor

lawrence-laz commented Apr 11, 2024

NeoVim Version
NVIM v0.10.0-dev-35f475d

Describe the bug
Neotest output usually contains useful messages regarding compilation errors, which usually include the exact file path, line and column numbers. Moving the cursor on such file path and pressing gF opens the file in that exact position. The problem is that doing this in a neotest-output floating window opens the file inside the floating window, which is inconvenient to edit.

To Reproduce

Steps to reproduce the behavior:

  1. Go to neotest-summary
  2. Run any test that contains a file path with line numbers and column in the output
  3. Open neotest-output for that test
image
  1. Move cursor to the file path

  2. Press gF

  3. The file opens in a floating window

image

Expected behavior
I would like the file to open in main window where other source files are edited, same as with pressing i (jumpto) in neotest-summary window.

@lawrence-laz
Copy link
Contributor Author

For the time being I got this working locally with this script:

vim.api.nvim_create_autocmd('filetype', {
    pattern = 'neotest-output',
    callback = function()
        -- Open file under cursor in the widest window available.
        vim.keymap.set('n', 'gF', function()
            local current_word = vim.fn.expand("<cWORD>")
            local tokens = vim.split(current_word, ":", { trimempty = true })
            local win_ids = vim.api.nvim_list_wins()
            local widest_win_id = -1;
            local widest_win_width = -1;
            for _, win_id in ipairs(win_ids) do
                if (vim.api.nvim_win_get_config(win_id).zindex) then
                    -- Skip floating windows.
                    goto continue
                end
                local win_width = vim.api.nvim_win_get_width(win_id)
                if (win_width > widest_win_width) then
                    widest_win_width = win_width
                    widest_win_id = win_id
                end
                ::continue::
            end
            vim.api.nvim_set_current_win(widest_win_id)
            if (#tokens == 1) then
                vim.cmd("e " .. tokens[1])
            else
                vim.cmd("e +" .. tokens[2] .. " " .. tokens[1])
            end
        end, { remap = true, buffer = true })
    end
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants