diff --git a/ftplugin/typescriptreact.lua b/ftplugin/typescriptreact.lua new file mode 100644 index 0000000..cf6ff46 --- /dev/null +++ b/ftplugin/typescriptreact.lua @@ -0,0 +1,83 @@ +local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status_ok then + return +end + +lspconfig.tsserver.setup({ + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + -- add cmd + cmd = { "typescript-language-server", "--stdio" }, + -- add file type support + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + -- add dynamic root dir support + root_dir = require("lspconfig.util").root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), + init_options = { + hostInfo = "neovim", + }, +}) + +lspconfig.emmet_ls.setup({ + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + -- add cmd + cmd = { "emmet-ls", "-c", "--stdio" }, + -- add file type support + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + -- add dynamic root dir support + root_dir = require("lspconfig.util").root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), +}) + +lspconfig.eslint.setup({ + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + -- add cmd + cmd = { "vscode-eslint-language-server", "--stdio" }, -- add file type support + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + -- add dynamic root dir support + root_dir = require("lspconfig.util").root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), +}) + +local status_ok, configs = pcall(require, "nvim-treesitter.configs") +if not status_ok then + return +end + +configs.setup({ + ensure_installed = { "typescript", "tsx" }, -- pastikan parser TypeScript terinstal + highlight = { + enable = true, -- aktifkan highlight berbasis treesitter + additional_vim_regex_highlighting = false, + }, + rainbow = { + enable = false, + }, + incremental_selection = { enable = true }, + indent = { enable = true, disable = { "python", "css" } }, + autopairs = { + enable = true, + }, +}) + +require("nvim-ts-autotag").setup() diff --git a/lazy-lock.json b/lazy-lock.json index 02145cb..9b91736 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -38,14 +38,14 @@ "nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" }, "nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" }, "nvim-scrollview": { "branch": "main", "commit": "c29c5f69d37040a1fac88cbea7f5e6f06f0aff4d" }, - "nvim-tree.lua": { "branch": "master", "commit": "2dbe4ea2b5dd29892f712835ed9f6df8afb22d75" }, + "nvim-tree.lua": { "branch": "master", "commit": "d35a8d5ec6358ada4b058431b367b32360737466" }, "nvim-treesitter": { "branch": "master", "commit": "f197a15b0d1e8d555263af20add51450e5aaa1f0" }, "nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "7ab799a9792f7cf3883cf28c6a00ad431f3d382a" }, "nvim-ts-rainbow2": { "branch": "master", "commit": "b3120cd5ae9ca524af9cb602f41e12e301fa985f" }, "nvim-web-devicons": { "branch": "master", "commit": "a55b801b7ef5719ca25692c3a0a5447fdfb692ed" }, "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, - "smart-splits.nvim": { "branch": "master", "commit": "36bfe63246386fc5ae2679aa9b17a7746b7403d5" }, + "smart-splits.nvim": { "branch": "master", "commit": "e1e1e6ca3754bd8ef971fb69673cc17965eb9e37" }, "telescope.nvim": { "branch": "master", "commit": "b744cf59752aaa01561afb4223006de26f3836fd" }, "toggleterm.nvim": { "branch": "main", "commit": "193786e0371e3286d3bc9aa0079da1cd41beaa62" }, "tokyonight.nvim": { "branch": "main", "commit": "67c6050e1ca41260c919236a098ba278472c7520" }, diff --git a/lua/custom/plugins/typescript.lua b/lua/custom/plugins/typescript.lua new file mode 100644 index 0000000..acae629 --- /dev/null +++ b/lua/custom/plugins/typescript.lua @@ -0,0 +1,10 @@ +return { + -- "pmizio/typescript-tools.nvim", + -- event = "BufRead", + -- dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + -- config = function() + -- require("typescript-tools").setup({ + -- on_attach = require("user.lsp.handlers").on_attach, + -- }) + -- end, +} diff --git a/lua/user/autopairs.lua b/lua/user/autopairs.lua index 3d49991..ea11b0a 100644 --- a/lua/user/autopairs.lua +++ b/lua/user/autopairs.lua @@ -4,6 +4,8 @@ if not status_ok then return end +local Rule = require("nvim-autopairs.rule") + npairs.setup({ check_ts = true, ts_config = { @@ -14,7 +16,7 @@ npairs.setup({ disable_filetype = { "TelescopePrompt", "spectre_panel" }, fast_wrap = { map = "", - chars = { "{", "[", "(", '"', "'" }, + chars = { "{", "[", "(", '"', "'", "`" }, pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), offset = 0, -- Offset from pattern match end_key = "$", @@ -25,6 +27,14 @@ npairs.setup({ }, }) +npairs.add_rules({ + Rule("/", ">"):with_pair(function(opts) + local pair = opts.line:sub(opts.col, opts.col + 1) + if (vim.bo.filetype == "jsx" or vim.bo.filetype == "tsx") and pair == "/" then + return npairs.esc("/>") .. "i" + end + end), +}) -- If you want insert `(` after select function or method item local cmp_autopairs = require("nvim-autopairs.completion.cmp") local cmp_status_ok, cmp = pcall(require, "cmp") diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua index a80118c..1481185 100644 --- a/lua/user/lsp/handlers.lua +++ b/lua/user/lsp/handlers.lua @@ -101,6 +101,10 @@ M.on_attach = function(client, bufnr) client.server_capabilities.documentFormattingProvider = false end + if client.supports_method("textDocument/inlayHint") then + vim.lsp.inlay_hint.enable(bufnr, true) + end + lsp_keymaps(bufnr) local status_ok, illuminate = pcall(require, "illuminate") if not status_ok then diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua index 4440e5f..d5f1a98 100644 --- a/lua/user/treesitter.lua +++ b/lua/user/treesitter.lua @@ -30,11 +30,11 @@ configs.setup({ -- }, rainbow = { enable = true, - disable = { "html" }, + disable = { "html", "jsx" }, equery = "rainbow-parens", strategy = require("ts-rainbow").strategy.global, }, - autotag = { enable = true }, + -- autotag = { enable = true, enable_rename = true, enable_close = true, enable_close_on_slash = true }, incremental_selection = { enable = true }, indent = { enable = true, disable = { "python", "css" } }, autopairs = { diff --git a/lua/user/webdevicons.lua b/lua/user/webdevicons.lua index f9b8501..46099bc 100644 --- a/lua/user/webdevicons.lua +++ b/lua/user/webdevicons.lua @@ -27,6 +27,12 @@ material_icon.setup({ cterm_color = "220", name = "jsx", }, + ["tsx"] = { + icon = "", + color = "#1354bf", + cterm_color = "220", + name = "Tsx", + }, ["svg"] = { icon = "󰜡", color = "#FDB03A",