33 lib ,
44 ...
55} : let
6- inherit ( builtins ) map ;
6+ inherit ( lib . attrsets ) filterAttrs mapAttrs' ;
7+ inherit ( lib . lists ) map count ;
78 inherit ( lib . modules ) mkIf mkMerge mkDefault ;
89 inherit ( lib . trivial ) boolToString ;
9- inherit ( lib . nvim . dag ) entryAnywhere ;
10+ inherit ( lib . nvim . dag ) entryAnywhere entryAfter ;
1011 inherit ( lib . nvim . lua ) toLuaObject ;
1112 inherit ( lib . generators ) mkLuaInline ;
1213
1314 cfg = config . vim . statusline . lualine ;
14- bCfg = config . vim . ui . breadcrumbs ;
15+
16+ cfgIntBreadcrumbs = cfg . integrations . breadcrumbs ;
1517in {
1618 config = mkMerge [
1719 {
@@ -37,17 +39,230 @@ in {
3739 ] ) ;
3840 }
3941
40- ( mkIf ( bCfg . enable && bCfg . lualine . winbar . enable && bCfg . source == "nvim-navic" ) {
41- vim . statusline . lualine . setupOpts = {
42- # TODO: rewrite in new syntax
43- winbar . lualine_c = mkDefault [
42+ {
43+ assertions = [
44+ {
45+ assertion =
46+ count ( x : x ) ( with cfgIntBreadcrumbs ; [
47+ vanilla . enable
48+ nvim-navic . enable
49+ lspsaga . enable
50+ ] )
51+ <= 1 ;
52+
53+ message = ''
54+ Only one lualine breadcrumb integration can be enabled at once.
55+ '' ;
56+ }
57+ ] ;
58+ }
59+
60+ ( mkIf cfgIntBreadcrumbs . vanilla . enable {
61+ vim . statusline . lualine . setupOpts . "${ cfgIntBreadcrumbs . location } " . "lualine_${ cfgIntBreadcrumbs . section } " = [
62+ (
63+ mkLuaInline ''
64+ function()
65+ local buffer = vim.api.nvim_get_current_buf()
66+
67+ local supported = false
68+ for _, client in pairs(vim.lsp.get_clients({ bufnr = buffer })) do
69+ if client.server_capabilities.documentSymbolProvider then
70+ supported = true
71+ break
72+ end
73+ end
74+
75+ if not supported then
76+ return ""
77+ end
78+
79+ local responses = vim.lsp.buf_request_sync(
80+ buffer,
81+ "textDocument/documentSymbol",
82+ { textDocument = { uri = vim.uri_from_bufnr(buffer) } },
83+ 100
84+ )
85+
86+ local symbols
87+ for _, response in pairs(responses or {}) do
88+ if response.result then
89+ symbols = response.result
90+ break
91+ end
92+ end
93+
94+ if not symbols then
95+ return ""
96+ end
97+
98+ local cursor_line, cursor_column = unpack(vim.api.nvim_win_get_cursor(0))
99+ cursor_line = cursor_line - 1
100+ local names = {}
101+
102+ local function find_symbols(symbols)
103+ for _, symbol in ipairs(symbols or {}) do
104+ local range = symbol.range
105+
106+ if
107+ range
108+ and (cursor_line > range.start.line or cursor_line == range.start.line and cursor_column >= range.start.character)
109+ and (
110+ cursor_line < range["end"].line
111+ or cursor_line == range["end"].line and cursor_column <= range["end"].character
112+ )
113+ then
114+ names[#names + 1] = symbol.name
115+ find_symbols(symbol.children)
116+ return
117+ end
118+ end
119+ end
120+
121+ find_symbols(symbols)
122+ return table.concat(names, "${ cfgIntBreadcrumbs . vanilla . separator } ")
123+ end
124+ ''
125+ )
126+ ] ;
127+ } )
128+
129+ ( mkIf cfgIntBreadcrumbs . nvim-navic . enable {
130+ vim = {
131+ startPlugins = [
132+ "nvim-lspconfig"
133+ "nvim-navic"
134+ ] ;
135+ statusline . lualine . setupOpts . "${ cfgIntBreadcrumbs . location } " . "lualine_${ cfgIntBreadcrumbs . section } " = [
44136 [
45137 "navic"
46- ( mkLuaInline "draw_empty = ${ boolToString bCfg . lualine . winbar . alwaysRender } " )
138+ ( mkLuaInline "draw_empty = ${ boolToString cfgIntBreadcrumbs . nvim-navic . alwaysRender } " )
47139 ]
48140 ] ;
141+
142+ pluginRC . breadcrumbs-navic = entryAfter [ "lspconfig" ] ''
143+ local navic = require("nvim-navic")
144+ require("nvim-navic").setup({
145+ highlight = true,
146+ })
147+ '' ;
148+
149+ autocmds = [
150+ {
151+ event = [ "LspAttach" ] ;
152+ callback = mkLuaInline ''
153+ function(event)
154+ local bufnr = event.buf
155+ local client = vim.lsp.get_client_by_id(event.data.client_id)
156+ if client.server_capabilities.documentSymbolProvider then
157+ require("nvim-navic").attach(client, bufnr)
158+ end
159+ end
160+ '' ;
161+ }
162+ ] ;
163+ } ;
164+ } )
165+
166+ ( mkIf cfgIntBreadcrumbs . navbuddy . enable {
167+ vim = {
168+ statusline . lualine . integrations . breadcrumbs . nvim-navic . enable = true ;
169+
170+ startPlugins = [
171+ "nvim-navbuddy"
172+ "nui-nvim"
173+ ] ;
174+
175+ pluginRC . breadcrumbs-navbuddy = entryAfter [ "lspconfig" "breadcrumbs-navic" ] ''
176+ local navbuddy = require("nvim-navbuddy")
177+ local actions = require("nvim-navbuddy.actions")
178+ navbuddy.setup ${ toLuaObject (
179+ cfgIntBreadcrumbs . navbuddy . setupOpts
180+ // {
181+ mappings =
182+ mapAttrs'
183+ ( name : key : {
184+ inherit name ;
185+ value =
186+ {
187+ close = mkLuaInline "actions.close()" ;
188+ nextSibling = mkLuaInline "actions.next_sibling()" ;
189+ previousSibling = mkLuaInline "actions.previous_sibling()" ;
190+ parent = mkLuaInline "actions.parent()" ;
191+ children = mkLuaInline "actions.children()" ;
192+ root = mkLuaInline "actions.root()" ;
193+
194+ visualName = mkLuaInline "actions.visual_name()" ;
195+ visualScope = mkLuaInline "actions.visual_scope()" ;
196+
197+ yankName = mkLuaInline "actions.yank_name()" ;
198+ yankScope = mkLuaInline "actions.yank_scope()" ;
199+
200+ insertName = mkLuaInline "actions.insert_name()" ;
201+ insertScope = mkLuaInline "actions.insert_scope()" ;
202+
203+ appendName = mkLuaInline "actions.append_name()" ;
204+ appendScope = mkLuaInline "actions.append_scope()" ;
205+
206+ rename = mkLuaInline "actions.rename()" ;
207+ delete = mkLuaInline "actions.delete()" ;
208+
209+ foldCreate = mkLuaInline "actions.fold_create()" ;
210+ foldDelete = mkLuaInline "actions.fold_delete()" ;
211+
212+ comment = mkLuaInline "actions.comment()" ;
213+ select = mkLuaInline "actions.select()" ;
214+
215+ moveDown = mkLuaInline "actions.move_down()" ;
216+ moveUp = mkLuaInline "actions.move_up()" ;
217+
218+ togglePreview = mkLuaInline "actions.toggle_preview()" ;
219+
220+ vsplit = mkLuaInline "actions.vsplit()" ;
221+ hsplit = mkLuaInline "actions.hsplit()" ;
222+
223+ telescope = mkLuaInline ''
224+ actions.telescope({
225+ layout_strategy = "horizontal",
226+ layout_config = {
227+ height = 0.60,
228+ width = 0.75,
229+ prompt_position = "top",
230+ preview_width = 0.50,
231+ },
232+ })
233+ '' ;
234+
235+ help = mkLuaInline "actions.help()" ;
236+ } . ${
237+ name
238+ } ;
239+ } )
240+ ( filterAttrs ( _ : key : key != null ) cfgIntBreadcrumbs . navbuddy . mappings ) ;
241+ }
242+ ) }
243+
244+ '' ;
245+ } ;
246+ } )
247+
248+ ( mkIf cfgIntBreadcrumbs . lspsaga . enable {
249+ vim = {
250+ lsp . lspsaga = {
251+ enable = true ;
252+ setupOpts . symbol_in_winbar . enable = true ;
253+ } ;
254+ statusline . lualine . setupOpts . "${ cfgIntBreadcrumbs . location } " . "lualine_${ cfgIntBreadcrumbs . section } " = [
255+ (
256+ mkLuaInline ''
257+ function()
258+ return require("lspsaga.symbol.winbar").get_bar()
259+ end
260+ ''
261+ )
262+ ] ;
49263 } ;
50264 } )
265+
51266 ( mkIf cfg . enable {
52267 vim = {
53268 startPlugins = [ "lualine-nvim" ] ;
0 commit comments