neoclide / coc-eslint

Eslint extension for coc.nvim
MIT License
396 stars 24 forks source link

eslint / tsserver errors won't disappear after being fixed #72

Closed ianchanning closed 3 years ago

ianchanning commented 4 years ago

Result from CocInfo

## versions

vim version: NVIM v0.4.4
node version: v12.18.3
coc.nvim version: 0.0.78-fc983ce6dd
term: xterm-256color
platform: linux

## Output channel: eslint

[Info  - 14:24:59] ESLint server running in node v12.18.3
[Info  - 14:25:00] ESLint library loaded from: /home/channi16/imec/innovatrix/images/front/node_modules/eslint/lib/api.js
[Info  - 15:11:19] ESLint library loaded from: /home/channi16/imec/innovatrix/images/api/node_modules/eslint/lib/api.js

Describe the bug

The bug is hard to reproduce because it is only temporary. But it happens multiple times per day.

It happens with both coc-eslint and coc-tsserver so I don't believe that it is an issue with those individually.

What happens is that I get a linting error message that shows a warning.

I then fix that error but the warning does not go away.

So I am left with a warning that I can't clear. I can run :CocRestart to clear the warning, but it seems like this is a bug.

Reproduce the bug

I can't reproduce this directly - it only happens on occasion about twice per day.

I have removed the coc-tsserver plugin to make sure it is nothing to do with coc-tsserver and coc-eslint conflicting.

Screenshots (optional)

You can see here that the eslint warning is pointing to line 661 where the variable used to be - but I have since move the variable a few lines up and fixed the warning.

Screenshot from 2020-09-08 19-37-04

chemzqm commented 4 years ago

Happens on unsaved buffer, but not exists file.

ianchanning commented 4 years ago

I'm getting these crashes more an more. It happens every couple of hours. I'll try and recreate a minimal version

BerkeleyTrue commented 4 years ago

I'm getting the same issue. I can fix the issue but coc still reports the issue (eslint in my case). I can re-read the file :e and it will update the eslint issues.

Prakhil-tp commented 4 years ago

I'm also getting the same issue. The error indication persists after the fix. Mostly happens when working with React files. The "workspace.showOutput" is clean with no errors.

ianchanning commented 4 years ago

Happens on unsaved buffer, but not exists file.

So this is not exactly what I see - but I think it's something close.

I believe the problems with Coc started after I turned on the eslint 'fix on save' option:

  "eslint.autoFixOnSave": true,

So in my case the file definitely exists, it's a relatively long (almost always 200+ lines) React JSX file. But I see that sometimes the fix on save doesn't properly work. After I save the file eslint will modify the file and I will need to save it again.

For the moment I have turned this off and I will see if I experience any more problems. If I don't have any more problems for a while, then I'll try turning the fix on save back on with a minimal config.

ianchanning commented 4 years ago

Even with autoFixOnSave turned off it still crashes:

Screenshot from 2020-09-14 22-53-54

chemzqm commented 4 years ago

I can't reproduced this with latest coc.nvim and eslint, please upload verbose output of eslint https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

ianchanning commented 4 years ago

So I'm now seeing this bug:

Screenshot from 2020-09-20 16-31-52

It got "stuck" after this error:

[eslint no-undef] [E] 'c' is not defined. (no-undef) for when I started typing const and then even though I've typed the rest of the line const checked = value === null ? false : checked; it stays with the error.

This is the output I get from :CocCommand workspace.showOutput, I've created a gist because it's too big to paste: https://gist.github.com/ianchanning/134988a5d3aed9f87a3dfb464682d51b

chemzqm commented 4 years ago

The content of document is wrong, maybe you're using old coc.nvim

ianchanning commented 4 years ago

CocInfo:

## versions

vim version: NVIM v0.4.4
node version: v12.18.4
coc.nvim version: 0.0.79-b71489207a
coc.nvim directory: /home/channi16/.vim/bundle/coc.nvim
term: xterm-256color
platform: linux
ianchanning commented 4 years ago

Indeed - I'm on 0.0.79 vs the 1.31 that is here. But as far as I know I'm just using Plug to pull in the latest version...

Plug 'neoclide/coc.nvim', {'branch': 'release'}

Oh - no, I'm mixing up the coc-eslint version and coc version. It does look like my coc version is the latest.

BerkeleyTrue commented 4 years ago

I'll add my data as well. Still run into the issue. It also happens when I do a / search. The thing I'm searching will throw errors.

## versions

vim version: NVIM v0.4.4
node version: v12.18.4
coc.nvim version: 0.0.79-b71489207a
coc.nvim directory: /home/berkeleytrue/.config/nvim/plugged/coc.nvim
term: screen-256color
platform: linux
  + coc-eslint 1.2.7 ~/.config/coc/extensions/node_modules/coc-eslint
ianchanning commented 4 years ago

I'm getting these errors so often now that I've switched to using the minimal vim mini.vim that you suggest when creating a new bug in for coc.nvim.

Here's my ~/.mini.vim:

set nocompatible
set runtimepath^=/home/channi16/.vim/bundle/coc.nvim
filetype plugin indent on
syntax on
set hidden

I start nvim using a Session that was created by Tim Pope's vim-obsession plugin:

cd ~/my-projects-root
vim -S Session.vim -u ~/mini.vim

After about an hour of using nvim I get the following error:

Screenshot from 2020-10-06 15-53-09

✖     const projectMemberIds = projectMembers.map((m) => m.Contact__c);
       [eslint no-undef] [E] 'c' is not defined. (no-undef)
       —————————————————————————————————————————————————————————————————————————————— 
       [eslint no-unused-expressions] [E] Expected an assignment or function call and 
       instead saw an expression. (no-unused-expressions)

It generated the error, which I then fixed, but the eslint error remains.

I have a fairly complex setup of projects, they mostly look similar to this project, but all under the one my-projects-root:

~/my-projects-root
└── my-project-1
    └── images
        │   front
        │   ├── node_modules
        │   ├── .eslintrc
        │   └── package.json
        └── api
            ├── node_modules
            ├── .eslintrc.json
            └── package.json

So I have lots of different directories with separate .eslintrc files.

However I haven't had a problem with linting for years, it has only started happening within the last few months.

johnpyp commented 4 years ago

I've been having similar problems for a long time, but it's been getting increasingly common recently from what I can tell. I have autoformatting with coc-eslint and coc-prettier turned on, but another reports that disabling it doesn't fix the issue so it might be related to something else.

ianchanning commented 4 years ago

I have currently given up with coc, it's a shame but there's nothing that I can see that is the problem. Perhaps it's something to do with my eslint setup, but I don't think so - I got tsserver errors. Anyway I'm going to switch back to trying with ALE and maybe some other linting plugins to see if they have similar issues.

coc is still the best LSP plugin I used if it works, so I'm hoping there is a fix for this somewhere.

chemzqm commented 4 years ago

Could be problem with neovim's buffer lines change event, I can't experience it, try :e! to reload the buffer.

ianchanning commented 4 years ago

Ok, I'll give that a try, I just did :CocRestart each time.

I could also try with Vim instead of Neovim to see if that has the same problems

ianchanning commented 4 years ago

I have now hit the same issue almost immediately when running this in Vim 8, so it's not a Neovim problem:

## versions

vim version: VIM - Vi IMproved 8.2 8021767
node version: v12.19.0
coc.nvim version: 0.0.79-d4d93dc25f
coc.nvim directory: /home/channi16/.vim/bundle/coc.nvim
term: dumb
platform: linux

## Output channel: eslint

[Info  - 14:24:01] ESLint server running in node v12.19.0
[Info  - 14:24:02] ESLint library loaded from: /home/channi16/imec/innovatrix/images/api/node_modules/eslint/lib/api.js

I can now get this to break every time.

I start a new line, type const the go onto the next line and then hit Esc to go back to normal mode.

It then generates errors for the first character I have typed but doesn't clear them.

Screenshot from 2020-10-16 14-33-32

It's as if it thinks all I have typed is c, on the second character of the line it has 'missing semi-colon'.

Screenshot from 2020-10-16 14-36-46

:e! does indeed remove the errors similar to :CocRestart, but obviously that is not a solution.

chemzqm commented 4 years ago

Can't reproduce, need connection log of coc.nvim to address this issue, please follow these steps:

ianchanning commented 4 years ago

Thanks for your replies. I did this with Vim8 as I can reproduce the error every time now. Output log file: https://gist.github.com/ianchanning/201cb323e9ae90aec06c37b719f2dac1

ianchanning commented 4 years ago

Also I don't know how relevant this is, but normally from what I remember the errors get put into the location list, but here, although I've got 3 errors (the E:3 in the tagline) there's nothing in the location list

Screenshot from 2020-10-18 12-00-36

chemzqm commented 4 years ago

Auto change location list was removed, use :CocDiagnistic command to open location list with diagnostics

johnpyp commented 4 years ago

Can you try adding "diagnostic.refreshOnInsertMode": true to your CocConfig and see if that fixes it?

Admittedly, the issue doesn't happen a ton to me, so I'm not sure if it is still occurring, but since adding this I haven't had any stale diagnostics.

EDIT: Seems like it's happened at least once now, but maybe it's reducing frequency?

ianchanning commented 4 years ago

@johnpyp No sadly that doesn't help.

However I have made some progress. If I type really slowly whilst in insert mode and wait for the errors to correct themselves as I am typing before returning to normal mode then it works correctly.

It's only if I type something very fast in insert mode and then quickly switch back to normal mode that it gets stuck with the error messages.

chemzqm commented 4 years ago

I have reproduced the problem with big file, looks like eslint server ignores new text documents when it's too busy.

kyle-mccarthy commented 4 years ago

@chemzqm fwiw I am having this issue on a file with only 32 loc; however, it is in a large project

benwainwright commented 3 years ago

Hey @chemzqm is there any progress on this? Its a huge detractor for the user experience of coc.nvim which would otherwise make vim every bit as good as VsCode

davidsierradz commented 3 years ago

I'm using iamcco/coc-diagnostic: diagnostic-languageserver extension for coc.nvim for eslint until coc-eslint improves on this:

coc-settings.json:

{
"diagnostic.refreshOnInsertMode": true,
"diagnostic.messageDelay": 500,
"diagnostic.refreshAfterSave": false,
"diagnostic-languageserver.filetypes": {
    "javascript": "eslint"
  },
"diagnostic-languageserver.linters": {
    "eslint": {
      "command": "./node_modules/.bin/eslint",
      "rootPatterns": [".git", "package.json"],
      "debounce": 100,
      "args": ["--stdin", "--stdin-filename", "%filepath", "--format", "json"],
      "sourceName": "eslint",
      "parseJson": {
        "errorsRoot": "[0].messages",
        "line": "line",
        "column": "column",
        "endLine": "endLine",
        "endColumn": "endColumn",
        "message": "${message} [${ruleId}]",
        "security": "severity"
      },
      "securities": {
        "2": "error",
        "1": "warning"
      }
    }
  }
}
benwainwright commented 3 years ago

@davidsierradz Thanks! I'll definitely give that a go. Hope it works!

chemzqm commented 3 years ago

Will try to fix after coc.nvim 0.0.80 released.

kyle-mccarthy commented 3 years ago

@chemzqm do you have any ideas about the cause? I would be willing to help if you were able to narrow down the problem.

I saw in https://github.com/neoclide/coc.nvim/issues/2662 that it could be an issue with the fastDiff dependency. I pulled this repo down locally and replaced fastDiff and getChange with a native implementation using the n-api. It greatly reduces the execution time of getChange, but coc-eslint remains really sluggish overall. Do you think it's an issue with eslint in general?

chemzqm commented 3 years ago

Could be issue with willSaveUntil, only one language server should be allowed for changes .

chemzqm commented 3 years ago

Try coc-eslint 1.4.0, if you still have this issue, open new issue with output of eslint.

ianchanning commented 3 years ago

Thank you this is great. I haven't tested it yet but I've done the upgrade. This wasn't obvious to me how to do this. If anyone else is wondering:

  1. Update coc.nvim to v0.0.8 - I'm using Plug and so :PlugUpdate fixed that.
  2. Re-start neovim
  3. To update coc-eslint either re-run :CocInstall coc-eslint or :CocUpdate will update the coc plugin.
ianchanning commented 3 years ago

From what I can tell this is working. It gets into the same state with incorrect errors but they now get cleaned up after a short while.

benwainwright commented 3 years ago

Yeah, same here. It appears to be working for me!