Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 24 additions & 24 deletions lua/guard/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ end

local function create_lspattach_autocmd(fmt_on_save)
api.nvim_create_autocmd('LspAttach', {
group = group,
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
---@diagnostic disable-next-line: need-check-nil
if not client.supports_method('textDocument/formatting') then
return
end
local ft = vim.bo[args.buf].filetype
if not(ft_handler[ft] and ft_handler[ft].format) then
ft_handler(ft):fmt('lsp')
end
group = group,
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
---@diagnostic disable-next-line: need-check-nil
if not client.supports_method('textDocument/formatting') then
return
end
local ft = vim.bo[args.buf].filetype
if not (ft_handler[ft] and ft_handler[ft].format) then
ft_handler(ft):fmt('lsp')
end

if
fmt_on_save
and #api.nvim_get_autocmds({
group = group,
event = 'FileType',
pattern = ft,
})
== 0
then
format.attach_to_buf(args.buf)
end
end,
})
if
fmt_on_save
and #api.nvim_get_autocmds({
group = group,
event = 'FileType',
pattern = ft,
})
== 0
then
format.attach_to_buf(args.buf)
end
end,
})
end

return {
Expand Down
4 changes: 2 additions & 2 deletions lua/guard/filetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local function box()

function tbl:env(env)
vim.validate({
env = { env, 'table' }
env = { env, 'table' },
})
if vim.tbl_count(env) == 0 then
return self
Expand All @@ -57,7 +57,7 @@ local function box()
tool.env = {}
env = vim.tbl_extend('force', vim.uv.os_environ(), env or {})
for k, v in pairs(env) do
tool.env[#tool.env + 1 ] = ('%s=%s'):format(k, tostring(v))
tool.env[#tool.env + 1] = ('%s=%s'):format(k, tostring(v))
end
return self
end
Expand Down
6 changes: 3 additions & 3 deletions lua/guard/tools/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ M['clang-format'] = {
M.djhtml = {
cmd = 'djhtml',
args = { '-' },
stdin = true
stdin = true,
}

M.fish_indent = {
Expand Down Expand Up @@ -78,7 +78,7 @@ M.mixformat = {

M.pg_format = {
cmd = 'pg_format',
stdin = true
stdin = true,
}

M.prettier = {
Expand Down Expand Up @@ -126,7 +126,7 @@ M.swiftformat = {

M['swift-format'] = {
cmd = 'swift-format',
stdin = true
stdin = true,
}

M['sql-formatter'] = {
Expand Down
4 changes: 2 additions & 2 deletions lua/guard/tools/linter/shellcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ return {
error = 1,
warning = 2,
info = 3,
style = 4
style = 4,
}

local diags = {}
Expand All @@ -33,5 +33,5 @@ return {
end, comments)

return diags
end
end,
}
12 changes: 10 additions & 2 deletions test/filetype_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,18 @@ describe('filetype module', function()
end)

it('can add extra command arguments', function()
ft('c'):fmt('clang-format'):extra('--verbose'):lint('clang-tidy'):extra('--fix')
ft('c')
:fmt({
cmd = 'clang-format',
args = '--style=Mozilla',
stdin = true,
})
:extra('--verbose')
:lint('clang-tidy')
:extra('--fix')
same({
cmd = 'clang-format',
args = { '--verbose', '-style=file' },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm nope this should keep . it should insert extra arguments to default args

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

args = { '--style=Mozilla', '--verbose' },
stdin = true,
}, require('guard.tools.formatter')['clang-format'])

Expand Down