pmizio / typescript-tools.nvim

⚡ TypeScript integration NeoVim deserves ⚡
MIT License
1.39k stars 41 forks source link

Move to new file not working using FZF Lua #231

Open marcoSven opened 7 months ago

marcoSven commented 7 months ago

"Move to new file" not working with typescript-tools and FZF Lua Code actions.

require("typescript-tools").setup {
  settings = {
      tsserver_logs = "verbose",
      code_lens_mode = "all",
      tsserver_file_preferences = {
        includeCompletionsForModuleExports = true,
        includeInlayParameterNameHints = "all",
        includeInlayParameterNameHintsWhenArgumentMatchesName = true,
        includeInlayFunctionParameterTypeHints = true,
        includeInlayVariableTypeHints = true,
        includeInlayPropertyDeclarationTypeHints = true,
        includeInlayFunctionLikeReturnTypeHints = true,
        includeInlayEnumMemberValueHints = true,
        importModuleSpecifierPreference = "non-relative",
        quotePreference = "auto"
      },
      separate_diagnostic_server = true,
      publish_diagnostic_on = "insert_leave",
      expose_as_code_action = "all",
      tsserver_max_memory = "auto",
      complete_function_calls = true,
      jsx_close_tag = {
        enable = true,
        filetypes = {"javascriptreact", "typescriptreact"}
      }
    }

"Move to new file" is working with lspconfig and FZF Lua

lspconfig["tsserver"].setup({})

This is a similar issue https://github.com/ibhagwan/fzf-lua/issues/1007

To reproduce the issue with typescript-tools

require("fzf-lua").lsp_code_actions {
  previewer = true,
  winopts = {
    width = 0.5,
    height = 0.5,
    preview = {horizontal = "down:50%", horizontal = "right:50%"}
  }
}

The issue can be resolved by disabling the previewer

require("fzf-lua").lsp_code_actions {
  previewer = false,
  winopts = {
    width = 0.5,
    height = 0.5,
  }
}

Please see comment

pmizio commented 7 months ago

I use telescope so I previously didn't bump into this problem. I'll look into it

yavorski commented 6 months ago

Maybe this is related too did not know where to properly report it ... https://github.com/ibhagwan/fzf-lua/issues/949 https://github.com/ibhagwan/fzf-lua/issues/949#issuecomment-1972838951

yavorski commented 6 months ago

I believe this https://github.com/ibhagwan/fzf-lua/issues/949#issuecomment-1973624200 from @ibhagwan about related issue would be useful here:

In order to display the diff for the code action preview, if the action doesn't contain the workspace edit section, fzf-lua will send a codeAction/resolve request to the LSP server, the first call works (as you found out) but any subsequent call is bugged (and returns nil) with typescript-tools.nvim. If fzf-lua sends a synchrounous request with:

:FzfLua lsp_code_actions previewer=codeaction_native

typescript-tools.nvim returns a nil action, with the latest commit, fzf-lua will fallback to the original unresolved action and display this message (no error but also no diff): image

If using the neovim builtin (non-native) previewer, fzf-lua will send an async LSP request and waits for a callback which never returns, e.g.:

:FzfLua lsp_code_actions previewer=codeaction

Resulting in: image

Originally posted by @ibhagwan in https://github.com/ibhagwan/fzf-lua/issues/949#issuecomment-1973624200

ibhagwan commented 6 months ago

I use telescope so I previously didn't bump into this problem. I'll look into it

@pmizio, the reason you didn’t bump into is probably because this requires using code action previews, I believe Telescope doesn’t come builtin with code action previews unless you’re using: https://github.com/aznhe21/actions-preview.nvim

Based on my testing this issue only happens after sending a codeAction/resolve request which doesn’t get called unless you’re using fzf-lua with preview or the above Telescope extension.

ibhagwan commented 6 months ago

Oh and @marcoSven, I’m pretty sure the "Move to new file" will work if you disable the code actions previewer by setting lsp.code_actions.previewer=false at setup.

marcoSven commented 6 months ago

@ibhagwan yes that is what I did, without preview "Move to new file" is working.