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] Null-ls root not working correctly #59

Closed tomaskallup closed 3 years ago

tomaskallup commented 3 years ago

FAQ

Issues

Neovim Version

NVIM v0.6.0-dev+15-g3de777d25

Steps to reproduce

Using following folder structure:

$ tree
website
├── backend
│   ├── src
│   │   └── index.ts
│   └── tsconfig.json
└── frontend
    ├── src
    │   └── index.ts
    └── tsconfig.json

Opening frontend/src/index.ts, my nvim is setup to set my pwd to the root dir (website in the tree above) because it contains .git folder. How ever my tsserver setup is set to find tsconfig.json as root, so it's setup inside frontend dir. It seems like null-ls or nvim-lsp-ts-utils doesn't follow tsserver and I can't find the option I need to set.

Expected behavior

Null-ls should use same root dir as tsserver for eslint.

Actual behavior

I get Parsing error: Cannot read file 'website/tsconfig.json'., but it should be looking for website/frontend/tsconfig.json.

Debug log

No response

Help

Yes, but I don't know how to start. I would need guidance

Implementation help

No response

jose-elias-alvarez commented 3 years ago

Can you tell me what feature this is related to? A couple of features do need to get the project's root, but this plugin bases the root on tsconfig.json, and I'm not sure what feature could be causing the error message you're seeing, since we don't do anything with the file except check if it exists.

tomaskallup commented 3 years ago

I feel like the error is comming from eslint, however it seems like the diagnostics stopped working completely once I fiddled with the configuration. Here is my config:

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

    -- defaults
    ts_utils.setup {
        disable_commands = false,
        debug = false,
        enable_import_on_completion = false,
        import_on_completion_timeout = 5000,
        -- eslint
        eslint_enable_code_actions = true,
        eslint_enable_disable_comments = true,
        eslint_bin = "eslint_d",
        eslint_config_fallback = nil,

        -- experimental settings!
        -- eslint diagnostics
        eslint_enable_diagnostics = true,
        eslint_diagnostics_debounce = 250,
        -- formatting
        enable_formatting = true,
        formatter = "prettierd",
        formatter_args = {"--stdin-filepath", "$FILENAME"},
        format_on_save = false,
        no_save_after_format = false,
        -- parentheses completion
        complete_parens = false,
        signature_help_in_parens = false,

        update_imports_on_move = true,
        require_confirmation_on_move = true
    }

    -- required to enable ESLint code actions and formatting
    ts_utils.setup_client(client)
end

It says null-ls is atteched to buffer, but I'm not getting any errors/warnings.

jose-elias-alvarez commented 3 years ago

I just copy-pasted your config and it's working fine (though you have some removed settings that you might want to clean up). I'm not sure if ESLint creates errors related to tsconfig.json, but could you try setting debug = true and post the output? Also, could you try running eslint_d --stop from the command line to rule that out, too?

tomaskallup commented 3 years ago

I checked in a different repo and everything works there (but that one has tsconfig.json in the root). I'll try to use debug mode and report back. eslint_d --stop seems to hang, is that expected? With eslint_d stop it seems to do something.

jose-elias-alvarez commented 3 years ago

Yep, sorry, that was my mistake. The correct command is eslint_d stop. Could you also verify whether fully removing the plugin solves the issue?

tomaskallup commented 3 years ago

Output with debug: true for nvim-lsp-ts-utils: image

Output with debug: true for null-ls: image

tomaskallup commented 3 years ago

It seems like the error does indeed come from null-ls/eslint, but for some reason it stopped showing up as diagnostic

jose-elias-alvarez commented 3 years ago

I see, I don't know too much about this integration, but does everything work as expected when you run eslint_d + the name of the file from the command line from the project root?

tomaskallup commented 3 years ago

No, it seems like eslint_d throws the same error. Running it from inside the apis folder makes it work. Which is what I think is the correct solution, eslint needs to be started from the folder containing tsconfig.json to run properly.

jose-elias-alvarez commented 3 years ago

Well, this seems to be fundamentally an issue with ESLint, as described in this issue. Could you try the workaround described there and see if that fixes it?

tomaskallup commented 3 years ago

Ah, that fixed it! Thanks a lot, guess I should've done a better research about the issue, sorry about that.