Skip to content

Commit 9d376dd

Browse files
authored
Preview & go to block references (#3)
1 parent ee733a8 commit 9d376dd

9 files changed

Lines changed: 521 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Open any `.md` file in your IWE project and enjoy:
9090
| `:IWE init` | Initialize IWE project in current directory |
9191
| `:IWE lsp start/stop/restart/status/toggle_inlay_hints` | Control LSP server |
9292
| `:IWE telescope find_files/paths/roots/grep/backlinks/headers` | Launch Telescope pickers |
93+
| `:IWE preview squash/export/export-headers/export-workspace` | Generate previews using IWE CLI |
9394
| `:IWE info` | Show plugin status and configuration |
9495

9596
## Telescope Integration
@@ -103,6 +104,15 @@ The plugin provides LSP-powered Telescope pickers:
103104
- **`:IWE telescope backlinks`** - LSP references as backlinks (gr equivalent)
104105
- **`:IWE telescope headers`** - Document symbols as headers (go equivalent)
105106

107+
## Preview Integration
108+
109+
The plugin provides preview generation using the IWE CLI:
110+
111+
- **`:IWE preview squash`** - Generate squashed markdown preview (combines content with depth 3)
112+
- **`:IWE preview export`** - Generate basic DOT graph as SVG (depth 2)
113+
- **`:IWE preview export-headers`** - Generate DOT graph with headers as SVG (depth 2, includes headers)
114+
- **`:IWE preview export-workspace`** - Generate full workspace graph as SVG (depth 1, all files)
115+
106116
## Configuration
107117

108118
The plugin works out of the box, but can be customized:
@@ -119,13 +129,19 @@ require('iwe').setup({
119129
enable_markdown_mappings = true, -- Core markdown editing keybindings
120130
enable_telescope_keybindings = false, -- Set to true to enable gf, gs, ga, g/, gr, go
121131
enable_lsp_keybindings = false, -- Set to true to enable IWE-specific LSP keybindings
132+
enable_preview_keybindings = false, -- Set to true to enable preview keybindings
122133
leader = "<leader>",
123134
localleader = "<localleader>"
124135
},
125136
telescope = {
126137
enabled = true,
127138
setup_config = true,
128139
load_extensions = { "ui-select", "emoji" }
140+
},
141+
preview = {
142+
output_dir = "~/tmp/preview", -- Directory for generated preview files
143+
temp_dir = "/tmp", -- Directory for temporary files
144+
auto_open = false -- Whether to automatically open generated previews
129145
}
130146
})
131147
```
@@ -186,6 +202,17 @@ Standard LSP actions are available when the LSP server is active:
186202
| `<leader>rn` | Rename symbol |
187203
| `<leader>f` | Format document |
188204

205+
### Preview Keybindings (when `enable_preview_keybindings = true`)
206+
207+
IWE CLI preview generation in markdown files:
208+
209+
| Key | Action |
210+
|-----|--------|
211+
| `<leader>ps` | Generate squash preview |
212+
| `<leader>pe` | Generate export graph preview |
213+
| `<leader>ph` | Generate export with headers preview |
214+
| `<leader>pw` | Generate workspace preview |
215+
189216
### Configuration Options
190217

191218
```lua
@@ -194,6 +221,7 @@ require('iwe').setup({
194221
enable_markdown_mappings = true, -- Enable markdown editing keybindings
195222
enable_telescope_keybindings = true, -- Enable telescope navigation keybindings
196223
enable_lsp_keybindings = true, -- Enable IWE-specific LSP keybindings
224+
enable_preview_keybindings = true, -- Enable preview keybindings
197225
}
198226
})
199227
```
@@ -214,6 +242,12 @@ vim.keymap.set('n', '<leader>e', '<Plug>(iwe-lsp-extract-section)')
214242
vim.keymap.set('n', '<leader>i', '<Plug>(iwe-lsp-inline-reference)')
215243
vim.keymap.set('n', '<leader>h', '<Plug>(iwe-lsp-rewrite-list-section)')
216244
vim.keymap.set('n', '<leader>l', '<Plug>(iwe-lsp-rewrite-section-list)')
245+
246+
-- Preview keybindings (when enable_preview_keybindings = true)
247+
vim.keymap.set('n', '<leader>ps', '<Plug>(iwe-preview-squash)')
248+
vim.keymap.set('n', '<leader>pe', '<Plug>(iwe-preview-export)')
249+
vim.keymap.set('n', '<leader>ph', '<Plug>(iwe-preview-export-headers)')
250+
vim.keymap.set('n', '<leader>pw', '<Plug>(iwe-preview-export-workspace)')
217251
```
218252

219253
## Requirements
@@ -222,6 +256,10 @@ vim.keymap.set('n', '<leader>l', '<Plug>(iwe-lsp-rewrite-section-list)')
222256
- `iwes` LSP server in PATH
223257
- `nvim-telescope/telescope.nvim`
224258

259+
**For Preview Functionality:**
260+
- `iwe` CLI in PATH (install from [iwe-org/iwe](https://github.com/iwe-org/iwe))
261+
- `neato` (Graphviz) for SVG generation
262+
225263
**Recommended:**
226264
- [`MeanderingProgrammer/markdown.nvim`](https://github.com/MeanderingProgrammer/markdown.nvim) - Enhanced markdown rendering that pairs perfectly with IWE's editing features
227265

@@ -235,6 +273,7 @@ Run `:checkhealth iwe` to diagnose any issues with:
235273
- Telescope integration
236274
- Project structure
237275
- Dependencies
276+
- Preview functionality (IWE CLI and Graphviz)
238277

239278
## Contributing
240279

‎doc/iwe.txt‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ COMMANDS *iwe-commands*
108108
Actions: start, stop, restart, status
109109

110110
telescope {action} Control Telescope pickers
111-
Actions: find_files, paths, roots, grep, backlinks,
112-
headers, setup
111+
Actions: find_files, paths, roots, grep, blockreferences,
112+
backlinks, headers, setup
113+
114+
preview {action} Generate previews using IWE CLI
115+
Actions: squash, export, export-headers, export-workspace
113116

114117
info Show plugin configuration and status
115118

@@ -138,7 +141,8 @@ Telescope keybindings (when enable_telescope_keybindings = true):
138141
`gs` <Plug>(iwe-telescope-paths)
139142
`ga` <Plug>(iwe-telescope-roots)
140143
`g/` <Plug>(iwe-telescope-grep)
141-
`gr` <Plug>(iwe-telescope-backlinks)
144+
`gr` <Plug>(iwe-telescope-blockreferences)
145+
`gR` <Plug>(iwe-telescope-backlinks)
142146
`go` <Plug>(iwe-telescope-headers)
143147

144148
IWE LSP keybindings (when enable_lsp_keybindings = true):
@@ -147,6 +151,12 @@ IWE LSP keybindings (when enable_lsp_keybindings = true):
147151
`<leader>h` <Plug>(iwe-lsp-rewrite-list-section)
148152
`<leader>l` <Plug>(iwe-lsp-rewrite-section-list)
149153

154+
Preview keybindings (when enable_preview_keybindings = true):
155+
`<leader>ps` <Plug>(iwe-preview-squash)
156+
`<leader>pe` <Plug>(iwe-preview-export)
157+
`<leader>ph` <Plug>(iwe-preview-export-headers)
158+
`<leader>pw` <Plug>(iwe-preview-export-workspace)
159+
150160
Default Neovim LSP keybindings (available when LSP is active):
151161
`gD` Go to declaration
152162
`gd` Go to definition
@@ -172,12 +182,17 @@ Available <Plug> Mappings:~
172182
*<Plug>(iwe-telescope-paths)* Workspace symbols - paths (gs equivalent)
173183
*<Plug>(iwe-telescope-roots)* Namespace symbols - roots (ga equivalent)
174184
*<Plug>(iwe-telescope-grep)* Live grep search (g/ equivalent)
175-
*<Plug>(iwe-telescope-backlinks)* LSP references - backlinks (gr equivalent)
185+
*<Plug>(iwe-telescope-blockreferences)* LSP references - blockreferences (gr equivalent)
186+
*<Plug>(iwe-telescope-backlinks)* LSP references - backlinks (gR equivalent)
176187
*<Plug>(iwe-telescope-headers)* Document symbols - headers (go equivalent)
177188
*<Plug>(iwe-lsp-extract-section)* Extract section (refactor)
178189
*<Plug>(iwe-lsp-inline-reference)* Inline reference (refactor)
179190
*<Plug>(iwe-lsp-rewrite-list-section)* Rewrite list section (refactor)
180191
*<Plug>(iwe-lsp-rewrite-section-list)* Rewrite section list (refactor)
192+
*<Plug>(iwe-preview-squash)* Generate squash markdown preview
193+
*<Plug>(iwe-preview-export)* Generate export graph preview
194+
*<Plug>(iwe-preview-export-headers)* Generate export graph with headers preview
195+
*<Plug>(iwe-preview-export-workspace)* Generate workspace graph preview
181196

182197
================================================================================
183198
FUNCTIONS *iwe-functions*
@@ -212,12 +227,27 @@ require('iwe.telescope').pickers.roots() *iwe.telescope.roots*
212227
require('iwe.telescope').pickers.grep() *iwe.telescope.grep*
213228
Launch live grep picker (g/ equivalent).
214229

230+
require('iwe.telescope').pickers.blockreferences() *iwe.telescope.blockreferences*
231+
Launch LSP references picker - blockreferences (gr equivalent).
232+
215233
require('iwe.telescope').pickers.backlinks() *iwe.telescope.backlinks*
216-
Launch LSP references picker - backlinks (gr equivalent).
234+
Launch LSP references picker - backlinks (gR equivalent).
217235

218236
require('iwe.telescope').pickers.headers() *iwe.telescope.headers*
219237
Launch document symbols picker - headers (go equivalent).
220238

239+
require('iwe.preview').generate_squash_preview() *iwe.preview.squash*
240+
Generate squashed markdown preview using iwe CLI.
241+
242+
require('iwe.preview').generate_export_preview() *iwe.preview.export*
243+
Generate basic DOT graph as SVG using iwe CLI.
244+
245+
require('iwe.preview').generate_export_headers_preview() *iwe.preview.export-headers*
246+
Generate DOT graph with headers as SVG using iwe CLI.
247+
248+
require('iwe.preview').generate_export_workspace_preview() *iwe.preview.export-workspace*
249+
Generate full workspace graph as SVG using iwe CLI.
250+
221251

222252
================================================================================
223253
HEALTH CHECKS *iwe-health*
@@ -233,6 +263,7 @@ The health check verifies:
233263
• Configuration path validity
234264
• Telescope availability and extensions
235265
• Optional dependencies
266+
• Preview functionality (iwe CLI and Graphviz)
236267
• Current LSP server status
237268

238269
================================================================================

‎doc/tags‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
<Plug>(iwe-insert-week) iwe.txt /*<Plug>(iwe-insert-week)*
55
<Plug>(iwe-link-next) iwe.txt /*<Plug>(iwe-link-next)*
66
<Plug>(iwe-link-prev) iwe.txt /*<Plug>(iwe-link-prev)*
7-
<Plug>(iwe-lsp-code-action) iwe.txt /*<Plug>(iwe-lsp-code-action)*
8-
<Plug>(iwe-lsp-declaration) iwe.txt /*<Plug>(iwe-lsp-declaration)*
9-
<Plug>(iwe-lsp-definition) iwe.txt /*<Plug>(iwe-lsp-definition)*
10-
<Plug>(iwe-lsp-diagnostic-next) iwe.txt /*<Plug>(iwe-lsp-diagnostic-next)*
11-
<Plug>(iwe-lsp-diagnostic-prev) iwe.txt /*<Plug>(iwe-lsp-diagnostic-prev)*
127
<Plug>(iwe-lsp-extract-section) iwe.txt /*<Plug>(iwe-lsp-extract-section)*
13-
<Plug>(iwe-lsp-implementation) iwe.txt /*<Plug>(iwe-lsp-implementation)*
148
<Plug>(iwe-lsp-inline-reference) iwe.txt /*<Plug>(iwe-lsp-inline-reference)*
15-
<Plug>(iwe-lsp-rename) iwe.txt /*<Plug>(iwe-lsp-rename)*
169
<Plug>(iwe-lsp-rewrite-list-section) iwe.txt /*<Plug>(iwe-lsp-rewrite-list-section)*
1710
<Plug>(iwe-lsp-rewrite-section-list) iwe.txt /*<Plug>(iwe-lsp-rewrite-section-list)*
1811
<Plug>(iwe-lsp-start) iwe.txt /*<Plug>(iwe-lsp-start)*
12+
<Plug>(iwe-preview-export) iwe.txt /*<Plug>(iwe-preview-export)*
13+
<Plug>(iwe-preview-export-headers) iwe.txt /*<Plug>(iwe-preview-export-headers)*
14+
<Plug>(iwe-preview-export-workspace) iwe.txt /*<Plug>(iwe-preview-export-workspace)*
15+
<Plug>(iwe-preview-squash) iwe.txt /*<Plug>(iwe-preview-squash)*
1916
<Plug>(iwe-telescope-backlinks) iwe.txt /*<Plug>(iwe-telescope-backlinks)*
2017
<Plug>(iwe-telescope-find-files) iwe.txt /*<Plug>(iwe-telescope-find-files)*
2118
<Plug>(iwe-telescope-grep) iwe.txt /*<Plug>(iwe-telescope-grep)*
@@ -38,6 +35,10 @@ iwe.get_project_root() iwe.txt /*iwe.get_project_root()*
3835
iwe.is_in_project() iwe.txt /*iwe.is_in_project()*
3936
iwe.lsp_available() iwe.txt /*iwe.lsp_available()*
4037
iwe.nvim iwe.txt /*iwe.nvim*
38+
iwe.preview.export iwe.txt /*iwe.preview.export*
39+
iwe.preview.export-headers iwe.txt /*iwe.preview.export-headers*
40+
iwe.preview.export-workspace iwe.txt /*iwe.preview.export-workspace*
41+
iwe.preview.squash iwe.txt /*iwe.preview.squash*
4142
iwe.setup() iwe.txt /*iwe.setup()*
4243
iwe.start_lsp() iwe.txt /*iwe.start_lsp()*
4344
iwe.telescope.backlinks iwe.txt /*iwe.telescope.backlinks*

‎lua/iwe/commands.lua‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local M = {}
33

44
local lsp = require('iwe.lsp')
55
local 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' }
1819
end
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
2128
local function init_iwe_project()
2229
local cwd = vim.fn.getcwd()
@@ -112,6 +119,27 @@ local function handle_telescope_command(subcmd)
112119
end
113120
end
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
117145
local 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
186225
end
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

Comments
 (0)