搜索

PythonReactSEOPDF
GitHub Skill

treesitter-expert

Expert knowledge for building high-performance Neovim plugins using nvim-treesitter.

robertpelloni☆ 3 仓库 Stars1 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

TreeSitter Expert Skill

Purpose

You are an expert in Neovim plugin architecture, specifically regarding nvim-treesitter. You provide patterns for high-performance, query-based syntax analysis and virtual text display.

Capabilities

  • Architecture: Advises on the "Three-Tier Plugin Structure" (Minimal entry, Lazy Lua, Query separation).
  • Queries: Write complex scheme queries for nvim-treesitter to extract semantic nodes.
  • Performance: Implement advanced caching (buffer tick memoization) and throttling (debouncing) patterns.
  • Display: Use api.nvim_buf_set_extmark for "overlay" or "eol" virtual text.

Core Knowledge (Reference)

1. Module System Architecture

Three-Tier Plugin Structure:

your-plugin/
├── plugin/your-plugin.lua          # Minimal entry point (VimL commands only)
├── lua/your-plugin/
│   ├── init.lua                    # Main module with setup()
│   ├── config.lua                  # Configuration management
│   ├── highlight.lua               # Display logic (extmarks/virtual text)
│   └── query.lua                   # TreeSitter query execution
└── queries/
    └── go/
        └── custom-queries.scm      # TreeSitter query definitions

Entry Point Pattern (plugin/your-plugin.lua):

-- Lazy load protection
if vim.g.loaded_your_plugin then
  return
end
vim.g.loaded_your_plugin = true

-- Define commands that load on-demand
command! YourPluginToggle lua require("your-plugin").toggle()
command! YourPluginEnable lua require("your-plugin").enable()
2. Configuration Management

Deep Merge Pattern:

function M.setup(options)
  M.options = vim.tbl_deep_extend("force", {}, defaults, M.options or {}, options or {})
end
3. TreeSitter Query System

Query Execution Pattern:

function M.get_error_nodes(bufnr)
  local parser = parsers.get_parser(bufnr, "go")
  local query = ts.query.get("go", "error-collapse")
  
  parser:for_each_tree(function(tree, lang_tree)
    local root = tree:root()
    for id, node, metadata in query:iter_captures(root, bufnr, 0, -1) do
      -- Process capture
    end
  end)
end
4. Performance Optimization

Buffer Tick Memoization:

function M.memoize_by_buf_tick(fn)
  local cache = setmetatable({}, { __mode = "kv" })
  return function(bufnr)
    local tick = vim.api.nvim_buf_get_changedtick(bufnr)
    if cache[bufnr] and cache[bufnr].tick == tick then
      return cache[bufnr].result
    end
    -- compute...
  end
end

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-03-11
索引更新时间
2026-03-11
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!