jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

[BUG] LSP looking for module that does not exist #52

Closed jonleopard closed 3 years ago

jonleopard commented 3 years ago

FAQ

Issues

Neovim Version

0.5.0

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

LSP is throwing this error when I open up a file: Error: cannot read config file: ...project/node_modules/eslint-config-prettier/index.js

I do not have this package installed, so I don't know what is telling the LSP to look for this module.

Here is my .lua config for nvim-lsp-ts-utils/null-ls

local nvim_lsp = require("lspconfig")

-- Make sure your LSP are installed globally.
-- npm install -g typescript typescript-language-server diagnostic-languageserver eslint_d

-- enable null-ls integration (optional)
require("null-ls").config {}
require("lspconfig")["null-ls"].setup {}

nvim_lsp.tsserver.setup {
  capabilities = capabilities,
  filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" },
    on_attach = function(client, bufnr)
        -- disable tsserver formatting if you plan on formatting via null-ls
        client.resolved_capabilities.document_formatting = false
        -- format on save
        vim.cmd("autocmd BufWritePost <buffer> lua vim.lsp.buf.formatting()")

        local ts_utils = require("nvim-lsp-ts-utils")

        -- defaults
        ts_utils.setup {
            debug = false,
            disable_commands = false,
            enable_import_on_completion = true,
            import_all_timeout = 5000, -- ms

            -- eslint
            eslint_enable_code_actions = true,
            eslint_enable_disable_comments = true,
            eslint_bin = "eslint_d",
            eslint_config_fallback = nil,
            eslint_enable_diagnostics = true,

            -- formatting
            enable_formatting = true,
            formatter = "eslint_d",
            formatter_config_fallback = nil,

            -- parentheses completion
            complete_parens = true,
            signature_help_in_parens = true,

            -- update imports on file move
            update_imports_on_move = true,
            require_confirmation_on_move = false,
            watch_dir = nil,
        }

        -- required to fix code action ranges
        ts_utils.setup_client(client)

        -- no default maps, so you may want to define some here
        local opts = {silent = true}
        vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize<CR>", opts)
        vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", opts)
        vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":TSLspRenameFile<CR>", opts)
        vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", ":TSLspImportAll<CR>", opts)
    end
}

For reference, I have the following packages installed and configs:

.eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "prettier"
    ]
}

.prettierrc.json

{
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": false,
  "singleQuote": true
}

I also have these installed in the project:

    "eslint-plugin-react": "^7.24.0",
    "prettier": "2.3.2",
    "prettier-eslint": "^13.0.0",

Globally, I have the following:

/usr/local/lib
├── diagnostic-languageserver@1.12.0
├── eslint_d@10.1.3
├── neovim@4.10.0
├── npm-check-updates@11.8.3
├── npm@7.20.0
├── typescript-language-server@0.5.4
└── typescript@4.3.5

Help

No

Implementation help

No response

jose-elias-alvarez commented 3 years ago

Could you try setting debug = true in your config and post the output from :messages? Does eslint_d run from the command line, and did you try running eslint_d stop?

To be clear, when you say that "LSP is throwing an error", do you mean that Neovim itself is throwing an error (meaning it's visible in :messages) or that you see an error diagnostic at the top of the file? (If relevant, a screenshot might help.)

jonleopard commented 3 years ago

The message is appearing at the top of the file, so I guess that means its an error diagnostic? I put debug = true in the config, and also tried eslint_d stop. Now the message is showing: Screenshot 2021-07-29 at 20 52 02

Nothing shows up when I type :messages.

I removed "prettier" from my eslintrc since it was complaining that it couldn't extend that. I'm either really confused as to how to properly set up eslint/prettier, or something else is going on. Thanks for your help!

jonleopard commented 3 years ago

Yah im 80% sure this is a config issue on my end. I can't get the my prettier/eslint configuration to work with eslint_d. The error in the above screenshot is in fact coming from eslint_d, but no formatting is working. I need to do some further reading on how to get these tools to work nice together.

Sorry for the noise!

jose-elias-alvarez commented 3 years ago

I recommend taking a look at this page – it's how I set up the formatting integration.