mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.76k stars 191 forks source link

sqlfluff TextChanged not working #469

Open petobens opened 7 months ago

petobens commented 7 months ago

Consider the following init.lua file:

local root = '/tmp/nvim-minimal'

-- Set stdpaths to use root dir
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
    vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- Bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        'git',
        'clone',
        '--filter=blob:none',
        '--single-branch',
        'https://github.com/folke/lazy.nvim.git',
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- Install plugins
local plugins = {
    {
        'mfussenegger/nvim-lint',
        config = function()
            local lint = require('lint')
            vim.api.nvim_create_autocmd(
                { 'BufEnter', 'BufWritePost', 'TextChanged', 'InsertLeave' },
                {
                    group = vim.api.nvim_create_augroup('nvim_lint', { clear = true }),
                    callback = function()
                        vim.defer_fn(function()
                            lint.try_lint(nil, { ignore_errors = true })
                        end, 1)
                    end,
                }
            )
            lint.linters_by_ft = {
                sql = { 'sqlfluff' },
            }
            require('lint').linters.sqlfluff.stdin = true
        end,
    },
}
require('lazy').setup(plugins, {
    root = root .. '/plugins',
})

Now, as in the GIF, do

  1. Open nvim with the minimal init.lua file above
  2. Edit a a foo.sql file with SELECT 1
  3. Add , to the line and exit insert mode
  4. Write the file

After 3. I would expect nvim lint to show diagnostics (since stdin is enabled and something like echo "SELECT 1," | sqlfluff lint --format=json --dialect=postgres - in the terminal works just fine).

sqlfluff

gustavooferreira commented 5 months ago

I was literally trying to do the exact same thing you did. Even trying to enable the stdin setting for the linter config, given that the default parameter is actually wrong and sqlfluff does indeed support linting from stdin. But no joy. Then I found your issue.

Bumping this issue.

petobens commented 4 months ago

Hi @gustavooferreira and @mfussenegger. This seems to be a general problem beyond sqlfluff.

I tried a similar exercise to the one in my OP but using markdownlint this time. In the terminal echo "Some veryyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooongggggggggg lineeeeeeeeeeeeeeeeeeeeeee indeed" | markdownlint --stdin works fine but if if I add stdin settings to the linter config as in

local linters = require('lint').linters
linters.markdownlint.args = { '--stdin'}
linters.markdownlint.stdin = true

then nothing happens. On the other hand if I remove the stdin lines then markdownlint does work but, as in the GIF, there is obviously no TextChanged triggered diagnostics (only when I save they get triggered).

Peek 2024-02-03 16-45

caliguIa commented 1 month ago

I'm also having this issue with eslint_d, anyone found a solution?