Skip to content
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

sqlfluff TextChanged not working #469

Open
petobens opened this issue Nov 20, 2023 · 4 comments
Open

sqlfluff TextChanged not working #469

petobens opened this issue Nov 20, 2023 · 4 comments

Comments

@petobens
Copy link

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
Copy link

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
Copy link
Author

petobens commented Feb 3, 2024

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
Copy link

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

@xudyang1
Copy link
Contributor

For sqlfluff, the stdin is disabled intentionally via #294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants