andymass/vim-matchup

[Feature Request]: Hybrid winbar/statusline option for offscreen matches

Closed this issue · 11 comments

Is your feature request related to a problem? Please describe.
I like the idea of having offscren matches be displayed in the status line, especially for those below the visible window. But it is somewhat unituitive for offscreen matches above to be displayed there, even with a directional indicator symbol $\Delta$.

Describe the solution you'd like
It would be cool if we could get an option to display offscreen matches below to display in the status line, and matches above in the winbar.

Describe alternatives you've considered
The popup option seems to address the aforementioned issue, but seems to have a limited horizontal width, causing much of the matching pair to be cutoff (e.g. for method headers).

You should be able to set fullwidth on the popup, does that help?

let g:matchup_matchparen_offscreen = {'method': 'popup', 'fullwidth': 1}

Thanks! I probably should've looked through the help file more carefully. It works great, especially with syntax highlighting enabled.

However, I noticed there's a vertical beam in the number column, but only on the top popup window. Is this intentional? If so, is there any way to disable this or maybe customize the decoration?

image

It would also be cool if there was an option to move the matching line number into the number column, as its current position somewhat messes with the horizontal alignment of the matching pair relative to its original position.

These are just suggestions though, so please don't feel pressured to do anything on my behalf :)

Edit: Ok I just realized the symbol in the number column depends on the type of matching pair.

Can you zoom the screenshot out a bit to show more context?

Yeah sure, hopefully these screenshots show it better. Ideally, I would like to get the matching line number to show up in the number column (along with all the other line numbers), replacing the weird symbol. Then the beginning of both matching lines would vertically be aligned (they would be at the same indent level as their actual location in the file like in the statusline in the final screenshot).

| Symbol in number column for matching function:
image

2 in number column for matching loop:
image

Comparison between statusline and popup display methods:
image

I think this is a bad interaction with the plugin you're using to draw lines, perhaps https://github.com/lukas-reineke/indent-blankline.nvim?

This should be fixable, though.

That being said, I can't actually reproduce it with indent-blankline.nvim, so I might be missing something

@andymass Okay, after some testing, it seems like the misalignment has to do with the signcolumn being enabled.

image

Here are steps to reproduce:

  1. Copy and paste the below config into repro.lua
  2. $ nvim -u repro.lua
  3. Hover over a text object with a matching pair
Minimal repro.lua
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{ "catppuccin/nvim", name = "catppuccin" },
	{
		"andymass/vim-matchup",
		init = function()
			vim.opt.relativenumber = true
			vim.opt.signcolumn = "yes"
			vim.g.matchup_matchparen_offscreen =
				{ method = "popup", fullwidth = 1, highlight = "Normal", syntax_hl = 1 }
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here

I'll have to look more into the weird symbols (I believe it has to do with the foldcolumn being enabled or nvim-ufo).

Alright, here's a minimal config that can reproduce the weird symbols in the number column. When signcolumns are enabled, everything in the matching line is shifted over to the right, and as a result, the stuff in the fold column is shifted into the number column:

image
Minimal repro.lua
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{ "catppuccin/nvim", name = "catppuccin" },
	{
		"andymass/vim-matchup",
		init = function()
			vim.opt.relativenumber = true
			vim.opt.signcolumn = "yes"
			vim.g.matchup_matchparen_offscreen =
				{ method = "popup", fullwidth = 1, highlight = "Normal", syntax_hl = 1 }
		end,
	},
	{
		"VonHeikemen/lsp-zero.nvim",
		branch = "v2.x",
		dependencies = {
			-- LSP Support
			{ "neovim/nvim-lspconfig" }, -- Required
			{ -- Optional
				"williamboman/mason.nvim",
				build = function()
					pcall(vim.api.nvim_command, "MasonUpdate")
				end,
			},
			{ "williamboman/mason-lspconfig.nvim" }, -- Optional

			-- Autocompletion
			{ "hrsh7th/nvim-cmp" }, -- Required
			{ "hrsh7th/cmp-nvim-lsp" }, -- Required
			{ "L3MON4D3/LuaSnip" }, -- Required
		},
	},
	{
		"kevinhwang91/nvim-ufo",
		event = "VeryLazy",
		dependencies = "kevinhwang91/promise-async",
		init = function()
			vim.o.foldcolumn = "1"
			vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
			vim.o.foldlevelstart = 99
			vim.o.foldenable = true

			-- Using ufo provider need remap `zR` and `zM`.
			vim.keymap.set("n", "zR", require("ufo").openAllFolds)
			vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
		end,
		config = function()
			require("ufo").setup()

			local lsp = require("lsp-zero").preset({})

			lsp.on_attach(function(client, bufnr)
				lsp.default_keymaps({ buffer = bufnr })
			end)

			lsp.set_server_config({
				capabilities = {
					textDocument = {
						foldingRange = {
							dynamicRegistration = false,
							lineFoldingOnly = true,
						},
					},
				},
			})

			lsp.setup()
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here

Thanks for the clear reproduction steps. I think I fixed it, let me know if there are more issues.

Thanks, that seems to have fixed the misalignment for the repro I sent, though I do wonder if there's any way to get the correct foldchar to display or just hide it altogether.

Actual line:
image

Matchparen popup:
image

Also, on my normal config it seems like line numbers are being incorrectly positioned in the signcolumn instead of the number column. Not entirely sure why, I'll have to investigate it some more.

Line numbers in signcolumn:
image

Okay, I found the root cause of the issue, it has to do with the fact the statuscolumn is enabled. It was added recently to Neovim 0.9.0, and allows for customization of all the side columns, including right-aligned relative line numbers, moving the signcolumn to the right of the number column, etc. As this is unrelated to the original focus of this issue, I'll just open a new one.