local bin_name = "typescript-language-server"
local cmd = { bin_name, "--stdio" }

local root_files = {
  "package.json",
  ".git",
}

vim.api.nvim_create_autocmd("FileType", {
  pattern = "typescript,javascript,javascriptreact,typescriptreact",
  callback = function()
    vim.lsp.start({
      name = "typescript-language-server",
      cmd = cmd,
      root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
      settings = {
        init_options = {
          completionDisableFilterText = true,
          hostInfo = 'neovim',
          preferences = {
            includeCompletionsForModuleExports = false
          },
        },
      },
    })
  end,
})
