tsgo.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ---@brief
  2. ---
  3. --- https://github.com/microsoft/typescript-go
  4. ---
  5. --- `typescript-go` is experimental port of the TypeScript compiler (tsc) and language server (tsserver) to the Go programming language.
  6. ---
  7. --- `tsgo` can be installed via npm `npm install @typescript/native-preview`.
  8. ---
  9. --- ### Monorepo support
  10. ---
  11. --- `tsgo` supports monorepos by default. It will automatically find the `tsconfig.json` or `jsconfig.json` corresponding to the package you are working on.
  12. --- This works without the need of spawning multiple instances of `tsgo`, saving memory.
  13. ---
  14. --- It is recommended to use the same version of TypeScript in all packages, and therefore have it available in your workspace root. The location of the TypeScript binary will be determined automatically, but only once.
  15. ---
  16. ---@type vim.lsp.Config
  17. return {
  18. cmd = { "tsgo", "--lsp", "--stdio" },
  19. filetypes = {
  20. "javascript",
  21. "javascriptreact",
  22. "javascript.jsx",
  23. "typescript",
  24. "typescriptreact",
  25. "typescript.tsx",
  26. },
  27. root_dir = function(bufnr, on_dir)
  28. -- The project root is where the LSP can be started from
  29. -- As stated in the documentation above, this LSP supports monorepos and simple projects.
  30. -- We select then from the project root, which is identified by the presence of a package
  31. -- manager lock file.
  32. local root_markers = { "package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock" }
  33. -- Give the root markers equal priority by wrapping them in a table
  34. root_markers = vim.fn.has("nvim-0.11.3") == 1 and { root_markers, { ".git" } }
  35. or vim.list_extend(root_markers, { ".git" })
  36. -- We fallback to the current working directory if no project root is found
  37. local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
  38. on_dir(project_root)
  39. end,
  40. }