Allow linter's cwd to be specifed as function #674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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... 🤔