nvim-lualine / lualine.nvim

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

Bug: Filetype icon for terminal acting weird #1253

Open MarcoBuess opened 1 month ago

MarcoBuess commented 1 month ago

Self Checks

How to reproduce the problem

Launching a terminal with term and thus starting vim.opt.shell will result in this filetype icon. image

Expected behaviour

Launching a terminal with term pwsh will yield the expected result. image

I don't quite get the difference other than that term pwsh will spawn 2 instances of pwsh as oppsed to term which will spawn just one instance of pwsh. In both cases filetype will be set to terminal by an autocommand. I tried several filetypes in the term session, but the icon didn't change. It also behaves the same for me no matter what shell you set. I even tried cmd.

Minimal config to reproduce the issue

-- Shell
vim.opt.shell = fn.executable("pwsh") and "pwsh" or "powershell"
vim.opt.shellcmdflag =
"-NonInteractive -NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;"
vim.opt.shellpipe = '2>&1 | %{ "$_" } | Tee-Object %s; exit $LastExitCode'
vim.opt.shellquote = ""
vim.opt.shellredir = '2>&1 | %{ "$_" } | Out-File %s; exit $LastExitCode'
vim.opt.shellxquote = ""

Additional information

OS: Windows 11 (10.0.22631) Neovim: v0.10.0, Release, LuaJIT 2.1.1713484068 lualine: 0a5a668 Terminal: Windows Terminal v1.20.11381.0

MarcoBuess commented 1 month ago

I just tested devicons.get_icon_by_filetype(vim.bo.filetype) which is returning the correct icon/highlight group while in the affected buffer.

MarcoBuess commented 1 month ago

So the problem lies somewhere here: https://github.com/nvim-lualine/lualine.nvim/blob/0a5a66803c7407767b799067986b4dc3036e1983/lua/lualine/components/filetype.lua#L34C34-L34C73

Lines 35-37 would potentially recover the problem but don't get triggert as icon != null. Any particular reason why getting the icon like that instead of just using vim.bo.filetype in general? vim.bo.filetype would also kinda allow the users to make small modifications by changing a buffers file type, which might be a good thing?

MarcoBuess commented 1 month ago

Seems like @arsmoriendy already found the same thing and filed a PR: https://github.com/nvim-lualine/lualine.nvim/pull/1252

arsmoriendy commented 1 month ago

Unfortunately some of my tests failed. One of the reason being that the filetype component test only simulates the buffer's filename and not the filetype (line 303 in component_spec.lua) . I will try to look further into it this weekend.