nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.17k stars 609 forks source link

Global options with lua not working if setup is run in the same file #681

Closed koopa1338 closed 3 years ago

koopa1338 commented 3 years ago

I have a config file for every plugin and read the migration guide. It seems like if the global options even if set before the setup function is run are not applied. If I move the global options to my init.lua where I require the configuration file of nvim-tree it works just fine. here the contents I expect to work:

local map = require('utils').map
local tree = require('nvim-tree')
local g = vim.g

g.nvim_tree_git_hl = 1
g.nvim_tree_indent_markers = 1
g.nvim_tree_hide_dotfiles = 1
g.nvim_tree_show_icons = {
    git = 1,
    folders = 1,
    files = 1,
}
g.nvim_tree_ignore = {'.git', 'node_modules', '.cache'}
g.nvim_tree_icons = {
    git = {
        unstaged = '☒',
        staged = '☑',
        unmerged = '',
        untracked = '✸'
    }
}

map('n', '<C-n>', "<cmd>NvimTreeToggle<CR>", { silent = true })

local tree_cb = require('nvim-tree.config').nvim_tree_callback
tree.setup({
    disable_netrw       = true,
    open_on_setup       = false,
    ignore_ft_on_setup  = {'startify'},
    update_to_buf_dir   = {
        enable = true,
        auto_open = true,
    },
    auto_close          = true,
    open_on_tab         = false,
    hijack_cursor       = false,
    update_cwd          = true,
    lsp_diagnostics     = true,
    update_focused_file = {
        enable      = false,
        update_cwd  = false,
        ignore_list = {}
    },
    system_open = {
        cmd  = nil,
        args = {}
    },
    view = {
        width = 40,
        auto_resize = true,
        mappings = {
            custom_only = false,
            list = {
                { key = { "." }, cb = tree_cb('cd') },
                { key = { "c" }, cb = tree_cb('rename') },
                { key = { "y" }, cb = tree_cb('copy') },
                { key = { "gn" }, cb = tree_cb("next_git_item") },
                { key = { "gp" }, cb = tree_cb("prev_git_item") },
            }
        }
    }
})
koopa1338 commented 3 years ago

I solved the issue. It seems like it is important when to require nvim-tree. If I require nvim-tree after setting the global options it works as expected, only executing the setup function after setting the global options is not sufficient.

kyazdani42 commented 3 years ago

indeed, some options are still loaded globally so if you require the plugin before setting up those variables it will not load properly. These will be ported shortly i hope :)