Skip to content

fix(hover): fix bad column offset at start #2629

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

Merged
merged 2 commits into from
Jan 21, 2024

Conversation

przepompownia
Copy link
Contributor

No description provided.

@przepompownia
Copy link
Contributor Author

Before (only right after finding)
image
After:
image

@przepompownia przepompownia marked this pull request as ready for review January 15, 2024 01:49
@alex-courtis
Copy link
Member

Change looks good, however I'm not able to replicate the problem to verify the fix.

Can you please provide a clean room replication and steps to reproduce?

@przepompownia
Copy link
Contributor Author

I'll try to provide it later.

@przepompownia
Copy link
Contributor Author

local thisInitFile = debug.getinfo(1).source:match('@?(.*)')
local configDir = vim.fs.dirname(thisInitFile)

vim.env['XDG_CONFIG_HOME'] = configDir
vim.env['XDG_DATA_HOME'] = vim.fs.joinpath(configDir, '.xdg/data')
vim.env['XDG_STATE_HOME'] = vim.fs.joinpath(configDir, '.xdg/state')
vim.env['XDG_CACHE_HOME'] = vim.fs.joinpath(configDir, '.xdg/cache')
local stdPathConfig = vim.fn.stdpath('config')

vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)

local function gitClone(url, installPath, branch)
  if vim.fn.isdirectory(installPath) ~= 0 then
    return
  end

  local command = {'git', 'clone', '--', url, installPath}
  if branch then
    table.insert(command, 3, '--branch')
    table.insert(command, 4, branch)
  end
  local sysObj = vim.system(command, {}):wait()
  if sysObj.code ~= 0 then
    error(sysObj.stderr)
  end
  vim.notify(sysObj.stdout)
  vim.notify(sysObj.stderr, vim.log.levels.WARN)
end

local pluginsPath = 'plugins'
vim.fn.mkdir(pluginsPath, 'p')
pluginsPath = vim.uv.fs_realpath(pluginsPath)

local plugins = {
  ['nvim-tree'] = {url = 'https://github.com/nvim-tree/nvim-tree.lua'},
  ['statuscol.nvim'] = {url = 'https://github.com/luukvbaal/statuscol.nvim'},
}

for name, repo in pairs(plugins) do
  local installPath = vim.fs.joinpath(pluginsPath, name)
  gitClone(repo.url, installPath, repo.branch)
  vim.opt.runtimepath:append(installPath)
end

require("nvim-tree").setup {
  view = {
    signcolumn = 'no',
  },
  renderer = {
    full_name = true,
  },
}

local builtin = require('statuscol.builtin')
require('statuscol').setup({
  segments = {
    {text = {builtin.lnumfunc, '     '}}, -- these spaces turn out relevant ;)
  }
})

local treeapi = require('nvim-tree.api')

local path = vim.uv.cwd() .. './plugins/nvim-tree/lua/nvim-tree/diagnostics.lua'
treeapi.tree.open({path = vim.uv.cwd(), find_file = true})

Let's give the init file some very long name

init='iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiinit.lua'; nvim --clean -u "$init" "$init"

@przepompownia
Copy link
Contributor Author

I tested it on master branch of nvim, where statuscol should be used from branch 0.10. It turns out not to matter to reproduction but let's use the below config:

local thisInitFile = debug.getinfo(1).source:match('@?(.*)')
local configDir = vim.fs.dirname(thisInitFile)

vim.env['XDG_CONFIG_HOME'] = configDir
vim.env['XDG_DATA_HOME'] = vim.fs.joinpath(configDir, '.xdg/data')
vim.env['XDG_STATE_HOME'] = vim.fs.joinpath(configDir, '.xdg/state')
vim.env['XDG_CACHE_HOME'] = vim.fs.joinpath(configDir, '.xdg/cache')
local stdPathConfig = vim.fn.stdpath('config')

vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)

local function gitClone(url, installPath, branch)
  if vim.fn.isdirectory(installPath) ~= 0 then
    return
  end

  local command = {'git', 'clone', '--', url, installPath}
  if branch then
    table.insert(command, 3, '--branch')
    table.insert(command, 4, branch)
  end
  local sysObj = vim.system(command, {}):wait()
  if sysObj.code ~= 0 then
    error(sysObj.stderr)
  end
  vim.notify(sysObj.stdout)
  vim.notify(sysObj.stderr, vim.log.levels.WARN)
end

local pluginsPath = 'plugins'
vim.fn.mkdir(pluginsPath, 'p')
pluginsPath = vim.uv.fs_realpath(pluginsPath)

local plugins = {
  ['nvim-tree'] = {url = 'https://github.com/nvim-tree/nvim-tree.lua'},
  ['statuscol.nvim'] = {url = 'https://github.com/luukvbaal/statuscol.nvim', branch = '0.10'},
}

for name, repo in pairs(plugins) do
  local installPath = vim.fs.joinpath(pluginsPath, name)
  gitClone(repo.url, installPath, repo.branch)
  vim.opt.runtimepath:append(installPath)
end
local builtin = require('statuscol.builtin')

require("nvim-tree").setup {
  view = {
    signcolumn = 'no',
  },
  renderer = {
    full_name = true,
  },
}

require('statuscol').setup({
  segments = {
    {text = {builtin.lnumfunc, '     '}}, -- these spaces turn out relevant ;)
  }
})

local treeapi = require('nvim-tree.api')

treeapi.tree.open({path = vim.uv.cwd(), find_file = true})

@przepompownia
Copy link
Contributor Author

przepompownia commented Jan 15, 2024

I had to remember what the space (single in my statuscol config) is for. Specifies the margin between the line number column and the contents of the buffer.

image

@przepompownia
Copy link
Contributor Author

require('statuscol').setup({
  ft_ignore = {'NvimTree'},
  segments = {
    {text = {builtin.lnumfunc, '     '}}, -- these spaces turn out relevant ;)
  }
})

allows to work the problem around.

@alex-courtis
Copy link
Member

Thanks for all the details; I'll get to this on the weekend.

@alex-courtis
Copy link
Member

Took me a while... looks good on nvim master and 0.9

Next time please give a reproducer that works with nvim released... changing all those vim.fs and removing the joinpaths took a while

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution!

@alex-courtis alex-courtis merged commit 75ff64e into nvim-tree:master Jan 21, 2024
@przepompownia przepompownia deleted the fix-hover branch January 21, 2024 12:49
@przepompownia
Copy link
Contributor Author

Took me a while... looks good on nvim master and 0.9

Next time please give a reproducer that works with nvim released... changing all those vim.fs and removing the joinpaths took a while

Good point: I did not check it on any stable version and didn't even mention what version I used to reproduction.

@alex-courtis
Copy link
Member

Took me a while... looks good on nvim master and 0.9
Next time please give a reproducer that works with nvim released... changing all those vim.fs and removing the joinpaths took a while

Good point: I did not check it on any stable version and didn't even mention what version I used to reproduction.

No worries! Your work is gratefully appreciated.

0.9 -> 0.10 is a big one and we need to be mindful of both when testing now, although backwards compatibility is "guaranteed".

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

Successfully merging this pull request may close these issues.

2 participants