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] Conflict with null-ls formatting config #61

Closed jason0x43 closed 3 years ago

jason0x43 commented 3 years ago

FAQ

Issues

Neovim Version

v0.6.0-dev+d628e4250

Steps to reproduce

Configure null_ls prettier source, excluding typescript from the filetypes list:

  sources = {
    null_ls.builtins.formatting.prettier.with({
      -- prettier for TS/JS is managed by nvim-lsp-ts-utils
      filetypes = { 'markdown', 'html', 'json', 'yaml', 'css' },
    }),
    null_ls.builtins.formatting.stylua,
  }

Use nvim-lsp-ts-utils.

Expected behavior

Running :lua vim.lsp.buf.formatting() should format an open Typescript buffer.

Actual behavior

Running :lua vim.lsp.buf.formatting() has no apparent affect. The debug log shows no output for the formatting call.

Formatting works if:

1) the prettier source config is entirely removed from from the null-ls config data

  sources = {
    null_ls.builtins.formatting.stylua,
  }

or 2) "typescript" is added to the list of filetypes

  sources = {
    null_ls.builtins.formatting.prettier.with({
      -- prettier for TS/JS is managed by nvim-lsp-ts-utils
      filetypes = { 'markdown', 'html', 'json', 'yaml', 'css', 'typescript' },
    }),
    null_ls.builtins.formatting.stylua,
  }

Either of these requirements makes sense, but this issue only came up in the past week or two. Previously, TypeScript formatting worked with my existing setup (a prettier source config for null-ls that didn't include TS, and nvim-lsp-ts-utils configured to support formatting with prettier).

Did something change in this plugin or null-ls recently that causes an existing null-ls source config to override the settings provided by nvim-lsp-ts-utils?

Debug log

No response

Help

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

Implementation help

I'd be happy to submit a PR if I determined specifically what the issue was (assuming to behavior is unexpected).

jason0x43 commented 3 years ago

Considering the default null-ls config for prettier, I'm guessing this is expected behavior, and my existing customized filetype list for prettier was unnecessary. However, the fact that it used to work and no longer does implies that something may have changed unintentionally. 🤷

jose-elias-alvarez commented 3 years ago

As you've guessed, this was caused by a recent change and is also unintentional. Essentially, under the hood this plugin is now using null-ls built-ins for formatting and diagnostics, to avoid having to maintain two separate (and nearly identical) sources for each program. As a consequence, you're not able to register the same built-in twice, which (I think) is causing the behavior you are seeing.

In the near future I plan on moving diagnostics and formatting entirely to null-ls and have this plugin only provide code actions (which are a little too heavy and language-specific to move to the null-ls core). In your situation, I recommend simply using the null-ls built-in directly and skipping the integration in this plugin.

jason0x43 commented 3 years ago

Sounds good 👍