Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions lua/astrocommunity/pack/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
This plugin pack does the following:

- Adds `typescript`, `javascript`, `tsx`, and `jsdoc` Treesitter parsers
- Adds `vtsls` and `eslint` language server
- Adds `prettierd` formatter
- Adds [JSON language support](../json)
- Adds support for dap for JS
- Adds `vtsls` language server
- Adds [nvim-dap](https://github.com/mfussenegger/nvim-dap) support
- Adds [nvim-vtsls](https://github.com/yioneko/nvim-vtsls) for language specific tooling
- Adds [package-info.nvim](https://github.com/vuki656/package-info.nvim) for project package management
- Adds [nvim-lsp-file-operations](https://github.com/antosha417/nvim-lsp-file-operations) to handles file imports on rename or move within neo-tree
Expand All @@ -21,22 +19,6 @@ To enable HTML, CSS and Emmet support, you can add the `html-css` pack to your `
{ import = "astrocommunity.pack.html-css" }
```

## How do I disable Eslint format on save?

To opt out of the Eslint format on save behaviour, you can disable the autocmd setup with the pack with this:

```lua
return {
"AstroNvim/astrolsp",
optional = true,
opts = {
autocmds = {
eslint_fix_on_save = false,
},
},
}
```

## How do I customize `neotest-jest`?

To customize the `neotest-jest` plugin, you need to configure it like you would with any other plugin
Expand Down
52 changes: 0 additions & 52 deletions lua/astrocommunity/pack/typescript/dap.lua

This file was deleted.

161 changes: 24 additions & 137 deletions lua/astrocommunity/pack/typescript/init.lua
Original file line number Diff line number Diff line change
@@ -1,91 +1,20 @@
local function decode_json(filename)
-- Open the file in read mode
local file = io.open(filename, "r")
if not file then
return false -- File doesn't exist or cannot be opened
end

-- Read the contents of the file
local content = file:read "*all"
file:close()

-- Parse the JSON content
local json_parsed, json = pcall(vim.fn.json_decode, content)
if not json_parsed or type(json) ~= "table" then
return false -- Invalid JSON format
end
return json
end

local format_filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }

local function check_json_key_exists(json, ...) return vim.tbl_get(json, ...) ~= nil end
local lsp_rooter, prettierrc_rooter
local has_prettier = function(bufnr)
if type(bufnr) ~= "number" then bufnr = vim.api.nvim_get_current_buf() end
local rooter = require "astrocore.rooter"
if not lsp_rooter then
lsp_rooter = rooter.resolve("lsp", {
ignore = {
servers = function(client)
return not vim.tbl_contains({ "eslint", "ts_ls", "typescript-tools", "volar", "vtsls" }, client.name)
end,
},
})
end
if not prettierrc_rooter then
prettierrc_rooter = rooter.resolve {
".prettierrc",
".prettierrc.json",
".prettierrc.yml",
".prettierrc.yaml",
".prettierrc.json5",
".prettierrc.js",
".prettierrc.cjs",
"prettier.config.js",
".prettierrc.mjs",
"prettier.config.mjs",
"prettier.config.cjs",
".prettierrc.toml",
}
end
local prettier_dependency = false
for _, root in ipairs(require("astrocore").list_insert_unique(lsp_rooter(bufnr), { vim.fn.getcwd() })) do
local package_json = decode_json(root .. "/package.json")
if
package_json
and (
check_json_key_exists(package_json, "dependencies", "prettier")
or check_json_key_exists(package_json, "devDependencies", "prettier")
)
then
prettier_dependency = true
break
end
end
return prettier_dependency or next(prettierrc_rooter(bufnr))
end

local null_ls_formatter = function(params)
if vim.tbl_contains(format_filetypes, params.filetype) then return has_prettier(params.bufnr) end
return true
end
local conform_formatter = function(bufnr) return has_prettier(bufnr) and { "prettierd" } or {} end

return {
{ import = "astrocommunity.lsp.nvim-lsp-file-operations" },
{
"nvim-treesitter/nvim-treesitter",
optional = true,
opts = function(_, opts)
if opts.ensure_installed ~= "all" then
opts.ensure_installed =
require("astrocore").list_insert_unique(opts.ensure_installed, { "javascript", "typescript", "tsx", "jsdoc" })
opts.ensure_installed = require("astrocore").list_insert_unique(
opts.ensure_installed or {},
{ "javascript", "typescript", "tsx", "jsdoc" }
)
end
end,
},
{
"AstroNvim/astrolsp",
optional = true,
---@type AstroLSPOpts
opts = {
mappings = {
Expand All @@ -97,42 +26,30 @@ return {
},
},
},
autocmds = {
eslint_fix_on_save = {
cond = function(client) return client.name == "eslint" and vim.fn.exists ":EslintFixAll" > 0 end,
{
event = "BufWritePost",
desc = "Fix all eslint errors",
callback = function(args)
if vim.F.if_nil(vim.b[args.buf].autoformat, vim.g.autoformat, true) then vim.cmd.EslintFixAll() end
end,
},
},
},
---@diagnostic disable: missing-fields
config = {
vtsls = {
settings = {
typescript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
enumMemberValues = { enabled = true },
functionLikeReturnTypes = { enabled = true },
parameterNames = { enabled = "all" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
variableTypes = { enabled = true },
},
},
javascript = {
updateImportsOnFileMove = { enabled = "always" },
inlayHints = {
enumMemberValues = { enabled = true },
functionLikeReturnTypes = { enabled = true },
parameterNames = { enabled = "literals" },
parameterTypes = { enabled = true },
variableTypes = { enabled = true },
propertyDeclarationTypes = { enabled = true },
functionLikeReturnTypes = { enabled = true },
enumMemberValues = { enabled = true },
variableTypes = { enabled = true },
},
},
vtsls = {
Expand All @@ -145,50 +62,24 @@ return {
},
{
"williamboman/mason-lspconfig.nvim",
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "vtsls", "eslint" })
end,
},
{
"jay-babu/mason-null-ls.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "prettierd" })
if not opts.handlers then opts.handlers = {} end

opts.handlers.prettierd = function(source_name, methods)
local null_ls = require "null-ls"
for _, method in ipairs(methods) do
null_ls.register(null_ls.builtins[method][source_name].with { runtime_condition = null_ls_formatter })
end
end
end,
},
{
"stevearc/conform.nvim",
optional = true,
opts = function(_, opts)
if not opts.formatters_by_ft then opts.formatters_by_ft = {} end
for _, filetype in ipairs(format_filetypes) do
opts.formatters_by_ft[filetype] = conform_formatter
end
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "vtsls" })
end,
},
{
"jay-babu/mason-nvim-dap.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, { "js" })
opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "js" })
end,
},
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
optional = true,
opts = function(_, opts)
opts.ensure_installed = require("astrocore").list_insert_unique(
opts.ensure_installed,
{ "vtsls", "eslint-lsp", "prettierd", "js-debug-adapter" }
)
opts.ensure_installed =
require("astrocore").list_insert_unique(opts.ensure_installed or {}, { "vtsls", "js-debug-adapter" })
end,
},
{
Expand Down Expand Up @@ -229,19 +120,15 @@ return {
{
"echasnovski/mini.icons",
optional = true,
opts = {
file = {
[".eslintrc.js"] = { glyph = "󰱺", hl = "MiniIconsYellow" },
[".node-version"] = { glyph = "", hl = "MiniIconsGreen" },
[".prettierrc"] = { glyph = "îš´", hl = "MiniIconsPurple" },
[".yarnrc.yml"] = { glyph = "îš§", hl = "MiniIconsBlue" },
["eslint.config.js"] = { glyph = "󰱺", hl = "MiniIconsYellow" },
["package.json"] = { glyph = "", hl = "MiniIconsGreen" },
["tsconfig.json"] = { glyph = "", hl = "MiniIconsAzure" },
["tsconfig.build.json"] = { glyph = "", hl = "MiniIconsAzure" },
["yarn.lock"] = { glyph = "îš§", hl = "MiniIconsBlue" },
},
},
opts = function(_, opts)
if not opts.file then opts.file = {} end
opts.file[".nvmrc"] = { glyph = "", hl = "MiniIconsGreen" }
opts.file[".node-version"] = { glyph = "", hl = "MiniIconsGreen" }
opts.file["package.json"] = { glyph = "", hl = "MiniIconsGreen" }
opts.file["tsconfig.json"] = { glyph = "", hl = "MiniIconsAzure" }
opts.file["tsconfig.build.json"] = { glyph = "", hl = "MiniIconsAzure" }
opts.file["yarn.lock"] = { glyph = "îš§", hl = "MiniIconsBlue" }
end,
},
{
"nvim-neotest/neotest",
Expand Down