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

Custom eslint settings not used #3211

Closed
ClementDreptin opened this issue Jun 20, 2024 · 9 comments
Closed

Custom eslint settings not used #3211

ClementDreptin opened this issue Jun 20, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@ClementDreptin
Copy link

ClementDreptin commented Jun 20, 2024

Description

Passing custom settings to require("lspconfig").eslint.setup() doesn't seem to have any effect.

Config

-- Loaded with lazy.nvim
return {
  "neovim/nvim-lspconfig",
  config = function()
    require("lspconfig").eslint.setup({
      settings = {
        enable = false,
      },
    })
  end
}

Expected behavior

I expect eslint not to report any diagnostics.

Actual behavior

Eslint still reports diagnostics.

What I tried

  • This doesn't seem to be an issue with vscode-eslint-language-server because the enable option works as expected within vscode.
  • I tried to start from a LazyVim config and add custom settings to the eslint lsp, and I have the same problem.
  • I tried to pass different shapes of objects to setup, and nothing made a difference.
    • { settings = { enable = false } }
    • { settings = { eslint = { enable = false } } }
    • { enable = false }
    • { eslint = { enable = false } }

I don't know if this is a bug, or if I'm missing something. If this is just a misunderstanding of the configuration on my part, I'm sorry.

@ClementDreptin ClementDreptin added the bug Something isn't working label Jun 20, 2024
@martenmatrix
Copy link

I've also tried these solutions, however they did not seem to have an effect.

@legobeat
Copy link

legobeat commented Jul 10, 2024

I can not seem to get either tsserver or gopls to recognize overriding cmd.

For example, with this config:

require('lspconfig')['tsserver'].setup{
    on_attach = on_attach,
    flags = lsp_flags,
    settings = {
      ["logVerbosity"] = 'verbose'
    },
    cmd = "sh -c 'sleep 1000'",
    root_dir = require'lspconfig/util'.root_pattern('tsconfig.json', 'jsconfig.json', 'package.json', '.git', vim.fn.getcwd()),
}

, it behaves exactly as it does when the typescript-language-server command is missing. No process is started and no errors in LspLog.

Removing it and no LSP is configured.

If a typescript-language-server is added in PATH, then that gets executed regardless of the above configuration (with errors in LspLog as expected if any should appear). I can observe in LspInfo that it's started with the default command and parameter regardless.

Maybe related? #2797

@ClementDreptin
Copy link
Author

ClementDreptin commented Jul 10, 2024

Maybe related? #2797

I'm not sure because eslint seems to be the only one not using the custom config. I have a custom config for lua_ls and nvim-lspconfig passes it with no issues.

@Delerme
Copy link

Delerme commented Jul 17, 2024

The setting you're looking for might be validate based on the language server settings: https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L217

Setting validate = 'off' worked for me

@ClementDreptin
Copy link
Author

I just tested validate and can confirm it works for me as well, so some settings seem to be used after all.

I wasn't actually looking for a way to disable eslint though, that's what I did in my example to make it easy to understand. I was trying to change the value of run to run eslint onSave instead of onType because the LSP is unacceptably slow on my machine.

@Delerme
Copy link

Delerme commented Jul 18, 2024

Ah yea, I was looking for the same thing and that's how I found this issue

What I discovered is since Neovim 10 the lsp is using pull diagnostics so the setting doesn't have an effect, because Neovim is explicitly requesting diagnostics when typing. Instead, you'll have to adjust the rate of neovim asking for diagnostics. I found two settings for the lsp setup function: allow_incremental_sync and debounce_text_changes

Check out :h lsp-clientand look at the flags params. For eslint in particular, turning off incremental sync and setting debounce to 1s worked well for me.

An alternative I didn't try was to change the capabilities in the setup to disable pull diagnostics for eslint, that way the run setting is used. If you try this approach, let me know how it goes!

@ClementDreptin
Copy link
Author

ClementDreptin commented Jul 18, 2024

Instead, you'll have to adjust the rate of neovim asking for diagnostics. I found two settings for the lsp setup function: allow_incremental_sync and debounce_text_changes

I just tried and it works great! I was supposed to do something like this, right?

require("lspconfig").eslint.setup({
  flags = {
    allow_incremental_sync = false,
    debounce_text_changes = 1000,
  },
})

An alternative I didn't try was to change the capabilities in the setup to disable pull diagnostics for eslint, that way the run setting is used. If you try this approach, let me know how it goes!

I can try but I what would I need to set the capabilities to? I tried to print the default capabilities returned by cmp-nvim-lsp and that's what I have

{                                                                                                                                                       
  textDocument = {                                                                                                                                      
    completion = {                                                                                                                                      
      completionItem = {                                                                                                                                
        commitCharactersSupport = true,                                                                                                                 
        deprecatedSupport = true,                                                                                                                       
        insertReplaceSupport = true,                                                                                                                    
        insertTextModeSupport = {                                                                                                                       
          valueSet = { 1, 2 }                                                                                                                           
        },                                                                                                                                              
        labelDetailsSupport = true,                                                                                                                     
        preselectSupport = true,                                                                                                                        
        resolveSupport = {                                                                                                                              
          properties = { "documentation", "detail", "additionalTextEdits", "sortText", "filterText", "insertText", "textEdit", "insertTextFormat", "inse
rtTextMode" }                                                                                                                                           
        },                                                                                                                                              
        snippetSupport = true,                                                                                                                          
        tagSupport = {                                                                                                                                  
          valueSet = { 1 }                                                                                                                              
        }                                                                                                                                               
      },                                                                                                                                                
      completionList = {                                                                                                                                
        itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data" }                                                
      },                                                                                                                                                
      contextSupport = true,                                                                                                                            
      dynamicRegistration = false,                                                                                                                      
      insertTextMode = 1                                                                                                                                
    }                                                                                                                                                   
  }                                                                                                                                                     
}

I expected to have a diagnostic table inside of the textDocument table.

@Delerme
Copy link

Delerme commented Jul 18, 2024

I just tried and it works great! I was supposed to do something like this, right?

Yes! Glad it works

I expected to have a diagnostic table inside of the textDocument table

Hmm yea I think the lsp checks for diagnosticProvider based on this code: https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp.lua#L66

So my plan was to get eslint's default capabilities, remove that one, and pass that to setup

@ClementDreptin
Copy link
Author

Hey, sorry for the delay, I've been pretty busy.

I wasn't able to mess around with the eslint lsp capabilities but I got a solution to my initial problem. I saw that you created an issue on the neovim repo so I think the conversation can continue there and we can close this issue now.

Thanks again for your very valuable help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants