Open dsoltysiuk opened 1 year ago
Does it work if you just use require("typescript").setup({})
? Those additional options are just there as an example.
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({})
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.
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.
Thanks @aswils for bringing it further!
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
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.
Hey @jose-elias-alvarez, thanks for a great plugin for Neovim!
I noticed when I use this, it does not launch the
tsserver
However, when I do
lspconfig.setup("tsserver", {})
right after this code, it launches perfectly fineI looked into the source code, and it seems like you are doing just that https://github.com/jose-elias-alvarez/typescript.nvim/blob/f66d4472606cb24615dfb7dbc6557e779d177624/src/lsp.ts#L29 But for some reason, it does not work for me