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.93k stars 203 forks source link

Inconsistent results with solhint. #379

Closed pauldesmondparker closed 5 months ago

pauldesmondparker commented 1 year ago

Problem

On certain *.sol files, although the buffer is written to stdin, the spawned solhint stdin process doesn't process that stdin to the stdout, and hence the function created by the read_output factory never receives a non-null chunk.

Sometimes the lint works immediately, sometimes I need to call the linter several (ten or more sometimes) to get results through into the chunk.

Debugging Attempts

  1. print out everything written to stdin (buffer contents, no issue)
  2. print status on chunk (shows that when it doesn't work, it's because there is no non-null chunk)
  3. move start_read call to after all stdin:write calls.
  4. Use custom config to use filename instead of solhint stdin, skipping stdin completely.
  5. Run :%!solhint stdin manually. Never fails.
  6. Remove trailing newline on the final stdin:write
  7. Run from bash cat filename.sol | npx solhint stdin. No issue.
  8. Confirm that the on_exit code for the spawned solhint process runs at the end, after on_done.
  9. Temporarily remove code that shuts down stdin and closes it.
  10. Confirm that handle exists and that streams aren't being closed prematurely.

Things I haven't yet done:

  1. create a minimal init.lua config that reproduces the behavior.

Before I reproduce this with minimal config, has anyone seen this kind of behavior before?

mortimr commented 5 months ago

Seeing some weird behaviors on my end aswell. For now I'm using both nvim-lint and ale with explicit configs so they don't compete on the same linters

return {
  {
    "mfussenegger/nvim-lint",
    opts = {
      linters_by_ft = {
        -- solidity = {"solhint"}
      },
    },
  },
  {
    "dense-analysis/ale",
    init = function()
      vim.cmd("let g:ale_linters = {'solidity': ['solhint']}")
      vim.cmd("let g:ale_linters_explicit = 1")
      vim.cmd("let g:ale_echo_cursor = 0")
    end,
  },
}

But I agree that there is something weird with how solhint behaves in nvim-lint. Haven't got the time but maybe have a look at what ale is doing differently (ale seems to be working fine on my end)

mfussenegger commented 5 months ago

Could you try and see if the stdin:write calls return any errors? E.g. by applying a change like:

diff --git a/lua/lint.lua b/lua/lint.lua
index 934bab1..e3ce4f7 100644
--- a/lua/lint.lua
+++ b/lua/lint.lua
@@ -364,11 +364,13 @@ function M.lint(linter, opts)
   local linter_proc = setmetatable(state, linter_proc_mt)
   linter_proc:start_read()
   if linter.stdin then
     local lines = api.nvim_buf_get_lines(0, 0, -1, true)
     for _, line in ipairs(lines) do
-      stdin:write(line .. '\n')
+      local _, err = stdin:write(line)
+      assert(not err, err)
+      stdin:write('\n')
     end
     stdin:write('', function()
       stdin:shutdown(function()
         stdin:close()
       end)
pauldesmondparker commented 5 months ago

I'm no longer seeing the issue.