neorg icon indicating copy to clipboard operation
neorg copied to clipboard

Randomly colors are not loaded properly

Open ilan-schemoul opened this issue 1 year ago • 17 comments

Prerequisites

  • [X] I am using the latest stable release of Neovim
  • [X] I am using the latest version of the plugin

Neovim Version

0.10.2

Neorg setup

return {
  "nvim-neorg/neorg",
  version = "v9.x.x",
  ft = "norg", -- lazy load on file type
  cmd = "Neorg", -- lazy load on command
  config = function()
    require("neorg").setup({
      load = {
        ["core.defaults"] = {
          config = {
            disable = {
              "core.esupports.indent",
            },
          },
        },
        ["core.esupports.indent"] = {
          config = {
            format_on_enter = false,
            format_on_escape = false,
          },
        },
        ["core.concealer"] = {},
        ["core.dirman"] = {
          config = {
            workspaces = {
              notes = "~/notes",
            },
            default_workspace = "notes",
          },
        },
        ["core.keybinds"] = {
          config = {
            default_keybinds = true,
          },
        },
      },
    })
    vim.api.nvim_create_autocmd("Filetype", {
      pattern = "norg",
      callback = function()
        vim.keymap.set("i", "<C-b>", "<Plug>(neorg.itero.next-iteration)", { buffer = true })
      end,
    })

    vim.wo.foldlevel = 99
  end,
}

Actual behavior

Sometimes color are here Capture d'écran 2024-11-23 130540

Sometimes not Capture d'écran 2024-11-23 130348

I don't have this problem with others filetypes. I didn't have this problem few months ago also so it might be related to a recent major update

Expected behavior

Colors

Steps to reproduce

It's random Sometimes colors are there sometiomes not

Potentially conflicting plugins

Treesitter related ?

Other information

My config https://github.com/ilan-schemoul/nvim-config

Help

Yes, but I don't know how to start. I would need guidance (check question below)

Implementation help

No response

ilan-schemoul avatar Nov 23 '24 12:11 ilan-schemoul

Same issue. Except I don't have colours at all.

Jellie06 avatar Nov 26 '24 11:11 Jellie06

Current workaround ":e!" 4-6 times in a row before i see the colours... @Jellie06 is it also random ? Do you also have lazy ? Please paste your config.

ilan-schemoul avatar Nov 26 '24 12:11 ilan-schemoul

Current workaround ":e!" 4-6 times in a row before i see the colours... @Jellie06 is it also random ? Do you also have lazy ? Please paste your config.

It's not random. It just doesn't work for me at all. I'm using lazy on Windows and have found no workaround. Here's my config

-- File: plugins/neorg.lua
return {
  "nvim-neorg/neorg",
  dependencies = { "nvim-treesitter/nvim-treesitter" }, -- Ensure Tree-sitter is installed
  build = function()
    vim.cmd("Neorg sync-parsers") -- Ensure parsers are up-to-date
  end,
  config = function()
    require("neorg").setup({
      load = {
        ["core.defaults"] = {}, -- Load default settings
        ["core.concealer"] = {}, -- Enable pretty icons and visual enhancements
        ["core.ui"] = {}, -- General UI improvements
        ["core.qol.toc"] = {}, -- Enable Table of Contents module
        ["core.dirman"] = { -- Manage Neorg workspaces
          config = {
            workspaces = {
              my_workspace = "~/OneDrive/Documents/neorg", -- Set your workspace path
              journal = "~/OneDrive/Documents/neorg/Journal", -- Add the journal workspace
            },
          },
        },
        ["core.keybinds"] = {}, -- Enable default keybindings
      },
    })
  end,
}

Jellie06 avatar Nov 26 '24 12:11 Jellie06

are you sure that you use treesitter highlighting? and are you sure your use a colorscheme which defines the required highlight groups?

use :InspectTree to see if the document is parsed properly and :Inspect on something which isn't highlighted but should be to see if there are highlight groups used which aren't defined

max397574 avatar Nov 26 '24 12:11 max397574

are you sure that you use treesitter highlighting? and are you sure your use a colorscheme which defines the required highlight groups?

use :InspectTree to see if the document is parsed properly and :Inspect on something which isn't highlighted but should be to see if there are highlight groups used which aren't defined

I do use treesitter and have it set up for norg. This is what I get on running :InspectTree

image

I apologise this is only the second time I've used Neovim

Jellie06 avatar Nov 26 '24 12:11 Jellie06

try :TSBufEnable highlight

max397574 avatar Nov 26 '24 13:11 max397574

Didn't do anything.

Jellie06 avatar Nov 26 '24 13:11 Jellie06

what colorscheme do you use? and do you have termguicolors set?

I'd recommend trying out the minimal config here https://github.com/nvim-neorg/neorg/wiki/Kickstart to see if this really is a neorg issue or an issue with your setup

max397574 avatar Nov 26 '24 13:11 max397574

Thank you so much. I had stupidly not installed any colorscheme. Working great now.

Jellie06 avatar Nov 26 '24 14:11 Jellie06

My issue is different. Colors randomly do not load if I use lazyloading (I cannot for not to use lazyloading for performance reasons so in my lazy config I have ft = "neorg"). If I have lazy loading then colors do not load except the dot before the headers in orange. Treesitter is loaded tho (:InspectTree to check), so is my colorscheme catppuccin. It used to work. I have waited for many months for a bug fix and it's a major problem for me to restart nvim many times a day and type ":e" around 15 times everytime I gotta load one single neorg file. @benlubas @max397574 @MaxVanDeursen can someone look into it Here is config for lazy but only "ft" is relevant (add or remove to trigger bug)

return {
  "nvim-neorg/neorg",
  version = "v9.x.x",
  ft = "norg", -- lazy load on file type
  config = function()
    require("neorg").setup({
      load = {
        ["core.defaults"] = {
          config = {
            disable = {
              "core.esupports.indent",
            },
          },
        },
        ["core.esupports.indent"] = {
          config = {
            format_on_enter = false,
            format_on_escape = false,
          },
        },
        ["core.concealer"] = {},
        ["core.dirman"] = {
          config = {
            workspaces = {
              notes = "~/notes",
            },
            default_workspace = "notes",
          },
        },
        ["core.keybinds"] = {
          config = {
            default_keybinds = true,
          },
        },
      },
    })
    vim.api.nvim_create_autocmd("Filetype", {
      pattern = "norg",
      callback = function()
        vim.keymap.set("i", "<C-b>", "<Plug>(neorg.itero.next-iteration)", { buffer = true })
      end,
    })

    vim.wo.foldlevel = 99
  end,
}

ilan-schemoul avatar Apr 02 '25 21:04 ilan-schemoul

Maybe lazy is not supported (to be frank there is so much doc everywhere between 50 wiki pages, entire youtube series and readme etcc. i'm not totally sure) ? The doc section about lazy gives example of lazy = false but it does not seem mandatory

ilan-schemoul avatar Apr 02 '25 21:04 ilan-schemoul

neorg is lazyloadable

return {
    {
        "nvim-neorg/neorg",
        ft = "norg",
        cmd = { "Neorg" },

works completely fine for me

so please stop ranting about something when it's just an issue with your setup

max397574 avatar Apr 03 '25 09:04 max397574

I can confirm with minimal config colors are all white (except the headers). I do not have this problem with any other filetype. It works without ft="norg". Lazy loading breaks color. Can you help debug it @max397574 I now have to load every time norg but it's 40 ms it's huge for my setup. neorg 9.3 nvim 0.11 ubuntu 22 in WSL 2 (same at work which is ubuntu 24, no WSL) return { "nvim-neorg/neorg", version = "v9.x.x", ft = "norg", config = function() require("neorg").setup({ load = { ["core.defaults"] = {}, ["core.concealer"] = {}, }, }) end, }

ilan-schemoul avatar Apr 03 '25 21:04 ilan-schemoul

I can confirm that things work with a minimal config with lazyloading neorg

latest nightly and latest neorg this is the setup

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-neorg/neorg",
            ft = "norg",
            opts = {
                load = {
                    ["core.defaults"] = {},
                },
            },
        },
        {
            "nvim-treesitter/nvim-treesitter",
            opts = {
                ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
                highlight = { enable = true },
            },
            config = function(_, opts)
                require("nvim-treesitter.configs").setup(opts)
            end,
        },
    },
})

max397574 avatar Apr 04 '25 06:04 max397574

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-neorg/neorg",
            ft = "norg",
            opts = {
                load = {
                    ["core.defaults"] = {},
                },
            },
        },
        {
            "nvim-treesitter/nvim-treesitter",
            opts = {
                ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
                highlight = { enable = true },
            },
            config = function(_, opts)
                require("nvim-treesitter.configs").setup(opts)
            end,
        },
        {
          "nvim-telescope/telescope.nvim",
          opts = {
            defaults = {
              layout_strategy = "vertical",
            },
          }
        },
    },
})

Telescope find_files Select a norg file => bug

So conditions are (that's kinda wild)

  1. Lazy loading neorg
  2. Telescope must be setup with layout strategy vertical (default horizontal is fine ?)
  3. Telescope find_files to open the file. Other way to open the file works

It is so weird

ilan-schemoul avatar Apr 13 '25 00:04 ilan-schemoul

I opened a Telescope issue too. I hope you guys can figure something out, I don't understand either codebase to understand what's going on in the slightest. I don't see a thing in layout strategy vertical explaining the bug. When I try to add print statements in what loads highlights with norg I see that everything seems to get properly called.

How in the world would the bug only happen on lazy filetype (because if I do event = "VeryLazy" or any other event it works fine), only if I load via telescope (any other works fine) and only if have vertical layout in telescope (horizontal works fine) ?

ilan-schemoul avatar Apr 13 '25 00:04 ilan-schemoul

Ah actually it's not "horizontal" or "vertical" it's just having a previewer that breaks highlights, when neorg is in lazy mode Workaround is to disable preview with Telescope: https://github.com/ilan-schemoul/nvim-config/commit/3f43f75c2feef3e56579c4fbe709043c012f5974

Classical nvim fashion, wasted 5/10 hours on a small integration details between two plugins. I assume it's a race condition or whatever. I can live with the workaround but would much appreciate understanding what's up if someone can figure it out (I figure this won't top of anyone's priority list)

ilan-schemoul avatar Apr 13 '25 00:04 ilan-schemoul