comparison .chezmoitemplates/init.lua @ 783:335b1f5c242d

feat: add winbar with navic (LSP based location breadcrumbs)
author zegervdv <zegervdv@me.com>
date Fri, 28 Apr 2023 08:18:06 +0200
parents 31605398117a
children add486ac2046
comparison
equal deleted inserted replaced
782:31605398117a 783:335b1f5c242d
90 signs = { 90 signs = {
91 fold_closed = '+', 91 fold_closed = '+',
92 fold_open = '-', 92 fold_open = '-',
93 done = '✓', 93 done = '✓',
94 }, 94 },
95 hg_cmd = { 'chg' }, 95 hg_cmd = { 'rhg' },
96 view = { 96 view = {
97 merge_tool = { 97 merge_tool = {
98 layout = 'diff4_mixed', 98 layout = 'diff4_mixed',
99 }, 99 },
100 }, 100 },
421 dependencies = { 'nvim-lua/plenary.nvim' }, 421 dependencies = { 'nvim-lua/plenary.nvim' },
422 }, 422 },
423 { 423 {
424 'vigoux/notifier.nvim', 424 'vigoux/notifier.nvim',
425 config = function() require('notifier').setup { status_width = 70 } end, 425 config = function() require('notifier').setup { status_width = 70 } end,
426 },
427
428 {
429 'SmiteshP/nvim-navic',
430 dependencies = { 'neovim/nvim-lspconfig' },
426 }, 431 },
427 432
428 { 433 {
429 'ThePrimeagen/refactoring.nvim', 434 'ThePrimeagen/refactoring.nvim',
430 dependencies = { 435 dependencies = {
664 hl = { bg = 'bg' }, 669 hl = { bg = 'bg' },
665 statusline_inactive, 670 statusline_inactive,
666 statusline_default, 671 statusline_default,
667 } 672 }
668 673
669 require('heirline').setup { statusline = statusline } 674 local navic = require 'nvim-navic'
675 local winbar = {
676 fallthrough = false,
677 condition = function() return navic.is_available() end,
678 static = {
679 -- bit operation dark magic, see below...
680 enc = function(line, col, winnr) return bit.bor(bit.lshift(line, 16), bit.lshift(col, 6), winnr) end,
681 -- line: 16 bit (65535); col: 10 bit (1023); winnr: 6 bit (63)
682 dec = function(c)
683 local line = bit.rshift(c, 16)
684 local col = bit.band(bit.rshift(c, 6), 1023)
685 local winnr = bit.band(c, 63)
686 return line, col, winnr
687 end,
688 },
689 init = function(self)
690 local data = navic.get_data() or {}
691 local children = {}
692 for i, loc in ipairs(data) do
693 local pos = self.enc(loc.scope.start.line, loc.scope.start.character, self.winnr)
694 local child = {
695 {
696 provider = loc.name,
697 on_click = {
698 minwid = pos,
699 callback = function(_, minwid)
700 local line, col, winnr = self.dec(minwid)
701 vim.api.nvim_win_set_cursor(vim.fn.win_getid(winnr), { line, col })
702 end,
703 name = 'heirline_navic',
704 },
705 },
706 }
707
708 if #data > 1 and i < #data then table.insert(child, { provider = ' > ' }) end
709 table.insert(children, child)
710 end
711
712 self.child = self:new(children, 1)
713 end,
714 provider = function(self) return self.child:eval() end,
715 update = 'CursorMoved',
716 }
717
718 require('heirline').setup {
719 statusline = statusline,
720 winbar = winbar,
721 opts = {
722 disable_winbar_cb = function(args)
723 return not conditions.buffer_matches { filetype = { 'python', 'verilog', 'systemverilog', 'cpp', 'c' } }
724 -- TODO: If LSP is not attached when opening the window, this does not work
725 -- return not navic.is_available(args.bufnr)
726 end,
727 },
728 }
670 end, 729 end,
671 }, 730 },
672 731
673 -- File navigation 732 -- File navigation
674 { 733 {
1189 if client.name == 'lua_ls' then 1248 if client.name == 'lua_ls' then
1190 client.server_capabilities.documentFormattingProvider = false 1249 client.server_capabilities.documentFormattingProvider = false
1191 client.server_capabilities.documentRangeFormattingProvider = false 1250 client.server_capabilities.documentRangeFormattingProvider = false
1192 end 1251 end
1193 1252
1253 if client.server_capabilities.documentSymbolProvider then
1254 local navic = require 'nvim-navic'
1255 navic.attach(client, bufnr)
1256 end
1257
1194 if client.supports_method 'textDocument/rangeFormatting' then 1258 if client.supports_method 'textDocument/rangeFormatting' then
1195 local root = vim.fs.find({ '.git', '.hg' }, { path = client.config.root_dir }) 1259 local root = vim.fs.find({ '.git', '.hg' }, { path = client.config.root_dir })
1196 local vcs = 'git' 1260 local vcs = 'git'
1197 if root and #root > 0 then vcs = vim.fs.basename(root[1]):sub(2) end 1261 if root and #root > 0 then vcs = vim.fs.basename(root[1]):sub(2) end
1198 1262