Skip to content

Commit

Permalink
ci: generate parser map
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Mar 24, 2024
1 parent 1fee4ad commit 4229e8a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/scripts/echo-nvim-ts-ft-maps.lua
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions .github/workflows/update-ft-ts-maps.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 4229e8a

Please sign in to comment.