3 Коммиты d896eb28df ... 7bce4fbb96

Автор SHA1 Сообщение Дата
  Nikita Chursin 7bce4fbb96 removed logging for tabline error 8 месяцев назад
  Nikita Chursin bbde0affd7 added dir name to statusline 8 месяцев назад
  Nikita Chursin b2ce576fe2 more colors for tabline 8 месяцев назад

+ 2 - 0
lua/ncvim/mission_control.lua

@@ -260,6 +260,8 @@ ncvim = {
   autocmds = {},
 }
 
+require('ncvim.utils')
+
 ncvim.add_autocmd = function(events, config)
   table.insert(ncvim.autocmds, {
     events = events,

+ 1 - 1
lua/ncvim/plugin_mgmt.lua

@@ -43,7 +43,7 @@ local transform_for_lazy = function(plugin)
     return plugin
   end
   plugin.init = plugin.setup
-  plugin.dependencies = plugin.requires
+  plugin.dependencies = plugin.dependencies or plugin.requires
   plugin.name = plugin.as
   plugin.lazy = plugin.opt
   plugin.build = plugin.run

+ 157 - 3
lua/ncvim/ui/bufferline.lua

@@ -29,8 +29,15 @@ end
 
 ncvim.plugin {
   'willothy/nvim-cokeline',
+
+  dependencies = {
+    "nvim-lua/plenary.nvim",       -- Required for v0.4.0+
+    "nvim-tree/nvim-web-devicons", -- If you want devicons
+    "stevearc/resession.nvim"      -- Optional, for persistent history
+  },
+
   config = function()
-    local buffers = require('cokeline.buffers')
+    local buffersApi = require('cokeline.buffers')
     local tabs = require('cokeline.tabs')
 
     local get_hex = require('cokeline.hlgroups').get_hl_attr
@@ -48,10 +55,10 @@ ncvim.plugin {
 
       local success, buff_nr = pcall(vim.api.nvim_win_get_buf, tabpage.focused.number)
       if success == false then
-        print("tab err: " .. buff_nr)
+        -- print("tab err: " .. buff_nr)
         return nil
       end
-      local buf = buffers.get_buffer(buff_nr)
+      local buf = buffersApi.get_buffer(buff_nr)
 
       return buf
     end
@@ -60,13 +67,103 @@ ncvim.plugin {
       active = {
         fg = function() return get_hex('Folded', 'fg') end,
         bg = function() return get_hex('Visual', 'bg') end,
+        error = {
+          fg = function() return get_hex('ErrorMsg', 'fg') end,
+        },
+        warning = {
+          fg = function() return get_hex('WarningMsg', 'fg') end,
+        },
       },
       inactive = {
         fg = function() return get_hex('CursorLine', 'fg') end,
         bg = function() return get_hex('CursorLine', 'bg') end,
+        error = {
+          fg = function() return get_hex('Substitute', 'fg') end,
+        },
+        warning = {
+          fg = function() return get_hex('WinBar', 'fg') end,
+        },
+      },
+
+      error = {
+        fg = function(buffer)
+          if buffer.is_focused then
+            return get_hex('ErrorMsg', 'fg')
+          else
+            return get_hex('Substitute', 'fg')
+          end
+        end
+      },
+
+      warning = {
+        fg = function(buffer)
+          if buffer.is_focused then
+            return get_hex('WarningMsg', 'fg')
+          else
+            return get_hex('WinBar', 'fg')
+          end
+        end
       },
     }
 
+    local get_window_buffer = function(window)
+      local success, buff_nr = pcall(vim.api.nvim_win_get_buf, window.number)
+      if success == false then
+        print("tab err: " .. buff_nr)
+        return nil
+      end
+      return buffersApi.get_buffer(buff_nr)
+    end
+
+    local get_tab_buffers = function(tabpage)
+      return ncvim.utils.filter(
+        function(v)
+          return v ~= nil
+        end,
+        ncvim.utils.map(
+          get_window_buffer,
+          tabpage.windows
+        )
+      )
+    end
+
+    local buffer_has_errors = function(buffer)
+      if buffer == nil or buffer.diagnostics == nil or buffer.diagnostics.errors == nil then
+        return false
+      end
+      return 0 < buffer.diagnostics.errors
+    end
+
+    local buffer_has_warnings = function(buffer)
+      if buffer == nil or buffer.diagnostics == nil or buffer.diagnostics.warnings == nil then
+        return false
+      end
+      return 0 < buffer.diagnostics.warnings
+    end
+
+    local tab_errors_num = function(tabpage)
+      local buffers = get_tab_buffers(tabpage)
+
+      if buffers == nil then
+        return 0
+      end
+
+      local total_errs = 0
+      for _, buff in pairs(buffers) do
+        if buff.diagnostics == nil or buff.diagnostics.errors == nil then
+          goto continue
+        end
+        total_errs = total_errs + buff.diagnostics.errors
+        ::continue::
+      end
+
+      return total_errs
+    end
+
+    local tab_has_errors = function(tabpage)
+      return 0 < tab_errors_num(tabpage)
+    end
+
     require('cokeline').setup({
       default_hl = {
         fg = function(tabpage)
@@ -178,6 +275,63 @@ ncvim.plugin {
               end
               return buffer.is_focused
             end,
+            fg = function(tabpage)
+              local buffer = get_tabpage_head_buffer(tabpage)
+              if buffer == nil then
+                return ''
+              end
+              return
+                  buffer_has_errors(buffer) and buffer.is_focused and highlight.active.error.fg()
+                  or buffer_has_errors(buffer) and not buffer.is_focused and highlight.inactive.error.fg()
+
+                  or buffer_has_warnings(buffer) and buffer.is_focused and highlight.active.warning.fg()
+                  or buffer_has_warnings(buffer) and not buffer.is_focused and highlight.inactive.warning.fg()
+
+                  or tab_has_errors(tabpage) and highlight.inactive.error.fg()
+
+                  or buffer.is_focused and highlight.active.fg()
+                  or highlight.inactive.fg()
+            end
+          },
+          {
+            text = function(tabpage)
+              local buffer = get_tabpage_head_buffer(tabpage)
+              if buffer == nil then
+                return ''
+              end
+              return
+                  (buffer.diagnostics.errors ~= 0 and '   ' .. buffer.diagnostics.errors)
+
+                  or (buffer.diagnostics.warnings ~= 0 and '  ' .. buffer.diagnostics.warnings)
+
+                  or tab_has_errors(tabpage) and '   ' .. tab_errors_num(tabpage)
+
+                  or ''
+            end,
+            fg = function(tabpage)
+              local buffer = get_tabpage_head_buffer(tabpage)
+              if buffer == nil then
+                return ''
+              end
+              return
+                  buffer_has_errors(buffer) and buffer.is_focused and highlight.active.error.fg()
+                  or buffer_has_errors(buffer) and not buffer.is_focused and highlight.inactive.error.fg()
+
+                  or buffer_has_warnings(buffer) and buffer.is_focused and highlight.active.warning.fg()
+                  or buffer_has_warnings(buffer) and not buffer.is_focused and highlight.inactive.warning.fg()
+
+                  or tab_has_errors(tabpage) and highlight.inactive.error.fg()
+
+                  or nil
+            end,
+            truncation = {
+              priority = 1,
+            },
+          },
+          {
+            text = function(tabpage)
+              return ' '
+            end,
           },
           {
             bg = highlight.inactive.bg,

+ 19 - 1
lua/ncvim/ui/statusline.lua

@@ -7,6 +7,24 @@ ncvim.plugin({
     }
   },
   config = function()
-    require('lualine').setup({})
+    function basename(str)
+      local name = string.gsub(str, "(.*/)(.*)", "%2")
+      return name
+    end
+
+    function get_cwd_basename()
+      return '󰙅 ' .. basename(vim.fn.getcwd())
+    end
+
+    require('lualine').setup({
+      sections = {
+        lualine_a = { 'mode' },
+        lualine_b = { get_cwd_basename, 'branch', 'diff', 'diagnostics' },
+        lualine_c = { 'filename' },
+        lualine_x = { 'encoding', 'fileformat', 'filetype' },
+        lualine_y = { 'progress' },
+        lualine_z = { 'location' }
+      },
+    })
   end
 })

+ 22 - 0
lua/ncvim/utils.lua

@@ -0,0 +1,22 @@
+ncvim.utils = {
+  map = function(predicate, tbl)
+    if nil == tbl then
+      return nil
+    end
+    local t = {}
+    for k, v in pairs(tbl) do
+      t[k] = predicate(v)
+    end
+    return t
+  end,
+
+  filter = function(predicate, tbl)
+    local t = {}
+    for k, v in pairs(tbl) do
+      if predicate(v) then
+        t[k] = v
+      end
+    end
+    return t
+  end,
+}