Browse Source

彩虹括号

scorpio 1 year ago
parent
commit
0e09f77cee
3 changed files with 157 additions and 21 deletions
  1. 115 16
      lua/plugin-config/nvim-treesitter.lua
  2. 13 1
      lua/plugins.lua
  3. 29 4
      plugin/packer_compiled.lua

+ 115 - 16
lua/plugin-config/nvim-treesitter.lua

@@ -1,27 +1,126 @@
 local status, treesitter = pcall(require, "nvim-treesitter.configs")
 if not status then
-    vim.notify("没有找到 nvim-treesitter")
-    return
+  vim.notify("没有找到 nvim-treesitter")
+  return
 end
 
+require("nvim-treesitter.install").prefer_git = true
 treesitter.setup({
-    -- 安装 language parser
-    -- :TSInstallInfo 命令查看支持的语言
-    ensure_installed = {"json", "html", "css", "vim", "lua", "javascript", "typescript", "tsx", "python", "scss", "vue"},
-    -- 启用代码高亮模块
-    highlight = {
-        enable = true,
-        additional_vim_regex_highlighting = false
+  sync_install = false,
+  -- 安装 language parser
+  -- :TSInstallInfo 命令查看支持的语言
+  -- ensure_installed = { "json", "html", "css", "vim", "lua", "javascript", "typescript", "tsx", "markdown" },
+  -- ensure_installed = "maintained",
+
+  -- 启用代码高亮模块
+  highlight = {
+    enable = true,
+    additional_vim_regex_highlighting = false,
+    disable = function(lang, bufnr) -- Disable in large C++ buffers
+      return vim.api.nvim_buf_line_count(bufnr) > 10000
+    end,
+  },
+  -- 启用增量选择模块
+  incremental_selection = {
+    enable = false,
+    keymaps = {
+      init_selection = "<CR>",
+      node_incremental = "<CR>",
+      node_decremental = "<BS>",
+      scope_incremental = "<TAB>",
     },
-    -- 启用代码缩进模块 (=)
-    indent = {
-        enable = true
+  },
+  -- 启用代码缩进模块 (=)
+  indent = {
+    enable = true,
+  },
+  -- p00f/nvim-ts-rainbow
+  rainbow = {
+    enable = true,
+    -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
+    extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
+    max_file_lines = 10000, -- Do not enable for files with more than n lines, int
+    colors = {
+      "#95ca60",
+      "#ee6985",
+      "#D6A760",
+      "#7794f4",
+      "#b38bf5",
+      "#7cc7fe",
+    }, -- table of hex strings
+    -- termcolors = { } -- table of colour name strings
+  },
+  -- https://github.com/JoosepAlviste/nvim-ts-context-commentstring
+  context_commentstring = {
+    enable = true,
+    enable_autocmd = false,
+  },
+  -- https://github.com/windwp/nvim-ts-autotag
+  autotag = {
+    enable = true,
+  },
+  -- nvim-treesitter/nvim-treesitter-refactor
+  refactor = {
+    highlight_definitions = {
+      enable = true,
+      -- Set to false if you have an `updatetime` of ~100.
+      clear_on_cursor_move = true,
     },
-    tree_docs = {
-       enable = true
-    }
-})
+    highlight_current_scope = { enable = true },
+  },
+  -- nvim-treesitter/nvim-treesitter-textobjects
+  textobjects = {
+    select = {
+      enable = true,
 
+      -- Automatically jump forward to textobj, similar to targets.vim
+      lookahead = true,
+
+      keymaps = {
+        -- You can use the capture groups defined in textobjects.scm
+        ["af"] = "@function.outer",
+        ["if"] = "@function.inner",
+        ["ac"] = "@class.outer",
+        ["ic"] = "@class.inner",
+        ["ai"] = "@conditional.outer",
+        ["ii"] = "@conditional.inner",
+        ["al"] = "@loop.outer",
+        ["il"] = "@loop.inner",
+        ["ab"] = "@block.outer",
+        ["ib"] = "@block.inner",
+      },
+    },
+    swap = {
+      enable = false,
+      swap_next = {
+        ["<leader>a"] = "@parameter.inner",
+      },
+      swap_previous = {
+        ["<leader>A"] = "@parameter.inner",
+      },
+    },
+    move = {
+      enable = true,
+      set_jumps = true, -- whether to set jumps in the jumplist
+      goto_next_start = {
+        ["]m"] = "@function.outer",
+        ["]]"] = "@class.outer",
+      },
+      goto_next_end = {
+        ["]M"] = "@function.outer",
+        ["]["] = "@class.outer",
+      },
+      goto_previous_start = {
+        ["[m"] = "@function.outer",
+        ["[["] = "@class.outer",
+      },
+      goto_previous_end = {
+        ["[M"] = "@function.outer",
+        ["[]"] = "@class.outer",
+      },
+    },
+  },
+})
 -- 开启 Folding 模块
 vim.opt.foldmethod = "expr"
 vim.opt.foldexpr = "nvim_treesitter#foldexpr()"

+ 13 - 1
lua/plugins.lua

@@ -62,7 +62,17 @@ packer.startup({
         -- treesitter 代码高亮
         use {
             'nvim-treesitter/nvim-treesitter',
-            run = ':TSUpdate'
+            run = ':TSUpdate',
+            requires = {
+              { "p00f/nvim-ts-rainbow" },
+              { "JoosepAlviste/nvim-ts-context-commentstring" },
+              { "windwp/nvim-ts-autotag" },
+              { "nvim-treesitter/nvim-treesitter-refactor" },
+              { "nvim-treesitter/nvim-treesitter-textobjects" },
+            },
+            config = function()
+              require("plugin-config.nvim-treesitter")
+            end,
         }
         use('nvim-treesitter/nvim-tree-docs')
         --------------------- LSP --------------------
@@ -150,6 +160,8 @@ packer.startup({
         use("b0o/schemastore.nvim")
         -- Rust 增强
         use("simrat39/rust-tools.nvim")
+        -- 彩虹括号
+        use("p00f/nvim-ts-rainbow")
 
     end,
     config = {

+ 29 - 4
plugin/packer_compiled.lua

@@ -218,15 +218,36 @@ _G.packer_plugins = {
     url = "https://github.com/kyazdani42/nvim-tree.lua"
   },
   ["nvim-treesitter"] = {
+    config = { "\27LJ\2\n=\0\0\3\0\2\0\0046\0\0\0'\2\1\0B\0\2\1K\0\1\0\"plugin-config.nvim-treesitter\frequire\0" },
     loaded = true,
     path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
     url = "https://github.com/nvim-treesitter/nvim-treesitter"
   },
+  ["nvim-treesitter-refactor"] = {
+    loaded = true,
+    path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-treesitter-refactor",
+    url = "https://github.com/nvim-treesitter/nvim-treesitter-refactor"
+  },
+  ["nvim-treesitter-textobjects"] = {
+    loaded = true,
+    path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-treesitter-textobjects",
+    url = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects"
+  },
   ["nvim-ts-autotag"] = {
     loaded = true,
     path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-ts-autotag",
     url = "https://github.com/windwp/nvim-ts-autotag"
   },
+  ["nvim-ts-context-commentstring"] = {
+    loaded = true,
+    path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-ts-context-commentstring",
+    url = "https://github.com/JoosepAlviste/nvim-ts-context-commentstring"
+  },
+  ["nvim-ts-rainbow"] = {
+    loaded = true,
+    path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-ts-rainbow",
+    url = "https://github.com/p00f/nvim-ts-rainbow"
+  },
   ["nvim-web-devicons"] = {
     loaded = true,
     path = "/Users/sdaduanbilei/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
@@ -300,10 +321,6 @@ _G.packer_plugins = {
 }
 
 time([[Defining packer_plugins]], false)
--- Config for: nvim-autopairs
-time([[Config for nvim-autopairs]], true)
-try_loadstring("\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0", "config", "nvim-autopairs")
-time([[Config for nvim-autopairs]], false)
 -- Config for: hop.nvim
 time([[Config for hop.nvim]], true)
 try_loadstring("\27LJ\2\nU\0\0\3\0\4\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0005\2\3\0B\0\2\1K\0\1\0\1\0\1\tkeys\28etovxqpdygfblzhckisuran\nsetup\bhop\frequire\0", "config", "hop.nvim")
@@ -312,6 +329,14 @@ time([[Config for hop.nvim]], false)
 time([[Config for Comment.nvim]], true)
 try_loadstring("\27LJ\2\n5\0\0\3\0\3\0\0066\0\0\0'\2\1\0B\0\2\0029\0\2\0B\0\1\1K\0\1\0\nsetup\fComment\frequire\0", "config", "Comment.nvim")
 time([[Config for Comment.nvim]], false)
+-- Config for: nvim-treesitter
+time([[Config for nvim-treesitter]], true)
+try_loadstring("\27LJ\2\n=\0\0\3\0\2\0\0046\0\0\0'\2\1\0B\0\2\1K\0\1\0\"plugin-config.nvim-treesitter\frequire\0", "config", "nvim-treesitter")
+time([[Config for nvim-treesitter]], false)
+-- Config for: nvim-autopairs
+time([[Config for nvim-autopairs]], true)
+try_loadstring("\27LJ\2\n@\0\0\3\0\3\0\a6\0\0\0'\2\1\0B\0\2\0029\0\2\0004\2\0\0B\0\2\1K\0\1\0\nsetup\19nvim-autopairs\frequire\0", "config", "nvim-autopairs")
+time([[Config for nvim-autopairs]], false)
 
 _G._packer.inside_compile = false
 if _G._packer.needs_bufread == true then