Skip to content

Commit

Permalink
fix: silent warning message & wrong exit status check (#81)
Browse files Browse the repository at this point in the history
* fix: silent warning message & wrong exit status check
  • Loading branch information
xiaoshihou514 authored Aug 25, 2023
1 parent f46ac07 commit d985721
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions lua/guard/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ local function create_lspattach_autocmd(fmt_on_save)
end

return {
group = group,
watch_ft = watch_ft,
create_lspattach_autocmd = create_lspattach_autocmd,
}
2 changes: 1 addition & 1 deletion lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ end

local function attach_to_buf(buf)
api.nvim_create_autocmd('BufWritePre', {
group = 'Guard',
group = require('guard.events').group,
buffer = buf,
callback = function(opt)
if not vim.bo[opt.buf].modified then
Expand Down
3 changes: 3 additions & 0 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local spawn = require('guard.spawn').try_spawn
local ns = api.nvim_create_namespace('Guard')
local get_prev_lines = require('guard.util').get_prev_lines
local vd = vim.diagnostic
local group = require('guard.events').group

local function do_lint(buf)
buf = buf or api.nvim_get_current_buf()
Expand Down Expand Up @@ -43,9 +44,11 @@ local debounce_timer = nil
local function register_lint(ft, extra)
api.nvim_create_autocmd('FileType', {
pattern = ft,
group = group,
callback = function(args)
api.nvim_create_autocmd(vim.list_extend({ 'BufEnter' }, extra), {
buffer = args.buf,
group = group,
callback = function(opt)
if debounce_timer then
debounce_timer:stop()
Expand Down
8 changes: 4 additions & 4 deletions lua/guard/spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

local function on_failed(msg)
vim.schedule(function()
vim.api.nvim_err_write('[Guard] ' .. msg)
vim.notify('[Guard] ' .. msg, vim.log.levels.ERROR)
end)
end

Expand Down Expand Up @@ -67,12 +67,12 @@ local function spawn(opt)
end
end)

if exit_code == 0 and num_stderr_chunks == 0 then
coroutine.resume(co, table.concat(chunks))
else
if exit_code ~= 0 and num_stderr_chunks ~= 0 then
on_failed(('process %s exited with non-zero exit code %s'):format(opt.cmd, exit_code))
coroutine.resume(co)
return
else
coroutine.resume(co, table.concat(chunks))
end
end)

Expand Down
5 changes: 3 additions & 2 deletions plugin/guard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ end
loaded = true

local api = vim.api
local group = require('guard.events').group
vim.api.nvim_create_user_command('GuardDisable', function(opts)
local arg = opts.args
local bufnr = (#opts.fargs == 0) and api.nvim_get_current_buf() or tonumber(arg)
if bufnr then
local bufau = api.nvim_get_autocmds({ group = 'Guard', event = 'BufWritePre', buffer = bufnr })
local bufau = api.nvim_get_autocmds({ group = group, event = 'BufWritePre', buffer = bufnr })
if #bufau ~= 0 then
api.nvim_del_autocmd(bufau[1].id)
end
Expand All @@ -19,7 +20,7 @@ vim.api.nvim_create_user_command('GuardEnable', function(opts)
local arg = opts.args
local bufnr = (#opts.fargs == 0) and api.nvim_get_current_buf() or tonumber(arg)
if bufnr then
local bufau = api.nvim_get_autocmds({ group = 'Guard', event = 'BufWritePre', buffer = bufnr })
local bufau = api.nvim_get_autocmds({ group = group, event = 'BufWritePre', buffer = bufnr })
if #bufau == 0 then
require('guard.format').attach_to_buf(bufnr)
end
Expand Down

0 comments on commit d985721

Please sign in to comment.