nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
6.03k stars 463 forks source link

Bug: E539: Illegal character in filename #820

Closed liuerfire closed 9 months ago

liuerfire commented 2 years ago

Self Checks

How to reproduce the problem

set path to any value (1, 2 or 3) except the default 0 in filename section.

require('lualine').setup {
  sections = {
    lualine_c = {
      { 'filename', path = 3, },
    },
  },
}

Install https://github.com/mfussenegger/nvim-jdtls and jump to the definition of a class.

Expected behaviour

no errors

Actual behaviour

image

Aditional information

The full path of this file is:

image

zeitchef commented 1 year ago

I'm getting the exact same error

ramanenka commented 1 year ago

I've got the same error and here is how I've solved it:

lualine_c = {
  function()
    local fn = vim.fn.expand('%:~:.')
    if vim.startswith(fn, "jdt://") then
      fn = string.sub(fn, 0, string.find(fn, "?") - 1)
    end
    if fn == '' then
      fn = '[No Name]'
    end
    if vim.bo.modified then
      fn = fn .. ' [+]'
    end
    if vim.bo.modifiable == false or vim.bo.readonly == true then
      fn = fn .. ' [-]'
    end
    local tfn = vim.fn.expand('%')
    if tfn ~= '' and vim.bo.buftype == '' and vim.fn.filereadable(tfn) == 0 then
      fn = fn .. ' [New]'
    end
    return fn
  end
},

For some reason writing the same logic in an fmt function didn't prevent the error from happening.

kmoschcau commented 1 year ago

@ramanenka I figured out why fmt isn't working. What you get in that function is probably already shortened and looks like this: j//c/j/j/N/%/h/k/.g/c/m/f/j/j/2/8/j/g/m/=/o/%%5C/WEB-INF%%5C/lib=/%%3Cjavax.persistence(NoResultException.class So your prefix check doesn't even work in there.

krish-r commented 1 year ago

Hi,

(I just encountered this issue. Took a quick peek at the code, so apologies if I'm incorrect).

Looks like there's already a check in-place to escape % in filenames. https://github.com/nvim-lualine/lualine.nvim/blob/4bfc6bc4f38355d570e56fed69e01c073d2b6a64/lua/lualine/components/filename.lua#L89

However, this seems to be an edge case trigged by the shorting_target block. https://github.com/nvim-lualine/lualine.nvim/blob/4bfc6bc4f38355d570e56fed69e01c073d2b6a64/lua/lualine/components/filename.lua#L95-L100

So, shouldn't this get fixed by simply moving that check after this block?

Thanks

1Jo1 commented 1 year ago

I've got the same error and here is how I've solved it:

lualine_c = {
  function()
    local fn = vim.fn.expand('%:~:.')
    if vim.startswith(fn, "jdt://") then
      fn = string.sub(fn, 0, string.find(fn, "?") - 1)
    end
    if fn == '' then
      fn = '[No Name]'
    end
    if vim.bo.modified then
      fn = fn .. ' [+]'
    end
    if vim.bo.modifiable == false or vim.bo.readonly == true then
      fn = fn .. ' [-]'
    end
    local tfn = vim.fn.expand('%')
    if tfn ~= '' and vim.bo.buftype == '' and vim.fn.filereadable(tfn) == 0 then
      fn = fn .. ' [New]'
    end
    return fn
  end
},

For some reason writing the same logic in an fmt function didn't prevent the error from happening.

I just had the same error, thanks for the this workaround fix probably it would be better to fix this issue in lualine I guess long term

massix commented 1 year ago

I've got the same error and here is how I've solved it:

[snip]

For some reason writing the same logic in an fmt function didn't prevent the error from happening.

Thanks to your input, I was able to fix it using the fmt parameter, without altering the already existing configuration nor the default behavior of lualine.

            {
              "filename",
              path = 1,
              symbols = { modified = "  ", readonly = "  ", unnamed = "  " },
              --- @param str string
              fmt = function(str)
                --- @type string
                local fn = vim.fn.expand("%:~:.")

                if vim.startswith(fn, "jdt://") then
                  return fn:gsub("?.*$", "")
                end
                return str
              end,
            },