-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Allow linter's cwd to be specifed as function #674
base: master
Are you sure you want to change the base?
Conversation
yeah I kinda forgot that I added support for this, and also regret it a bit. Linter definitions should be mostly static & shareable between users and the cwd is more of a dynamic thing as it depends on the environment. Looking at your configuration I wonder if this wouldn't be better solved by setting up different E.g. I do have a generic: create_autocmd({'BufWritePost', 'BufEnter'}, {
group = api.nvim_create_augroup('lint', { clear = true }),
callback = function() lint.try_lint() end,
}) For the linters defined in local checkstyle_config = vim.uv.cwd() .. "/checkstyle.xml"
local has_checkstyle = vim.uv.fs_stat(checkstyle_config) and vim.fn.executable("checkstyle")
local is_main = api.nvim_buf_get_name(0):find("src/main/java") ~= nil
if has_checkstyle and is_main then
api.nvim_create_autocmd({"BufEnter", "BufWritePost"}, {
buffer = bufnr,
group = api.nvim_create_augroup("checkstyle-" .. bufnr, { clear = true }),
callback = function()
if not vim.bo[bufnr].modified then
require("lint.linters.checkstyle").config_file = checkstyle_config
require("lint").try_lint("checkstyle")
end
end
})
end With that approach you could pass along the |
Thanks, that works. The vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost" }, {
pattern = { "*.proto" },
callback = function()
require("lint").try_lint("buf_lint", {
args = buf_lint_args,
cwd = buf_lint_cwd(),
append_fname = false,
})
end,
}) However, since Either way, thanks for your hard work on nvim-lint and this suggestion! 😄 |
dd0c6b3
to
7871371
Compare
@mfussenegger I just saw you merged #735 and so I rebased this PR and tweaked my original change. Do you think something like this could work? |
Why this change?
When I set per-linter
cwd
I'm noticing that the value gets evaluated too early, when Neovim is launched while the lazy package manager is assembling all plugins'opts
. This becomes problematic as I have some logic that needs to find a certain configuration file in order to give me back the desired path for thecwd
. And it's also only applicable if I open a certain file type in a neovim buffer.So, I'd like to instead provide
cwd
as a function, so that it will be called when actually performing the linting and only for relevant file types.To better explain what I mean, I define my nvim-lint linters in per-language lua config files, and then I have a main nvim-lint lua file which merges all the opts before actually passing the opts into nvim-lint:
You can see how I need to specify the
cwd
for protobuf and I don't want that logic to run for any other linter.What was changed?
opts.cwd
in case a function was passed in.Notes
cwd
per linter is not even possible (or desired)... It feels like I've misunderstood something quite fundamental. But the docs mention it here anduv.spawn
does receive thecwd
as part of thelinter_opts
passed into it (here). It seems to me I can setcwd
per-linter just fine... and this PR change seems to also work... 🤔