Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

BUG: Does not run tsserver #72

Open
dsoltysiuk opened this issue May 24, 2023 · 7 comments
Open

BUG: Does not run tsserver #72

dsoltysiuk opened this issue May 24, 2023 · 7 comments

Comments

@dsoltysiuk
Copy link

dsoltysiuk commented May 24, 2023

Hey @jose-elias-alvarez, thanks for a great plugin for Neovim!

I noticed when I use this, it does not launch the tsserver

require("typescript").setup({
	debug = false, -- enable debug logging for commands
	go_to_source_definition = {
		fallback = true, -- fall back to standard LSP definition on failure
	},
	-- server = { -- pass options to lspconfig's setup method
	-- 	on_attach = ...,
	-- },
})

However, when I do lspconfig.setup("tsserver", {}) right after this code, it launches perfectly fine

I looked into the source code, and it seems like you are doing just that

tsserver.setup(resolvedConfig.server);

But for some reason, it does not work for me

@jose-elias-alvarez
Copy link
Owner

Does it work if you just use require("typescript").setup({})? Those additional options are just there as an example.

@aswils
Copy link

aswils commented May 28, 2023

I am experiencing something very similar. If I open a file directly with neovim, $ nvim myfile.ts, tsserver does not start. However, this only occurs if it is the first buffer I open. If I start neovim with a separate file and then edit myfile.ts, tssserver starts as expected.

This behavior occurs with a simple require('typescript').setup({})

@jose-elias-alvarez
Copy link
Owner

If either of you (or anyone else experiencing this issue) can put together a minimal reproduction (meaning something like this) I can look into this more, otherwise there's not much I can do.

@aswils
Copy link

aswils commented May 30, 2023

I have adapted the minimal script like so:

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
  local path_sep = on_windows and "\\" or "/"
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local ts_config = function()
  local ts = require("typescript")
  -- add only what you need to reproduce your issue
  ts.setup({})
end

local function load_plugins()
  -- only add other plugins if they are necessary to reproduce the issue
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      {
        "jose-elias-alvarez/typescript.nvim",
        {
          "neovim/nvim-lspconfig"
        },
        config = ts_config,
      },
    },
    config = {
      package_root = package_root,
      compile_path = compile_path,
    },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
  load_plugins()
  require("packer").sync()
else
  load_plugins()
  require("packer").sync()
end

I then navigated to a very very minimal node project, including a package.json, a tsconfig.json and a typescript file.

I opened the file with $ nvim -u path/to/config.lua myFile.ts and can confirm that the tsserver lsp exists but does not attach.

@dsoltysiuk
Copy link
Author

Thanks @aswils for bringing it further!

@jose-elias-alvarez
Copy link
Owner

I can reproduce your issue, but there's something weird about your minimal config, because I'm getting the same issue with nvim-lspconfig. This config works for me, both with this plugin and when using nvim-lspconfig directly:

local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local ts_config = function()
    require("typescript").setup({}) -- works
    -- require("lspconfig").tsserver.setup({}) -- also works
end

local function load_plugins()
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            {
                "jose-elias-alvarez/typescript.nvim",
                requires = {
                    "neovim/nvim-lspconfig",
                },
                config = ts_config,
            },
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

@aswils
Copy link

aswils commented Jun 17, 2023

Aha yes, I accidentally left out the requires in the packer startup, good catch!

Anyways, with your minimal config I can't reproduce the issue. It must be something with how I have lspconfig setup. Thanks for looking into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants