enhance: set default diagnostics source to nvim-lsp & coc

doc: update docs for options.
This commit is contained in:
shadmansaleh 2021-09-21 12:26:19 +06:00
parent 07d3df01a1
commit ceec01bc6c
5 changed files with 74 additions and 22 deletions

View File

@ -106,7 +106,7 @@ Lualine has sections as shown below.
Each sections holds it's components e.g. current vim's mode. Each sections holds it's components e.g. current vim's mode.
<details><summary>Configuring from `.vim` file</summary> <details><summary>Configuring lualine in init.vim</summary>
All the examples below are in lua. You can use the same examples All the examples below are in lua. You can use the same examples
in `.vim` file by wrapping them in lua heredoc like this: in `.vim` file by wrapping them in lua heredoc like this:
@ -332,26 +332,40 @@ shown . On the other hand branch will be formatted with global formatter
<details> <details>
<summary><b>Global options</b></summary> <summary><b>Global options</b></summary>
These are `options` that are used in options table.
They set behavior of lualine.
Values set here are treated as default for other options
that work in component level.
for example even though `icons_enabled` is a general component option.
you can set `icons_enabled` to `false` and icons will be disabled on all
component. You can still overwrite defaults set in option table by specifying
the option value in component.
```lua ```lua
options = { options = {
icons_enabled = true, -- displays icons in alongside component theme = 'auto', -- lualine theme
padding = 1, -- adds padding to the left and right of components component_separators = {left = '', right = ''},
-- padding can be specified to left or right separately like section_separators = {left = '', right = ''},
-- padding = { left = left_padding, right = right_padding } disabled_filetypes = {}, -- filetypes to diable lualine on
fmt = nil -- fmt function, formats component's output
} }
``` ```
</details> </details>
<details> <details>
<summary><b>Local options</b></summary> <summary><b>General component options</b></summary>
These are options that control behavior at component level
and are available for all components.
```lua ```lua
sections = { sections = {
lualine_a = { lualine_a = {
{ {
'mode', 'mode',
icons_enabled = true, -- displays icons in alongside component
icon = nil, -- displays icon in front of the component icon = nil, -- displays icon in front of the component
separator = nil, -- Determines what separator to use for the component. separator = nil, -- Determines what separator to use for the component.
-- when a string is given it's treated as component_separator. -- when a string is given it's treated as component_separator.
@ -375,6 +389,10 @@ sections = {
-- luae(lua expressions), vimf(viml function name) -- luae(lua expressions), vimf(viml function name)
-- luae is short for lua-expression and vimf is short fror vim-function -- luae is short for lua-expression and vimf is short fror vim-function
type = nil, type = nil,
padding = 1, -- adds padding to the left and right of components
-- padding can be specified to left or right separately like
-- padding = { left = left_padding, right = right_padding }
fmt = nil, -- format function, formats component's output
} }
} }
} }
@ -383,7 +401,11 @@ sections = {
</details> </details>
<details> <details>
<summary><b>Component specific local options</b></summary> <summary><b>Component specific options</b></summary>
These are options that are available on specific components.
For example you have option on `diagnostics` component to
specify what your diagnostic sources will be.
#### buffers component options #### buffers component options
@ -422,7 +444,7 @@ sections = {
-- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp' -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp'
-- Or a function that returns a table like -- Or a function that returns a table like
-- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt}
sources = {}, sources = {'nvim_lsp', 'coc'},
-- displays diagnostics from defined severity -- displays diagnostics from defined severity
sections = {'error', 'warn', 'info', 'hint'}, sections = {'error', 'warn', 'info', 'hint'},
-- all colors are in format #rrggbb -- all colors are in format #rrggbb

View File

@ -82,7 +82,7 @@ Lualine has sections as shown below.
Each sections holds its components e.g. current vims mode. Each sections holds its components e.g. current vims mode.
Configuring from `.vim` file Configuring lualine in init.vim
All the examples below are in lua. You can use the same examples in `.vim` file All the examples below are in lua. You can use the same examples in `.vim` file
by wrapping them in lua heredoc like this: by wrapping them in lua heredoc like this:
@ -313,24 +313,40 @@ shown. On the other hand branch will be formatted with global formatter
Global options ~ Global options ~
Available options These are `options` that are used in
options table. They set behavior of
lualine.
Values set here are treated as default for other options that work in component
level.
for example even though `icons_enabled` is a general component option. you can
set `icons_enabled` to `false` and icons will be disabled on all component. You
can still overwrite defaults set in option table by specifying the option value
in component.
> >
options = { options = {
icons_enabled = true, -- displays icons in alongside component theme = 'auto', -- lualine theme
padding = 1, -- adds padding to the left and right of components component_separators = {left = '', right = ''},
-- padding can be specified to left or right separately like section_separators = {left = '', right = ''},
-- padding = { left = left_padding, right = right_padding } disabled_filetypes = {}, -- filetypes to diable lualine on
fmt = nil -- fmt function, formats component's output
} }
< <
Local options ~ General component options ~
These are options that control behavior at component level and are available
for all components.
> >
sections = { sections = {
lualine_a = { lualine_a = {
{ {
'mode', 'mode',
icons_enabled = true, -- displays icons in alongside component
icon = nil, -- displays icon in front of the component icon = nil, -- displays icon in front of the component
separator = nil, -- Determines what separator to use for the component. separator = nil, -- Determines what separator to use for the component.
-- when a string is given it's treated as component_separator. -- when a string is given it's treated as component_separator.
@ -354,13 +370,21 @@ Local options ~
-- luae(lua expressions), vimf(viml function name) -- luae(lua expressions), vimf(viml function name)
-- luae is short for lua-expression and vimf is short fror vim-function -- luae is short for lua-expression and vimf is short fror vim-function
type = nil, type = nil,
padding = 1, -- adds padding to the left and right of components
-- padding can be specified to left or right separately like
-- padding = { left = left_padding, right = right_padding }
fmt = nil, -- format function, formats component's output
} }
} }
} }
< <
Component specific local options ~ Component specific options ~
These are options that are available on specific components. For example you
have option on `diagnostics` component to specify what your diagnostic sources
will be.
*lualine-buffers-component-options* *lualine-buffers-component-options*
@ -400,7 +424,7 @@ Component specific local options ~
-- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp' -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp'
-- Or a function that returns a table like -- Or a function that returns a table like
-- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt}
sources = {}, sources = {'nvim_lsp', 'coc'},
-- displays diagnostics from defined severity -- displays diagnostics from defined severity
sections = {'error', 'warn', 'info', 'hint'}, sections = {'error', 'warn', 'info', 'hint'},
-- all colors are in format #rrggbb -- all colors are in format #rrggbb

View File

@ -14,6 +14,10 @@ local default_options = {
fzf = 'FZF', fzf = 'FZF',
alpha = 'Alpha', alpha = 'Alpha',
}, },
buffers_color = {
active = nil,
inactive = nil,
},
} }
local function get_hl(section, is_active) local function get_hl(section, is_active)
@ -42,13 +46,11 @@ end
function Buffer:get_props() function Buffer:get_props()
self.file = vim.fn.bufname(self.bufnr) self.file = vim.fn.bufname(self.bufnr)
self.filepath = vim.fn.expand('#' .. self.bufnr .. ':p:~')
self.buftype = vim.api.nvim_buf_get_option(self.bufnr, 'buftype') self.buftype = vim.api.nvim_buf_get_option(self.bufnr, 'buftype')
self.filetype = vim.api.nvim_buf_get_option(self.bufnr, 'filetype') self.filetype = vim.api.nvim_buf_get_option(self.bufnr, 'filetype')
local modified = self.options.show_modified_status and vim.api.nvim_buf_get_option(self.bufnr, 'modified') local modified = self.options.show_modified_status and vim.api.nvim_buf_get_option(self.bufnr, 'modified')
local modified_icon = self.options.icons_enabled and '' or ' +' local modified_icon = self.options.icons_enabled and '' or ' +'
self.modified_icon = modified and modified_icon or '' self.modified_icon = modified and modified_icon or ''
self.visible = vim.fn.bufwinid(self.bufnr) ~= -1
self.icon = '' self.icon = ''
if self.options.icons_enabled then if self.options.icons_enabled then
local dev local dev

View File

@ -49,7 +49,7 @@ local default_symbols = {
local default_options = { local default_options = {
colored = true, colored = true,
update_in_insert = false, update_in_insert = false,
sources = nil, sources = { 'nvim_lsp', 'coc' },
sections = { 'error', 'warn', 'info', 'hint' }, sections = { 'error', 'warn', 'info', 'hint' },
diagnostics_color = { diagnostics_color = {
error = { error = {
@ -122,7 +122,7 @@ Diagnostics.new = function(self, options, child)
end end
-- Error out no source -- Error out no source
if new_diagnostics.options.sources == nil then if #new_diagnostics.options.sources < 1 then
print 'no sources for diagnostics configured' print 'no sources for diagnostics configured'
return '' return ''
end end

View File

@ -6,6 +6,10 @@ local highlight = require 'lualine.highlight'
local default_options = { local default_options = {
max_length = 0, max_length = 0,
mode = 0, mode = 0,
tabs_color = {
active = nil,
inactive = nil,
},
} }
local function get_hl(section, is_active) local function get_hl(section, is_active)