NvChad / ui

Lightweight & high performance UI plugin for nvchad
GNU General Public License v3.0
286 stars 130 forks source link

Tabufline error #5

Closed ternenges closed 2 years ago

ternenges commented 2 years ago

I ran an update today then i got this bufline erro

then this on buffline buffline error2

i removed ui folder from plugins intallation path then cloned this repo to replace it. now every thing i alright

[ QUESTION ] is it possible to modify status line icons without modifying the source.

JulesNP commented 2 years ago

The same issue was happening to me whenever I saved a file. The suggested workaround solved it for me also.

ternenges commented 2 years ago

I ran an update today then i got this bufline erro

then this on buffline buffline error2

i removed ui folder from plugins intallation path then cloned this repo to replace it. now every thing i alright

[ QUESTION ] is it possible to modify status line icons without modifying the source.

I have come to notice that doing this will break down nvchad so I resolved it by adding this field to

plugins/init.lua ->

[NvChad/ui ] = { ... commit = "6d18c5482b30bbcb02ac20049f2b0b67be9ea164", ... }

this will will lock to that particular head .

siduck commented 2 years ago

ok got the culprit, this is causing it


   -- check for same buffer names under different dirs
    for _, value in ipairs(vim.t.bufs) do
      if name == fn.fnamemodify(api.nvim_buf_get_name(value), ":t") and value ~= bufnr then
        name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
      end
    end
tomasky commented 2 years ago

@siduck You can adopt my method and check :messages why buflist function is called more times if open more files

siduck commented 2 years ago

@siduck You can adopt my method and check :messages why buflist function is called more times if open more files

i dont understand your method!!

tomasky commented 2 years ago

i said ,you can print the method result first . the method just records duplicate values

tomasky commented 2 years ago

the reason I wrote it this way, because bufferflist function is called more times

siduck commented 2 years ago

i said ,you can print the method result first . the method just records duplicate values

that just prints stuff to the cmdline area

tomasky commented 2 years ago

check :messages

siduck commented 2 years ago

ok can u provide a git diff of the changes that could be done now, your way also contains other un-needed stuffs too so i cant read the code properly

tomasky commented 2 years ago
+    local buf = vim.g.bufnrs[name]
+    if not buf then
+      vim.g.bufnrs[name] = {id = bufnr, num = 0}
+    elseif buf.id ~= bufnr and buf.num == 0 then
+      buf.num = buf.num + 1
+    elseif buf.num > 0 then
+     name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
+    end
new_cmd("Tbufclose", function()
+  vim.g.bufnrs = {}
   require("core.utils").close_buffer()
 end, {})
siduck commented 2 years ago

now bufferline doesnt start

image image

tomasky commented 2 years ago

hold on ,i will check that

tomasky commented 2 years ago

sorry, forgot init bufnrs table, check :messages, hold on ,i wll rewrite it .

tomasky commented 2 years ago

You can't use vim global here, just use local bufnrs:

    local buf = bufnrs[name]
    if not buf then
      bufnrs[name] = {id = bufnr, dup = false}
    elseif buf.id ~= bufnr and not buf.dup then
      buf.dup = true
    elseif buf.dup then
     name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
    end
+local bufnrs = {}
 new_cmd("Tbufclose", function()
+  bufnrs = {}
   require("core.utils").close_buffer()
 end, {})
siduck commented 2 years ago

ok error is gone but when there's just one buffer, it doesnt update the value

image

tomasky commented 2 years ago

i said before , map <leader>x to Tbufclose

siduck commented 2 years ago

ok done, now the dirname updates only when i cycle through buffer or when i open telescope

even tho i redrawtabline
image

siduck commented 2 years ago

https://user-images.githubusercontent.com/59060246/182290536-b996d745-c342-4303-9ebb-b993a8981ec0.mp4

look @tomasky

tomasky commented 2 years ago

i dont understand your mean ,i just test it by opening the same name files using nvim-tree, can you give me your reproduce steps ?

tomasky commented 2 years ago

oh ,i got it ,i will check that

siduck commented 2 years ago

https://user-images.githubusercontent.com/59060246/182292666-969463ba-4bfd-401b-be14-99bb337bc00f.mp4

tomasky commented 2 years ago

I already know why that is, This is because this bufferlist function is only called once, when the file is opened from telescope result list

tomasky commented 2 years ago

i will check why that is

siduck commented 2 years ago

I already know why that is, This is because this bufferlist function is only called once, when the file is opened from telescope result list

maybe, then why did my method worked? :thinking:

tomasky commented 2 years ago

only such:

     elseif buf.id ~= bufnr and not buf.dup then
       buf.dup = true
+      name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
siduck commented 2 years ago
name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"

image

after going to next buffer image

tomasky commented 2 years ago

i know , why is your method working?

siduck commented 2 years ago

i know , why is your method working?

idk :thinking: , try it yourself

tomasky commented 2 years ago

@siduck look this: , i open three files , and print open at bufferlist function top,i dont cycle through buffer and dont open telescope, i think it should print two or three open.And your method works is because vim.t.bufs contains all buffer ids

images

siduck commented 2 years ago

@tomasky what to do then :thinking:

siduck commented 2 years ago

my method isnt that heavy, it will stop looping when the result is found but it breaks whole bufferline when format on save

tomasky commented 2 years ago

no, you need to break foreach , because there may be three of the same file names, i dont know why the bufferlist function is called only once when opening from telescope. if it is called twice ,my method will work

siduck commented 2 years ago

no, you need to break foreach , because there may be three of the same file names, i dont know why the bufferlist function is called only once when opening from telescope. if it is called twice ,my method will work

3 files will still work with my method, try

tomasky commented 2 years ago

i know it works, but you need to break foreach

siduck commented 2 years ago

i know it works, but you need to break foreach

yes we need a working alternative for it

tomasky commented 2 years ago

why i cant reproduce the problem of your method?

siduck commented 2 years ago

why i cant reproduce the problem of your method?

add this in your null-ls setup and try to save

 on_attach = function(client)
    if client.resolved_capabilities.document_formatting then
      vim.cmd "autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()"
    end
  end,
siduck commented 2 years ago

ok fixed it

 for _, nr in ipairs(vim.t.bufs) do
      if name == fn.fnamemodify(fn.bufname(nr), ":t") and nr ~= bufnr then
        name = fn.bufname(bufnr):match "[^/]*/?[^/]*$"
      end
    end
i used bufname function instead of api_nvim_get_buf_name 
tomasky commented 2 years ago
 for _, nr in ipairs(vim.t.bufs) do
      if name == fn.fnamemodify(fn.bufname(nr), ":t") and nr ~= bufnr then
        name = fn.bufname(bufnr):match "[^/]*/?[^/]*$"
+       break
      end
    end
siduck commented 2 years ago
   for _, value in ipairs(vim.t.bufs) do
      if name == fn.fnamemodify(api.nvim_buf_get_name(value), ":t") and value ~= bufnr then
        name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
      end
    end

yea thats better

siduck commented 2 years ago

@tomasky invalid bufname is causing this, whenever formatting lsp stuff does some shady stuff in the background

image

siduck commented 2 years ago

not sure how fn.bufname handles this

tomasky commented 2 years ago

my method can work, but needs more refactoring of file tabufline/modules.lua, also because i dont known when is the bufferlist called . I am troubled by this problem

siduck commented 2 years ago

my method can work, but needs more refactoring of file tabufline/modules.lua, also because i dont known when is the bufferlist called . I am troubled by this problem

it needs more work, u told me to clear the buf table in tbufclose command but if i close buffers by clicking their close buttons then this wont work cuz they dont use tbufclose command at all, they use the core utils function directly

tomasky commented 2 years ago

my method can work, but needs more refactoring of file tabufline/modules.lua, also because i dont known when is the bufferlist called . I am troubled by this problem

it needs more work, u told me to clear the buf table in tbufclose command but if i close buffers by clicking their close buttons then this wont work cuz they dont use tbufclose command at all, they use the core utils function directly

yea, so i said , map <leader>x to tbufclose

siduck commented 2 years ago

my method can work, but needs more refactoring of file tabufline/modules.lua, also because i dont known when is the bufferlist called . I am troubled by this problem

it needs more work, u told me to clear the buf table in tbufclose command but if i close buffers by clicking their close buttons then this wont work cuz they dont use tbufclose command at all, they use the core utils function directly

yea, so i said , map <leader>x to tbufclose

that will work for current buffer only, if i click other buffer's close btn then it wont work and those who lazyload tbufline wont have tbufclose command unless tabufline starts

siduck commented 2 years ago

both work but which is faster? @max397574 @tomasky

 for _, nr in ipairs(vim.t.bufs) do
      if name == fn.fnamemodify(fn.bufname(nr), ":t") and nr ~= bufnr then
        name = fn.bufname(bufnr):match "[^/]*/?[^/]*$"
        break
      end
 end
 for _, value in ipairs(vim.t.bufs) do
      if api.nvim_buf_is_valid(value) then
        if name == fn.fnamemodify(api.nvim_buf_get_name(value), ":t") and value ~= bufnr then
          name = api.nvim_buf_get_name(bufnr):match "[^/]*/?[^/]*$"
          break
        end
      end
 end
tomasky commented 2 years ago

Why didn't the first one check nvim_buf_is_valid, if the buf not valid , what is its significance

siduck commented 2 years ago

Why didn't the first one check nvim_buf_is_valid, if the buf not valid , what is it significance

i asked someone and he told me that it just returns some empty string