Skip to content

Commit

Permalink
fix lsp_as_default close #39
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Jul 28, 2023
1 parent 1307eee commit aa947b8
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions lua/guard/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ local group = api.nvim_create_augroup('Guard', { clear = true })
local fts_config = require('guard.filetype')
local util = require('guard.util')

local function fmt_event(buf)
api.nvim_create_autocmd('BufWritePre', {
group = group,
buffer = buf,
callback = function(opt)
require('guard.format').do_fmt(opt.buf)
end,
})
end

local function register_event(fts)
api.nvim_create_autocmd('FileType', {
group = group,
pattern = fts,
callback = function(args)
api.nvim_create_autocmd('BufWritePre', {
group = group,
buffer = args.buf,
callback = function()
require('guard.format').do_fmt(args.buf)
end,
})
fmt_event(args.buf)
end,
desc = 'guard',
})
Expand Down Expand Up @@ -75,11 +79,23 @@ local function setup(opt)
return
end
local fthandler = require('guard.filetype')
if fthandler[vim.bo[args.buf].filetype] and fthandler[vim.bo[args.buf].filetype].fmt then
table.insert(fthandler[vim.bo[args.buf]], 1, 'lsp')
if fthandler[vim.bo[args.buf].filetype] and fthandler[vim.bo[args.buf].filetype].format then
table.insert(fthandler[vim.bo[args.buf].filetype].format, 1, 'lsp')
else
fthandler(vim.bo[args.buf].filetype):fmt('lsp')
end

if
opt.fmt_on_save
and #api.nvim_get_autocmds({
group = 'Guard',
event = 'FileType',
pattern = vim.bo[args.buf].filetype,
})
== 0
then
fmt_event(args.buf)
end
end,
})
end
Expand Down

0 comments on commit aa947b8

Please sign in to comment.