mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-22 08:53:31 +02:00
fix: tsx support lsp and treesitter
This commit is contained in:
parent
523588ee4f
commit
a25f1abde3
7 changed files with 118 additions and 5 deletions
83
ftplugin/typescriptreact.lua
Normal file
83
ftplugin/typescriptreact.lua
Normal file
|
@ -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()
|
|
@ -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" },
|
||||
|
|
10
lua/custom/plugins/typescript.lua
Normal file
10
lua/custom/plugins/typescript.lua
Normal file
|
@ -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,
|
||||
}
|
|
@ -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 = "<M-e>",
|
||||
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("/>") .. "<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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue