-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: minor code simplification * feat!: event api * fix: test * feat: provide command interface * chore(doc): auto generate docs * feat: add error reporting for linters * chore(doc): auto generate docs * ci: add linter test * ci: more tests * chore: update bug report issue template * Update bug_report.yml * chore(doc): auto generate docs * wip: add custom event support for formatting * chore(doc): auto generate docs * ci: add tests for custom formatter events * fix: enable/disable-fmt * fix(side quest): fix generic linters properly * update * fix: type check * scaffold more stuff * chore(doc): auto generate docs * feat: add custom linter event logic * chore(doc): auto generate docs * update * feat: auto_lint * chore(doc): auto generate docs * special treat * fix global state * feat: add lint interval option + naming changes * chore(doc): auto generate docs * Update lua/guard/filetype.lua Co-authored-by: glepnir <[email protected]> * Update lua/guard/filetype.lua Co-authored-by: glepnir <[email protected]> * Update lua/guard/events.lua Co-authored-by: glepnir <[email protected]> * Update lua/guard/events.lua Co-authored-by: glepnir <[email protected]> * Update lua/guard/events.lua Co-authored-by: glepnir <[email protected]> * feat: unify guard info with healthcheck * chore: tweak issue template --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: glepnir <[email protected]>
- Loading branch information
1 parent
0a6d015
commit 25ba07f
Showing
19 changed files
with
920 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
-- These are considered public API and changing their signature would be a breaking change | ||
local M = {} | ||
local api = vim.api | ||
local events = require('guard.events') | ||
|
||
---Format bufnr or current buffer | ||
---@param bufnr number? | ||
function M.fmt(bufnr) | ||
require('guard.format').do_fmt(bufnr) | ||
end | ||
|
||
---Lint bufnr or current buffer | ||
---@param bufnr number? | ||
function M.lint(bufnr) | ||
require('guard.lint').do_lint(bufnr) | ||
end | ||
|
||
---Enable format for bufnr or current buffer | ||
---@param bufnr number? | ||
function M.enable_fmt(bufnr) | ||
local buf = bufnr or api.nvim_get_current_buf() | ||
local ft_handler = require('guard.filetype') | ||
local ft = vim.bo[buf].ft | ||
local head = vim.tbl_get(ft_handler, ft, 'formatter', 1) | ||
if type(head) == 'table' and type(head.events) == 'table' then | ||
events.fmt_attach_custom(ft, head.events) | ||
else | ||
events.try_attach_fmt_to_buf(buf) | ||
end | ||
end | ||
|
||
---Disable format for bufnr or current buffer | ||
---@param bufnr number? | ||
function M.disable_fmt(bufnr) | ||
local buf = bufnr or api.nvim_get_current_buf() | ||
vim.iter(events.get_format_autocmds(buf)):each(function(it) | ||
api.nvim_del_autocmd(it.id) | ||
end) | ||
events.user_fmt_autocmds[vim.bo[buf].ft] = {} | ||
end | ||
|
||
---Enable lint for bufnr or current buffer | ||
---@param bufnr number? | ||
function M.enable_lint(bufnr) | ||
local buf = bufnr or api.nvim_get_current_buf() | ||
local ft = require('guard.filetype')[vim.bo[buf].ft] or {} | ||
if ft.linter and #ft.linter > 0 then | ||
events.try_attach_lint_to_buf( | ||
buf, | ||
require('guard.util').linter_events(ft.linter[1]), | ||
vim.bo[buf].ft | ||
) | ||
end | ||
end | ||
|
||
---Disable format for bufnr or current buffer | ||
---@param bufnr number? | ||
function M.disable_lint(bufnr) | ||
local aus = events.get_lint_autocmds(bufnr or api.nvim_get_current_buf()) | ||
vim.iter(aus):each(function(au) | ||
api.nvim_del_autocmd(au.id) | ||
end) | ||
end | ||
|
||
---Show guard info for current buffer | ||
function M.info() | ||
vim.cmd('checkhealth guard') | ||
end | ||
|
||
return M |
Oops, something went wrong.