feat: add ts/js react to formatter

main
jaredgoldman 2024-04-28 15:10:40 -04:00
parent bbd51a0b85
commit 267f59c18a
6 changed files with 200 additions and 160 deletions

View File

@ -1,34 +1,36 @@
{ {
"FTerm.nvim": { "branch": "master", "commit": "d1320892cc2ebab472935242d9d992a2c9570180" }, "FTerm.nvim": { "branch": "master", "commit": "d1320892cc2ebab472935242d9d992a2c9570180" },
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"catppuccin": { "branch": "main", "commit": "02bdd749931a5d739063562e57531c118e081882" }, "catppuccin": { "branch": "main", "commit": "a1439ad7c584efb3d0ce14ccb835967f030450fe" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"conform.nvim": { "branch": "master", "commit": "9d5ba06d6ee7418c674f498634617416d15b6239" }, "conform.nvim": { "branch": "master", "commit": "4660e534bf7678ee0f85879aa75fdcb6855612c2" },
"copilot.vim": { "branch": "release", "commit": "f45ecd95c1474885e278f20d6ae86a6e30de2151" }, "copilot.vim": { "branch": "release", "commit": "1e135c5303bc60598f6314a2276f31dc91aa34dd" },
"dashboard-nvim": { "branch": "master", "commit": "681300934baf36f6184ca41f0b26aed22056d4ee" }, "dashboard-nvim": { "branch": "master", "commit": "6d06924b562de6f0bb136edf1bf549afbf6b7d00" },
"git-blame.nvim": { "branch": "master", "commit": "a0282d05adbee80aaf4e2ff35b81b52940b67bed" }, "git-blame.nvim": { "branch": "master", "commit": "ad1d1365c9189d89797fe8d559677d5f55dc2830" },
"harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" },
"lazy.nvim": { "branch": "main", "commit": "31ddbea7c10b6920c9077b66c97951ca8682d5c8" }, "lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" },
"lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "44509689b9bf3984d729cc264aacb31cb7f41668" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "1a14770dc8c7cb29643870ac79788eec6f7ce1f8" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "67210c0e775adec55de9826b038e8b62de554afc" },
"mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" },
"monokai.nvim": { "branch": "master", "commit": "b8bd44d5796503173627d7a1fc51f77ec3a08a63" }, "monokai.nvim": { "branch": "master", "commit": "b8bd44d5796503173627d7a1fc51f77ec3a08a63" },
"nvim-autopairs": { "branch": "master", "commit": "4f41e5940bc0443fdbe5f995e2a596847215cd2a" }, "nvim-autopairs": { "branch": "master", "commit": "4f41e5940bc0443fdbe5f995e2a596847215cd2a" },
"nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, "nvim-cmp": { "branch": "main", "commit": "8f3c541407e691af6163e2447f3af1bd6e17f9a3" },
"nvim-comment": { "branch": "main", "commit": "e9ac16ab056695cad6461173693069ec070d2b23" }, "nvim-comment": { "branch": "main", "commit": "e9ac16ab056695cad6461173693069ec070d2b23" },
"nvim-dap": { "branch": "master", "commit": "405df1dcc2e395ab5173a9c3d00e03942c023074" }, "nvim-dap": { "branch": "master", "commit": "6ae8a14828b0f3bff1721a35a1dfd604b6a933bb" },
"nvim-grey": { "branch": "main", "commit": "e5fc8cc1e0c88c23bc6c92845f19a342f561c409" }, "nvim-grey": { "branch": "main", "commit": "d822f82a990198e354845fe4d191f5f527302444" },
"nvim-lspconfig": { "branch": "master", "commit": "b3014f2209503944f2714cf27c95591433a0c7d8" }, "nvim-lspconfig": { "branch": "master", "commit": "cfa386fc4027e847156ee16141ea1f4c0bc2f0a4" },
"nvim-tree.lua": { "branch": "master", "commit": "81eb8d519233c105f30dc0a278607e62b20502fd" }, "nvim-tree.lua": { "branch": "master", "commit": "62008e5cf2e8745c9d23bb599ef642963131057e" },
"nvim-treesitter": { "branch": "master", "commit": "5c4892b0556d1258c423e2369d6a602d9b2a4988" }, "nvim-treesitter": { "branch": "master", "commit": "b04ccbd0e041bb05f3eef271124da02497d9d10c" },
"nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" }, "nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" },
"nvim-web-devicons": { "branch": "master", "commit": "6e355632387a085f15a66ad68cf681c1d7374a04" }, "nvim-web-devicons": { "branch": "master", "commit": "beb6367ab8496c9e43f22e0252735fdadae1872d" },
"plenary.nvim": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" }, "plenary.nvim": { "branch": "master", "commit": "5129a3693c482fcbc5ab99a7706ffc4360b995a0" },
"telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" },
"themery.nvim": { "branch": "main", "commit": "1005a58801276d29c4b1e11244cf7631250f9143" }, "themery.nvim": { "branch": "main", "commit": "1005a58801276d29c4b1e11244cf7631250f9143" },
"vim-maximizer": { "branch": "master", "commit": "2e54952fe91e140a2e69f35f22131219fcd9c5f1" } "vim-maximizer": { "branch": "master", "commit": "2e54952fe91e140a2e69f35f22131219fcd9c5f1" },
"vscode-js-debug": { "branch": "main", "commit": "774a6fb444c75724914f23c2d07e8b0a9fcb080d" }
} }

View File

@ -1,30 +1,32 @@
require("conform").setup({ require("conform").setup({
formatters_by_ft = { formatters_by_ft = {
lua = { "stylua" }, lua = { "stylua" },
javascript = { { "prettierd", "prettier" } }, javascript = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } }, typescript = { { "prettierd", "prettier" } },
json = { { "prettierd", "prettier" } }, javascriptreact = { "prettierd", "prettier" },
markdown = { { "marksman", "prettierd", "prettier" } }, typescriptreact = { "prettierd", "prettier" },
}, json = { { "prettierd", "prettier" } },
markdown = { { "marksman", "prettier", "prettierd" } },
},
}) })
local M = {} local M = {}
M.format = function(args) M.format = function(args)
local range = nil local range = nil
if args and args.count ~= -1 then if args and args.count ~= -1 then
-- Assuming args.line1 and args.line2 are provided and valid -- Assuming args.line1 and args.line2 are provided and valid
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1] local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = { range = {
start = { args.line1, 0 }, start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() }, ["end"] = { args.line2, end_line:len() },
} }
end end
require("conform").format({ async = true, lsp_fallback = true, range = range }) require("conform").format({ async = true, lsp_fallback = true, range = range })
end end
vim.api.nvim_create_user_command("Format", function(args) vim.api.nvim_create_user_command("Format", function(args)
M.format(args) M.format(args)
end, { range = true }) end, { range = true })
return M return M

30
lua/config/dap.lua 100644
View File

@ -0,0 +1,30 @@
require("dap-vscode-js").setup({
-- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node"
-- debugger_path = "(runtimedir)/site/pack/packer/opt/vscode-js-debug", -- Path to vscode-js-debug installation.
-- debugger_cmd = { "js-debug-adapter" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`.
adapters = { 'pwa-node', 'pwa-chrome', 'pwa-msedge', 'node-terminal', 'pwa-extensionHost' }, -- which adapters to register in nvim-dap
-- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging
-- log_file_level = false -- Logging level for output to file. Set to false to disable file logging.
-- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output.
})
for _, language in ipairs({ "typescript", "javascript" }) do
require("dap").configurations[language] = {
{
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = "${workspaceFolder}",
},
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require 'dap.utils'.pick_process,
cwd = "${workspaceFolder}",
}
}
}
end

View File

@ -4,45 +4,45 @@ harpoon.setup({})
-- basic telescope configuration -- basic telescope configuration
local conf = require("telescope.config").values local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files) local function toggle_telescope(harpoon_files)
local file_paths = {} local file_paths = {}
for _, item in ipairs(harpoon_files.items) do for _, item in ipairs(harpoon_files.items) do
table.insert(file_paths, item.value) table.insert(file_paths, item.value)
end end
require("telescope.pickers") require("telescope.pickers")
.new({}, { .new({}, {
prompt_title = "Harpoon", prompt_title = "Harpoon",
finder = require("telescope.finders").new_table({ finder = require("telescope.finders").new_table({
results = file_paths, results = file_paths,
}), }),
previewer = conf.file_previewer({}), previewer = conf.file_previewer({}),
sorter = conf.generic_sorter({}), sorter = conf.generic_sorter({}),
}) })
:find() :find()
end end
local function toggle_mark() local function toggle_mark()
local current_file = api.nvim_buf_get_name(0) -- Get the current buffer's file path local current_file = api.nvim_buf_get_name(0) -- Get the current buffer's file path
local item, index = harpoon:list():get_by_value(current_file) local item, index = harpoon:list():get_by_value(current_file)
if item then if item then
harpoon:list():remove_at(index) harpoon:list():remove_at(index)
print("Removed from Harpoon: " .. current_file) print("Removed from Harpoon: " .. current_file)
else else
harpoon:list():add({ value = current_file }) harpoon:list():add({ value = current_file })
print("Added to Harpoon: " .. current_file) print("Added to Harpoon: " .. current_file)
end end
end end
-- Commands -- Commands
api.nvim_create_user_command("HarpoonClear", function() api.nvim_create_user_command("HarpoonClear", function()
harpoon:list():clear() harpoon:list():clear()
end, { bang = true }) end, { bang = true })
api.nvim_create_user_command("HarpoonAdd", function() api.nvim_create_user_command("HarpoonAdd", function()
harpoon:list():add() harpoon:list():add()
end, { bang = true }) end, { bang = true })
api.nvim_create_user_command("HarpoonToggleFile", function() api.nvim_create_user_command("HarpoonToggleFile", function()
toggle_mark() toggle_mark()
end, { bang = true }) end, { bang = true })
api.nvim_create_user_command("HarpoonUI", function() api.nvim_create_user_command("HarpoonUI", function()
toggle_telescope(harpoon:list()) toggle_telescope(harpoon:list())
end, { bang = true }) end, { bang = true })

View File

@ -6,7 +6,7 @@ local formatter = require("config.conform")
-- Hint: use `:h <option>` to figure out the meaning if needed -- Hint: use `:h <option>` to figure out the meaning if needed
opt.clipboard = "unnamedplus" -- use system clipboard opt.clipboard = "unnamedplus" -- use system clipboard
opt.completeopt = { "menu", "menuone", "noselect" } opt.completeopt = { "menu", "menuone", "noselect" }
opt.mouse = "a" -- allow the mouse to be used in Nvim opt.mouse = "a" -- allow the mouse to be used in Nvim
-- General -- General
opt.wrap = false opt.wrap = false
@ -19,24 +19,24 @@ opt.cursorline = true
opt.backspace = "indent,eol,start" opt.backspace = "indent,eol,start"
-- Tab -- Tab
opt.tabstop = 2 -- number of visual spaces per TAB opt.tabstop = 2 -- number of visual spaces per TAB
opt.softtabstop = 2 -- number of spacesin tab when editing opt.softtabstop = 2 -- number of spacesin tab when editing
opt.shiftwidth = 2 -- insert 4 spaces on a tab opt.shiftwidth = 2 -- insert 4 spaces on a tab
opt.expandtab = true -- tabs are spaces, mainly because of python opt.expandtab = true -- tabs are spaces, mainly because of python
-- UI config -- UI config
opt.number = true -- show absolute number opt.number = true -- show absolute number
-- opt.relativenumber = true -- add numbers to each line on the left side -- opt.relativenumber = true -- add numbers to each line on the left side
opt.cursorline = true -- highlight cursor line underneath the cursor horizontally opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
opt.splitbelow = true -- open new vertical split bottom opt.splitbelow = true -- open new vertical split bottom
opt.splitright = true -- open new horizontal splits right opt.splitright = true -- open new horizontal splits right
opt.termguicolors = true -- enabl 24-bit RGB color in the TUI opt.termguicolors = true -- enabl 24-bit RGB color in the TUI
-- Searching -- Searching
opt.incsearch = true -- search as characters are entered opt.incsearch = true -- search as characters are entered
opt.hlsearch = false -- do not highlight matches opt.hlsearch = false -- do not highlight matches
opt.ignorecase = true -- ignore case in searches by default opt.ignorecase = true -- ignore case in searches by default
opt.smartcase = true -- but make it case sensitive if an uppercase is entered opt.smartcase = true -- but make it case sensitive if an uppercase is entered
-- History -- History
opt.undofile = true opt.undofile = true
@ -46,14 +46,14 @@ opt.undodir = os.getenv("HOME") .. "/.local/share/nvim/undo"
api.nvim_set_option("list", true) api.nvim_set_option("list", true)
api.nvim_set_option("listchars", "eol:$,nbsp:_,tab:>-,trail:~,extends:>,precedes:<") api.nvim_set_option("listchars", "eol:$,nbsp:_,tab:>-,trail:~,extends:>,precedes:<")
api.nvim_create_autocmd({ "BufWritePre" }, { api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = { "*" }, pattern = { "*" },
command = [[if &filetype !~# 'lsp' | %s/\s\+$//e | endif]], command = [[if &filetype !~# 'lsp' | %s/\s\+$//e | endif]],
}) })
-- Formatting -- Formatting
vim.api.nvim_create_autocmd("BufWritePre", { vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*", pattern = "*",
callback = function() callback = function()
formatter.format(nil) formatter.format(nil)
end, end,
}) })

View File

@ -2,90 +2,96 @@ local dashboard = require("config.dashboard")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({ vim.fn.system({
"git", "git",
"clone", "clone",
"--filter=blob:none", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git", "https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release "--branch=stable", -- latest stable release
lazypath, lazypath,
}) })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("lazy").setup({ require("lazy").setup({
-- Dashboard -- Dashboard
{ {
"nvimdev/dashboard-nvim", "nvimdev/dashboard-nvim",
event = "VimEnter", event = "VimEnter",
opts = dashboard.dashboard_config, opts = dashboard.dashboard_config,
}, },
-- Theming -- Theming
"tanvirtin/monokai.nvim", "tanvirtin/monokai.nvim",
"yorickpeterse/nvim-grey", "yorickpeterse/nvim-grey",
{ "catppuccin/nvim", name = "catppuccin", priority = 1000 }, { "catppuccin/nvim", name = "catppuccin", priority = 1000 },
{ {
"onsails/lspkind.nvim", "onsails/lspkind.nvim",
event = { "VimEnter" }, event = { "VimEnter" },
}, },
-- Auto-completion engine -- Auto-completion engine
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
dependencies = { "lspkind.nvim" }, dependencies = { "lspkind.nvim" },
config = function() config = function()
require("config.nvim-cmp") require("config.nvim-cmp")
end, end,
}, },
{ "hrsh7th/cmp-nvim-lsp", dependencies = { "nvim-cmp" } }, { "hrsh7th/cmp-nvim-lsp", dependencies = { "nvim-cmp" } },
{ "hrsh7th/cmp-buffer", dependencies = { "nvim-cmp" } }, -- buffer auto-completion { "hrsh7th/cmp-buffer", dependencies = { "nvim-cmp" } }, -- buffer auto-completion
{ "hrsh7th/cmp-path", dependencies = { "nvim-cmp" } }, -- path auto-completion { "hrsh7th/cmp-path", dependencies = { "nvim-cmp" } }, -- path auto-completion
{ "hrsh7th/cmp-cmdline", dependencies = { "nvim-cmp" } }, -- cmdline auto-completion { "hrsh7th/cmp-cmdline", dependencies = { "nvim-cmp" } }, -- cmdline auto-completion
-- Code snippet engine -- Code snippet engine
{ {
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
version = "v2.*", version = "v2.*",
}, },
"williamboman/mason.nvim", "williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
"nvim-tree/nvim-tree.lua", "nvim-tree/nvim-tree.lua",
version = "*", version = "*",
lazy = false, lazy = false,
dependencies = { dependencies = {
"nvim-tree/nvim-web-devicons", "nvim-tree/nvim-web-devicons",
}, },
{ {
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
tag = "0.1.6", tag = "0.1.6",
dependencies = { "nvim-lua/plenary.nvim" }, dependencies = { "nvim-lua/plenary.nvim" },
}, },
"zaldih/themery.nvim", "zaldih/themery.nvim",
"terrortylor/nvim-comment", "terrortylor/nvim-comment",
"szw/vim-maximizer", "szw/vim-maximizer",
{ {
"nvim-lualine/lualine.nvim", "nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" }, dependencies = { "nvim-tree/nvim-web-devicons" },
}, },
"numToStr/FTerm.nvim", "numToStr/FTerm.nvim",
"github/copilot.vim", "github/copilot.vim",
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
{ {
"ThePrimeagen/harpoon", "ThePrimeagen/harpoon",
branch = "harpoon2", branch = "harpoon2",
requires = { { "nvim-lua/plenary.nvim" } }, requires = { { "nvim-lua/plenary.nvim" } },
}, },
{ {
"windwp/nvim-autopairs", "windwp/nvim-autopairs",
event = "InsertEnter", event = "InsertEnter",
config = true, config = true,
}, },
"windwp/nvim-ts-autotag", "windwp/nvim-ts-autotag",
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
"mfussenegger/nvim-dap", {
{ "mfussenegger/nvim-dap",
"stevearc/conform.nvim", opt = true,
opts = {}, run = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
}, },
"f-person/git-blame.nvim", "jay-babu/mason-nvim-dap.nvim",
"microsoft/vscode-js-debug",
{
"stevearc/conform.nvim",
opts = {},
},
"f-person/git-blame.nvim",
}) })