nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

typescriptreact file type does not start lsp automatically

Open hemedani opened this issue 2 years ago • 5 comments

Description

I have this config for tsserver and denolsp:

-- local on_attach = require("lsp.lsp-setup").on_attach
local setup = require("lsp.lsp-setup")
local nvim_lsp = require("lspconfig")

local function file_exists(name)
  local f = io.open(name, "r")
  if f ~= nil then
    io.close(f)
    return true
  else
    return false
  end
end

if file_exists(os.getenv("PWD") .. "/deno.json") or file_exists(os.getenv("PWD") .. "/deno.jsonc") then
  nvim_lsp.denols.setup({
    capabilities = setup.capabilities,
    autostart = true,
    cmd = { "deno", "lsp" },
    on_attach = require("lsp.lsp-attach").on_attach,
    filetypes = {
      "javascript",
      "javascriptreact",
      "javascript.jsx",
      "typescript",
      "typescriptreact",
      "typescript.tsx",
    },
    init_options = {
      enable = true,
      lint = true,
      unstable = true,
    },
    root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc"),
  })
else
  nvim_lsp.tsserver.setup({
    capabilities = setup.capabilities,
    autostart = true,
    filetypes = {
      "javascript",
      "javascriptreact",
      "javascript.jsx",
      "typescript",
      "typescriptreact",
      "typescript.tsx",
    },
    on_attach = require("lsp.lsp-attach").on_attach, -- This makes sure tsserver is not used for formatting (I prefer prettier)
    settings = { documentFormatting = false },
    root_dir = nvim_lsp.util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"),
  })
end

LSP starts automatically in any ts or js files Screen Shot 1402-05-11 at 15 29 36

but in tsx files it does not start automatically Screen Shot 1402-05-11 at 15 32 03

Neovim version

NVIM v0.10.0-dev-751+gd086bc1e8-Homebrew Build type: Release LuaJIT 2.1.0-beta3 Run "nvim -V1 -v" for more info

Nvim-lspconfig version

No response

Operating system and version

macOS 12.6.7

Affected language servers

denols and tsserver

Steps to reproduce

I'm writing a full document here https://github.com/MiaadTeam/lesvim

Actual behavior

does not start automatically tsserver or denols on tsx files.

Expected behavior

No response

Minimal config

https://github.com/MiaadTeam/lesvim

LSP log

https://gist.github.com/hemedani/0af44169fdeb0c7de850d0b58062bde7#file-lsp-log

hemedani avatar Aug 02 '23 12:08 hemedani

Same issue for me on:

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

aanari avatar Aug 07 '23 17:08 aanari

hmm you have a if to check start deno or tsserver . the deno run the tsserver not run ? . I can't reproduce with default tsserver config.

glepnir avatar Aug 08 '23 06:08 glepnir

please check and fixed the issue also in the typescriptreact file type, we should use w! for the first time to save the files.

hemedani avatar Aug 09 '23 10:08 hemedani

I had a similar issue using lazy.nvim and lsp-zero.

typescriptreact files would not start tsserver and attach it to the buffer. Regular typescript files however where working fine. The same was also true for saving where a typescriptreact file would require force writing to save the the file.

For me it turned out the problem was the usage of treesitter with additional plugins. In particular using p00f/nvim-ts-rainbow was creating an issue (at least disabling that plugin fixed the issue).

You could potentially quickly validating this by disabling treesitter temporarily.

Error message from the neovim logs
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21: Error executing lua: ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:22: BufReadPost Autocommands for "*"..FileType
Autocommands for "*": Vim(append):Error executing lua callback: ...im/0.9.1/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 538 for language tsx
stack traceback:
        [C]: in function '_ts_parse_query'
        ...im/0.9.1/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'get_query'
        .../nvim/lazy/nvim-treesitter/lua/nvim-treesitter/query.lua:108: in function 'get_query'
        ...p/.local/share/nvim/lazy/nvim-ts-rainbow/lua/rainbow.lua:26: in function 'is_supported'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:387: in function 'is_enabled'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:507: in function 'attach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>
        [C]: in function 'nvim_cmd'
        ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:22: in function <...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21: in function <...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:22: in function <...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21: in function <...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21: in function <...brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:10>

Someone was also facing a similar issue with treesitter

hmttrp avatar Aug 15 '23 06:08 hmttrp

I also have similar issue using lazy.nvim

  {
    "neovim/nvim-lspconfig",
    event = { "BufReadPre", "BufNewFile" },
    dependencies = {
      {
        "folke/neodev.nvim",
        config = function()
          require("neodev").setup()
        end
      },
      "williamboman/mason.nvim",
      "williamboman/mason-lspconfig.nvim",
      {
        "j-hui/fidget.nvim",
        branch = "legacy"
      },
      {
        "https://git.sr.ht/~whynothugo/lsp_lines.nvim",
        config = function()
          require("lsp_lines").setup()
        end,
      },
    },
    config = function()
      require("plugin.config.lsp").setup()
    end,
    cmd = { "Mason" }
  },

plugin.config.lsp

coderj001 avatar Oct 25 '23 13:10 coderj001