added folding and lint
This commit is contained in:
parent
e6be670294
commit
cfa2d19f59
|
|
@ -0,0 +1,27 @@
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
'kevinhwang91/nvim-ufo',
|
||||||
|
dependencies = {
|
||||||
|
'kevinhwang91/promise-async',
|
||||||
|
},
|
||||||
|
event = 'VeryLazy',
|
||||||
|
init = function()
|
||||||
|
vim.o.foldcolumn = '1'
|
||||||
|
vim.o.foldlevel = 99
|
||||||
|
vim.o.foldlevelstart = 99
|
||||||
|
vim.o.foldenable = true
|
||||||
|
end,
|
||||||
|
opts = {
|
||||||
|
provider_selector = function(_, _, _)
|
||||||
|
return { 'treesitter', 'indent' }
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
config = function(_, opts)
|
||||||
|
local ufo = require 'ufo'
|
||||||
|
ufo.setup(opts)
|
||||||
|
|
||||||
|
vim.keymap.set('n', 'zR', ufo.openAllFolds, { desc = 'Open all folds' })
|
||||||
|
vim.keymap.set('n', 'zM', ufo.closeAllFolds, { desc = 'Close all folds' })
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -53,12 +53,6 @@ return {
|
||||||
-- lint.linters_by_ft['terraform'] = nil
|
-- lint.linters_by_ft['terraform'] = nil
|
||||||
-- lint.linters_by_ft['text'] = nil
|
-- lint.linters_by_ft['text'] = nil
|
||||||
|
|
||||||
-- Create autocommand which carries out the actual linting
|
|
||||||
-- on the specified events.
|
|
||||||
local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true })
|
|
||||||
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
|
|
||||||
group = lint_augroup,
|
|
||||||
callback = function()
|
|
||||||
local function executable_cmd(cmd)
|
local function executable_cmd(cmd)
|
||||||
if type(cmd) == 'function' then
|
if type(cmd) == 'function' then
|
||||||
local ok, value = pcall(cmd)
|
local ok, value = pcall(cmd)
|
||||||
|
|
@ -73,7 +67,6 @@ return {
|
||||||
local function available_linters_for(ft)
|
local function available_linters_for(ft)
|
||||||
local configured = lint.linters_by_ft[ft] or {}
|
local configured = lint.linters_by_ft[ft] or {}
|
||||||
local available = {}
|
local available = {}
|
||||||
|
|
||||||
for _, linter_name in ipairs(configured) do
|
for _, linter_name in ipairs(configured) do
|
||||||
local linter = lint.linters[linter_name]
|
local linter = lint.linters[linter_name]
|
||||||
local cmd = linter and executable_cmd(linter.cmd)
|
local cmd = linter and executable_cmd(linter.cmd)
|
||||||
|
|
@ -81,20 +74,51 @@ return {
|
||||||
table.insert(available, linter_name)
|
table.insert(available, linter_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return available
|
return available
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Only run the linter in buffers that you can modify in order to
|
local function trigger_lint()
|
||||||
-- avoid superfluous noise, notably within the handy LSP pop-ups that
|
|
||||||
-- describe the hovered symbol using Markdown.
|
|
||||||
if vim.bo.modifiable then
|
if vim.bo.modifiable then
|
||||||
local filetype = vim.bo.filetype
|
local linters = available_linters_for(vim.bo.filetype)
|
||||||
local linters = available_linters_for(filetype)
|
|
||||||
if #linters > 0 then
|
if #linters > 0 then
|
||||||
lint.try_lint(linters)
|
lint.try_lint(linters)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Toggle lint on/off
|
||||||
|
local lint_enabled = true
|
||||||
|
vim.keymap.set('n', '<leader>tl', function()
|
||||||
|
lint_enabled = not lint_enabled
|
||||||
|
if not lint_enabled then
|
||||||
|
local cleared = {}
|
||||||
|
for _, linters in pairs(lint.linters_by_ft) do
|
||||||
|
for _, linter_name in ipairs(linters) do
|
||||||
|
local ns = lint.get_namespace(linter_name)
|
||||||
|
if not cleared[ns] then
|
||||||
|
vim.diagnostic.reset(ns)
|
||||||
|
cleared[ns] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
trigger_lint()
|
||||||
|
end
|
||||||
|
vim.notify('Lint ' .. (lint_enabled and 'enabled' or 'disabled'))
|
||||||
|
end, { desc = '[T]oggle [L]int' })
|
||||||
|
|
||||||
|
-- Create autocommand which carries out the actual linting
|
||||||
|
-- on the specified events.
|
||||||
|
local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true })
|
||||||
|
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
|
||||||
|
group = lint_augroup,
|
||||||
|
-- Only run the linter in buffers that you can modify in order to
|
||||||
|
-- avoid superfluous noise, notably within the handy LSP pop-ups that
|
||||||
|
-- describe the hovered symbol using Markdown.
|
||||||
|
callback = function()
|
||||||
|
if lint_enabled then
|
||||||
|
trigger_lint()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue