Linting a whole project in neovim, more advanced search with telescope
Some issues with neovim that I've solved recently that took me way too much time to solve so I'm writing here in the hope that others will encounter these suggestions…
Linting a whole project
Let's say you add some eslint rule or switch linters in a project: you want to lint the whole project. This took me a long time to figure out how to do, because I expected full-project linting to connect to nvim-lint or the LSP system in Neovim. It turns out that the Language Server Protocol doesn't really have a concept of full-project linting: VS Code does it by a weird hack. workspace-diagnostics.nvim tries to replicate that hack for Neovim, but I couldn't get that to work.
The solution was overseer.nvim, which I installed via LazyVim and lets me run just npm run lint and it parses the results into diagnostics that I can browse via trouble.nvim. Works great. TSC.nvim does the same thing, but specialized for checking a project with TypeScript.
Searching for text in files in directories
I run neovim with no file tree - to toggle into the file view, I use oil.nvim, which shows a single level at a time. Nearly all of my navigation is via telescope.nvim, whether searching for filenames, or live-grepping the codebase. But in large projects I sometimes want a more precise search experience - for example, only searching for a string if it appears in a file in a directory.
The solution is the live-grep-args plugin to telescope:
return {
{
"nvim-telescope/telescope.nvim",
dependencies = {
{
"nvim-telescope/telescope-live-grep-args.nvim",
-- This will not install any breaking changes.
-- For major updates, this must be adjusted manually.
version = "^1.0.0",
},
},
config = function()
require("telescope").load_extension("live_grep_args")
end
}
}It's pretty easy to use: if you search for an unquoted string like const e, then it uses the default mode. If you quote that string, like "const e" then it starts treating it as a filtered query, so you can write "const e" app to only search for that string within the app directory.