lsp-mode does not work with latest un-merged but published version of eslint language server

Created on 17 Jul 2020  ·  34Comments  ·  Source: emacs-lsp/lsp-mode

All the tests were done with clean emacs 27+ and config from here: https://github.com/emacs-lsp/lsp-mode/blob/master/scripts/lsp-start-plain.el.

Describe the bug
Eslint doesn't apply fixes. lsp-eslint-apply-all-fixes doesn't produce any results.

To Reproduce
Create a following test.js file.

function abc ()         {
  return 23;;
}

abc(

)

Create package.json file:

{
  "name": "lsp",
  "version": "1.0.0",
  "description": "",
  "main": "test.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "standard": "^14.3.4"
  }
}

Create .eslintrc.js

module.exports = {
  env: {
    browser: true,
    es6: true
  },
  extends: [
    'standard'
  ]
}

Run

npm install

Command line tools work!

/data/tmp/lsp 
❯ eslint test.js
/data/tmp/lsp/test.js
1:16  error  Multiple spaces found before '{'    no-multi-spaces
2:12  error  Extra semicolon                     semi
2:12  error  Missing whitespace after semicolon  semi-spacing
✖ 3 problems (3 errors, 0 warnings)
3 errors and 0 warnings potentially fixable with the `--fix` option.

When --fix option is applied it fixes all the errors in the file.

Expected behavior

  1. Errors are highlighted.
  2. lsp-eslint-apply-all-fixes fixes what is automatically possible.

Which Language Server did you use
dbaeumer.vscode-eslint-2.1.8.vsix with lsp-eslint

OS
Linux

* LSP Log*

[Trace - 09:59:07 PM] Received response 'textDocument/codeAction - (202)' in 17ms.
Result: []


[Trace - 09:59:14 PM] Sending request 'workspace/executeCommand - (204)'.
Params: {
  "command": "eslint.applyAllFixes",
  "arguments": [
    {
      "uri": "file:///data/dev/cloud-sdk/src/test.js",
      "version": 4
    }
  ]
}


[Trace - 09:59:14 PM] Received request 'workspace/applyEdit - (9).
Params: {
  "edit": {
    "documentChanges": [
      {
        "edits": [],
        "textDocument": {
          "version": 4,
          "uri": "file:///data/dev/cloud-sdk/src/test.js"
        }
      }
    ]
  }
}


[Trace - 09:59:14 PM] Sending response 'workspace/applyEdit - (9)'. Processing request took 2ms
Params: {
  "jsonrpc": "2.0",
  "id": 9,
  "result": {
    "applied": true
  }
}


[Trace - 09:59:14 PM] Received response 'workspace/executeCommand - (204)' in 17ms.
Result: {
}
eslint server-extension-breaking-change

Most helpful comment

Installing version 2.1.8 of vscode-eslint worked for me.

I downloaded it from here: https://github.com/microsoft/vscode-eslint/releases/tag/release%2F2.1.8
I unzipped the .vsix file into .emacs.d/.cache/lsp/eslint/unzipped (but first removed the files that were there currently)
Then I started emacs again and it worked.

All 34 comments

AFACS the server code has changed so we have to adjust lsp-mode.

A couple of screenshots to get an idea.
image
image

Understood @yyoncho, at least I won't be duping time to configure it in vain and make a gig to make it work again.

Yes. The issue is that the server hasn't been configured properly before that so it is sending empty edits when performing quick fix.

Probably if you try to switch to an older version of the server it will work. The issue might be caused also by a regression in lsp-mode as well. I will take a look to find out how much effort will be to sync lsp-mode with latest eslint.

I downloaded https://github.com/Microsoft/vscode-eslint and then npm install and then configured lsp-mode to point to vscode-eslint/server/out/eslintServer.js and it was working fine.

At the same time, it does not work with the eslint downloaded from market place. I cannot find which version was used for 2.1.8 version of vscode package. Also, I got a notification request when I was using the marketplace version('eslint/confirmLocalESLint') but I was unable to find that in the github sources so it seems to me that this was not released from GH repo.

The commits corresponding to the latest versions haven't been merged into the master branch yet: https://github.com/microsoft/vscode-eslint/issues/1011

The commits corresponding to the latest versions haven't been merged into the master branch yet: microsoft/vscode-eslint#1011

This is really something unexpected...

It's indeed weird and unexpected... Thanks for looking into this @yyoncho and @leungbk

So this is a bit messy. The new esilnt/confirmLocalESLint request introduced in https://github.com/microsoft/vscode-eslint/commit/455cab65ec8b687d20d1efa53828a93110c1f2fd on the 2.1.x branch is the cause of the problem.

Upstream, they are still debating on the best way of doing this: https://github.com/microsoft/vscode-eslint/issues/1012. I don't think we can work around this by merely sending Allow every time since eslint is a mult-root server.

For anyone that still has this problem, I reverted back to 2.1.5, npm installed it, npm run compiled it, changed the lsp-eslint-server-command location and it works. This is a good workaround until this issue gets resolved :+1:

You can also add a dummy handler for the request to ignore it. Although I think we should manage this request properly at some point:

modified   clients/lsp-eslint.el
@@ -210,6 +210,10 @@ source.fixAll code action."
   "Open documentation."
   (browse-url url))

+(lsp-defun lsp-eslint--confirm-local-eslint ()
+  "Confirm Local Eslint"
+  nil) ;; TODO
+
 (defun lsp-eslint-apply-all-fixes ()
   "Apply all autofixes in the current buffer."
   (interactive)
@@ -248,7 +252,8 @@ source.fixAll code action."
   :multi-root t
   :notification-handlers (ht ("eslint/status" #'lsp-eslint-status-handler))
   :request-handlers (ht ("workspace/configuration" #'lsp-eslint--configuration)
-                        ("eslint/openDoc" 'lsp-eslint--open-doc))
+                        ("eslint/openDoc" 'lsp-eslint--open-doc)
+                        ("eslint/confirmLocalEslint" 'lsp-eslint--confirm-local-eslint))
   :server-id 'eslint
   :initialized-fn (lambda (workspace)
                     (with-lsp-workspace workspace

Other requests not handled? https://github.com/microsoft/vscode-eslint/pull/1053#issuecomment-681760741

You can also add a dummy handler for the request to ignore it. Although I think we should manage this request properly at some point:

modified   clients/lsp-eslint.el
@@ -210,6 +210,10 @@ source.fixAll code action."
   "Open documentation."
   (browse-url url))

+(lsp-defun lsp-eslint--confirm-local-eslint ()
+  "Confirm Local Eslint"
+  nil) ;; TODO
+
 (defun lsp-eslint-apply-all-fixes ()
   "Apply all autofixes in the current buffer."
   (interactive)
@@ -248,7 +252,8 @@ source.fixAll code action."
   :multi-root t
   :notification-handlers (ht ("eslint/status" #'lsp-eslint-status-handler))
   :request-handlers (ht ("workspace/configuration" #'lsp-eslint--configuration)
-                        ("eslint/openDoc" 'lsp-eslint--open-doc))
+                        ("eslint/openDoc" 'lsp-eslint--open-doc)
+                        ("eslint/confirmLocalEslint" 'lsp-eslint--confirm-local-eslint))
   :server-id 'eslint
   :initialized-fn (lambda (workspace)
                     (with-lsp-workspace workspace

I thought about doing this a while ago. It seems like they're working toward a solution upstream (https://github.com/microsoft/vscode-eslint/issues/1012#issuecomment-684870074), but it's not clear when it'll be finalized. So I think for now, we should go with this. A PR would be appreciated.

Reopening - they just published 2.1.0

2.1.10 even! I had to revert to 2.0.9, because the way ESlint libraries are handled now. It can't find eslint-prettier. This means that the flow described in the readme will probably have to be replicated in Emacs' LSP.

Here's the error I'm getting:

(node:308860) UnhandledPromiseRejectionWarning: Error: Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
Require stack:
- /path/to/__placeholder__.js
Referenced from: /path/to/.eslintrc.json
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.resolve (/path/to/node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadPlugin (/path/to/node_modules/eslint/lib/cli-engine/config-array-factory.js:959:39)
    at ConfigArrayFactory._loadExtendedPluginConfig (/path/to/node_modules/eslint/lib/cli-engine/config-array-factory.js:779:29)
    at ConfigArrayFactory._loadExtends (/path/to/node_modules/eslint/lib/cli-engine/config-array-factory.js:725:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/path/to/node_modules/eslint/lib/cli-engine/config-array-factory.js:660:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (/path/to/node_modules/eslint/lib/cli-engine/config-array-factory.js:596:20)
    at _normalizeObjectConfigData.next (<anonymous>)
(node:308860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:308860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is this the thread should be following if I'm having this issue? Whenever I open a JS file i get several of this error

    Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution
    Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution
    Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution
    Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution

I'm using lsp-mode I think through flychecker, I could be wrong as this part of emacs usage is a little complicated to me still. If I do flycheck-verify-setup this is my output.

lsp-mode seems to work for .vue files just fine.

Syntax checkers for buffer media-with-content.spec.js in js2-mode:

First checker to run:

  lsp (explicitly selected)
    - may enable: yes
    - may run:    t

@komali2 Have you tried it with vscode-eslint version 2.0.9? I had the same problem

    Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution

This is about the eslint libraries/modules, I presume.

Oh, huh, uh, these errors are coming to me from emacs. I think my stack looks like lsp-mode talking to my local node_modules eslint, which is version 7.1.0. I'm very confused, clearly. But in any case it's my impression that vscode isn't involved at all?

using 2.1.8 should work.

version 2.1.8 of what?

I don't use visual studio code, so I'm not sure how installing a different version of a vscode extension would help me.

@komali2 The installation path for the eslint LSP server is either through the VSCode extension, or through the repository at https://github.com/Microsoft/vscode-eslint.

In my experience, though, if you're using eslint plugins like prettier, you'll need to use 2.0.9, not 2.1.8. You could try out either version.

@komali2 the solution proposed here fixed your problem? I'm having the exactly same problem and I didn't understand how to fix those warning messages.

Installing version 2.1.8 of vscode-eslint worked for me.

I downloaded it from here: https://github.com/microsoft/vscode-eslint/releases/tag/release%2F2.1.8
I unzipped the .vsix file into .emacs.d/.cache/lsp/eslint/unzipped (but first removed the files that were there currently)
Then I started emacs again and it worked.

@zanemayo, I'll give it a go today, thanks for testing.

@zanemayo I did exactly what you said and seems to work just fine. I'll keep testing it during the day and report again later, thanks!

@zanemayo 's solution worked for me. Thanks zanemayo for the explicit instructions!

FTR I forced automatic installation to download and install 2.1.8 version. Thus, you will be able to install eslint by doing M-x lsp-install-server and it will install the right versions. This issue will be still open, but it will be with much lower priority since the default will just work.

@yyoncho, I pullet the latest lsp-mode from GH with straight and I don't see an option to install a eslint server. Should I do some extra steps to make it work?
image

By manually installing 2.1.8, I can confirm that `lsp-eslint-apply-all-fixes' works. For me, it does the job on the whole buffer. With version 2.1.10 it doesn't work.

@yyoncho, I pullet the latest lsp-mode from GH with straight and I don't see an option to install a eslint server. Should I do some extra steps to make it work?

You have to remove the manually installed one and reset all lsp-eslint related settings.

I have the same annoying warning (Warning (lsp-mode): Unknown request method: eslint/confirmESLintExecution ) on my setup. I've been trying versions 1.9.1, 2.1.8, 2.0.9 of vscode-eslint.

2.1.8 works for me

Strangely, using the 2.1.8 version pulled by install-lsp-server doesn't display this warning, but using the release/2.1.8 tag from the git repository does (using a clean clone and running npm i && npm run webpack

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sid-kap picture sid-kap  ·  5Comments

raxod502 picture raxod502  ·  5Comments

yyoncho picture yyoncho  ·  5Comments

michaelpj picture michaelpj  ·  4Comments

cprussin picture cprussin  ·  3Comments