-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pack): modularization of all typescript packs
- Loading branch information
Showing
6 changed files
with
270 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1 @@ | ||
local utils = require "astrocommunity.utils" | ||
|
||
return { | ||
{ import = "astrocommunity.pack.json" }, | ||
{ | ||
"nvim-treesitter/nvim-treesitter", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table or string "all". | ||
if not opts.ensure_installed then | ||
opts.ensure_installed = {} | ||
elseif opts.ensure_installed == "all" then | ||
return | ||
end | ||
-- Add the required file types to opts.ensure_installed. | ||
utils.list_insert_unique(opts.ensure_installed, { "javascript", "typescript", "tsx" }) | ||
end, | ||
}, | ||
{ | ||
"williamboman/mason-lspconfig.nvim", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table. | ||
if not opts.ensure_installed then opts.ensure_installed = {} end | ||
-- Add tsserver to opts.ensure_installed using vim.list_extend. | ||
utils.list_insert_unique(opts.ensure_installed, "denols") | ||
end, | ||
}, | ||
{ | ||
"jay-babu/mason-nvim-dap.nvim", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table. | ||
if not opts.ensure_installed then opts.ensure_installed = {} end | ||
-- Add to opts.ensure_installed using table.insert. | ||
utils.list_insert_unique(opts.ensure_installed, "js") | ||
end, | ||
}, | ||
{ | ||
"mfussenegger/nvim-dap", | ||
ft = { "ts", "js", "tsx", "jsx" }, | ||
enabled = true, | ||
dependencies = { | ||
{ | ||
"mxsdev/nvim-dap-vscode-js", | ||
opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } }, | ||
}, | ||
{ "theHamsta/nvim-dap-virtual-text", config = true }, | ||
{ "rcarriga/nvim-dap-ui", config = true }, | ||
}, | ||
config = function() | ||
local dap = require "dap" | ||
for _, language in ipairs { "typescript", "typescriptreact", "javascript", "javascriptreact" } do | ||
if not dap.configurations[language] then dap.configurations[language] = {} end | ||
|
||
utils.list_insert_unique(dap.configurations[language], { | ||
{ | ||
request = "launch", | ||
name = "(Deno) Launch current file", | ||
type = "pwa-node", | ||
program = "${file}", | ||
cwd = vim.fn.getcwd(), | ||
runtimeExecutable = "deno", | ||
runtimeArgs = { "run", "--inspect-wait", "--allow-all" }, | ||
attachSimplePort = 9229, | ||
}, | ||
{ | ||
request = "launch", | ||
name = "(Deno) Launch main.ts", | ||
type = "pwa-node", | ||
program = "${workspaceFolder}/main.ts", | ||
cwd = vim.fn.getcwd(), | ||
runtimeExecutable = "deno", | ||
runtimeArgs = { "run", "--inspect-wait", "--allow-all" }, | ||
attachSimplePort = 9229, | ||
}, | ||
}) | ||
end | ||
end, | ||
}, | ||
{ | ||
"sigmasd/deno-nvim", | ||
init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "denols") end, | ||
ft = { | ||
"typescript", | ||
"typescriptreact", | ||
"javascript", | ||
"javascriptreact", | ||
}, | ||
opts = function() return { server = require("astronvim.utils.lsp").config "denols" } end, | ||
}, | ||
} | ||
return require("astrocommunity.pack.typescript-tsserver-and-denols.denols").get_config() |
59 changes: 59 additions & 0 deletions
59
lua/astrocommunity/pack/typescript-tsserver-and-denols/denols.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local utils = require "astrocommunity.utils" | ||
local ts_config = require "astrocommunity.pack.typescript-tsserver-and-denols.ts-config" | ||
|
||
local Deno = { | ||
dap_config = { | ||
{ | ||
request = "launch", | ||
name = "(Deno) Launch current file", | ||
type = "pwa-node", | ||
program = "${file}", | ||
cwd = vim.fn.getcwd(), | ||
runtimeExecutable = "deno", | ||
runtimeArgs = { "run", "--inspect-wait", "--allow-all" }, | ||
attachSimplePort = 9229, | ||
}, | ||
{ | ||
request = "launch", | ||
name = "(Deno) Launch main.ts", | ||
type = "pwa-node", | ||
program = "${workspaceFolder}/main.ts", | ||
cwd = vim.fn.getcwd(), | ||
runtimeExecutable = "deno", | ||
runtimeArgs = { "run", "--inspect-wait", "--allow-all" }, | ||
attachSimplePort = 9229, | ||
}, | ||
}, | ||
} | ||
|
||
function Deno.get_base_config() | ||
local base_config = ts_config.get_base_config "denols" | ||
|
||
table.insert(base_config, { | ||
"sigmasd/deno-nvim", | ||
init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "denols") end, | ||
ft = ts_config.filetypes, | ||
opts = function() return { server = require("astronvim.utils.lsp").config "denols" } end, | ||
}) | ||
return base_config | ||
end | ||
|
||
function Deno.get_dap_config() | ||
local base_dap_config = ts_config.get_base_dap_config | ||
|
||
base_dap_config.config = function() | ||
local dap = require "dap" | ||
for _, language in ts_config.filetypes do | ||
dap.configurations[language] = Deno.dap_config | ||
end | ||
end | ||
return base_dap_config | ||
end | ||
|
||
function Deno.get_config() | ||
local base_config = Deno.get_base_config() | ||
table.insert(base_config, Deno.get_dap_config()) | ||
return base_config | ||
end | ||
|
||
return Deno |
60 changes: 60 additions & 0 deletions
60
lua/astrocommunity/pack/typescript-tsserver-and-denols/ts-config.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
local utils = require "astrocommunity.utils" | ||
|
||
local filetypes = { "javascript", "typescript", "javascriptreact", "typescriptreact" } | ||
|
||
local M = { | ||
filetypes = filetypes, | ||
get_base_dap_config = { | ||
"mfussenegger/nvim-dap", | ||
ft = filetypes, | ||
enabled = true, | ||
dependencies = { | ||
{ | ||
"mxsdev/nvim-dap-vscode-js", | ||
opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } }, | ||
}, | ||
{ "theHamsta/nvim-dap-virtual-text", config = true }, | ||
{ "rcarriga/nvim-dap-ui", config = true }, | ||
}, | ||
}, | ||
} | ||
|
||
function M.get_base_config(lsp) | ||
if lsp ~= "tsserver" and lsp ~= "denols" then error("Invalid lsp: " .. lsp) end | ||
return { | ||
{ import = "astrocommunity.pack.json" }, | ||
{ | ||
"nvim-treesitter/nvim-treesitter", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table or string "all". | ||
if not opts.ensure_installed then | ||
opts.ensure_installed = {} | ||
elseif opts.ensure_installed == "all" then | ||
return | ||
end | ||
-- Add the required file types to opts.ensure_installed. | ||
utils.list_insert_unique(opts.ensure_installed, { "javascript", "typescript", "tsx" }) | ||
end, | ||
}, | ||
{ | ||
"williamboman/mason-lspconfig.nvim", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table. | ||
if not opts.ensure_installed then opts.ensure_installed = {} end | ||
-- Add tsserver to opts.ensure_installed using vim.list_extend. | ||
utils.list_insert_unique(opts.ensure_installed, lsp) | ||
end, | ||
}, | ||
{ | ||
"jay-babu/mason-nvim-dap.nvim", | ||
opts = function(_, opts) | ||
-- Ensure that opts.ensure_installed exists and is a table. | ||
if not opts.ensure_installed then opts.ensure_installed = {} end | ||
-- Add to opts.ensure_installed using table.insert. | ||
utils.list_insert_unique(opts.ensure_installed, "js") | ||
end, | ||
}, | ||
} | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
lua/astrocommunity/pack/typescript-tsserver-and-denols/tsserver.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
local utils = require "astrocommunity.utils" | ||
local ts_config = require "astrocommunity.pack.typescript-tsserver-and-denols.ts-config" | ||
|
||
local TSServer = { | ||
dap_attach_config = { | ||
request = "attach", | ||
name = "Attach to ...", | ||
type = "pwa-node", | ||
cwd = "${workspaceFolder}", | ||
processId = function(...) return require("dap.utils").pick_process(...) end, | ||
}, | ||
dap_javascript_config = { | ||
{ | ||
request = "launch", | ||
name = "Launch file", | ||
type = "pwa-node", | ||
cwd = "${workspaceFolder}", | ||
program = "${file}", | ||
}, | ||
}, | ||
dap_typescript_config = { | ||
{ | ||
type = "pwa-node", | ||
request = "launch", | ||
name = "(TS-Server) Launch current file", | ||
program = "${file}", | ||
cwd = "${workspaceFolder}", | ||
runtimeExecutable = "ts-node", | ||
sourceMaps = true, | ||
protocol = "inspector", | ||
console = "integratedTerminal", | ||
resolveSourceMapLocations = { | ||
"${workspaceFolder}/dist/**/*.js", | ||
"${workspaceFolder}/**", | ||
"!**/node_modules/**", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
function TSServer.get_base_config() | ||
local base_config = ts_config.get_base_config "tsserver" | ||
|
||
local events = require "neo-tree.events" | ||
local function on_file_remove(args) | ||
local ts_clients = vim.lsp.get_active_clients { name = "tsserver" } | ||
for _, ts_client in ipairs(ts_clients) do | ||
ts_client.request("workspace/executeCommand", { | ||
command = "_typescript.applyRenameFile", | ||
arguments = { | ||
{ | ||
sourceUri = vim.uri_from_fname(args.source), | ||
targetUri = vim.uri_from_fname(args.destination), | ||
}, | ||
}, | ||
}) | ||
end | ||
end | ||
|
||
table.insert(base_config, { | ||
"jay-babu/mason-null-ls.nvim", | ||
opts = function(_, opts) | ||
if not opts.ensure_installed then opts.ensure_installed = {} end | ||
|
||
utils.list_insert_unique(opts.ensure_installed, "prettierd") | ||
utils.list_insert_unique(opts.ensure_installed, "eslint_d") | ||
end, | ||
}) | ||
|
||
table.insert(base_config, { | ||
"jose-elias-alvarez/typescript.nvim", | ||
init = function() utils.list_insert_unique(astronvim.lsp.skip_setup, "tsserver") end, | ||
ft = ts_config.filetypes, | ||
opts = function() return { server = require("astronvim.utils.lsp").config "tsserver" } end, | ||
}) | ||
|
||
table.insert(base_config, { | ||
"nvim-neo-tree/neo-tree.nvim", | ||
opts = { | ||
event_handlers = { | ||
{ | ||
event = events.FILE_MOVED, | ||
handler = on_file_remove, | ||
}, | ||
{ | ||
event = events.FILE_RENAMED, | ||
handler = on_file_remove, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
table.insert(base_config, { | ||
"vuki656/package-info.nvim", | ||
requires = "MunifTanjim/nui.nvim", | ||
config = true, | ||
event = "BufRead package.json", | ||
}) | ||
|
||
return base_config | ||
end | ||
|
||
function TSServer.get_dap_config() | ||
local base_dap_config = ts_config.get_base_dap_config | ||
base_dap_config.config = function() | ||
local dap = require "dap" | ||
|
||
for _, language in ipairs { "typescript", "typescriptreact" } do | ||
if not dap.configurations[language] then dap.configurations[language] = {} end | ||
|
||
utils.list_insert_unique(dap.configurations[language], TSServer.dap_attach_config) | ||
utils.list_insert_unique(dap.configurations[language], TSServer.dap_typescript_config) | ||
end | ||
|
||
for _, language in ipairs { "javascript", "javascriptreact" } do | ||
if not dap.configurations[language] then dap.configurations[language] = {} end | ||
|
||
utils.list_insert_unique(dap.configurations[language], TSServer.dap_attach_config) | ||
utils.list_insert_unique(dap.configurations[language], TSServer.dap_javascript_config) | ||
end | ||
end | ||
return base_dap_config | ||
end | ||
|
||
function TSServer.get_config() | ||
local base_config = TSServer.get_base_config() | ||
table.insert(base_config, TSServer.get_dap_config()) | ||
return base_config | ||
end | ||
|
||
return TSServer |
Oops, something went wrong.