diff --git a/.github/workflows/test-queries.yml b/.github/workflows/test-queries.yml index be9b758a4..0387482fb 100644 --- a/.github/workflows/test-queries.yml +++ b/.github/workflows/test-queries.yml @@ -1,12 +1,12 @@ name: Test queries on: - push: - branches: - - "master" + # push: + # branches: + # - "main" pull_request: branches: - - "master" + - "main" # Cancel any in-progress CI runs for a PR if it is updated concurrency: @@ -24,29 +24,33 @@ jobs: matrix: os: [ubuntu-latest, windows-2022, macos-latest] cc: [gcc, clang] - nvim_tag: [stable] + nvim_tag: [nightly] exclude: - os: ubuntu-latest cc: clang - nvim_tag: stable + nvim_tag: nightly - os: macos-latest cc: gcc - nvim_tag: stable + nvim_tag: nightly + + - os: windows-2022 + cc: gcc + nvim_tag: nightly - os: windows-2022 cc: clang - nvim_tag: stable - - include: - - os: windows-2022 - cc: cl - nvim_tag: stable - - - os: ubuntu-latest - cc: gcc nvim_tag: nightly + # include: + # - os: windows-2022 + # cc: cl + # nvim_tag: nightly + + # - os: ubuntu-latest + # cc: gcc + # nvim_tag: nightly + name: Parser compilation runs-on: ${{ matrix.os }} env: @@ -72,16 +76,12 @@ jobs: uses: actions/cache@v3 with: path: | - ./parser/ - ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/ - key: ${{ matrix.os }}-${{ matrix.cc }}-${{ matrix.nvim_tag }}-parsers-v1-${{ hashFiles('./lockfile.json', './lua/nvim-treesitter/parsers.lua', './lua/nvim-treesitter/install.lua', './lua/nvim-treesitter/shell_command_selectors.lua') }} + ~/.local/share/nvim/site/parser/ + ~/AppData/Local/nvim-data/site/parser/ + key: ${{ matrix.os }}-${{ matrix.cc }}-${{ matrix.nvim_tag }}-parsers-v1-${{ hashFiles('./lockfile.json', './lua/nvim-treesitter/parsers.lua', './lua/nvim-treesitter/install.lua', './lua/nvim-treesitter/util.lua') }} - name: Compile parsers - run: $NVIM --headless -c "lua require'nvim-treesitter.install'.prefer_git=false" -c "TSInstallSync all" -c "q" - - - name: Post compile Windows - if: matrix.os == 'windows-2022' - run: cp -r ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/* parser + run: $NVIM -l ./scripts/install-parsers.lua - name: Check query files run: ./scripts/check-queries.lua diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2393a78dc..59f852e1b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,12 +1,12 @@ name: Tests on: - push: - branches: - - "master" + # push: + # branches: + # - "main" pull_request: branches: - - "master" + - "main" # Cancel any in-progress CI runs for a PR if it is updated concurrency: @@ -42,7 +42,7 @@ jobs: - name: Install and prepare Neovim env: - NVIM_TAG: stable + NVIM_TAG: nightly TREE_SITTER_CLI_TAG: v0.20.8 run: | bash ./scripts/ci-install-${{ matrix.os }}.sh @@ -58,8 +58,7 @@ jobs: - name: Compile parsers Unix like if: ${{ matrix.os != 'windows-latest' && steps.parsers-cache.outputs.cache-hit != 'true' }} - run: | - nvim --headless -c "TSInstallSync all" -c "q" + run: nvim -l ./scripts/install-parsers.lua - name: Tests run: PATH=/usr/local/bin:$PATH ./scripts/run_tests.sh diff --git a/.github/workflows/update-lockfile.yml b/.github/workflows/update-lockfile.yml index 0956fd2c0..dca4296d1 100644 --- a/.github/workflows/update-lockfile.yml +++ b/.github/workflows/update-lockfile.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: master + ref: main - name: Prepare env: diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 8a3691134..e01657698 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -3,7 +3,7 @@ name: Update README on: push: branches: - - master + - main workflow_dispatch: jobs: diff --git a/TODO.md b/TODO.md index d61d179d6..e5d9448a2 100644 --- a/TODO.md +++ b/TODO.md @@ -5,8 +5,9 @@ This document lists the planned and finished changes in this rewrite towards [Nv ## TODO - [ ] **`query_predicates.lua`:** upstream/remove -- [ ] **`parsers.lua`:** modularize? +- [ ] **`parsers.lua`:** add dependencies (and "query-only" langs like ecma, jsx, html_tags, ...) - [ ] **`parsers.lua`:** assign tiers +- [ ] **`parsers.lua`:** modularize? - [ ] **`install.lua`:** simplify compilation: - hardcode one compiler + args per platform - provide `install.compile_command` for overriding (function that takes files, ...?) diff --git a/plugin/query_predicates.lua b/plugin/query_predicates.lua index 9de929aad..d01970acf 100644 --- a/plugin/query_predicates.lua +++ b/plugin/query_predicates.lua @@ -1,6 +1,6 @@ local query = vim.treesitter.query --- register custom predicates +-- register custom predicates (overwrite existing; needed for CI) ---@param match (TSNode|nil)[] ---@param pred string[] @@ -13,7 +13,7 @@ query.add_predicate('has-type?', function(match, _, _, pred) local types = { unpack(pred, 3) } return vim.list_contains(types, node:type()) -end) +end, true) -- register custom directives @@ -43,7 +43,7 @@ query.add_directive('set-lang-from-mimetype!', function(match, _, bufnr, pred, m local parts = vim.split(type_attr_value, '/', {}) metadata['injection.language'] = parts[#parts] end -end) +end, true) local injection_aliases = { ex = 'elixir', @@ -68,7 +68,7 @@ query.add_directive('set-lang-from-info-string!', function(match, _, bufnr, pred local injection_alias = vim.treesitter.get_node_text(node, bufnr) local filetype = vim.filetype.match({ filename = 'a.' .. injection_alias }) metadata['injection.language'] = filetype or injection_aliases[injection_alias] or injection_alias -end) +end, true) query.add_directive('downcase!', function(match, _, bufnr, pred, metadata) local text, key, value ---@type string|string[], string, string|integer @@ -95,7 +95,7 @@ query.add_directive('downcase!', function(match, _, bufnr, pred, metadata) else metadata[key] = string.lower(text) end -end) +end, true) -- Trim blank lines from end of the region -- Arguments are the captures to trim. @@ -138,4 +138,4 @@ query.add_directive('trim!', function(match, _, bufnr, pred, metadata) metadata[id].range = { start_row, start_col, end_row, end_col } end end -end) +end, true) diff --git a/scripts/check-queries.lua b/scripts/check-queries.lua index fd039fa30..7e54ff368 100755 --- a/scripts/check-queries.lua +++ b/scripts/check-queries.lua @@ -104,17 +104,20 @@ local ok, result = pcall(do_check) local allowed_to_fail = vim.split(vim.env.ALLOWED_INSTALLATION_FAILURES or '', ',', true) for k, v in pairs(require('nvim-treesitter.parsers').configs) do - if #vim.api.nvim_get_runtime_file('parser/' .. k .. '.*', false) == 0 then - -- On CI all parsers that can be installed from C files should be installed - if - vim.env.CI - and not v.install_info.requires_generate_from_grammar - and not vim.list_contains(allowed_to_fail, k) - then - io_print('Error: parser for ' .. k .. ' is not installed') - vim.cmd('cq') - else - io_print('Warning: parser for ' .. k .. ' is not installed') + if v.install_info then + -- skip "query only" languages + if #vim.api.nvim_get_runtime_file('parser/' .. k .. '.*', false) == 0 then + -- On CI all parsers that can be installed from C files should be installed + if + vim.env.CI + and not v.install_info.requires_generate_from_grammar + and not vim.list_contains(allowed_to_fail, k) + then + io_print('Error: parser for ' .. k .. ' is not installed') + vim.cmd('cq') + else + io_print('Warning: parser for ' .. k .. ' is not installed') + end end end end diff --git a/scripts/install-parsers.lua b/scripts/install-parsers.lua new file mode 100755 index 000000000..ab06e538f --- /dev/null +++ b/scripts/install-parsers.lua @@ -0,0 +1,15 @@ +#!/usr/bin/env -S nvim -l + +vim.opt.runtimepath:append('.') + +-- needed on CI +vim.fn.mkdir(vim.fn.stdpath('cache'), 'p') + +local done = false +require('nvim-treesitter.install').install('all', {}, function() + done = true +end) + +vim.wait(6000000, function() + return done +end) diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua index 85665a4b0..c5edaf048 100644 --- a/scripts/minimal_init.lua +++ b/scripts/minimal_init.lua @@ -2,11 +2,11 @@ vim.opt.runtimepath:append('.') vim.cmd.runtime({ 'plugin/plenary.vim', bang = true }) vim.cmd.runtime({ 'plugin/nvim-treesitter.lua', bang = true }) vim.cmd.runtime({ 'plugin/query_predicates.lua', bang = true }) +vim.cmd.runtime({ 'plugin/filetypes.lua', bang = true }) vim.filetype.add({ extension = { conf = 'hocon', - cmm = 't32', hurl = 'hurl', ncl = 'nickel', tig = 'tiger', @@ -24,6 +24,6 @@ require('nvim-treesitter').setup() vim.api.nvim_create_autocmd('FileType', { callback = function(args) pcall(vim.treesitter.start) - vim.bo[args.buffer].indentexpr = 'v:lua.require"nvim-treesitter".indentexpr()' + vim.bo[args.buf].indentexpr = 'v:lua.require"nvim-treesitter".indentexpr()' end, }) diff --git a/scripts/pre-push b/scripts/pre-push deleted file mode 100755 index 8d425b3b6..000000000 --- a/scripts/pre-push +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Can be used as a pre-push hook -# Just symlink this file to .git/hooks/pre-push - -echo "Running linter..." -luacheck . - -echo "Checking formatting..." -stylua --check . diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index c6660a7f6..7ae6b22c5 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -4,7 +4,7 @@ HERE="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" cd $HERE/.. run() { - nvim --headless --noplugin -u scripts/minimal_init.lua \ + nvim --headless --noplugin -u scripts/minimal_init.lua \ -c "PlenaryBustedDirectory $1 { minimal_init = './scripts/minimal_init.lua' }" } diff --git a/tests/indent/common.lua b/tests/indent/common.lua index b0212c0f6..3550ebbe5 100644 --- a/tests/indent/common.lua +++ b/tests/indent/common.lua @@ -74,7 +74,7 @@ assert:register( local function compare_indent(before, after, xfail) assert:add_formatter(format_indent) if xfail then - io.stdout:write('Warning! Known failure of this test! Please help to fix it! ') + -- io.stdout:write('Warning! Known failure of this test! Please help to fix it! ') assert.is_not.same_indent(before, after) else assert.is.same_indent(before, after)