aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lsp/tsgo.lua
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-10-20 20:55:26 +0300
committerawy <awy@awy.one>2025-10-20 20:55:26 +0300
commit662dafc52b2c8a9426bb2197ab9246a8cda318e4 (patch)
treef9d1f20e3864360bf941fd6bc02848ed77b037a8 /.config/nvim/lsp/tsgo.lua
parent8131d9f2898b991a2d2c7a2ac601ce9e07cc9c9f (diff)
downloadhyprdots-662dafc52b2c8a9426bb2197ab9246a8cda318e4.tar.gz
nvqw
Diffstat (limited to '.config/nvim/lsp/tsgo.lua')
-rw-r--r--.config/nvim/lsp/tsgo.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/.config/nvim/lsp/tsgo.lua b/.config/nvim/lsp/tsgo.lua
new file mode 100644
index 0000000..b99c731
--- /dev/null
+++ b/.config/nvim/lsp/tsgo.lua
@@ -0,0 +1,42 @@
+---@brief
+---
+--- https://github.com/microsoft/typescript-go
+---
+--- `typescript-go` is experimental port of the TypeScript compiler (tsc) and language server (tsserver) to the Go programming language.
+---
+--- `tsgo` can be installed via npm `npm install @typescript/native-preview`.
+---
+--- ### Monorepo support
+---
+--- `tsgo` supports monorepos by default. It will automatically find the `tsconfig.json` or `jsconfig.json` corresponding to the package you are working on.
+--- This works without the need of spawning multiple instances of `tsgo`, saving memory.
+---
+--- 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.
+---
+
+---@type vim.lsp.Config
+return {
+ cmd = { 'tsgo', '--lsp', '--stdio' },
+ filetypes = {
+ 'javascript',
+ 'javascriptreact',
+ 'javascript.jsx',
+ 'typescript',
+ 'typescriptreact',
+ 'typescript.tsx',
+ },
+ root_dir = function(bufnr, on_dir)
+ -- The project root is where the LSP can be started from
+ -- As stated in the documentation above, this LSP supports monorepos and simple projects.
+ -- We select then from the project root, which is identified by the presence of a package
+ -- manager lock file.
+ local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock' }
+ -- Give the root markers equal priority by wrapping them in a table
+ root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
+ or vim.list_extend(root_markers, { '.git' })
+ -- We fallback to the current working directory if no project root is found
+ local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
+
+ on_dir(project_root)
+ end,
+}