@@ -114,55 +114,53 @@ local function setup_autocommands()
114114 require (" nvim-tree.renderer.components.full-name" ).setup_autocommands ()
115115end
116116
117- function M .purge_all_state ()
118- local view = require (" nvim-tree.view" )
119- local core = require (" nvim-tree.core" )
120-
121- view .close_all_tabs ()
122- view .abandon_all_windows ()
123- local explorer = core .get_explorer ()
124- if explorer then
125- require (" nvim-tree.git" ).purge_state ()
126- explorer :destroy ()
127- core .reset_explorer ()
128- end
129- -- purge orphaned that were not destroyed by their nodes
130- require (" nvim-tree.watcher" ).purge_watchers ()
131- end
132-
133- --- @param config_user ? nvim_tree.config user supplied subset of config
117+ --- `require("nvim-tree").setup` must be called once to initialise nvim-tree.
118+ ---
119+ --- Call again to apply a change in configuration without restarting Nvim.
120+ ---
121+ --- See :help nvim-tree-setup
122+ ---
123+ --- @param config_user ? nvim_tree.config subset , uses defaults when nil
134124function M .setup (config_user )
135125 local log = require (" nvim-tree.log" )
136126
127+ -- Nvim version check
137128 if vim .fn .has (" nvim-0.9" ) == 0 then
138129 require (" nvim-tree.notify" ).warn (" nvim-tree.lua requires Neovim 0.9 or higher" )
139130 return
140131 end
141132
133+ -- validate and merge with defaults as config.g
142134 config .setup (config_user )
143135
136+ -- optionally create the log file
144137 log .start ()
145138
139+ -- optionally log the configuration
146140 if log .enabled (" config" ) then
147141 log .line (" config" , " default config + user" )
148142 log .raw (" config" , " %s\n " , vim .inspect (config .g ))
149143 end
150144
145+ -- idempotent highlight definition
151146 require (" nvim-tree.appearance" ).highlight ()
152147
148+ -- set the initial view state based on config
153149 require (" nvim-tree.view-state" ).initialize ()
154150
151+ -- idempotent au (re)definition
155152 setup_autocommands ()
156153
154+ -- subsequent calls to setup clear all state
157155 if vim .g .NvimTreeSetup == 1 then
158- -- subsequent calls to setup
159- M .purge_all_state ()
156+ require (" nvim-tree.core" ).purge_all_state ()
160157 end
161158
159+ -- hydrate post setup API
160+ require (" nvim-tree.api.impl" ).hydrate_post_setup (require (" nvim-tree.api" ))
161+
162162 vim .g .NvimTreeSetup = 1
163163 vim .api .nvim_exec_autocmds (" User" , { pattern = " NvimTreeSetup" })
164-
165- require (" nvim-tree.api.impl" ).hydrate_post_setup (require (" nvim-tree.api" ))
166164end
167165
168166vim .g .NvimTreeRequired = 1
0 commit comments