@@ -3,6 +3,7 @@ local M = {}
33
44local lsp = require (' iwe.lsp' )
55local telescope = require (' iwe.telescope' )
6+ local preview = require (' iwe.preview' )
67
78
89--- Get completion for LSP commands
@@ -17,6 +18,12 @@ local function complete_telescope_commands()
1718 return { ' find_files' , ' paths' , ' roots' , ' grep' , ' backlinks' , ' headers' , ' setup' }
1819end
1920
21+ --- Get completion for Preview commands
22+ --- @return string[]
23+ local function complete_preview_commands ()
24+ return { ' squash' , ' export' , ' export-headers' , ' export-workspace' }
25+ end
26+
2027--- Initialize IWE project in current directory
2128local function init_iwe_project ()
2229 local cwd = vim .fn .getcwd ()
@@ -112,6 +119,27 @@ local function handle_telescope_command(subcmd)
112119 end
113120end
114121
122+ --- Handle Preview subcommands
123+ --- @param subcmd string The subcommand (squash , export , export-headers , export-workspace )
124+ local function handle_preview_command (subcmd )
125+ if not preview .is_available () then
126+ vim .notify (" Preview not available - please install iwe CLI and neato (Graphviz)" , vim .log .levels .ERROR )
127+ return
128+ end
129+
130+ if subcmd == ' squash' then
131+ preview .generate_squash_preview ()
132+ elseif subcmd == ' export' then
133+ preview .generate_export_preview ()
134+ elseif subcmd == ' export-headers' then
135+ preview .generate_export_headers_preview ()
136+ elseif subcmd == ' export-workspace' then
137+ preview .generate_export_workspace_preview ()
138+ else
139+ vim .notify (string.format (" Unknown Preview command: %s" , subcmd ), vim .log .levels .ERROR )
140+ end
141+ end
142+
115143--- Main IWE command handler
116144--- @param opts table Command options from nvim_create_user_command
117145local function iwe_command (opts )
@@ -137,6 +165,12 @@ local function iwe_command(opts)
137165 return
138166 end
139167 handle_telescope_command (args [2 ])
168+ elseif subcmd == ' preview' or subcmd == ' prev' then
169+ if # args < 2 then
170+ vim .notify (" Usage: IWE preview <squash|export|export-headers|export-workspace>" , vim .log .levels .ERROR )
171+ return
172+ end
173+ handle_preview_command (args [2 ])
140174 elseif subcmd == ' init' then
141175 init_iwe_project ()
142176 elseif subcmd == ' info' then
@@ -163,13 +197,18 @@ local function iwe_command(opts)
163197 string.format (" Setup Config: %s" , config .telescope .setup_config ),
164198 string.format (" Extensions: %s" , table.concat (config .telescope .load_extensions , " , " )),
165199 " " ,
200+ " Preview Configuration:" ,
201+ string.format (" Output Dir: %s" , config .preview .output_dir ),
202+ string.format (" Auto Open: %s" , config .preview .auto_open ),
203+ " " ,
166204 " Status:" ,
167205 string.format (" LSP Available: %s" , lsp .is_available () and " Yes" or " No" )
168206 }
169207
170208 local clients = vim .lsp .get_clients ({ name = ' iwes' })
171209 table.insert (lines , string.format (" LSP Running: %s" , # clients > 0 and " Yes" or " No" ))
172210 table.insert (lines , string.format (" Telescope Available: %s" , telescope .is_available () and " Yes" or " No" ))
211+ table.insert (lines , string.format (" Preview Available: %s" , preview .is_available () and " Yes" or " No" ))
173212
174213 -- Check for .iwe marker in current directory
175214 local iwe_root = vim .fs .root (0 , {' .iwe' })
@@ -181,7 +220,7 @@ local function iwe_command(opts)
181220 end
182221 else
183222 vim .notify (string.format (" Unknown IWE command: %s" , subcmd ), vim .log .levels .ERROR )
184- vim .notify (" Available commands: lsp, telescope, init, info" , vim .log .levels .INFO )
223+ vim .notify (" Available commands: lsp, telescope, preview, init, info" , vim .log .levels .INFO )
185224 end
186225end
187226
@@ -196,7 +235,7 @@ local function complete_iwe_command(arg_lead, cmd_line, _)
196235
197236 -- If we're completing the first argument after IWE
198237 if arg_count == 1 then
199- local subcommands = { ' lsp' , ' telescope' , ' tel' , ' init' , ' info' }
238+ local subcommands = { ' lsp' , ' telescope' , ' tel' , ' preview ' , ' prev ' , ' init' , ' info' }
200239 return vim .tbl_filter (function (cmd )
201240 return cmd :find (' ^' .. vim .pesc (arg_lead ))
202241 end , subcommands )
@@ -209,6 +248,8 @@ local function complete_iwe_command(arg_lead, cmd_line, _)
209248 return complete_lsp_commands ()
210249 elseif subcmd == ' telescope' or subcmd == ' tel' then
211250 return complete_telescope_commands ()
251+ elseif subcmd == ' preview' or subcmd == ' prev' then
252+ return complete_preview_commands ()
212253 end
213254 end
214255
0 commit comments