From 4229e8a6d1798a747409af7006db272cf2706050 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sun, 24 Mar 2024 02:58:45 +0100 Subject: [PATCH] ci: generate parser map --- .github/scripts/echo-nvim-ts-ft-maps.lua | 29 +++++++++++++++ .github/workflows/update-ft-ts-maps.yml | 45 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 .github/scripts/echo-nvim-ts-ft-maps.lua create mode 100644 .github/workflows/update-ft-ts-maps.yml diff --git a/.github/scripts/echo-nvim-ts-ft-maps.lua b/.github/scripts/echo-nvim-ts-ft-maps.lua new file mode 100755 index 0000000..091a68c --- /dev/null +++ b/.github/scripts/echo-nvim-ts-ft-maps.lua @@ -0,0 +1,29 @@ +#!/usr/bin/env -S nvim -u NONE -U NONE -N -i NONE -l + +vim.opt.rtp:append(vim.fs.joinpath(vim.fn.getcwd(), "nvim-treesitter")) + +local parser_configs = require("nvim-treesitter.parsers").configs +for lang, config in pairs(parser_configs) do + config.lang = lang +end +local parser_map = vim.iter(parser_configs) + :filter(function(config) + return config.filetype ~= nil + end) + :fold({}, function(acc, config) + acc[config.filetype] = config.lang + return acc + end) + +local mod = ([==[ +---@mod rocks_treesitter.ft_parser_map +---@brief [[ +--- +---This module is generated. Do not edit by hand! +--- +---@brief ]] + +return %s +]==]):format(vim.inspect(parser_map)) + +io.write(mod) diff --git a/.github/workflows/update-ft-ts-maps.yml b/.github/workflows/update-ft-ts-maps.yml new file mode 100644 index 0000000..14f0590 --- /dev/null +++ b/.github/workflows/update-ft-ts-maps.yml @@ -0,0 +1,45 @@ + +--- +name: Update filetype -> parser mappings + +# Prevent concurrent auto-commits +concurrency: + group: update-filetype-parser-mappings + cancel-in-progress: true + +on: + push: + branches: + - 'main' + paths: + - '.github/scripts/echo-nvim-ts-ft-maps.lua' + - .github/workflows/update-ft-ts-maps.yml + schedule: + # Runs at midnight + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + update-filetype-parser-mappings: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + - uses: actions/checkout@v4 + with: + repository: nvim-treesitter/nvim-treesitter + path: nvim-treesitter + ref: main + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - name: Update tree-sitter parsers JSON + run: | + ./.github/scripts/echo-nvim-ts-ft-maps.lua > lua/rocks_treesitter/ft_parser_map.lua + - name: commit + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore: update filetype -> parser map" + file_pattern: "lua/rocks_treesitter/ft_parser_map.lua"