pmizio / typescript-tools.nvim

⚡ TypeScript integration NeoVim deserves ⚡
MIT License
1.48k stars 43 forks source link

[bug] Error in setup #59

Closed vitaliydolbilov closed 1 year ago

vitaliydolbilov commented 1 year ago

When I call require("typescript-tools").setup({})

I get the following error -

E5113: Error while calling lua chunk: ...gged/typescript-tools.nvim/lua/typescript-tools/init.lua:45: attempt to call field 'setup' (a nil value)
stack traceback: ...gged/typescript-tools.nvim/lua/typescript-tools/init.lua:45: in function 'setup'

I'm using vim-plug for plugins - have plenary & nvim-lspconfig defined before typescript-tools

tsc -v -> Version 4.7.2 nvim -v -> NVIM v.0.8.3 node -v -> v16.16.0

And lspconfig.tsserver.setup({}) (the nvim-lspconfig way) was working fine before and I did remove it

Thanks!

pmizio commented 1 year ago

It may be connected with vim-plug I never tested plugin with this package manager.

simoneeti commented 1 year ago

Same here!

FelipeSharkao commented 1 year ago

As requested, here's a minimal config where the bug happens

-- install lazy.nvim if it's not installed already
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    "williamboman/mason.nvim",
    "williamboman/mason-lspconfig.nvim",
    "neovim/nvim-lspconfig",
    {
        "pmizio/typescript-tools.nvim",
        dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
        opts = {},
    },
})

require("mason").setup()
require("mason-lspconfig").setup({
    ensure_installed = {},
})

local on_attach = function(_, bufnr)
    vim.keymap.keymap("n", "gh", vim.lsp.buf.hover, {
        noremap = true,
        silent = true,
        buffer = bufnr,
    })
end

require("typescript-tools").setup({
    on_attach = on_attach,
    settings = {
        separate_diagnostic_server = true,
        publish_diagnostic_on = "insert_leave",
        tsserver_plugins = {},
        tsserver_format_options = {},
        tsserver_file_preferences = {},
    },
})

tsc -v -> Version 4.7.4 nvim -v -> NVIM v.0.9.1 node -v -> v14.19.1, v20.2.0 (I've tested in both)

FelipeSharkao commented 1 year ago

I've been poking at the code. I added a this right before the setup call:

  print(vim.inspect(lspconfig[plugin_config.plugin_name]))

The result was this:

{
  _setup_buffer = <function 1>,
  commands = <1>{},
  document_config = {
    commands = <table 1>,
    default_config = {
      cmd = <function 2>,
      filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" },
      root_dir = <function 3>,
      single_file_support = true
    }
  },
  name = "typescript-tools",
  setup = <function 4>
}
{
  default_config = {
    cmd = <function 1>,
    filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" },
    root_dir = <function 2>,
    single_file_support = true
  }
}
Erro detectado ao processar /home/felipe/Downloads/minimal-cfg.lua:
E5113: Error while calling lua chunk: ...lazy/typescript-tools.nvim/lua/typescript-tools/init.lua:47: attempt to call field 'setup' (a nil value)
stack traceback:
    ...lazy/typescript-tools.nvim/lua/typescript-tools/init.lua:47: in function 'setup'
    /home/felipe/Downloads/minimal-cfg.lua:39: in main chunk

It seems that require("typescript-tools").setup is being called twice, so the second one doesn't hit lspconfig.configs.__newindex

pmizio commented 1 year ago

@FelipeSharkao Thanks for catching this! @simoneeti @vitaliydolbilov Can you retest this it's merged to master now!

simoneeti commented 1 year ago

working now! thanks