nvimdev / guard.nvim

async fast minimalist plugin make format easy in neovim
MIT License
448 stars 24 forks source link

Linter don't respect the `find` property. #141

Closed UnderCooled closed 3 months ago

UnderCooled commented 9 months ago

If I setup a filetype to use LSP as formatter, I cannot set find property to linter?

Lots of linters have config files, without find property, how can you skip those paths which don't have a config file?

xiaoshihou514 commented 9 months ago

The find property is used for controlling whether a formatter should run in a certain directory https://github.com/nvimdev/guard.nvim/blob/d4782860b7da344d7409edbe7ee3693d5b8ea226/README.md?plain=1#L95 For configuration, take a look at the docs of the respective linter, it shouldn't have anything to do with guard :)

UnderCooled commented 9 months ago

I'm trying to add "golangci-lint" to my guard configuration, it depends on "the current working directory should be project root directory", or it won't find imported modules in the project. I thought linter's find property acting like lspconfig "root_dir".

Likewise, I've added "editorconfig-checker" to my generic linters, I want it only runs when find ".editorconfig" file exist in the project root directory, how should I config this linter without find property?

Maybe my use case fit using efm-language-server with lspconfig or null-ls better? Adding find project root support may make guard.nvim too complex?


I see an undocumented property cwd in "spawn.lua", it should fit my use case.

https://github.com/nvimtools/none-ls.nvim/blob/7e146f3a188853843bb4ca1bff24c912bb9b7177/lua/null-ls/builtins/diagnostics/golangci_lint.lua#L16-L33

It seems that null-ls has utils to cache and find project root pattern, and supports linting with multiple files, I might go back to this heavier plugin again.

xiaoshihou514 commented 9 months ago

I'm trying to add "golangci-lint" to my guard configuration, it depends on "the current working directory should be project root directory", or it won't find imported modules in the project. I thought linter's find property acting like lspconfig "root_dir".

I believe guard-collection has a config for that, you may want to take a look.

Likewise, I've added "editorconfig-checker" to my generic linters, I want it only runs when find ".editorconfig" file exist in the project root directory, how should I config this linter without find property?

Hmm, maybe it has to be implemented for linters as well.

Maybe my use case fit using efm-language-server with lspconfig or null-ls better? Adding find project root support may make guard.nvim too complex?

guard defaults to lsp root, then fallback to vim.fn.cwd() for formatting, I guess linters don't have that capability because there haven't been a use case yet.

Personally I find null-ls and efm a bit bloated, they essentially do the same thing as guard but they parse the diagnostics/formatted text a into lsp responses/text edits and neovim has to read it on top of that...

UnderCooled commented 9 months ago

Yeah, that's why I was trying to switch to guard.nvim... My lspconfig configuration file get blaoted again. 😢


You can check guard-collection's golangci-lint config and null-ls one I posted above. Null-ls can search "go.mod" path, and set it to command cwd, and cache that result. It will work on multiple-files use case:

multiple_files If set, signals that the generator will return results that apply to more than one file. The null-ls diagnostics handler allows applying results to more than one file if this option is true and each diagnostic specifies a bufnr or filename specifying the file to which the diagnostic applies.

It checks exit code (guard.nvim #109).

xiaoshihou514 commented 9 months ago

OK, so there are two problems here.