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

Possible eslint related race condition #1730

Closed
rauchg opened this issue Jan 2, 2023 · 5 comments
Closed

Possible eslint related race condition #1730

rauchg opened this issue Jan 2, 2023 · 5 comments

Comments

@rauchg
Copy link

rauchg commented Jan 2, 2023

I frequently get post-save errors that complain that ESLint can't access a file. It seems completely random. If I save again it usually succeeds.

ESLint: ENOENT: no such file or directory" "Please see the 'ESLint' output channel for details

telegram-cloud-photo-size-1-4929190999499057972-y

My ~/.config/nvim/lua/custom/plugins/lspconfig.lua:

local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities

local lspconfig = require "lspconfig"
local servers = {

  "tsserver",
  "bashls",
  "html",
  "cssls",
  "cssmodules_ls",
  "eslint",
  "grammarly",
  "jsonls",
  "tailwindcss",
  "svelte",
}

for _, lsp in ipairs(servers) do
  lspconfig[lsp].setup {
    on_attach = on_attach,
    capabilities = capabilities,
  }
end

My ~/.config/nvim/lua/custom/plugins/null-ls.lua:

local present, null_ls = pcall(require, "null-ls")

if not present then
  return
end

local b = null_ls.builtins

local sources = {
  -- JS html css stuff
  b.formatting.prettierd.with {
    filetypes = {
      "html",
      "json",
      "markdown",
      "css",
      "java",
      "javascript",
      "javascriptreact",
      "typescript",
      "typescriptreact",
    },
  },
  -- b.diagnostics.eslint.with {
  --    command = "eslint_d",
  -- },

  -- Lua
  b.formatting.stylua,
  b.diagnostics.luacheck.with { extra_args = { "--global vim" } },

  -- Shell
  b.formatting.shfmt,
  b.diagnostics.shellcheck.with { diagnostics_format = "#{m} [#{c}]" },

  -- Rust,
  b.formatting.rustfmt,
}

local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

null_ls.setup {
  debug = true,
  sources = sources,
  -- you can reuse a shared lspconfig on_attach callback here
  on_attach = function(client, bufnr)
    if client.supports_method "textDocument/formatting" then
      vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
      vim.api.nvim_create_autocmd("BufWritePre", {
        group = augroup,
        buffer = bufnr,
        callback = function()
          vim.lsp.buf.format { bufnr = bufnr }
        end,
      })
    end
  end,
}

I've installed both eslint-lsp and eslint_d via :Mason

CleanShot 2023-01-01 at 16 57 48@2x

My environment details:

▲  uname -a
Darwin Guillermos-MacBook-Air.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64 arm Darwin
▲  echo $TERM_PROGRAM
Hyper
▲  echo $TERM
xterm-256color
▲  echo $SHELL
/bin/zsh
▲  nvim --version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-004.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.1/share/nvim"
@siduck
Copy link
Member

siduck commented Jan 2, 2023

do you get this issue with vscode? I doubt if this is related to nvchad, also related to microsoft/vscode-eslint#1229

@siduck
Copy link
Member

siduck commented Jan 2, 2023

backup your nvchad config and try this init.lua as your config https://github.com/nvim-lua/kickstart.nvim ( no need to setup lsp in it, just install eslint binary from Mason window) , lemme know if this works, if yes then its an issue with nvchad 🤔

@thenbe
Copy link

thenbe commented Jan 5, 2023

@rauchg null-ls recommends adding a simple filter when enabling format on save. Might that be relevant here?

Snippet: https://github.com/jose-elias-alvarez/null-ls.nvim/wiki/Formatting-on-save#choosing-a-client-for-formatting


Totally unrelated, but if you're anything like me and forgot about the null-ls debug = true flag, you might want to keep an eye on the log file size in ~/.cache/nvim/.

@otanriverdi
Copy link

@rauchg you should try passing the async flag to the format function otherwise bunch of race conditions happen and sometimes your file gets modified after save.

vim.lsp.buf.format { bufnr = bufnr, async = false }

@siduck
Copy link
Member

siduck commented Jan 14, 2023

closing this as it doesnt seem to be a nvchad issue

@siduck siduck closed this as completed Jan 14, 2023
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