Skip to content
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

🐞 Bug: ft variable issue when using devicons #282

Closed
1 of 2 tasks
zerochae opened this issue Feb 6, 2025 · 1 comment · Fixed by #279
Closed
1 of 2 tasks

🐞 Bug: ft variable issue when using devicons #282

zerochae opened this issue Feb 6, 2025 · 1 comment · Fixed by #279
Labels
bug Something isn't working

Comments

@zerochae
Copy link

zerochae commented Feb 6, 2025

🤖 Which branch are you using?

  • dev
  • main

📜 Issue description:

as-is to-be
Image Image

When setting icon_provider to devicons, there is an issue with the ft (filetype) variable declaration.

-- setup function

  preview = {
    icon_provider = "devicons",
  },

In the fts.get function, ft is first processed using vim.filetype.match, and its result is stored in _ft. However, later in the function, when retrieving the icon using nvim-web-devicons, the original ft variable is used instead of _ft.

-- markview/filetypes.lua

fts.get = function (ft)
	local _ft = ft;

	if vim.filetype.match({ filename = string.format("example.%s", _ft) }) then
		_ft = vim.filetype.match({ filename = string.format("example.%s", _ft) }); 
	end

	local spec = require("markview.spec");
	local provider_name = spec.get({ "preview", "icon_provider" }, { fallback = "internal", ignore_enable = true });
	local conf = {};

	if provider_name == "devicons" and pcall(require, "nvim-web-devicons") then
		conf.icon, conf.icon_hl = require("nvim-web-devicons").get_icon_by_filetype(
			ft, -- 🔴 `_ft` should be used here instead of `ft`
			{ default = true }
		);
...

📑 Reproduction steps:

  1. Open a markdown file (.md) in Neovim with markview.nvim and nvim-web-devicons enabled.
  2. Create a code block inside the markdown file with the js (JavaScript) filetype:
    ```js
    console.log("Hello!");
    ```
    
  3. Check if the icon for the js filetype is displayed in the preview.

💻 Minimal init:

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "nvim-treesitter/nvim-treesitter",
            build = ":TSUpdate",

            ensure_installed = { "html", "latex", "markdown", "markdown_inline", "typst", "yaml" }
        },
        {
            "OXY2DEV/markview.nvim",
             lazy = false,
             dependencies = {
               "nvim-tree/nvim-web-devicons", 
             },
             config = function() { require("markview").setup({ preview = { icon_provicer = "devicons" } }) } end
         }
    },
});

📜 Logs:

Plugin: markview.nvim
Time: Thu Feb  6 14:49:52 2025
Nvim version: 0.10.4
Colorscheme: 

Level description,
  1 = START
  2 = PAUSE
  3 = STOP
  4 = ERROR
  5 = LOG
  6 = ENABLE
  7 = DISABLE
  8 = ATTACH
  9 = DETACH

Trace,
-------------------------------•-------•--------------------------------------------------------------------------------------------------------------------------------
           Time-stamp          | Level |                                                             Action                                                             
-------------------------------•-------•--------------------------------------------------------------------------------------------------------------------------------
          14:49:45             |   1   | Start
          14:49:45             |   5   | Created highlight groups
          14:49:45             |   5   | Added tree-sitter directive {conceal-patch!}
          14:49:46             |   8   | Attached: 11
            14:49:46           |   1   | Callback: {on_attach}
            14:49:46           |   1   | Callback: {on_enable}
            14:49:46           |   1   | Clearing: 11
            14:49:46           |   3   | Clearing(end, 0ms): 11
            14:49:46           |   1   | Parsing(start): 11
            14:49:46           |   3   | Parsing(end, 1ms): 11
            14:49:46           |   1   | Rendering(main): 11
              14:49:46         |   3   | Render(main): 0ms
              14:49:46         |   3   | Render(post): 0ms
            14:49:46           |   3   | Rendering(end, 0ms): 11
            14:49:46           |   1   | Callback: {on_hybrid_enable}
          14:49:46             |   5   | Registered source for nvim-cmp.
          14:49:46             |   1   | Mode(n): 11
            14:49:46           |   1   | Clearing: 11
            14:49:46           |   3   | Clearing(end, 0ms): 11
            14:49:46           |   1   | Parsing(start): 11
            14:49:46           |   3   | Parsing(end, 0ms): 11
            14:49:46           |   1   | Rendering(main): 11
              14:49:46         |   3   | Render(main): 0ms
              14:49:46         |   3   | Render(post): 0ms
            14:49:46           |   3   | Rendering(end, 0ms): 11
            14:49:46           |   1   | Callback: {on_mode_change}
          14:49:47             |   1   | Mode(c): 11
            14:49:47           |   1   | Callback: {on_mode_change}
          14:49:52             |   1   | Mode(n): 11
            14:49:52           |   1   | Callback: {on_mode_change}
-------------------------------•-------•--------------------------------------------------------------------------------------------------------------------------------

vim:nomodifiable:nowrap:nospell:

Neovim version:

v0.10.4

✅ Expected behavior:

  • The js filetype should be recognized correctly, and the corresponding devicon should be displayed.
@zerochae zerochae added the bug Something isn't working label Feb 6, 2025
@OXY2DEV OXY2DEV closed this as completed in 25d987a Feb 6, 2025
@OXY2DEV
Copy link
Owner

OXY2DEV commented Feb 6, 2025

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants