@@ -114,53 +114,46 @@ 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+ --- Call again to apply a change in configuration without restarting Nvim.
119+ --- @param config_user ? nvim_tree.config subset , uses defaults when nil
134120function M .setup (config_user )
135121 local log = require (" nvim-tree.log" )
136122
123+ -- Nvim version check
137124 if vim .fn .has (" nvim-0.9" ) == 0 then
138125 require (" nvim-tree.notify" ).warn (" nvim-tree.lua requires Neovim 0.9 or higher" )
139126 return
140127 end
141128
129+ -- validate and merge with defaults as config.g
142130 config .setup (config_user )
143131
132+ -- optionally create the log file
144133 require (" nvim-tree.log" ).start ()
145134
135+ -- optionally log the configuration
146136 if log .enabled (" config" ) then
147137 log .line (" config" , " default config + user" )
148138 log .raw (" config" , " %s\n " , vim .inspect (config .g ))
149139 end
150140
141+ -- idempotent highlight definition
151142 require (" nvim-tree.appearance" ).set_hl ()
152143
144+ -- idempotent au (re)definition
153145 setup_autocommands ()
154146
147+ -- subsequent calls to setup clear all state
155148 if vim .g .NvimTreeSetup == 1 then
156- -- subsequent calls to setup
157- M .purge_all_state ()
149+ require (" nvim-tree.core" ).purge_all_state ()
158150 end
159151
152+ -- hydrate post setup API
153+ require (" nvim-tree.api.impl" ).hydrate_post_setup (require (" nvim-tree.api" ))
154+
160155 vim .g .NvimTreeSetup = 1
161156 vim .api .nvim_exec_autocmds (" User" , { pattern = " NvimTreeSetup" })
162-
163- require (" nvim-tree.api.impl" ).hydrate_post_setup (require (" nvim-tree.api" ))
164157end
165158
166159vim .g .NvimTreeRequired = 1
0 commit comments