Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: event API #181

Merged
merged 39 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2d67975
chore: minor code simplification
xiaoshihou514 Dec 9, 2024
d2b03a1
feat!: event api
xiaoshihou514 Dec 9, 2024
7911e94
fix: test
xiaoshihou514 Dec 9, 2024
bd33a3b
feat: provide command interface
xiaoshihou514 Dec 10, 2024
7b7fb54
chore(doc): auto generate docs
github-actions[bot] Dec 10, 2024
771fa7b
feat: add error reporting for linters
xiaoshihou514 Dec 12, 2024
1193099
chore(doc): auto generate docs
github-actions[bot] Dec 12, 2024
596b3a3
ci: add linter test
xiaoshihou514 Dec 12, 2024
b82a8f7
Merge branch 'main' of github.com:xiaoshihou514/guard.nvim
xiaoshihou514 Dec 12, 2024
fbcbafd
ci: more tests
xiaoshihou514 Dec 12, 2024
8e12ec8
chore: update bug report issue template
xiaoshihou514 Dec 12, 2024
5510a1f
Update bug_report.yml
xiaoshihou514 Dec 12, 2024
964e5e3
chore(doc): auto generate docs
github-actions[bot] Dec 13, 2024
4ad9e63
wip: add custom event support for formatting
xiaoshihou514 Dec 15, 2024
c91acd5
chore(doc): auto generate docs
github-actions[bot] Dec 15, 2024
dcba169
ci: add tests for custom formatter events
xiaoshihou514 Dec 15, 2024
8678e4e
fix: enable/disable-fmt
xiaoshihou514 Dec 15, 2024
83350ac
fix(side quest): fix generic linters properly
xiaoshihou514 Dec 15, 2024
ec7a632
update
xiaoshihou514 Dec 15, 2024
3a36483
Merge branch 'main' into main
xiaoshihou514 Dec 15, 2024
5975c60
fix: type check
xiaoshihou514 Dec 15, 2024
e3dc4b8
scaffold more stuff
xiaoshihou514 Dec 18, 2024
7bb6967
chore(doc): auto generate docs
github-actions[bot] Dec 18, 2024
1eda07b
feat: add custom linter event logic
xiaoshihou514 Dec 23, 2024
016f0e9
chore(doc): auto generate docs
github-actions[bot] Dec 23, 2024
f39be05
update
xiaoshihou514 Dec 23, 2024
3897c36
feat: auto_lint
xiaoshihou514 Dec 23, 2024
0042dbe
chore(doc): auto generate docs
github-actions[bot] Dec 23, 2024
c8ea85f
special treat
xiaoshihou514 Dec 23, 2024
fb45f0f
fix global state
xiaoshihou514 Dec 23, 2024
a2cd3ea
feat: add lint interval option + naming changes
xiaoshihou514 Dec 23, 2024
9cb6efb
chore(doc): auto generate docs
github-actions[bot] Dec 23, 2024
101e2db
Update lua/guard/filetype.lua
xiaoshihou514 Dec 23, 2024
cde7233
Update lua/guard/filetype.lua
xiaoshihou514 Dec 23, 2024
bd3a151
Update lua/guard/events.lua
xiaoshihou514 Dec 23, 2024
422dedb
Update lua/guard/events.lua
xiaoshihou514 Dec 23, 2024
46649a9
Update lua/guard/events.lua
xiaoshihou514 Dec 23, 2024
6d36c7d
feat: unify guard info with healthcheck
xiaoshihou514 Dec 23, 2024
a5f309e
chore: tweak issue template
xiaoshihou514 Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ft('lang'):fmt('format-tool-1')
:lint('lint-tool-1')
:extra(extra_args)

-- change this anywhere in your config, these are the defaults
-- change this anywhere in your config (or not), these are the defaults
vim.g.guard_config = {
-- format on write to buffer
fmt_on_save = true,
Expand All @@ -58,7 +58,9 @@ vim.g.guard_config = {
-- whether or not to save the buffer after formatting
save_on_fmt = true,
-- automatic linting
auto_lint = true
auto_lint = true,
-- how frequently can linters be called
lint_interval = 500
}
```

Expand Down
8 changes: 4 additions & 4 deletions lua/guard/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local function debounced_lint(opt)
end
---@diagnostic disable-next-line: undefined-field
debounce_timer = assert(uv.new_timer()) --[[uv_timer_t]]
debounce_timer:start(500, 0, function()
debounce_timer:start(util.getopt('lint_interval'), 0, function()
debounce_timer:stop()
debounce_timer:close()
debounce_timer = nil
Expand Down Expand Up @@ -172,7 +172,7 @@ end

---@param ft string
---@param formatters FmtConfig[]
function M.fmt_watch_ft(ft, formatters)
function M.fmt_on_ft(ft, formatters)
xiaoshihou514 marked this conversation as resolved.
Show resolved Hide resolved
-- check if all cmds executable before registering formatter
iter(formatters):any(function(config)
if type(config) == 'table' and config.cmd and vim.fn.executable(config.cmd) ~= 1 then
Expand Down Expand Up @@ -208,7 +208,7 @@ function M.maybe_default_to_lsp(config, ft, buf)
pattern = ft,
}) == 0
then
M.fmt_watch_ft(ft, config.formatter)
M.fmt_on_ft(ft, config.formatter)
xiaoshihou514 marked this conversation as resolved.
Show resolved Hide resolved
end
M.try_attach_fmt_to_buf(buf)
end
Expand All @@ -234,7 +234,7 @@ end

---@param ft string
---@param events string[]
function M.lint_watch_ft(ft, events)
function M.lint_on_ft(ft, events)
xiaoshihou514 marked this conversation as resolved.
Show resolved Hide resolved
iter(require('guard.filetype')[ft].linter):any(function(config)
if config.cmd and vim.fn.executable(config.cmd) ~= 1 then
report_error(config.cmd .. ' not executable')
Expand Down
4 changes: 2 additions & 2 deletions lua/guard/filetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function box(ft)
-- use user's custom events
events.fmt_attach_custom(it, config.events)
else
events.fmt_watch_ft(it, self.formatter)
events.fmt_on_ft(it, self.formatter)
xiaoshihou514 marked this conversation as resolved.
Show resolved Hide resolved
events.fmt_attach_to_existing(it)
end
end
Expand All @@ -105,7 +105,7 @@ local function box(ft)
-- use user's custom events
events.lint_attach_custom(it, config)
else
events.lint_watch_ft(it, evs)
events.lint_on_ft(it, evs)
xiaoshihou514 marked this conversation as resolved.
Show resolved Hide resolved
events.lint_attach_to_existing(it, evs)
end
end
Expand Down
1 change: 1 addition & 0 deletions lua/guard/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function M.getopt(opt)
lsp_as_default_formatter = false,
save_on_fmt = true,
auto_lint = true,
lint_interval = 500,
}
if
not vim.g.guard_config
Expand Down
Loading