diff --git a/lua/hardline.lua b/lua/hardline.lua index a09d665..deedb69 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -16,6 +16,8 @@ M.options = { {class = 'high', item = require('hardline.parts.git').get_item}, {class = 'med', item = require('hardline.parts.filename').get_item}, {class = 'med', item ='%='}, + {class = 'warning', item = require('hardline.parts.lsp').get_warning}, + {class = 'error', item = require('hardline.parts.lsp').get_error}, {class = 'high', item = require('hardline.parts.filetype').get_item}, {class = 'mode', item = require('hardline.parts.line').get_item}, }, diff --git a/lua/hardline/parts/line.lua b/lua/hardline/parts/line.lua index 160829e..2b51bf6 100644 --- a/lua/hardline/parts/line.lua +++ b/lua/hardline/parts/line.lua @@ -14,7 +14,7 @@ local function get_line() end local function get_column() - local nb_columns = vim.fn.col('$') + local nb_columns = vim.fn.col('$') - 1 local column = vim.fn.col('.') local max_dots = get_dots(nb_columns, 999) local dots = get_dots(column, 999) diff --git a/lua/hardline/parts/lsp.lua b/lua/hardline/parts/lsp.lua index ce84ef3..e6d0e83 100644 --- a/lua/hardline/parts/lsp.lua +++ b/lua/hardline/parts/lsp.lua @@ -1,8 +1,19 @@ -local M = {} - -function M.get_item() - return table.concat({ - }) +local function get_diagnostic(prefix, severity) + if vim.tbl_isempty(vim.lsp.buf_get_clients(0)) then return '' end + local count = vim.lsp.diagnostic.get_count(0, severity) + if count < 1 then return '' end + return table.concat({' ', string.format('%s:%d', prefix, count), ' '}) end -return M +local function get_error() + return get_diagnostic('E', 'Error') +end + +local function get_warning() + return get_diagnostic('W', 'Warning') +end + +return { + get_error = get_error, + get_warning = get_warning, +}