Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescriptreact file type does not start lsp automatically #2744

Open
hemedani opened this issue Aug 2, 2023 · 6 comments
Open

typescriptreact file type does not start lsp automatically #2744

hemedani opened this issue Aug 2, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@hemedani
Copy link

hemedani commented Aug 2, 2023

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 hemedani added the bug Something isn't working label Aug 2, 2023
@aanari
Copy link

aanari commented Aug 7, 2023

Same issue for me on:

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

@glepnir
Copy link
Member

glepnir commented Aug 8, 2023

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.

@hemedani
Copy link
Author

hemedani commented Aug 9, 2023

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

@hmttrp
Copy link

hmttrp commented Aug 15, 2023

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

@coderj001
Copy link

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

@justinmk
Copy link
Member

send a pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants