Install nvim-treesitter
This commit is contained in:
parent
0dca450ffc
commit
c379cdec0e
1500 changed files with 82622 additions and 0 deletions
20
pack/ant/start/nvim-treesitter/.editorconfig
Normal file
20
pack/ant/start/nvim-treesitter/.editorconfig
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
tab_width = 8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
[*.lua]
|
||||||
|
tab_width = 2
|
||||||
|
|
||||||
|
[*.py]
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 4
|
||||||
|
|
||||||
|
[{Makefile,**/Makefile,runtime/doc/*.txt}]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 8
|
2
pack/ant/start/nvim-treesitter/.github/FUNDING.yml
vendored
Normal file
2
pack/ant/start/nvim-treesitter/.github/FUNDING.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
open_collective: "nvim-treesitter"
|
||||||
|
github: "nvim-treesitter"
|
58
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
58
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
name: Bug report
|
||||||
|
description: Create a report to help us improve
|
||||||
|
labels: [bug]
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
# Before reporting
|
||||||
|
Please do the following steps before reporting an issue.
|
||||||
|
|
||||||
|
- I have updated my neovim version to latest _master_
|
||||||
|
- I have updated my plugin to the latest version
|
||||||
|
- I have run `:TSUpdate`
|
||||||
|
- I have read the [troubleshooting section](https://github.com/nvim-treesitter/nvim-treesitter#troubleshooting)
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the bug
|
||||||
|
description: A clear and concise description of what the bug is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: To Reproduce
|
||||||
|
description: Steps to reproduce the behavior.
|
||||||
|
placeholder: |
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Expected behavior
|
||||||
|
description: A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Output of `:checkhealth nvim-treesitter`
|
||||||
|
render: markdown
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Output of `nvim --version`
|
||||||
|
render: text
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any context about the problem here.
|
19
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
19
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ""
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ""
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
98
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/highlighting_issue.yml
vendored
Normal file
98
pack/ant/start/nvim-treesitter/.github/ISSUE_TEMPLATE/highlighting_issue.yml
vendored
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
name: Highlighting issue
|
||||||
|
description: Missing or incorrect highlights or you want to change the way something is highlighted
|
||||||
|
labels: [highlights]
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
# Before reporting
|
||||||
|
Please perform the following steps before reporting an issue.
|
||||||
|
- I have updated my neovim version to latest _master_.
|
||||||
|
- I have updated my plugin to the latest version.
|
||||||
|
- I have run `:TSUpdate`.
|
||||||
|
- I have inspected the syntax tree using `:InspectTree` and made sure
|
||||||
|
that no `ERROR` nodes are in the syntax tree. nvim-treesitter can not guarantee correct highlighting in the
|
||||||
|
presence of `ERROR`s -- in this case, please report the bug directly at corresponding parser's repository. (You can find all repository URLs in [README.md](https://github.com/nvim-treesitter/nvim-treesitter#supported-languages).)
|
||||||
|
- I have used `:Inspect` to inspect which highlight groups Neovim is using and that legacy syntax highlighting is not interfering (i.e., what you are observing is actual tree-sitter highlighting).
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the highlighting problem
|
||||||
|
description: A clear and concise description of what should be highlighted in a different way.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Example snippet that causes the problem
|
||||||
|
description: Please provide an example snippet in plain text that causes the problem.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Tree-sitter parsing result
|
||||||
|
description: |
|
||||||
|
Please provide the output of `:InspectTree` (screenshot or plain text)
|
||||||
|
with the following options enabled (pressing the key):
|
||||||
|
- `I` (name of the parsed language)
|
||||||
|
- `t` (toggle injected languages)
|
||||||
|
- `a` (show anonymous nodes)
|
||||||
|
placeholder: |
|
||||||
|
This should look somehow like this:
|
||||||
|
```
|
||||||
|
preproc_ifdef [0, 0] - [4, 6] cpp
|
||||||
|
"#ifdef" [0, 0] - [0, 6] cpp
|
||||||
|
name: identifier [0, 7] - [0, 17] cpp
|
||||||
|
preproc_def [1, 0] - [2, 0] cpp
|
||||||
|
"#define" [1, 0] - [1, 7] cpp
|
||||||
|
name: identifier [1, 8] - [1, 16] cpp
|
||||||
|
value: preproc_arg [1, 16] - [1, 27] cpp
|
||||||
|
"\n" [1, 27] - [2, 0] cpp
|
||||||
|
alternative: preproc_else [2, 0] - [4, 0] cpp
|
||||||
|
"#else" [2, 0] - [2, 5] cpp
|
||||||
|
preproc_def [3, 0] - [4, 0] cpp
|
||||||
|
"#define" [3, 0] - [3, 7] cpp
|
||||||
|
name: identifier [3, 8] - [3, 16] cpp
|
||||||
|
value: preproc_arg [3, 16] - [3, 29] cpp
|
||||||
|
```
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Example screenshot
|
||||||
|
description: |
|
||||||
|
Please provide a screenshot of the current highlighting. Please also tell us the `:h colorscheme` you are using
|
||||||
|
and how to install it. If applicable, you can also upload a screenshot with the contents of
|
||||||
|
`:Inspect`.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Expected behavior
|
||||||
|
description: |
|
||||||
|
A clear and concise description of what you expect to be changed. You can provide screenshot of
|
||||||
|
other editors or traditional Vim highlighting that don't show this problem or show a screenshot how
|
||||||
|
nvim-treesitter highlighting would look like when a problematic query would be removed/altered.
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Output of `:checkhealth nvim-treesitter`
|
||||||
|
render: markdown
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Output of `nvim --version`
|
||||||
|
render: text
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any context about the problem here.
|
51
pack/ant/start/nvim-treesitter/.github/workflows/lint.yml
vendored
Normal file
51
pack/ant/start/nvim-treesitter/.github/workflows/lint.yml
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
name: Linting and style checking
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
luacheck:
|
||||||
|
name: Luacheck
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install luarocks -y
|
||||||
|
sudo luarocks install luacheck
|
||||||
|
|
||||||
|
- name: Run Luacheck
|
||||||
|
run: luacheck .
|
||||||
|
|
||||||
|
stylua:
|
||||||
|
name: StyLua
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Lint with stylua
|
||||||
|
uses: JohnnyMorganz/stylua-action@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
version: latest
|
||||||
|
args: --check .
|
||||||
|
|
||||||
|
format-queries:
|
||||||
|
name: Lint queries
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
NVIM_TAG: stable
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
bash ./scripts/ci-install.sh
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: |
|
||||||
|
nvim --headless -c "TSInstallSync query" -c "q"
|
||||||
|
nvim -l scripts/format-queries.lua
|
||||||
|
git diff --exit-code
|
24
pack/ant/start/nvim-treesitter/.github/workflows/release.yml
vendored
Normal file
24
pack/ant/start/nvim-treesitter/.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
name: "release"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: # Will upload to luarocks.org
|
||||||
|
- "*"
|
||||||
|
pull_request: # Will test a local install without uploading to luarocks.org
|
||||||
|
paths:
|
||||||
|
- 'contrib/*.rockspec'
|
||||||
|
- .github/workflows/release.yml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
luarocks-upload:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: nvim-neorocks/luarocks-tag-release@v5
|
||||||
|
env:
|
||||||
|
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
|
||||||
|
with:
|
||||||
|
name: nvim-treesitter
|
||||||
|
detailed_description: |
|
||||||
|
The goal of nvim-treesitter is both to provide a simple and easy way to use the interface for tree-sitter in Neovim
|
||||||
|
and to provide some basic functionality such as highlighting based on it.
|
||||||
|
template: contrib/nvim-treesitter-luarocks.template
|
88
pack/ant/start/nvim-treesitter/.github/workflows/test-queries.yml
vendored
Normal file
88
pack/ant/start/nvim-treesitter/.github/workflows/test-queries.yml
vendored
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
name: Test queries
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
# Cancel any in-progress CI runs for a PR if it is updated
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_compilation:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-14]
|
||||||
|
cc: [gcc, clang]
|
||||||
|
nvim_tag: [stable]
|
||||||
|
exclude:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
cc: clang
|
||||||
|
nvim_tag: stable
|
||||||
|
|
||||||
|
- os: macos-14
|
||||||
|
cc: gcc
|
||||||
|
nvim_tag: stable
|
||||||
|
|
||||||
|
- os: windows-latest
|
||||||
|
cc: clang
|
||||||
|
nvim_tag: stable
|
||||||
|
|
||||||
|
include:
|
||||||
|
- os: windows-latest
|
||||||
|
cc: cl
|
||||||
|
nvim_tag: nightly
|
||||||
|
|
||||||
|
- os: ubuntu-latest
|
||||||
|
cc: gcc
|
||||||
|
nvim_tag: nightly
|
||||||
|
|
||||||
|
name: Parser compilation
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
CC: ${{ matrix.cc }}
|
||||||
|
NVIM: ${{ matrix.os == 'windows-latest' && 'nvim-win64\\bin\\nvim.exe' || 'nvim' }}
|
||||||
|
ALLOWED_INSTALLATION_FAILURES: ${{ matrix.os == 'windows-latest' && 'rnoweb' }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: tree-sitter/setup-action/cli@v1
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
|
||||||
|
- name: Install and prepare Neovim
|
||||||
|
env:
|
||||||
|
NVIM_TAG: ${{ matrix.nvim_tag }}
|
||||||
|
run: |
|
||||||
|
bash ./scripts/ci-install.sh
|
||||||
|
|
||||||
|
- name: Setup Parsers Cache
|
||||||
|
id: parsers-cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
./parser/
|
||||||
|
~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/
|
||||||
|
key: parsers-${{ join(matrix.*, '-') }}-${{ hashFiles(
|
||||||
|
'./lockfile.json',
|
||||||
|
'./lua/nvim-treesitter/install.lua',
|
||||||
|
'./lua/nvim-treesitter/parsers.lua',
|
||||||
|
'./lua/nvim-treesitter/shell_command_selectors.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: runner.os == 'Windows'
|
||||||
|
run: cp -r ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/* parser
|
||||||
|
|
||||||
|
- name: Check query files
|
||||||
|
run: $NVIM -l scripts/check-queries.lua
|
64
pack/ant/start/nvim-treesitter/.github/workflows/tests.yml
vendored
Normal file
64
pack/ant/start/nvim-treesitter/.github/workflows/tests.yml
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "master"
|
||||||
|
|
||||||
|
# Cancel any in-progress CI runs for a PR if it is updated
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check_compilation:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
cc: [gcc]
|
||||||
|
|
||||||
|
name: Run tests
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
CC: ${{ matrix.cc }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: tree-sitter/setup-action/cli@v1
|
||||||
|
|
||||||
|
- name: Test Dependencies
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.local/share/nvim/site/pack/plenary.nvim/start
|
||||||
|
cd ~/.local/share/nvim/site/pack/plenary.nvim/start
|
||||||
|
git clone https://github.com/nvim-lua/plenary.nvim
|
||||||
|
curl -L https://github.com/theHamsta/highlight-assertions/releases/download/v0.1.6/highlight-assertions_v0.1.6_x86_64-unknown-linux-gnu.tar.gz | tar -xz
|
||||||
|
cp highlight-assertions /usr/local/bin
|
||||||
|
|
||||||
|
- name: Install and prepare Neovim
|
||||||
|
env:
|
||||||
|
NVIM_TAG: stable
|
||||||
|
run: |
|
||||||
|
bash ./scripts/ci-install.sh
|
||||||
|
|
||||||
|
- name: Setup Parsers Cache
|
||||||
|
id: parsers-cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
./parser/
|
||||||
|
~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/
|
||||||
|
key: parsers-${{ join(matrix.*, '-') }}-${{ hashFiles(
|
||||||
|
'./lockfile.json',
|
||||||
|
'./lua/nvim-treesitter/install.lua',
|
||||||
|
'./lua/nvim-treesitter/parsers.lua',
|
||||||
|
'./lua/nvim-treesitter/shell_selectors.lua') }}
|
||||||
|
|
||||||
|
- name: Compile parsers Unix like
|
||||||
|
run: |
|
||||||
|
nvim --headless -c "TSInstallSync all" -c "q"
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: PATH=/usr/local/bin:$PATH ./scripts/run_tests.sh
|
58
pack/ant/start/nvim-treesitter/.github/workflows/update-lockfile.yml
vendored
Normal file
58
pack/ant/start/nvim-treesitter/.github/workflows/update-lockfile.yml
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
name: Update lockfile
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "30 6 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-lockfile:
|
||||||
|
name: Update lockfile
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: master
|
||||||
|
|
||||||
|
- uses: actions/create-github-app-token@v1
|
||||||
|
id: app-token
|
||||||
|
with:
|
||||||
|
app-id: ${{ vars.TOKEN_ID }}
|
||||||
|
private-key: ${{ secrets.TOKEN_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
env:
|
||||||
|
NVIM_TAG: stable
|
||||||
|
run: |
|
||||||
|
wget https://github.com/josephburnett/jd/releases/download/v1.7.1/jd-amd64-linux
|
||||||
|
mv jd-amd64-linux /tmp/jd
|
||||||
|
chmod +x /tmp/jd
|
||||||
|
bash scripts/ci-install.sh
|
||||||
|
|
||||||
|
- name: Update parsers
|
||||||
|
env:
|
||||||
|
SKIP_LOCKFILE_UPDATE_FOR_LANGS: "djot"
|
||||||
|
run: |
|
||||||
|
cp lockfile.json /tmp/old_lockfile.json
|
||||||
|
nvim -l scripts/write-lockfile.lua
|
||||||
|
# Pretty print
|
||||||
|
cp lockfile.json /tmp/lockfile.json
|
||||||
|
cat /tmp/lockfile.json | jq --sort-keys > lockfile.json
|
||||||
|
UPDATED_PARSERS=$(/tmp/jd -f merge /tmp/old_lockfile.json lockfile.json | jq -r 'keys | join(", ")')
|
||||||
|
echo "UPDATED_PARSERS=$UPDATED_PARSERS" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v7
|
||||||
|
with:
|
||||||
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
|
sign-commits: true
|
||||||
|
commit-message: "bot(lockfile): update ${{ env.UPDATED_PARSERS }}"
|
||||||
|
title: "Update lockfile.json: ${{ env.UPDATED_PARSERS }}"
|
||||||
|
body: "[beep boop](https://github.com/peter-evans/create-pull-request)"
|
||||||
|
branch: update-lockfile-pr
|
||||||
|
base: ${{ github.head_ref }}
|
||||||
|
|
||||||
|
- name: Enable Pull Request Automerge
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||||
|
run: gh pr merge --rebase --auto update-lockfile-pr
|
46
pack/ant/start/nvim-treesitter/.github/workflows/update-readme.yml
vendored
Normal file
46
pack/ant/start/nvim-treesitter/.github/workflows/update-readme.yml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
name: Update README
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-readme:
|
||||||
|
name: Update README
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/create-github-app-token@v1
|
||||||
|
id: app-token
|
||||||
|
with:
|
||||||
|
app-id: ${{ vars.TOKEN_ID }}
|
||||||
|
private-key: ${{ secrets.TOKEN_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
env:
|
||||||
|
NVIM_TAG: stable
|
||||||
|
run: |
|
||||||
|
bash ./scripts/ci-install.sh
|
||||||
|
|
||||||
|
- name: Check README
|
||||||
|
run: |
|
||||||
|
nvim -l scripts/update-readme.lua || echo 'Needs update'
|
||||||
|
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v7
|
||||||
|
with:
|
||||||
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
|
sign-commits: true
|
||||||
|
commit-message: "bot(readme): update"
|
||||||
|
title: Update README
|
||||||
|
body: "[beep boop](https://github.com/peter-evans/create-pull-request)"
|
||||||
|
branch: update-readme-pr
|
||||||
|
base: ${{ github.head_ref }}
|
||||||
|
|
||||||
|
- name: Enable Pull Request Automerge
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||||
|
run: gh pr merge --rebase --auto update-readme-pr
|
7
pack/ant/start/nvim-treesitter/.gitignore
vendored
Normal file
7
pack/ant/start/nvim-treesitter/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
doc/tags
|
||||||
|
.luacheckcache
|
||||||
|
/tags
|
||||||
|
nvim.appimage
|
||||||
|
nvim-linux64*
|
||||||
|
nvim-macos*
|
||||||
|
nvim-win64*
|
21
pack/ant/start/nvim-treesitter/.luacheckrc
Normal file
21
pack/ant/start/nvim-treesitter/.luacheckrc
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
-- Rerun tests only if their modification time changed.
|
||||||
|
cache = true
|
||||||
|
codes = true
|
||||||
|
|
||||||
|
exclude_files = {
|
||||||
|
"tests/indent/lua/"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Glorious list of warnings: https://luacheck.readthedocs.io/en/stable/warnings.html
|
||||||
|
ignore = {
|
||||||
|
"212", -- Unused argument, In the case of callback function, _arg_name is easier to understand than _, so this option is set to off.
|
||||||
|
"411", -- Redefining a local variable.
|
||||||
|
"412", -- Redefining an argument.
|
||||||
|
"422", -- Shadowing an argument
|
||||||
|
"122" -- Indirectly setting a readonly global
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Global objects defined by the C code
|
||||||
|
read_globals = {
|
||||||
|
"vim",
|
||||||
|
}
|
25
pack/ant/start/nvim-treesitter/.luarc.json
Normal file
25
pack/ant/start/nvim-treesitter/.luarc.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
|
||||||
|
"runtime": {
|
||||||
|
"version": "LuaJIT"
|
||||||
|
},
|
||||||
|
"workspace": {
|
||||||
|
"library": [
|
||||||
|
"lua",
|
||||||
|
"$VIMRUNTIME",
|
||||||
|
"${3rd}/luv/library"
|
||||||
|
],
|
||||||
|
"checkThirdParty": false
|
||||||
|
},
|
||||||
|
"diagnostics": {
|
||||||
|
"groupFileStatus": {
|
||||||
|
"strict": "Opened",
|
||||||
|
"strong": "Opened"
|
||||||
|
},
|
||||||
|
"groupSeverity": {
|
||||||
|
"strong": "Warning",
|
||||||
|
"strict": "Warning"
|
||||||
|
},
|
||||||
|
"unusedLocalExclude": [ "_*" ]
|
||||||
|
}
|
||||||
|
}
|
6
pack/ant/start/nvim-treesitter/.stylua.toml
Normal file
6
pack/ant/start/nvim-treesitter/.stylua.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
column_width = 120
|
||||||
|
line_endings = "Unix"
|
||||||
|
indent_type = "Spaces"
|
||||||
|
indent_width = 2
|
||||||
|
quote_style = "AutoPreferDouble"
|
||||||
|
call_parentheses = "None"
|
1
pack/ant/start/nvim-treesitter/.styluaignore
Normal file
1
pack/ant/start/nvim-treesitter/.styluaignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
tests/indent/lua/
|
401
pack/ant/start/nvim-treesitter/CONTRIBUTING.md
Normal file
401
pack/ant/start/nvim-treesitter/CONTRIBUTING.md
Normal file
|
@ -0,0 +1,401 @@
|
||||||
|
# Contributing to `nvim-treesitter`
|
||||||
|
|
||||||
|
First of all, thank you very much for contributing to `nvim-treesitter`.
|
||||||
|
|
||||||
|
If you haven't already, you should really come and reach out to us on our
|
||||||
|
[Matrix channel], so we can help you with any question you might have!
|
||||||
|
|
||||||
|
As you know, `nvim-treesitter` is roughly split in two parts:
|
||||||
|
|
||||||
|
- Parser configurations : for various things like `locals`, `highlights`
|
||||||
|
- What we like to call _modules_ : tiny Lua modules that provide a given feature, based on parser configurations
|
||||||
|
|
||||||
|
Depending on which part of the plugin you want to contribute to, please read the appropriate section.
|
||||||
|
|
||||||
|
## Style Checks and Tests
|
||||||
|
|
||||||
|
We haven't implemented any functional tests yet. Feel free to contribute.
|
||||||
|
However, we check code style with `luacheck` and `stylua`!
|
||||||
|
Please install luacheck and activate our `pre-push` hook to automatically check style before
|
||||||
|
every push:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
luarocks install luacheck
|
||||||
|
cargo install stylua
|
||||||
|
ln -s ../../scripts/pre-push .git/hooks/pre-push
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding new modules
|
||||||
|
|
||||||
|
If you want to see a new functionality added to `nvim-treesitter` feel free to first open an issue
|
||||||
|
to that we can track our solution!
|
||||||
|
Thus far, there is basically two types of modules:
|
||||||
|
|
||||||
|
- Little modules (like `incremental selection`) that are built in `nvim-treesitter`, we call them
|
||||||
|
`builtin modules`.
|
||||||
|
- Bigger modules (like `completion-treesitter`, or `nvim-tree-docs`), or modules that integrate
|
||||||
|
with other plugins, that we call `remote modules`.
|
||||||
|
|
||||||
|
In any case, you can build your own module! To help you started in the process, we have a template
|
||||||
|
repository designed to build new modules [here](https://github.com/nvim-treesitter/module-template).
|
||||||
|
Feel free to use it, and contact us over on our
|
||||||
|
on the "Neovim tree-sitter" [Matrix channel].
|
||||||
|
|
||||||
|
## Parser configurations
|
||||||
|
|
||||||
|
Contributing to parser configurations is basically modifying one of the `queries/*/*.scm`.
|
||||||
|
Each of these `scheme` files contains a _tree-sitter query_ for a given purpose.
|
||||||
|
Before going any further, we highly suggest that you [read more about tree-sitter queries](https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries).
|
||||||
|
|
||||||
|
Each query has an appropriate name, which is then used by modules to extract data from the syntax tree.
|
||||||
|
For now these are the types of queries used by `nvim-treesitter`:
|
||||||
|
|
||||||
|
- `highlights.scm`: used for syntax highlighting, using the `highlight` module.
|
||||||
|
- `locals.scm`: used to extract keyword definitions, scopes, references, etc, using the `locals` module.
|
||||||
|
- `textobjects.scm`: used to define text objects.
|
||||||
|
- `folds.scm`: used to define folds.
|
||||||
|
- `injections.scm`: used to define injections.
|
||||||
|
|
||||||
|
For these types there is a _norm_ you will have to follow so that features work fine.
|
||||||
|
Here are some global advices:
|
||||||
|
|
||||||
|
- If your language is listed [here](https://github.com/nvim-treesitter/nvim-treesitter#supported-languages),
|
||||||
|
you can install the [playground plugin](https://github.com/nvim-treesitter/playground).
|
||||||
|
- If your language is listed [here](https://github.com/nvim-treesitter/nvim-treesitter#supported-languages),
|
||||||
|
you can debug and experiment with your queries there.
|
||||||
|
- If not, you should consider installing the [tree-sitter CLI](https://github.com/tree-sitter/tree-sitter/tree/master/cli),
|
||||||
|
you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the
|
||||||
|
parsers repo.
|
||||||
|
- Examples of queries can be found in [queries/](queries/)
|
||||||
|
- Matches in the bottom will override queries that are above of them.
|
||||||
|
|
||||||
|
#### Inheriting languages
|
||||||
|
|
||||||
|
If your language is an extension of a language (TypeScript is an extension of JavaScript for
|
||||||
|
example), you can include the queries from your base language by adding the following _as the first
|
||||||
|
line of your file_.
|
||||||
|
|
||||||
|
```query
|
||||||
|
; inherits: lang1,(optionallang)
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to inherit a language, but don't want the languages inheriting from yours to inherit it,
|
||||||
|
you can mark the language as optional (by putting it between parenthesis).
|
||||||
|
|
||||||
|
#### Formatting
|
||||||
|
|
||||||
|
All queries are expected to follow a standard format, with every node on a single line and indented by two spaces for each level of nesting. You can automatically format the bundled queries by running the provided formatter `./scripts/format-queries.lua` on a single file (ending in `.scm`) or directory to format.
|
||||||
|
|
||||||
|
Should you need to preserve a specific format for a node, you can exempt it (and all contained nodes) by placing before it
|
||||||
|
```query
|
||||||
|
; format-ignore
|
||||||
|
```
|
||||||
|
|
||||||
|
### Highlights
|
||||||
|
|
||||||
|
As languages differ quite a lot, here is a set of captures available to you when building a `highlights.scm` query. Note that your color scheme needs to define (or link) these captures as highlight groups.
|
||||||
|
|
||||||
|
#### Identifiers
|
||||||
|
|
||||||
|
```query
|
||||||
|
@variable ; various variable names
|
||||||
|
@variable.builtin ; built-in variable names (e.g. `this`)
|
||||||
|
@variable.parameter ; parameters of a function
|
||||||
|
@variable.parameter.builtin ; special parameters (e.g. `_`, `it`)
|
||||||
|
@variable.member ; object and struct fields
|
||||||
|
|
||||||
|
@constant ; constant identifiers
|
||||||
|
@constant.builtin ; built-in constant values
|
||||||
|
@constant.macro ; constants defined by the preprocessor
|
||||||
|
|
||||||
|
@module ; modules or namespaces
|
||||||
|
@module.builtin ; built-in modules or namespaces
|
||||||
|
@label ; GOTO and other labels (e.g. `label:` in C), including heredoc labels
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Literals
|
||||||
|
|
||||||
|
```query
|
||||||
|
@string ; string literals
|
||||||
|
@string.documentation ; string documenting code (e.g. Python docstrings)
|
||||||
|
@string.regexp ; regular expressions
|
||||||
|
@string.escape ; escape sequences
|
||||||
|
@string.special ; other special strings (e.g. dates)
|
||||||
|
@string.special.symbol ; symbols or atoms
|
||||||
|
@string.special.url ; URIs (e.g. hyperlinks)
|
||||||
|
@string.special.path ; filenames
|
||||||
|
|
||||||
|
@character ; character literals
|
||||||
|
@character.special ; special characters (e.g. wildcards)
|
||||||
|
|
||||||
|
@boolean ; boolean literals
|
||||||
|
@number ; numeric literals
|
||||||
|
@number.float ; floating-point number literals
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Types
|
||||||
|
|
||||||
|
```query
|
||||||
|
@type ; type or class definitions and annotations
|
||||||
|
@type.builtin ; built-in types
|
||||||
|
@type.definition ; identifiers in type definitions (e.g. `typedef <type> <identifier>` in C)
|
||||||
|
|
||||||
|
@attribute ; attribute annotations (e.g. Python decorators, Rust lifetimes)
|
||||||
|
@attribute.builtin ; builtin annotations (e.g. `@property` in Python)
|
||||||
|
@property ; the key in key/value pairs
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Functions
|
||||||
|
|
||||||
|
```query
|
||||||
|
@function ; function definitions
|
||||||
|
@function.builtin ; built-in functions
|
||||||
|
@function.call ; function calls
|
||||||
|
@function.macro ; preprocessor macros
|
||||||
|
|
||||||
|
@function.method ; method definitions
|
||||||
|
@function.method.call ; method calls
|
||||||
|
|
||||||
|
@constructor ; constructor calls and definitions
|
||||||
|
@operator ; symbolic operators (e.g. `+` / `*`)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Keywords
|
||||||
|
|
||||||
|
```query
|
||||||
|
@keyword ; keywords not fitting into specific categories
|
||||||
|
@keyword.coroutine ; keywords related to coroutines (e.g. `go` in Go, `async/await` in Python)
|
||||||
|
@keyword.function ; keywords that define a function (e.g. `func` in Go, `def` in Python)
|
||||||
|
@keyword.operator ; operators that are English words (e.g. `and` / `or`)
|
||||||
|
@keyword.import ; keywords for including or exporting modules (e.g. `import` / `from` in Python)
|
||||||
|
@keyword.type ; keywords describing namespaces and composite types (e.g. `struct`, `enum`)
|
||||||
|
@keyword.modifier ; keywords modifying other constructs (e.g. `const`, `static`, `public`)
|
||||||
|
@keyword.repeat ; keywords related to loops (e.g. `for` / `while`)
|
||||||
|
@keyword.return ; keywords like `return` and `yield`
|
||||||
|
@keyword.debug ; keywords related to debugging
|
||||||
|
@keyword.exception ; keywords related to exceptions (e.g. `throw` / `catch`)
|
||||||
|
|
||||||
|
@keyword.conditional ; keywords related to conditionals (e.g. `if` / `else`)
|
||||||
|
@keyword.conditional.ternary ; ternary operator (e.g. `?` / `:`)
|
||||||
|
|
||||||
|
@keyword.directive ; various preprocessor directives & shebangs
|
||||||
|
@keyword.directive.define ; preprocessor definition directives
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Punctuation
|
||||||
|
|
||||||
|
```query
|
||||||
|
@punctuation.delimiter ; delimiters (e.g. `;` / `.` / `,`)
|
||||||
|
@punctuation.bracket ; brackets (e.g. `()` / `{}` / `[]`)
|
||||||
|
@punctuation.special ; special symbols (e.g. `{}` in string interpolation)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Comments
|
||||||
|
|
||||||
|
```query
|
||||||
|
@comment ; line and block comments
|
||||||
|
@comment.documentation ; comments documenting code
|
||||||
|
|
||||||
|
@comment.error ; error-type comments (e.g. `ERROR`, `FIXME`, `DEPRECATED`)
|
||||||
|
@comment.warning ; warning-type comments (e.g. `WARNING`, `FIX`, `HACK`)
|
||||||
|
@comment.todo ; todo-type comments (e.g. `TODO`, `WIP`)
|
||||||
|
@comment.note ; note-type comments (e.g. `NOTE`, `INFO`, `XXX`)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Markup
|
||||||
|
|
||||||
|
Mainly for markup languages.
|
||||||
|
|
||||||
|
```query
|
||||||
|
@markup.strong ; bold text
|
||||||
|
@markup.italic ; italic text
|
||||||
|
@markup.strikethrough ; struck-through text
|
||||||
|
@markup.underline ; underlined text (only for literal underline markup!)
|
||||||
|
|
||||||
|
@markup.heading ; headings, titles (including markers)
|
||||||
|
@markup.heading.1 ; top-level heading
|
||||||
|
@markup.heading.2 ; section heading
|
||||||
|
@markup.heading.3 ; subsection heading
|
||||||
|
@markup.heading.4 ; and so on
|
||||||
|
@markup.heading.5 ; and so forth
|
||||||
|
@markup.heading.6 ; six levels ought to be enough for anybody
|
||||||
|
|
||||||
|
@markup.quote ; block quotes
|
||||||
|
@markup.math ; math environments (e.g. `$ ... $` in LaTeX)
|
||||||
|
|
||||||
|
@markup.link ; text references, footnotes, citations, etc.
|
||||||
|
@markup.link.label ; link, reference descriptions
|
||||||
|
@markup.link.url ; URL-style links
|
||||||
|
|
||||||
|
@markup.raw ; literal or verbatim text (e.g. inline code)
|
||||||
|
@markup.raw.block ; literal or verbatim text as a stand-alone block
|
||||||
|
; (use priority 90 for blocks with injections)
|
||||||
|
|
||||||
|
@markup.list ; list markers
|
||||||
|
@markup.list.checked ; checked todo-style list markers
|
||||||
|
@markup.list.unchecked ; unchecked todo-style list markers
|
||||||
|
```
|
||||||
|
|
||||||
|
```query
|
||||||
|
@diff.plus ; added text (for diff files)
|
||||||
|
@diff.minus ; deleted text (for diff files)
|
||||||
|
@diff.delta ; changed text (for diff files)
|
||||||
|
```
|
||||||
|
|
||||||
|
```query
|
||||||
|
@tag ; XML-style tag names (and similar)
|
||||||
|
@tag.builtin ; builtin tag names (e.g. HTML5 tags)
|
||||||
|
@tag.attribute ; XML-style tag attributes
|
||||||
|
@tag.delimiter ; XML-style tag delimiters
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Non-highlighting captures
|
||||||
|
|
||||||
|
```query
|
||||||
|
@none ; completely disable the highlight
|
||||||
|
@conceal ; captures that are only meant to be concealed
|
||||||
|
```
|
||||||
|
|
||||||
|
```query
|
||||||
|
@spell ; for defining regions to be spellchecked
|
||||||
|
@nospell ; for defining regions that should NOT be spellchecked
|
||||||
|
```
|
||||||
|
|
||||||
|
The main types of nodes which are spell checked are:
|
||||||
|
- Comments
|
||||||
|
- Strings; where it makes sense. Strings that have interpolation or are typically used for non text purposes are not spell checked (e.g. bash).
|
||||||
|
|
||||||
|
#### Predicates
|
||||||
|
|
||||||
|
Captures can be restricted according to node contents using [predicates](https://neovim.io/doc/user/treesitter.html#treesitter-predicates). For performance reasons, prefer earlier predicates in this list:
|
||||||
|
|
||||||
|
1. `#eq?` (literal match)
|
||||||
|
2. `#any-of?` (one of several literal matches)
|
||||||
|
3. `#lua-match?` (match against a [Lua pattern](https://neovim.io/doc/user/luaref.html#lua-pattern))
|
||||||
|
4. `#match?`/`#vim-match?` (match against a [Vim regular expression](https://neovim.io/doc/user/pattern.html#regexp)
|
||||||
|
|
||||||
|
#### Conceal
|
||||||
|
|
||||||
|
Captures can be concealed by setting the [`conceal` metadata](https://neovim.io/doc/user/treesitter.html#treesitter-highlight-conceal), e.g..,
|
||||||
|
```query
|
||||||
|
(fenced_code_block_delimiter @markup.raw.block (#set! conceal ""))
|
||||||
|
```
|
||||||
|
The capture should be meaningful to allow proper highlighting when `set conceallevel=0`. If the unconcealed capture should not be highlighted (e.g., because an earlier pattern handles this), you can use `@conceal`.
|
||||||
|
|
||||||
|
A conceal can be restricted to part of the capture via the [`#offset!` directive](https://neovim.io/doc/user/treesitter.html#treesitter-directive-offset%21).
|
||||||
|
|
||||||
|
#### Priority
|
||||||
|
|
||||||
|
Captures can be assigned a priority to control precedence of highlights via the
|
||||||
|
`#set! priority <number>` directive (see `:h treesitter-highlight-priority`).
|
||||||
|
The default priority for treesitter highlights is `100`; queries should only
|
||||||
|
set priorities between `90` and `120`, to avoid conflict with other sources of
|
||||||
|
highlighting (such as diagnostics or LSP semantic tokens).
|
||||||
|
|
||||||
|
### Locals
|
||||||
|
|
||||||
|
Locals are used to keep track of definitions and references in local or global
|
||||||
|
scopes, see [upstream
|
||||||
|
documentation](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables).
|
||||||
|
Note that nvim-treesitter uses more specific subcaptures for definitions and
|
||||||
|
**does not use locals for highlighting**.
|
||||||
|
|
||||||
|
```query
|
||||||
|
@local.definition ; various definitions
|
||||||
|
@local.definition.constant ; constants
|
||||||
|
@local.definition.function ; functions
|
||||||
|
@local.definition.method ; methods
|
||||||
|
@local.definition.var ; variables
|
||||||
|
@local.definition.parameter ; parameters
|
||||||
|
@local.definition.macro ; preprocessor macros
|
||||||
|
@local.definition.type ; types or classes
|
||||||
|
@local.definition.field ; fields or properties
|
||||||
|
@local.definition.enum ; enumerations
|
||||||
|
@local.definition.namespace ; modules or namespaces
|
||||||
|
@local.definition.import ; imported names
|
||||||
|
@local.definition.associated ; the associated type of a variable
|
||||||
|
|
||||||
|
@local.scope ; scope block
|
||||||
|
@local.reference ; identifier reference
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Definition Scope
|
||||||
|
|
||||||
|
You can set the scope of a definition by setting the `scope` property on the definition.
|
||||||
|
|
||||||
|
For example, a JavaScript function declaration creates a scope. The function name is captured as the definition.
|
||||||
|
This means that the function definition would only be available WITHIN the scope of the function, which is not the case.
|
||||||
|
The definition can be used in the scope the function was defined in.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
function doSomething() {}
|
||||||
|
|
||||||
|
doSomething(); // Should point to the declaration as the definition
|
||||||
|
```
|
||||||
|
|
||||||
|
```query
|
||||||
|
(function_declaration
|
||||||
|
((identifier) @local.definition.var)
|
||||||
|
(#set! definition.var.scope "parent"))
|
||||||
|
```
|
||||||
|
|
||||||
|
Possible scope values are:
|
||||||
|
|
||||||
|
- `parent`: The definition is valid in the containing scope and one more scope above that scope
|
||||||
|
- `global`: The definition is valid in the root scope
|
||||||
|
- `local`: The definition is valid in the containing scope. This is the default behavior
|
||||||
|
|
||||||
|
### Folds
|
||||||
|
|
||||||
|
You can define folds for a given language by adding a `folds.scm` query :
|
||||||
|
|
||||||
|
```query
|
||||||
|
@fold ; fold this node
|
||||||
|
```
|
||||||
|
|
||||||
|
If the `folds.scm` query is not present, this will fall back to the `@local.scope` captures in the `locals`
|
||||||
|
query.
|
||||||
|
|
||||||
|
### Injections
|
||||||
|
|
||||||
|
Some captures are related to language injection (like markdown code blocks). They are used in `injections.scm`.
|
||||||
|
|
||||||
|
If you want to dynamically detect the language (e.g. for Markdown blocks) use the `@injection.language` to capture
|
||||||
|
the node describing the language and `@injection.content` to describe the injection region.
|
||||||
|
|
||||||
|
```query
|
||||||
|
@injection.language ; dynamic detection of the injection language (i.e. the text of the captured node describes the language)
|
||||||
|
@injection.content ; region for the dynamically detected language
|
||||||
|
```
|
||||||
|
|
||||||
|
For example, to inject javascript into HTML's `<script>` tag
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script>someJsCode();</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
```query
|
||||||
|
(script_element
|
||||||
|
(raw_text) @injection.content
|
||||||
|
(#set! injection.language "javascript")) ; set the parser language for @injection.content region to javascript
|
||||||
|
```
|
||||||
|
|
||||||
|
For regions that don't have a corresponding `@injection.language`, you need to manually set the language
|
||||||
|
through `(#set injection.language "lang_name")`
|
||||||
|
|
||||||
|
To combine all matches of a pattern as one single block of content, add `(#set! injection.combined)` to such pattern
|
||||||
|
|
||||||
|
### Indents
|
||||||
|
|
||||||
|
```query
|
||||||
|
@indent.begin ; indent children when matching this node
|
||||||
|
@indent.end ; marks the end of indented block
|
||||||
|
@indent.align ; behaves like python aligned/hanging indent
|
||||||
|
@indent.dedent ; dedent children when matching this node
|
||||||
|
@indent.branch ; dedent itself when matching this node
|
||||||
|
@indent.ignore ; do not indent in this node
|
||||||
|
@indent.auto ; behaves like 'autoindent' buffer option
|
||||||
|
@indent.zero ; sets this node at position 0 (no indent)
|
||||||
|
```
|
||||||
|
|
||||||
|
[Matrix channel]: https://matrix.to/#/#nvim-treesitter:matrix.org
|
201
pack/ant/start/nvim-treesitter/LICENSE
Normal file
201
pack/ant/start/nvim-treesitter/LICENSE
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
7
pack/ant/start/nvim-treesitter/Makefile
Normal file
7
pack/ant/start/nvim-treesitter/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# https://github.com/luarocks/luarocks/wiki/Creating-a-Makefile-that-plays-nice-with-LuaRocks
|
||||||
|
build:
|
||||||
|
echo "Do nothing"
|
||||||
|
|
||||||
|
install:
|
||||||
|
mkdir -p $(INST_LUADIR)
|
||||||
|
cp -r lua/* $(INST_LUADIR)
|
833
pack/ant/start/nvim-treesitter/README.md
Normal file
833
pack/ant/start/nvim-treesitter/README.md
Normal file
|
@ -0,0 +1,833 @@
|
||||||
|
<div align="center">
|
||||||
|
<h1>nvim-treesitter</h1>
|
||||||
|
<p>
|
||||||
|
<a href="https://matrix.to/#/#nvim-treesitter:matrix.org">
|
||||||
|
<img alt="Matrix Chat" src="https://img.shields.io/matrix/nvim-treesitter:matrix.org" />
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/nvim-treesitter/nvim-treesitter/actions?query=workflow%3A%22Linting+and+style+checking%22+branch%3Amaster">
|
||||||
|
<img alt="Linting and Style" src="https://github.com/nvim-treesitter/nvim-treesitter/workflows/Linting%20and%20style%20checking/badge.svg" />
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/nvim-treesitter/nvim-treesitter/actions?query=workflow%3A%22Check+loading+of+syntax+files%22+branch%3Amaster">
|
||||||
|
<img alt="Syntax files" src="https://github.com/nvim-treesitter/nvim-treesitter/workflows/Check%20loading%20of%20syntax%20files/badge.svg" />
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<p>
|
||||||
|
<img src="assets/logo.png" align="center" alt="Logo" />
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://github.com/tree-sitter/tree-sitter">Treesitter</a>
|
||||||
|
configurations and abstraction layer for
|
||||||
|
<a href="https://github.com/neovim/neovim/">Neovim</a>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>
|
||||||
|
Logo by <a href="https://github.com/steelsojka">@steelsojka</a>
|
||||||
|
</i>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
The goal of `nvim-treesitter` is both to provide a simple and easy way to use the interface for [tree-sitter](https://github.com/tree-sitter/tree-sitter) in Neovim and to provide some basic functionality such as highlighting based on it:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Traditional highlighting (left) vs Treesitter-based highlighting (right).
|
||||||
|
More examples can be found in [our gallery](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Gallery).
|
||||||
|
|
||||||
|
**Warning: Treesitter and nvim-treesitter highlighting are an experimental feature of Neovim.
|
||||||
|
Please consider the experience with this plug-in as experimental until Tree-Sitter support in Neovim is stable!
|
||||||
|
We recommend using the nightly builds of Neovim if possible.
|
||||||
|
You can find the current roadmap [here](https://github.com/nvim-treesitter/nvim-treesitter/issues/4767).
|
||||||
|
The roadmap and all features of this plugin are open to change, and any suggestion will be highly appreciated!**
|
||||||
|
|
||||||
|
Nvim-treesitter is based on three interlocking features: [**language parsers**](#language-parsers), [**queries**](#adding-queries), and [**modules**](#available-modules), where _modules_ provide features – e.g., highlighting – based on _queries_ for syntax objects extracted from a given buffer by _language parsers_.
|
||||||
|
Users will generally only need to interact with parsers and modules as explained in the next section.
|
||||||
|
For more detailed information on setting these up, see ["Advanced setup"](#advanced-setup).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Table of contents
|
||||||
|
|
||||||
|
- [Quickstart](#quickstart)
|
||||||
|
- [Supported languages](#supported-languages)
|
||||||
|
- [Available modules](#available-modules)
|
||||||
|
- [Advanced setup](#advanced-setup)
|
||||||
|
- [Extra features](#extra-features)
|
||||||
|
- [Troubleshooting](#troubleshooting)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Quickstart
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **Neovim 0.9.2** or later ([nightly](https://github.com/neovim/neovim#install-from-source) recommended)
|
||||||
|
- `tar` and `curl` in your path (or alternatively `git`)
|
||||||
|
- A C compiler in your path and libstdc++ installed ([Windows users please read this!](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support)).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
You can install `nvim-treesitter` with your favorite package manager (or using the native `package` feature of vim, see `:h packages`).
|
||||||
|
|
||||||
|
**NOTE: This plugin is only guaranteed to work with specific versions of language parsers** (as specified in the `lockfile.json`). **When upgrading the plugin, you must make sure that all installed parsers are updated to the latest version** via `:TSUpdate`.
|
||||||
|
It is strongly recommended to automate this; e.g., if you are using [vim-plug](https://github.com/junegunn/vim-plug), put this in your `init.vim` file:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
|
||||||
|
```
|
||||||
|
|
||||||
|
For other plugin managers such as `packer.nvim`, see this [Installation page from the wiki](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Installation) (Note that this page is community maintained).
|
||||||
|
|
||||||
|
## Language parsers
|
||||||
|
|
||||||
|
Treesitter uses a different _parser_ for every language, which needs to be generated via `tree-sitter-cli` from a `grammar.js` file, then compiled to a `.so` library that needs to be placed in neovim's `runtimepath` (typically under `parser/{language}.so`).
|
||||||
|
To simplify this, `nvim-treesitter` provides commands to automate this process.
|
||||||
|
If the language is already [supported by `nvim-treesitter`](#supported-languages), you can install it with
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:TSInstall <language_to_install>
|
||||||
|
```
|
||||||
|
|
||||||
|
This command supports tab expansion.
|
||||||
|
You can also get a list of all available languages and their installation status with `:TSInstallInfo`.
|
||||||
|
Parsers not on this list can be added manually by following the steps described under ["Adding parsers"](#adding-parsers) below.
|
||||||
|
|
||||||
|
To make sure a parser is at the latest compatible version (as specified in `nvim-treesitter`'s `lockfile.json`), use `:TSUpdate {language}`. To update all parsers unconditionally, use `:TSUpdate all` or just `:TSUpdate`.
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
Each module provides a distinct tree-sitter-based feature such as [highlighting](#highlight), [indentation](#indentation), or [folding](#folding); see [`:h nvim-treesitter-modules`](doc/nvim-treesitter.txt) or ["Available modules"](#available-modules) below for a list of modules and their options.
|
||||||
|
|
||||||
|
Following examples assume that you are configuring neovim with lua. If you are using vimscript, see `:h lua-heredoc`.
|
||||||
|
All modules are disabled by default and need to be activated explicitly in your `init.lua`, e.g., via
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
-- A list of parser names, or "all" (the listed parsers MUST always be installed)
|
||||||
|
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" },
|
||||||
|
|
||||||
|
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||||
|
sync_install = false,
|
||||||
|
|
||||||
|
-- Automatically install missing parsers when entering buffer
|
||||||
|
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
|
||||||
|
auto_install = true,
|
||||||
|
|
||||||
|
-- List of parsers to ignore installing (or "all")
|
||||||
|
ignore_install = { "javascript" },
|
||||||
|
|
||||||
|
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
|
||||||
|
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
|
||||||
|
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
|
||||||
|
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
|
||||||
|
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
|
||||||
|
-- the name of the parser)
|
||||||
|
-- list of language that will be disabled
|
||||||
|
disable = { "c", "rust" },
|
||||||
|
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
|
||||||
|
disable = function(lang, buf)
|
||||||
|
local max_filesize = 100 * 1024 -- 100 KB
|
||||||
|
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
|
||||||
|
if ok and stats and stats.size > max_filesize then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||||
|
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
|
||||||
|
-- Using this option may slow down your editor, and you may see some duplicate highlights.
|
||||||
|
-- Instead of true it can also be a list of languages
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Each module can also be enabled or disabled interactively through the following commands:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:TSBufEnable {module} " enable module on current buffer
|
||||||
|
:TSBufDisable {module} " disable module on current buffer
|
||||||
|
:TSEnable {module} [{ft}] " enable module on every buffer. If filetype is specified, enable only for this filetype.
|
||||||
|
:TSDisable {module} [{ft}] " disable module on every buffer. If filetype is specified, disable only for this filetype.
|
||||||
|
:TSModuleInfo [{module}] " list information about modules state for each filetype
|
||||||
|
```
|
||||||
|
|
||||||
|
Check [`:h nvim-treesitter-commands`](doc/nvim-treesitter.txt) for a list of all available commands.
|
||||||
|
It may be necessary to reload the buffer (e.g., via `:e`) after enabling a module interactively.
|
||||||
|
|
||||||
|
# Supported languages
|
||||||
|
|
||||||
|
For `nvim-treesitter` to support a specific feature for a specific language requires both a parser for that language and an appropriate language-specific query file for that feature.
|
||||||
|
|
||||||
|
The following is a list of languages for which a parser can be installed through `:TSInstall`; a checked box means that `nvim-treesitter` also contains queries at least for the `highlight` module.
|
||||||
|
|
||||||
|
Experimental parsers are parsers that have a maintainer but are not stable enough for
|
||||||
|
daily use yet.
|
||||||
|
|
||||||
|
We are looking for maintainers to add more parsers and to write query files for their languages. Check our [tracking issue](https://github.com/nvim-treesitter/nvim-treesitter/issues/2282) for open language requests.
|
||||||
|
|
||||||
|
<!--This section of the README is automatically updated by a CI job-->
|
||||||
|
<!--parserinfo-->
|
||||||
|
- [x] [ada](https://github.com/briot/tree-sitter-ada) (maintained by @briot)
|
||||||
|
- [x] [agda](https://github.com/tree-sitter/tree-sitter-agda) (maintained by @Decodetalkers)
|
||||||
|
- [x] [angular](https://github.com/dlvandenberg/tree-sitter-angular) (experimental, maintained by @dlvandenberg)
|
||||||
|
- [x] [apex](https://github.com/aheber/tree-sitter-sfapex) (maintained by @aheber, @xixiaofinland)
|
||||||
|
- [x] [arduino](https://github.com/ObserverOfTime/tree-sitter-arduino) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [asm](https://github.com/RubixDev/tree-sitter-asm) (maintained by @RubixDev)
|
||||||
|
- [x] [astro](https://github.com/virchau13/tree-sitter-astro) (maintained by @virchau13)
|
||||||
|
- [x] [authzed](https://github.com/mleonidas/tree-sitter-authzed) (maintained by @mattpolzin)
|
||||||
|
- [ ] [awk](https://github.com/Beaglefoot/tree-sitter-awk)
|
||||||
|
- [x] [bash](https://github.com/tree-sitter/tree-sitter-bash) (maintained by @TravonteD)
|
||||||
|
- [x] [bass](https://github.com/vito/tree-sitter-bass) (maintained by @amaanq)
|
||||||
|
- [x] [beancount](https://github.com/polarmutex/tree-sitter-beancount) (maintained by @polarmutex)
|
||||||
|
- [x] [bibtex](https://github.com/latex-lsp/tree-sitter-bibtex) (maintained by @theHamsta, @clason)
|
||||||
|
- [x] [bicep](https://github.com/amaanq/tree-sitter-bicep) (maintained by @amaanq)
|
||||||
|
- [x] [bitbake](https://github.com/amaanq/tree-sitter-bitbake) (maintained by @amaanq)
|
||||||
|
- [x] [blueprint](https://gitlab.com/gabmus/tree-sitter-blueprint.git) (experimental, maintained by @gabmus)
|
||||||
|
- [x] [bp](https://github.com/ambroisie/tree-sitter-bp) (maintained by @ambroisie)
|
||||||
|
- [x] [c](https://github.com/tree-sitter/tree-sitter-c) (maintained by @amaanq)
|
||||||
|
- [x] [c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) (maintained by @amaanq)
|
||||||
|
- [x] [cairo](https://github.com/amaanq/tree-sitter-cairo) (maintained by @amaanq)
|
||||||
|
- [x] [capnp](https://github.com/amaanq/tree-sitter-capnp) (maintained by @amaanq)
|
||||||
|
- [x] [chatito](https://github.com/ObserverOfTime/tree-sitter-chatito) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [clojure](https://github.com/sogaiu/tree-sitter-clojure) (maintained by @NoahTheDuke)
|
||||||
|
- [x] [cmake](https://github.com/uyha/tree-sitter-cmake) (maintained by @uyha)
|
||||||
|
- [x] [comment](https://github.com/stsewd/tree-sitter-comment) (maintained by @stsewd)
|
||||||
|
- [x] [commonlisp](https://github.com/theHamsta/tree-sitter-commonlisp) (maintained by @theHamsta)
|
||||||
|
- [x] [cooklang](https://github.com/addcninblue/tree-sitter-cooklang) (maintained by @addcninblue)
|
||||||
|
- [x] [corn](https://github.com/jakestanger/tree-sitter-corn) (maintained by @jakestanger)
|
||||||
|
- [x] [cpon](https://github.com/amaanq/tree-sitter-cpon) (maintained by @amaanq)
|
||||||
|
- [x] [cpp](https://github.com/tree-sitter/tree-sitter-cpp) (maintained by @theHamsta)
|
||||||
|
- [x] [css](https://github.com/tree-sitter/tree-sitter-css) (maintained by @TravonteD)
|
||||||
|
- [x] [csv](https://github.com/amaanq/tree-sitter-csv) (maintained by @amaanq)
|
||||||
|
- [x] [cuda](https://github.com/theHamsta/tree-sitter-cuda) (maintained by @theHamsta)
|
||||||
|
- [x] [cue](https://github.com/eonpatapon/tree-sitter-cue) (maintained by @amaanq)
|
||||||
|
- [x] [d](https://github.com/gdamore/tree-sitter-d) (maintained by @amaanq)
|
||||||
|
- [x] [dart](https://github.com/UserNobody14/tree-sitter-dart) (maintained by @akinsho)
|
||||||
|
- [x] [devicetree](https://github.com/joelspadin/tree-sitter-devicetree) (maintained by @jedrzejboczar)
|
||||||
|
- [x] [dhall](https://github.com/jbellerb/tree-sitter-dhall) (maintained by @amaanq)
|
||||||
|
- [x] [diff](https://github.com/the-mikedavis/tree-sitter-diff) (maintained by @gbprod)
|
||||||
|
- [x] [disassembly](https://github.com/ColinKennedy/tree-sitter-disassembly) (maintained by @ColinKennedy)
|
||||||
|
- [x] [djot](https://github.com/treeman/tree-sitter-djot) (maintained by @NoahTheDuke)
|
||||||
|
- [x] [dockerfile](https://github.com/camdencheek/tree-sitter-dockerfile) (maintained by @camdencheek)
|
||||||
|
- [x] [dot](https://github.com/rydesun/tree-sitter-dot) (maintained by @rydesun)
|
||||||
|
- [x] [doxygen](https://github.com/amaanq/tree-sitter-doxygen) (maintained by @amaanq)
|
||||||
|
- [x] [dtd](https://github.com/tree-sitter-grammars/tree-sitter-xml) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [earthfile](https://github.com/glehmann/tree-sitter-earthfile) (maintained by @glehmann)
|
||||||
|
- [x] [ebnf](https://github.com/RubixDev/ebnf) (experimental, maintained by @RubixDev)
|
||||||
|
- [x] [editorconfig](https://github.com/ValdezFOmar/tree-sitter-editorconfig) (maintained by @ValdezFOmar)
|
||||||
|
- [x] [eds](https://github.com/uyha/tree-sitter-eds) (maintained by @uyha)
|
||||||
|
- [x] [eex](https://github.com/connorlay/tree-sitter-eex) (maintained by @connorlay)
|
||||||
|
- [x] [elixir](https://github.com/elixir-lang/tree-sitter-elixir) (maintained by @connorlay)
|
||||||
|
- [x] [elm](https://github.com/elm-tooling/tree-sitter-elm) (maintained by @zweimach)
|
||||||
|
- [x] [elsa](https://github.com/glapa-grossklag/tree-sitter-elsa) (maintained by @glapa-grossklag, @amaanq)
|
||||||
|
- [x] [elvish](https://github.com/elves/tree-sitter-elvish) (maintained by @elves)
|
||||||
|
- [ ] [embedded_template](https://github.com/tree-sitter/tree-sitter-embedded-template)
|
||||||
|
- [x] [erlang](https://github.com/WhatsApp/tree-sitter-erlang) (maintained by @filmor)
|
||||||
|
- [x] [facility](https://github.com/FacilityApi/tree-sitter-facility) (maintained by @bryankenote)
|
||||||
|
- [x] [faust](https://github.com/khiner/tree-sitter-faust) (maintained by @khiner)
|
||||||
|
- [x] [fennel](https://github.com/alexmozaidze/tree-sitter-fennel) (maintained by @alexmozaidze)
|
||||||
|
- [x] [fidl](https://github.com/google/tree-sitter-fidl) (maintained by @chaopeng)
|
||||||
|
- [x] [firrtl](https://github.com/amaanq/tree-sitter-firrtl) (maintained by @amaanq)
|
||||||
|
- [x] [fish](https://github.com/ram02z/tree-sitter-fish) (maintained by @ram02z)
|
||||||
|
- [x] [foam](https://github.com/FoamScience/tree-sitter-foam) (experimental, maintained by @FoamScience)
|
||||||
|
- [x] [forth](https://github.com/AlexanderBrevig/tree-sitter-forth) (maintained by @amaanq)
|
||||||
|
- [x] [fortran](https://github.com/stadelmanma/tree-sitter-fortran) (maintained by @amaanq)
|
||||||
|
- [x] [fsh](https://github.com/mgramigna/tree-sitter-fsh) (maintained by @mgramigna)
|
||||||
|
- [x] [fsharp](https://github.com/ionide/tree-sitter-fsharp) (maintained by @nsidorenco)
|
||||||
|
- [x] [func](https://github.com/amaanq/tree-sitter-func) (maintained by @amaanq)
|
||||||
|
- [x] [fusion](https://gitlab.com/jirgn/tree-sitter-fusion.git) (maintained by @jirgn)
|
||||||
|
- [x] [GAP system](https://github.com/gap-system/tree-sitter-gap) (maintained by @reiniscirpons)
|
||||||
|
- [x] [GAP system test files](https://github.com/gap-system/tree-sitter-gaptst) (maintained by @reiniscirpons)
|
||||||
|
- [x] [Godot (gdscript)](https://github.com/PrestonKnopp/tree-sitter-gdscript) (maintained by @PrestonKnopp)
|
||||||
|
- [x] [gdshader](https://github.com/GodOfAvacyn/tree-sitter-gdshader) (maintained by @godofavacyn)
|
||||||
|
- [x] [git_config](https://github.com/the-mikedavis/tree-sitter-git-config) (maintained by @amaanq)
|
||||||
|
- [x] [git_rebase](https://github.com/the-mikedavis/tree-sitter-git-rebase) (maintained by @gbprod)
|
||||||
|
- [x] [gitattributes](https://github.com/ObserverOfTime/tree-sitter-gitattributes) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [gitcommit](https://github.com/gbprod/tree-sitter-gitcommit) (maintained by @gbprod)
|
||||||
|
- [x] [gitignore](https://github.com/shunsambongi/tree-sitter-gitignore) (maintained by @theHamsta)
|
||||||
|
- [x] [gleam](https://github.com/gleam-lang/tree-sitter-gleam) (maintained by @amaanq)
|
||||||
|
- [x] [Glimmer and Ember](https://github.com/ember-tooling/tree-sitter-glimmer) (maintained by @NullVoxPopuli)
|
||||||
|
- [x] [glimmer_javascript](https://github.com/NullVoxPopuli/tree-sitter-glimmer-javascript) (maintained by @NullVoxPopuli)
|
||||||
|
- [x] [glimmer_typescript](https://github.com/NullVoxPopuli/tree-sitter-glimmer-typescript) (maintained by @NullVoxPopuli)
|
||||||
|
- [x] [glsl](https://github.com/theHamsta/tree-sitter-glsl) (maintained by @theHamsta)
|
||||||
|
- [x] [GN (Generate Ninja)](https://github.com/amaanq/tree-sitter-gn) (maintained by @amaanq)
|
||||||
|
- [x] [gnuplot](https://github.com/dpezto/tree-sitter-gnuplot) (maintained by @dpezto)
|
||||||
|
- [x] [go](https://github.com/tree-sitter/tree-sitter-go) (maintained by @theHamsta, @WinWisely268)
|
||||||
|
- [x] [goctl](https://github.com/chaozwn/tree-sitter-goctl) (maintained by @chaozwn)
|
||||||
|
- [x] [Godot Resources (gdresource)](https://github.com/PrestonKnopp/tree-sitter-godot-resource) (maintained by @pierpo)
|
||||||
|
- [x] [gomod](https://github.com/camdencheek/tree-sitter-go-mod) (maintained by @camdencheek)
|
||||||
|
- [x] [gosum](https://github.com/amaanq/tree-sitter-go-sum) (maintained by @amaanq)
|
||||||
|
- [x] [gotmpl](https://github.com/ngalaiko/tree-sitter-go-template) (maintained by @qvalentin)
|
||||||
|
- [x] [gowork](https://github.com/omertuc/tree-sitter-go-work) (maintained by @omertuc)
|
||||||
|
- [x] [gpg](https://github.com/ObserverOfTime/tree-sitter-gpg-config) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [graphql](https://github.com/bkegley/tree-sitter-graphql) (maintained by @bkegley)
|
||||||
|
- [x] [gren](https://github.com/MaeBrooks/tree-sitter-gren) (maintained by @MaeBrooks)
|
||||||
|
- [x] [groovy](https://github.com/murtaza64/tree-sitter-groovy) (maintained by @murtaza64)
|
||||||
|
- [x] [gstlaunch](https://github.com/theHamsta/tree-sitter-gstlaunch) (maintained by @theHamsta)
|
||||||
|
- [ ] [hack](https://github.com/slackhq/tree-sitter-hack)
|
||||||
|
- [x] [hare](https://github.com/amaanq/tree-sitter-hare) (maintained by @amaanq)
|
||||||
|
- [x] [haskell](https://github.com/tree-sitter/tree-sitter-haskell) (maintained by @mrcjkb)
|
||||||
|
- [x] [haskell_persistent](https://github.com/MercuryTechnologies/tree-sitter-haskell-persistent) (maintained by @lykahb)
|
||||||
|
- [x] [hcl](https://github.com/MichaHoffmann/tree-sitter-hcl) (maintained by @MichaHoffmann)
|
||||||
|
- [x] [heex](https://github.com/connorlay/tree-sitter-heex) (maintained by @connorlay)
|
||||||
|
- [x] [helm](https://github.com/ngalaiko/tree-sitter-go-template) (maintained by @qvalentin)
|
||||||
|
- [x] [hjson](https://github.com/winston0410/tree-sitter-hjson) (maintained by @winston0410)
|
||||||
|
- [x] [hlsl](https://github.com/theHamsta/tree-sitter-hlsl) (maintained by @theHamsta)
|
||||||
|
- [x] [hlsplaylist](https://github.com/Freed-Wu/tree-sitter-hlsplaylist) (maintained by @Freed-Wu)
|
||||||
|
- [x] [hocon](https://github.com/antosha417/tree-sitter-hocon) (maintained by @antosha417)
|
||||||
|
- [x] [hoon](https://github.com/urbit-pilled/tree-sitter-hoon) (experimental, maintained by @urbit-pilled)
|
||||||
|
- [x] [html](https://github.com/tree-sitter/tree-sitter-html) (maintained by @TravonteD)
|
||||||
|
- [x] [htmldjango](https://github.com/interdependence/tree-sitter-htmldjango) (experimental, maintained by @ObserverOfTime)
|
||||||
|
- [x] [http](https://github.com/rest-nvim/tree-sitter-http) (maintained by @amaanq, @NTBBloodbath)
|
||||||
|
- [x] [hurl](https://github.com/pfeiferj/tree-sitter-hurl) (maintained by @pfeiferj)
|
||||||
|
- [x] [hyprlang](https://github.com/luckasRanarison/tree-sitter-hyprlang) (maintained by @luckasRanarison)
|
||||||
|
- [x] [idl](https://github.com/cathaysia/tree-sitter-idl) (maintained by @cathaysia)
|
||||||
|
- [x] [ini](https://github.com/justinmk/tree-sitter-ini) (experimental, maintained by @theHamsta)
|
||||||
|
- [x] [inko](https://github.com/inko-lang/tree-sitter-inko) (maintained by @yorickpeterse)
|
||||||
|
- [x] [ispc](https://github.com/fab4100/tree-sitter-ispc) (maintained by @fab4100)
|
||||||
|
- [x] [janet_simple](https://github.com/sogaiu/tree-sitter-janet-simple) (maintained by @sogaiu)
|
||||||
|
- [x] [java](https://github.com/tree-sitter/tree-sitter-java) (maintained by @p00f)
|
||||||
|
- [x] [javascript](https://github.com/tree-sitter/tree-sitter-javascript) (maintained by @steelsojka)
|
||||||
|
- [x] [jq](https://github.com/flurie/tree-sitter-jq) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [jsdoc](https://github.com/tree-sitter/tree-sitter-jsdoc) (maintained by @steelsojka)
|
||||||
|
- [x] [json](https://github.com/tree-sitter/tree-sitter-json) (maintained by @steelsojka)
|
||||||
|
- [x] [json5](https://github.com/Joakker/tree-sitter-json5) (maintained by @Joakker)
|
||||||
|
- [x] [JSON with comments](https://gitlab.com/WhyNotHugo/tree-sitter-jsonc.git) (maintained by @WhyNotHugo)
|
||||||
|
- [x] [jsonnet](https://github.com/sourcegraph/tree-sitter-jsonnet) (maintained by @nawordar)
|
||||||
|
- [x] [julia](https://github.com/tree-sitter/tree-sitter-julia) (maintained by @theHamsta)
|
||||||
|
- [x] [just](https://github.com/IndianBoy42/tree-sitter-just) (maintained by @Hubro)
|
||||||
|
- [x] [kconfig](https://github.com/amaanq/tree-sitter-kconfig) (maintained by @amaanq)
|
||||||
|
- [x] [kdl](https://github.com/amaanq/tree-sitter-kdl) (maintained by @amaanq)
|
||||||
|
- [x] [kotlin](https://github.com/fwcd/tree-sitter-kotlin) (maintained by @SalBakraa)
|
||||||
|
- [x] [koto](https://github.com/koto-lang/tree-sitter-koto) (maintained by @irh)
|
||||||
|
- [x] [kusto](https://github.com/Willem-J-an/tree-sitter-kusto) (maintained by @Willem-J-an)
|
||||||
|
- [x] [lalrpop](https://github.com/traxys/tree-sitter-lalrpop) (maintained by @traxys)
|
||||||
|
- [x] [latex](https://github.com/latex-lsp/tree-sitter-latex) (maintained by @theHamsta, @clason)
|
||||||
|
- [x] [ledger](https://github.com/cbarrete/tree-sitter-ledger) (maintained by @cbarrete)
|
||||||
|
- [x] [leo](https://github.com/r001/tree-sitter-leo) (maintained by @r001)
|
||||||
|
- [x] [linkerscript](https://github.com/amaanq/tree-sitter-linkerscript) (maintained by @amaanq)
|
||||||
|
- [x] [liquid](https://github.com/hankthetank27/tree-sitter-liquid) (maintained by @hankthetank27)
|
||||||
|
- [x] [liquidsoap](https://github.com/savonet/tree-sitter-liquidsoap) (maintained by @toots)
|
||||||
|
- [x] [llvm](https://github.com/benwilliamgraham/tree-sitter-llvm) (maintained by @benwilliamgraham)
|
||||||
|
- [x] [lua](https://github.com/MunifTanjim/tree-sitter-lua) (maintained by @muniftanjim)
|
||||||
|
- [x] [luadoc](https://github.com/amaanq/tree-sitter-luadoc) (maintained by @amaanq)
|
||||||
|
- [x] [lua patterns](https://github.com/amaanq/tree-sitter-luap) (maintained by @amaanq)
|
||||||
|
- [x] [luau](https://github.com/amaanq/tree-sitter-luau) (maintained by @amaanq)
|
||||||
|
- [x] [m68k](https://github.com/grahambates/tree-sitter-m68k) (maintained by @grahambates)
|
||||||
|
- [x] [make](https://github.com/alemuller/tree-sitter-make) (maintained by @lewis6991)
|
||||||
|
- [x] [markdown (basic highlighting)](https://github.com/MDeiml/tree-sitter-markdown) (experimental, maintained by @MDeiml)
|
||||||
|
- [x] [markdown_inline (needed for full highlighting)](https://github.com/MDeiml/tree-sitter-markdown) (experimental, maintained by @MDeiml)
|
||||||
|
- [x] [matlab](https://github.com/acristoffers/tree-sitter-matlab) (maintained by @acristoffers)
|
||||||
|
- [x] [menhir](https://github.com/Kerl13/tree-sitter-menhir) (maintained by @Kerl13)
|
||||||
|
- [ ] [mermaid](https://github.com/monaqa/tree-sitter-mermaid) (experimental)
|
||||||
|
- [x] [meson](https://github.com/Decodetalkers/tree-sitter-meson) (maintained by @Decodetalkers)
|
||||||
|
- [x] [mlir](https://github.com/artagnon/tree-sitter-mlir) (experimental, maintained by @artagnon)
|
||||||
|
- [x] [muttrc](https://github.com/neomutt/tree-sitter-muttrc) (maintained by @Freed-Wu)
|
||||||
|
- [x] [nasm](https://github.com/naclsn/tree-sitter-nasm) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [nginx](https://github.com/opa-oz/tree-sitter-nginx) (maintained by @opa-oz)
|
||||||
|
- [ ] [nickel](https://github.com/nickel-lang/tree-sitter-nickel)
|
||||||
|
- [x] [nim](https://github.com/alaviss/tree-sitter-nim) (maintained by @aMOPel)
|
||||||
|
- [x] [nim_format_string](https://github.com/aMOPel/tree-sitter-nim-format-string) (maintained by @aMOPel)
|
||||||
|
- [x] [ninja](https://github.com/alemuller/tree-sitter-ninja) (maintained by @alemuller)
|
||||||
|
- [x] [nix](https://github.com/cstrahan/tree-sitter-nix) (maintained by @leo60228)
|
||||||
|
- [x] [norg](https://github.com/nvim-neorg/tree-sitter-norg) (maintained by @JoeyGrajciar, @vhyrro)
|
||||||
|
- [x] [nqc](https://github.com/amaanq/tree-sitter-nqc) (maintained by @amaanq)
|
||||||
|
- [x] [objc](https://github.com/amaanq/tree-sitter-objc) (maintained by @amaanq)
|
||||||
|
- [x] [objdump](https://github.com/ColinKennedy/tree-sitter-objdump) (maintained by @ColinKennedy)
|
||||||
|
- [x] [ocaml](https://github.com/tree-sitter/tree-sitter-ocaml) (maintained by @undu)
|
||||||
|
- [x] [ocaml_interface](https://github.com/tree-sitter/tree-sitter-ocaml) (maintained by @undu)
|
||||||
|
- [x] [ocamllex](https://github.com/atom-ocaml/tree-sitter-ocamllex) (maintained by @undu)
|
||||||
|
- [x] [odin](https://github.com/amaanq/tree-sitter-odin) (maintained by @amaanq)
|
||||||
|
- [ ] [org](https://github.com/milisims/tree-sitter-org)
|
||||||
|
- [x] [pascal](https://github.com/Isopod/tree-sitter-pascal) (maintained by @Isopod)
|
||||||
|
- [x] [passwd](https://github.com/ath3/tree-sitter-passwd) (maintained by @amaanq)
|
||||||
|
- [x] [pem](https://github.com/ObserverOfTime/tree-sitter-pem) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [perl](https://github.com/tree-sitter-perl/tree-sitter-perl) (maintained by @RabbiVeesh, @LeoNerd)
|
||||||
|
- [x] [php](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka, @calebdw)
|
||||||
|
- [x] [php_only](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka, @calebdw)
|
||||||
|
- [x] [phpdoc](https://github.com/claytonrcarter/tree-sitter-phpdoc) (experimental, maintained by @mikehaertl)
|
||||||
|
- [x] [pioasm](https://github.com/leo60228/tree-sitter-pioasm) (maintained by @leo60228)
|
||||||
|
- [x] [po](https://github.com/erasin/tree-sitter-po) (maintained by @amaanq)
|
||||||
|
- [x] [pod](https://github.com/tree-sitter-perl/tree-sitter-pod) (maintained by @RabbiVeesh, @LeoNerd)
|
||||||
|
- [x] [Path of Exile item filter](https://github.com/ObserverOfTime/tree-sitter-poe-filter) (experimental, maintained by @ObserverOfTime)
|
||||||
|
- [x] [pony](https://github.com/amaanq/tree-sitter-pony) (maintained by @amaanq, @mfelsche)
|
||||||
|
- [x] [powershell](https://github.com/airbus-cert/tree-sitter-powershell) (maintained by @L2jLiga)
|
||||||
|
- [x] [printf](https://github.com/ObserverOfTime/tree-sitter-printf) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [prisma](https://github.com/victorhqc/tree-sitter-prisma) (maintained by @elianiva)
|
||||||
|
- [x] [problog](https://github.com/foxyseta/tree-sitter-prolog) (maintained by @foxyseta)
|
||||||
|
- [x] [prolog](https://github.com/foxyseta/tree-sitter-prolog) (maintained by @foxyseta)
|
||||||
|
- [x] [promql](https://github.com/MichaHoffmann/tree-sitter-promql) (maintained by @MichaHoffmann)
|
||||||
|
- [x] [properties](https://github.com/tree-sitter-grammars/tree-sitter-properties) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [proto](https://github.com/treywood/tree-sitter-proto) (maintained by @treywood)
|
||||||
|
- [x] [prql](https://github.com/PRQL/tree-sitter-prql) (maintained by @matthias-Q)
|
||||||
|
- [x] [psv](https://github.com/amaanq/tree-sitter-csv) (maintained by @amaanq)
|
||||||
|
- [x] [pug](https://github.com/zealot128/tree-sitter-pug) (experimental, maintained by @zealot128)
|
||||||
|
- [x] [puppet](https://github.com/amaanq/tree-sitter-puppet) (maintained by @amaanq)
|
||||||
|
- [x] [purescript](https://github.com/postsolar/tree-sitter-purescript) (maintained by @postsolar)
|
||||||
|
- [x] [PyPA manifest](https://github.com/ObserverOfTime/tree-sitter-pymanifest) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [python](https://github.com/tree-sitter/tree-sitter-python) (maintained by @stsewd, @theHamsta)
|
||||||
|
- [x] [ql](https://github.com/tree-sitter/tree-sitter-ql) (maintained by @pwntester)
|
||||||
|
- [x] [qmldir](https://github.com/Decodetalkers/tree-sitter-qmldir) (maintained by @amaanq)
|
||||||
|
- [x] [qmljs](https://github.com/yuja/tree-sitter-qmljs) (maintained by @Decodetalkers)
|
||||||
|
- [x] [Tree-Sitter query language](https://github.com/nvim-treesitter/tree-sitter-query) (maintained by @steelsojka)
|
||||||
|
- [x] [r](https://github.com/r-lib/tree-sitter-r) (maintained by @ribru17)
|
||||||
|
- [ ] [racket](https://github.com/6cdh/tree-sitter-racket)
|
||||||
|
- [x] [ralph](https://github.com/alephium/tree-sitter-ralph) (maintained by @tdroxler)
|
||||||
|
- [x] [rasi](https://github.com/Fymyte/tree-sitter-rasi) (maintained by @Fymyte)
|
||||||
|
- [x] [rbs](https://github.com/joker1007/tree-sitter-rbs) (maintained by @joker1007)
|
||||||
|
- [x] [re2c](https://github.com/amaanq/tree-sitter-re2c) (maintained by @amaanq)
|
||||||
|
- [x] [readline](https://github.com/ribru17/tree-sitter-readline) (maintained by @ribru17)
|
||||||
|
- [x] [regex](https://github.com/tree-sitter/tree-sitter-regex) (maintained by @theHamsta)
|
||||||
|
- [x] [rego](https://github.com/FallenAngel97/tree-sitter-rego) (maintained by @FallenAngel97)
|
||||||
|
- [x] [pip requirements](https://github.com/ObserverOfTime/tree-sitter-requirements) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [rescript](https://github.com/rescript-lang/tree-sitter-rescript) (maintained by @ribru17)
|
||||||
|
- [x] [rnoweb](https://github.com/bamonroe/tree-sitter-rnoweb) (maintained by @bamonroe)
|
||||||
|
- [x] [robot](https://github.com/Hubro/tree-sitter-robot) (maintained by @Hubro)
|
||||||
|
- [x] [robots](https://github.com/opa-oz/tree-sitter-robots-txt) (maintained by @opa-oz)
|
||||||
|
- [x] [roc](https://github.com/faldor20/tree-sitter-roc) (maintained by @nat-418)
|
||||||
|
- [x] [ron](https://github.com/amaanq/tree-sitter-ron) (maintained by @amaanq)
|
||||||
|
- [x] [rst](https://github.com/stsewd/tree-sitter-rst) (maintained by @stsewd)
|
||||||
|
- [x] [ruby](https://github.com/tree-sitter/tree-sitter-ruby) (maintained by @TravonteD)
|
||||||
|
- [x] [rust](https://github.com/tree-sitter/tree-sitter-rust) (maintained by @amaanq)
|
||||||
|
- [x] [scala](https://github.com/tree-sitter/tree-sitter-scala) (maintained by @stevanmilic)
|
||||||
|
- [x] [scfg](https://github.com/rockorager/tree-sitter-scfg) (maintained by @WhyNotHugo)
|
||||||
|
- [ ] [scheme](https://github.com/6cdh/tree-sitter-scheme)
|
||||||
|
- [x] [scss](https://github.com/serenadeai/tree-sitter-scss) (maintained by @elianiva)
|
||||||
|
- [x] [sflog](https://github.com/aheber/tree-sitter-sfapex) (maintained by @aheber, @xixiaofinland)
|
||||||
|
- [x] [slang](https://github.com/theHamsta/tree-sitter-slang) (experimental, maintained by @theHamsta)
|
||||||
|
- [x] [slint](https://github.com/slint-ui/tree-sitter-slint) (maintained by @hunger)
|
||||||
|
- [x] [smali](https://github.com/tree-sitter-grammars/tree-sitter-smali) (maintained by @amaanq)
|
||||||
|
- [x] [smithy](https://github.com/indoorvivants/tree-sitter-smithy) (maintained by @amaanq, @keynmol)
|
||||||
|
- [ ] [snakemake](https://github.com/osthomas/tree-sitter-snakemake) (experimental)
|
||||||
|
- [x] [solidity](https://github.com/JoranHonig/tree-sitter-solidity) (maintained by @amaanq)
|
||||||
|
- [x] [soql](https://github.com/aheber/tree-sitter-sfapex) (maintained by @aheber, @xixiaofinland)
|
||||||
|
- [x] [sosl](https://github.com/aheber/tree-sitter-sfapex) (maintained by @aheber, @xixiaofinland)
|
||||||
|
- [x] [sourcepawn](https://github.com/nilshelmig/tree-sitter-sourcepawn) (maintained by @Sarrus1)
|
||||||
|
- [x] [sparql](https://github.com/GordianDziwis/tree-sitter-sparql) (maintained by @GordianDziwis)
|
||||||
|
- [x] [sql](https://github.com/derekstride/tree-sitter-sql) (maintained by @derekstride)
|
||||||
|
- [x] [squirrel](https://github.com/amaanq/tree-sitter-squirrel) (maintained by @amaanq)
|
||||||
|
- [x] [ssh_config](https://github.com/ObserverOfTime/tree-sitter-ssh-config) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [starlark](https://github.com/amaanq/tree-sitter-starlark) (maintained by @amaanq)
|
||||||
|
- [x] [strace](https://github.com/sigmaSd/tree-sitter-strace) (maintained by @amaanq)
|
||||||
|
- [x] [styled](https://github.com/mskelton/tree-sitter-styled) (maintained by @mskelton)
|
||||||
|
- [x] [supercollider](https://github.com/madskjeldgaard/tree-sitter-supercollider) (maintained by @madskjeldgaard)
|
||||||
|
- [x] [superhtml](https://github.com/kristoff-it/superhtml) (maintained by @rockorager)
|
||||||
|
- [x] [surface](https://github.com/connorlay/tree-sitter-surface) (maintained by @connorlay)
|
||||||
|
- [x] [svelte](https://github.com/tree-sitter-grammars/tree-sitter-svelte) (maintained by @amaanq)
|
||||||
|
- [x] [swift](https://github.com/alex-pinkus/tree-sitter-swift) (maintained by @alex-pinkus)
|
||||||
|
- [x] [sxhkdrc](https://github.com/RaafatTurki/tree-sitter-sxhkdrc) (maintained by @RaafatTurki)
|
||||||
|
- [x] [systemtap](https://github.com/ok-ryoko/tree-sitter-systemtap) (maintained by @ok-ryoko)
|
||||||
|
- [x] [t32](https://gitlab.com/xasc/tree-sitter-t32.git) (maintained by @xasc)
|
||||||
|
- [x] [tablegen](https://github.com/amaanq/tree-sitter-tablegen) (maintained by @amaanq)
|
||||||
|
- [x] [tact](https://github.com/tact-lang/tree-sitter-tact) (maintained by @novusnota)
|
||||||
|
- [x] [tcl](https://github.com/tree-sitter-grammars/tree-sitter-tcl) (maintained by @lewis6991)
|
||||||
|
- [x] [teal](https://github.com/euclidianAce/tree-sitter-teal) (maintained by @euclidianAce)
|
||||||
|
- [x] [templ](https://github.com/vrischmann/tree-sitter-templ) (maintained by @vrischmann)
|
||||||
|
- [x] [terraform](https://github.com/MichaHoffmann/tree-sitter-hcl) (maintained by @MichaHoffmann)
|
||||||
|
- [x] [textproto](https://github.com/PorterAtGoogle/tree-sitter-textproto) (maintained by @Porter)
|
||||||
|
- [x] [thrift](https://github.com/duskmoon314/tree-sitter-thrift) (maintained by @amaanq, @duskmoon314)
|
||||||
|
- [x] [tiger](https://github.com/ambroisie/tree-sitter-tiger) (maintained by @ambroisie)
|
||||||
|
- [x] [tlaplus](https://github.com/tlaplus-community/tree-sitter-tlaplus) (maintained by @ahelwer, @susliko)
|
||||||
|
- [x] [tmux](https://github.com/Freed-Wu/tree-sitter-tmux) (maintained by @Freed-Wu)
|
||||||
|
- [x] [todotxt](https://github.com/arnarg/tree-sitter-todotxt) (experimental, maintained by @arnarg)
|
||||||
|
- [x] [toml](https://github.com/tree-sitter-grammars/tree-sitter-toml) (maintained by @tk-shirasaka)
|
||||||
|
- [x] [tsv](https://github.com/amaanq/tree-sitter-csv) (maintained by @amaanq)
|
||||||
|
- [x] [tsx](https://github.com/tree-sitter/tree-sitter-typescript) (maintained by @steelsojka)
|
||||||
|
- [x] [turtle](https://github.com/GordianDziwis/tree-sitter-turtle) (maintained by @GordianDziwis)
|
||||||
|
- [x] [twig](https://github.com/gbprod/tree-sitter-twig) (maintained by @gbprod)
|
||||||
|
- [x] [typescript](https://github.com/tree-sitter/tree-sitter-typescript) (maintained by @steelsojka)
|
||||||
|
- [x] [typespec](https://github.com/happenslol/tree-sitter-typespec) (maintained by @happenslol)
|
||||||
|
- [x] [typoscript](https://github.com/Teddytrombone/tree-sitter-typoscript) (maintained by @Teddytrombone)
|
||||||
|
- [x] [typst](https://github.com/uben0/tree-sitter-typst) (maintained by @uben0, @RaafatTurki)
|
||||||
|
- [x] [udev](https://github.com/ObserverOfTime/tree-sitter-udev) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [ungrammar](https://github.com/Philipp-M/tree-sitter-ungrammar) (maintained by @Philipp-M, @amaanq)
|
||||||
|
- [x] [unison](https://github.com/kylegoetz/tree-sitter-unison) (maintained by @tapegram)
|
||||||
|
- [x] [usd](https://github.com/ColinKennedy/tree-sitter-usd) (maintained by @ColinKennedy)
|
||||||
|
- [x] [uxn tal](https://github.com/amaanq/tree-sitter-uxntal) (maintained by @amaanq)
|
||||||
|
- [x] [v](https://github.com/vlang/v-analyzer) (maintained by @kkharji, @amaanq)
|
||||||
|
- [x] [vala](https://github.com/vala-lang/tree-sitter-vala) (maintained by @Prince781)
|
||||||
|
- [x] [vento](https://github.com/ventojs/tree-sitter-vento) (maintained by @wrapperup, @oscarotero)
|
||||||
|
- [x] [verilog](https://github.com/gmlarumbe/tree-sitter-systemverilog) (maintained by @zhangwwpeng)
|
||||||
|
- [x] [vhdl](https://github.com/jpt13653903/tree-sitter-vhdl) (maintained by @jpt13653903)
|
||||||
|
- [x] [vhs](https://github.com/charmbracelet/tree-sitter-vhs) (maintained by @caarlos0)
|
||||||
|
- [x] [vim](https://github.com/neovim/tree-sitter-vim) (maintained by @clason)
|
||||||
|
- [x] [vimdoc](https://github.com/neovim/tree-sitter-vimdoc) (maintained by @clason)
|
||||||
|
- [x] [vrl](https://github.com/belltoy/tree-sitter-vrl) (maintained by @belltoy)
|
||||||
|
- [x] [vue](https://github.com/tree-sitter-grammars/tree-sitter-vue) (maintained by @WhyNotHugo, @lucario387)
|
||||||
|
- [x] [wgsl](https://github.com/szebniok/tree-sitter-wgsl) (maintained by @szebniok)
|
||||||
|
- [x] [wgsl_bevy](https://github.com/theHamsta/tree-sitter-wgsl-bevy) (maintained by @theHamsta)
|
||||||
|
- [x] [wing](https://github.com/winglang/tree-sitter-wing) (maintained by @gshpychka, @MarkMcCulloh)
|
||||||
|
- [x] [wit](https://github.com/liamwh/tree-sitter-wit) (maintained by @liamwh)
|
||||||
|
- [x] [xcompose](https://github.com/ObserverOfTime/tree-sitter-xcompose) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [xml](https://github.com/tree-sitter-grammars/tree-sitter-xml) (maintained by @ObserverOfTime)
|
||||||
|
- [x] [xresources](https://github.com/ValdezFOmar/tree-sitter-xresources) (maintained by @ValdezFOmar)
|
||||||
|
- [x] [yaml](https://github.com/tree-sitter-grammars/tree-sitter-yaml) (maintained by @amaanq)
|
||||||
|
- [x] [yang](https://github.com/Hubro/tree-sitter-yang) (maintained by @Hubro)
|
||||||
|
- [x] [yuck](https://github.com/Philipp-M/tree-sitter-yuck) (maintained by @Philipp-M, @amaanq)
|
||||||
|
- [x] [zathurarc](https://github.com/Freed-Wu/tree-sitter-zathurarc) (maintained by @Freed-Wu)
|
||||||
|
- [x] [zig](https://github.com/tree-sitter-grammars/tree-sitter-zig) (maintained by @amaanq)
|
||||||
|
- [x] [ziggy](https://github.com/kristoff-it/ziggy) (maintained by @rockorager)
|
||||||
|
- [x] [ziggy_schema](https://github.com/kristoff-it/ziggy) (maintained by @rockorager)
|
||||||
|
<!--parserinfo-->
|
||||||
|
|
||||||
|
For related information on the supported languages, including related plugins, see [this wiki page](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Supported-Languages-Information).
|
||||||
|
|
||||||
|
# Available modules
|
||||||
|
|
||||||
|
Modules provide the top-level features of `nvim-treesitter`.
|
||||||
|
The following is a list of modules included in `nvim-treesitter` and their configuration via `init.lua` (where multiple modules can be combined in a single call to `setup`).
|
||||||
|
Note that not all modules work for all languages (depending on the queries available for them).
|
||||||
|
Additional modules can be provided as [external plugins](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Extra-modules-and-plugins).
|
||||||
|
|
||||||
|
#### Highlight
|
||||||
|
|
||||||
|
Consistent syntax highlighting.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||||
|
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
|
||||||
|
-- Using this option may slow down your editor, and you may see some duplicate highlights.
|
||||||
|
-- Instead of true it can also be a list of languages
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To customize the syntax highlighting of a capture, simply define or link a highlight group of the same name:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- Highlight the @foo.bar capture group with the "Identifier" highlight group
|
||||||
|
vim.api.nvim_set_hl(0, "@foo.bar", { link = "Identifier" })
|
||||||
|
```
|
||||||
|
|
||||||
|
For a language-specific highlight, append the name of the language:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- Highlight @foo.bar as "Identifier" only in Lua files
|
||||||
|
vim.api.nvim_set_hl(0, "@foo.bar.lua", { link = "Identifier" })
|
||||||
|
```
|
||||||
|
|
||||||
|
See `:h treesitter-highlight-groups` for details.
|
||||||
|
|
||||||
|
#### Incremental selection
|
||||||
|
|
||||||
|
Incremental selection based on the named nodes from the grammar.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
incremental_selection = {
|
||||||
|
enable = true,
|
||||||
|
keymaps = {
|
||||||
|
init_selection = "gnn", -- set to `false` to disable one of the mappings
|
||||||
|
node_incremental = "grn",
|
||||||
|
scope_incremental = "grc",
|
||||||
|
node_decremental = "grm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Indentation
|
||||||
|
|
||||||
|
Indentation based on treesitter for the `=` operator.
|
||||||
|
**NOTE: This is an experimental feature**.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
indent = {
|
||||||
|
enable = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Folding
|
||||||
|
|
||||||
|
Tree-sitter based folding (implemented in Neovim itself, see `:h vim.treesitter.foldexpr()`). To enable it for the current window, set
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.wo.foldmethod = 'expr'
|
||||||
|
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||||
|
```
|
||||||
|
|
||||||
|
This will respect your `foldminlines` and `foldnestmax` settings.
|
||||||
|
|
||||||
|
# Advanced setup
|
||||||
|
|
||||||
|
## Changing the parser install directory
|
||||||
|
|
||||||
|
If you want to install the parsers to a custom directory you can specify this
|
||||||
|
directory with `parser_install_dir` option in that is passed to `setup`.
|
||||||
|
`nvim-treesitter` will then install the parser files into this directory.
|
||||||
|
|
||||||
|
This directory must be writeable and must be explicitly prepended to the
|
||||||
|
`runtimepath`. For example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- It MUST be at the beginning of runtimepath. Otherwise the parsers from Neovim itself
|
||||||
|
-- is loaded that may not be compatible with the queries from the 'nvim-treesitter' plugin.
|
||||||
|
vim.opt.runtimepath:prepend("/some/path/to/store/parsers")
|
||||||
|
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
parser_install_dir = "/some/path/to/store/parsers",
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If this option is not included in the setup options, or is explicitly set to
|
||||||
|
`nil` then the default install directories will be used. If this value is set
|
||||||
|
the default directories will be ignored.
|
||||||
|
|
||||||
|
Bear in mind that any parser installed into a parser folder on the runtime path
|
||||||
|
will still be considered installed. (For example if
|
||||||
|
"~/.local/share/nvim/site/parser/c.so" exists then the "c" parser will be
|
||||||
|
considered installed, even though it is not in `parser_install_dir`)
|
||||||
|
|
||||||
|
The default paths are:
|
||||||
|
|
||||||
|
1. first the package folder. Where `nvim-treesitter` is installed.
|
||||||
|
2. second the site directory. This is the "site" subdirectory of `stdpath("data")`.
|
||||||
|
|
||||||
|
## Adding parsers
|
||||||
|
|
||||||
|
If you have a parser that is not on the list of supported languages (either as a repository on Github or in a local directory), you can add it manually for use by `nvim-treesitter` as follows:
|
||||||
|
|
||||||
|
1. Clone the repository or [create a new project](https://tree-sitter.github.io/tree-sitter/creating-parsers#project-setup) in, say, `~/projects/tree-sitter-zimbu`. Make sure that the `tree-sitter-cli` executable is installed and in your path; see <https://tree-sitter.github.io/tree-sitter/creating-parsers#installation> for installation instructions.
|
||||||
|
2. Run `tree-sitter generate` in this directory (followed by `tree-sitter test` for good measure).
|
||||||
|
3. Add the following snippet to your `init.lua`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
|
||||||
|
parser_config.zimbu = {
|
||||||
|
install_info = {
|
||||||
|
url = "~/projects/tree-sitter-zimbu", -- local path or git repo
|
||||||
|
files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
|
||||||
|
-- optional entries:
|
||||||
|
branch = "main", -- default branch in case of git repo if different from master
|
||||||
|
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
|
||||||
|
requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
|
||||||
|
},
|
||||||
|
filetype = "zu", -- if filetype does not match the parser name
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you wish to set a specific parser for a filetype, you should use `vim.treesitter.language.register()`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.treesitter.language.register('python', 'someft') -- the someft filetype will use the python parser and queries.
|
||||||
|
```
|
||||||
|
|
||||||
|
Note this requires Nvim v0.9.
|
||||||
|
|
||||||
|
4. Start `nvim` and `:TSInstall zimbu`.
|
||||||
|
|
||||||
|
You can also skip step 2 and use `:TSInstallFromGrammar zimbu` to install directly from a `grammar.js` in the top-level directory specified by `url`.
|
||||||
|
Once the parser is installed, you can update it (from the latest revision of the `main` branch if `url` is a Github repository) with `:TSUpdate zimbu`.
|
||||||
|
|
||||||
|
Note that neither `:TSInstall` nor `:TSInstallFromGrammar` copy query files from the grammar repository.
|
||||||
|
If you want your installed grammar to be useful, you must manually [add query files](#adding-queries) to your local nvim-treesitter installation.
|
||||||
|
Note also that module functionality is only triggered if your language's filetype is correctly identified.
|
||||||
|
If Neovim does not detect your language's filetype by default, you can use [Neovim's `vim.filetype.add()`](<https://neovim.io/doc/user/lua.html#vim.filetype.add()>) to add a custom detection rule.
|
||||||
|
|
||||||
|
If you use a git repository for your parser and want to use a specific version, you can set the `revision` key
|
||||||
|
in the `install_info` table for you parser config.
|
||||||
|
|
||||||
|
## Adding queries
|
||||||
|
|
||||||
|
Queries are what `nvim-treesitter` uses to extract information from the syntax tree;
|
||||||
|
they are located in the `queries/{language}/*` runtime directories (see `:h rtp`),
|
||||||
|
like the `queries` folder of this plugin, e.g. `queries/{language}/{locals,highlights,textobjects}.scm`.
|
||||||
|
Other modules may require additional queries such as `folding.scm`. You can find a
|
||||||
|
list of all supported capture names in [CONTRIBUTING.md](https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md#parser-configurations).
|
||||||
|
|
||||||
|
The first query file on `runtimepath` will be used (see `:h treesitter-query`).
|
||||||
|
If you want to make a query on the user config extend other queries instead of
|
||||||
|
replacing them, see `:h treesitter-query-modeline-extends`.
|
||||||
|
|
||||||
|
If you want to completely override a query, you can use `:h vim.treesitter.query.set()`.
|
||||||
|
For example, to override the `injections` queries from `c` with your own:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.treesitter.query.set("c", "injections", "(comment) @comment")
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: when using `query.set()`, all queries in the runtime directories will be ignored.
|
||||||
|
|
||||||
|
## Adding modules
|
||||||
|
|
||||||
|
If you wish you write your own module, you need to support
|
||||||
|
|
||||||
|
- tree-sitter language detection support;
|
||||||
|
- attaching and detaching to buffers;
|
||||||
|
- all nvim-treesitter commands.
|
||||||
|
|
||||||
|
At the top level, you can use the `define_modules` function to define one or more modules or module groups:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'nvim-treesitter'.define_modules {
|
||||||
|
my_cool_plugin = {
|
||||||
|
attach = function(bufnr, lang)
|
||||||
|
-- Do cool stuff here
|
||||||
|
end,
|
||||||
|
detach = function(bufnr)
|
||||||
|
-- Undo cool stuff here
|
||||||
|
end,
|
||||||
|
is_supported = function(lang)
|
||||||
|
-- Check if the language is supported
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
with the following properties:
|
||||||
|
|
||||||
|
- `module_path` specifies a require path (string) that exports a module with an `attach` and `detach` function. This is not required if the functions are on this definition.
|
||||||
|
- `enable` determines if the module is enabled by default. This is usually overridden by the user.
|
||||||
|
- `disable` takes a list of languages that this module is disabled for. This is usually overridden by the user.
|
||||||
|
- `is_supported` takes a function that takes a language and determines if this module supports that language.
|
||||||
|
- `attach` takes a function that attaches to a buffer. This is required if `module_path` is not provided.
|
||||||
|
- `detach` takes a function that detaches from a buffer. This is required if `module_path` is not provided.
|
||||||
|
|
||||||
|
# Extra features
|
||||||
|
|
||||||
|
### Statusline indicator
|
||||||
|
|
||||||
|
```vim
|
||||||
|
echo nvim_treesitter#statusline(90) " 90 can be any length
|
||||||
|
module->expression_statement->call->identifier
|
||||||
|
```
|
||||||
|
|
||||||
|
### Utilities
|
||||||
|
|
||||||
|
You can get some utility functions with
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||||
|
```
|
||||||
|
|
||||||
|
Check [`:h nvim-treesitter-utils`](doc/nvim-treesitter.txt) for more information.
|
||||||
|
|
||||||
|
# Troubleshooting
|
||||||
|
|
||||||
|
Before doing anything, make sure you have the latest version of this plugin and run `:checkhealth nvim-treesitter`.
|
||||||
|
It can also help to update the parsers via `:TSUpdate`.
|
||||||
|
|
||||||
|
#### Feature `X` does not work for `{language}`...
|
||||||
|
|
||||||
|
First, check the `health#nvim_treesitter#check` and the `health#treesitter#check` sections of `:checkhealth` for any warning.
|
||||||
|
If there is one, it's highly likely that this is the cause of the problem.
|
||||||
|
|
||||||
|
Next check the `## Parser/Features` subsection of the `health#nvim_treesitter#check` section of `:checkhealth` to ensure the desired module is enabled for your language.
|
||||||
|
If not, you might be missing query files; see [Adding queries](#adding-queries).
|
||||||
|
|
||||||
|
Finally, ensure Neovim is correctly identifying your language's filetype using the `:echo &filetype` command while one of your language's files is open in Neovim.
|
||||||
|
If not, add a short Vimscript file to nvim-treesitter's `ftdetect` runtime directory following [Neovim's documentation](https://neovim.io/doc/user/filetype.html#new-filetype) on filetype detection.
|
||||||
|
You can also quickly & temporarily set the filetype for a single buffer with the `:set filetype=langname` command to test whether it fixes the problem.
|
||||||
|
|
||||||
|
If everything is okay, then it might be an actual error.
|
||||||
|
In that case, feel free to [open an issue here](https://github.com/nvim-treesitter/nvim-treesitter/issues/new/choose).
|
||||||
|
|
||||||
|
#### I get `module 'vim.treesitter.query' not found`
|
||||||
|
|
||||||
|
Make sure you have the latest version of Neovim.
|
||||||
|
|
||||||
|
#### I get `Error detected while processing .../plugin/nvim-treesitter.vim` every time I open Neovim
|
||||||
|
|
||||||
|
This is probably due to a change in a parser's grammar or its queries.
|
||||||
|
Try updating the parser that you suspect has changed (`:TSUpdate {language}`) or all of them (`:TSUpdate`).
|
||||||
|
If the error persists after updating all parsers,
|
||||||
|
please [open an issue](https://github.com/nvim-treesitter/nvim-treesitter/issues/new/choose).
|
||||||
|
|
||||||
|
#### I get `query error: invalid node type at position`
|
||||||
|
|
||||||
|
This could be due a query file outside this plugin using outdated nodes,
|
||||||
|
or due to an outdated parser.
|
||||||
|
|
||||||
|
- Make sure you have the parsers up to date with `:TSUpdate`
|
||||||
|
- Make sure you don't have more than one `parser` runtime directory.
|
||||||
|
You can execute this command `:echo nvim_get_runtime_file('parser', v:true)` to find all runtime directories.
|
||||||
|
If you get more than one path, remove the ones that are outside this plugin (`nvim-treesitter` directory),
|
||||||
|
so the correct version of the parser is used.
|
||||||
|
|
||||||
|
#### I experience weird highlighting issues similar to [#78](https://github.com/nvim-treesitter/nvim-treesitter/issues/78)
|
||||||
|
|
||||||
|
This is a well known issue, which arises when the tree and the buffer have gotten out of sync.
|
||||||
|
As this is an upstream issue, we don't have any definite fix.
|
||||||
|
To get around this, you can force reparsing the buffer with
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:write | edit | TSBufEnable highlight
|
||||||
|
```
|
||||||
|
|
||||||
|
This will save, restore and enable highlighting for the current buffer.
|
||||||
|
|
||||||
|
#### I experience bugs when using `nvim-treesitter`'s `foldexpr` similar to [#194](https://github.com/nvim-treesitter/nvim-treesitter/issues/194)
|
||||||
|
|
||||||
|
This might happen, and is known to happen, with `vim-clap`.
|
||||||
|
To avoid these kind of errors, please use `setlocal` instead of `set` for the respective filetypes.
|
||||||
|
|
||||||
|
#### I run into errors like `module 'nvim-treesitter.configs' not found` at startup
|
||||||
|
|
||||||
|
This is because of `rtp` management in `nvim`, adding `packadd
|
||||||
|
nvim-treesitter` should fix the issue.
|
||||||
|
|
||||||
|
#### I want to use Git instead of curl for downloading the parsers
|
||||||
|
|
||||||
|
In your Lua config:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require("nvim-treesitter.install").prefer_git = true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### I want to use a HTTP proxy for downloading the parsers
|
||||||
|
|
||||||
|
You can either configure curl to use additional CLI arguments in your Lua config:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require("nvim-treesitter.install").command_extra_args = {
|
||||||
|
curl = { "--proxy", "<proxy url>" },
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or you can configure git via `.gitconfig` and use git instead of curl
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require("nvim-treesitter.install").prefer_git = true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### I want to use a mirror instead of "https://github.com/"
|
||||||
|
|
||||||
|
In your Lua config:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
for _, config in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
|
||||||
|
config.install_info.url = config.install_info.url:gsub("https://github.com/", "something else")
|
||||||
|
end
|
||||||
|
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
--
|
||||||
|
--
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using an existing parser for another filetype
|
||||||
|
|
||||||
|
For example, to use the `bash` tree-sitter to highlight file with
|
||||||
|
`filetype=apkbuild`, use:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
vim.treesitter.language.register("bash", "apkbuild")
|
||||||
|
```
|
||||||
|
|
||||||
|
The `bash` tree-sitter must be installed following the usual procedure [as
|
||||||
|
described above](#language-parsers).
|
BIN
pack/ant/start/nvim-treesitter/assets/logo.png
Normal file
BIN
pack/ant/start/nvim-treesitter/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
27
pack/ant/start/nvim-treesitter/autoload/nvim_treesitter.vim
Normal file
27
pack/ant/start/nvim-treesitter/autoload/nvim_treesitter.vim
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
function! nvim_treesitter#statusline(...) abort
|
||||||
|
return luaeval("require'nvim-treesitter.statusline'.statusline(_A)", get(a:, 1, {}))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#foldexpr() abort
|
||||||
|
return luaeval(printf('require"nvim-treesitter.fold".get_fold_indic(%d)', v:lnum))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#installable_parsers(arglead, cmdline, cursorpos) abort
|
||||||
|
return join(luaeval("require'nvim-treesitter.parsers'.available_parsers()") + ['all'], "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#installed_parsers(arglead, cmdline, cursorpos) abort
|
||||||
|
return join(luaeval("require'nvim-treesitter.info'.installed_parsers()") + ['all'], "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#available_modules(arglead, cmdline, cursorpos) abort
|
||||||
|
return join(luaeval("require'nvim-treesitter.configs'.available_modules()"), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#available_query_groups(arglead, cmdline, cursorpos) abort
|
||||||
|
return join(luaeval("require'nvim-treesitter.query'.available_query_groups()"), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! nvim_treesitter#indent() abort
|
||||||
|
return luaeval(printf('require"nvim-treesitter.indent".get_indent(%d)', v:lnum))
|
||||||
|
endfunction
|
|
@ -0,0 +1,41 @@
|
||||||
|
local git_ref = '$git_ref'
|
||||||
|
local modrev = '$modrev'
|
||||||
|
local specrev = '-1'
|
||||||
|
|
||||||
|
local repo_url = '$repo_url'
|
||||||
|
|
||||||
|
rockspec_format = '3.0'
|
||||||
|
package = '$package'
|
||||||
|
version = modrev .. specrev
|
||||||
|
|
||||||
|
description = {
|
||||||
|
summary = 'Nvim Treesitter configurations and abstraction layer',
|
||||||
|
detailed = $detailed_description,
|
||||||
|
labels = { 'neovim' },
|
||||||
|
homepage = 'https://github.com/nvim-treesitter/nvim-treesitter',
|
||||||
|
license = 'Apache-2.0',
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies = {
|
||||||
|
'lua >= 5.1',
|
||||||
|
}
|
||||||
|
|
||||||
|
-- source = file:///.
|
||||||
|
|
||||||
|
source = {
|
||||||
|
url = repo_url .. '/archive/' .. git_ref .. '.zip',
|
||||||
|
dir = '$repo_name-' .. '$archive_dir_suffix',
|
||||||
|
}
|
||||||
|
|
||||||
|
build = {
|
||||||
|
type = 'make',
|
||||||
|
build_pass = false,
|
||||||
|
install_variables = {
|
||||||
|
INST_PREFIX='$(PREFIX)',
|
||||||
|
INST_BINDIR='$(BINDIR)',
|
||||||
|
INST_LIBDIR='$(LIBDIR)',
|
||||||
|
INST_LUADIR='$(LUADIR)',
|
||||||
|
INST_CONFDIR='$(CONFDIR)',
|
||||||
|
},
|
||||||
|
copy_directories = $copy_directories,
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
local MODREV, SPECREV = 'scm', '-1'
|
||||||
|
rockspec_format = '3.0'
|
||||||
|
package = 'nvim-treesitter'
|
||||||
|
version = MODREV .. SPECREV
|
||||||
|
|
||||||
|
description = {
|
||||||
|
summary = 'Nvim Treesitter configurations and abstraction layer',
|
||||||
|
labels = { 'neovim' },
|
||||||
|
homepage = 'https://github.com/nvim-treesitter/nvim-treesitter',
|
||||||
|
license = 'Apache-2.0',
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies = {
|
||||||
|
'lua >= 5.1',
|
||||||
|
}
|
||||||
|
|
||||||
|
source = {
|
||||||
|
url = 'git://github.com/nvim-treesitter/nvim-treesitter',
|
||||||
|
}
|
||||||
|
|
||||||
|
build = {
|
||||||
|
type = 'make',
|
||||||
|
install_variables = {
|
||||||
|
INST_PREFIX='$(PREFIX)',
|
||||||
|
INST_BINDIR='$(BINDIR)',
|
||||||
|
INST_LIBDIR='$(LIBDIR)',
|
||||||
|
INST_LUADIR='$(LUADIR)',
|
||||||
|
INST_CONFDIR='$(CONFDIR)',
|
||||||
|
},
|
||||||
|
copy_directories = {
|
||||||
|
'autoload',
|
||||||
|
'doc',
|
||||||
|
'plugin',
|
||||||
|
'queries'
|
||||||
|
}
|
||||||
|
}
|
590
pack/ant/start/nvim-treesitter/doc/nvim-treesitter.txt
Normal file
590
pack/ant/start/nvim-treesitter/doc/nvim-treesitter.txt
Normal file
|
@ -0,0 +1,590 @@
|
||||||
|
*nvim-treesitter* Treesitter configurations and abstraction layer for Neovim.
|
||||||
|
|
||||||
|
Minimum version of neovim: nightly
|
||||||
|
|
||||||
|
Authors:
|
||||||
|
Kiyan Yazdani <yazdani.kiyan@protonmail.com>
|
||||||
|
Thomas Vigouroux <tomvig38@gmail.com>
|
||||||
|
Stephan Seitz <stephan.seitz@fau.de>
|
||||||
|
Steven Sojka <Steven.Sojka@tdameritrade.com>
|
||||||
|
Santos Gallegos <stsewd@protonmail.com>
|
||||||
|
https://github.com/nvim-treesitter/nvim-treesitter/graphs/contributors
|
||||||
|
|
||||||
|
Type |gO| to see the table of contents.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
INTRODUCTION *nvim-treesitter-intro*
|
||||||
|
|
||||||
|
nvim-treesitter wraps the Neovim treesitter API to provide functionalities
|
||||||
|
such as highlighting and incremental selection, and a command to easily
|
||||||
|
install parsers.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
QUICK START *nvim-treesitter-quickstart*
|
||||||
|
|
||||||
|
Install the parser for your language
|
||||||
|
|
||||||
|
>
|
||||||
|
:TSInstall {language}
|
||||||
|
<
|
||||||
|
|
||||||
|
To get a list of supported languages
|
||||||
|
|
||||||
|
>
|
||||||
|
:TSInstallInfo
|
||||||
|
<
|
||||||
|
|
||||||
|
By default, everything is disabled.
|
||||||
|
To enable supported features, put this in your `init.lua` file:
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
-- A directory to install the parsers into.
|
||||||
|
-- If this is excluded or nil parsers are installed
|
||||||
|
-- to either the package dir, or the "site" dir.
|
||||||
|
-- If a custom path is used (not nil) it must be added to the runtimepath.
|
||||||
|
parser_install_dir = "/some/path/to/store/parsers",
|
||||||
|
|
||||||
|
-- A list of parser names, or "all"
|
||||||
|
ensure_installed = { "c", "lua", "rust" },
|
||||||
|
|
||||||
|
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||||
|
sync_install = false,
|
||||||
|
|
||||||
|
-- Automatically install missing parsers when entering buffer
|
||||||
|
auto_install = false,
|
||||||
|
|
||||||
|
-- List of parsers to ignore installing (for "all")
|
||||||
|
ignore_install = { "javascript" },
|
||||||
|
|
||||||
|
highlight = {
|
||||||
|
-- `false` will disable the whole extension
|
||||||
|
enable = true,
|
||||||
|
|
||||||
|
-- list of language that will be disabled
|
||||||
|
disable = { "c", "rust" },
|
||||||
|
|
||||||
|
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||||
|
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
|
||||||
|
-- Using this option may slow down your editor, and you may see some duplicate highlights.
|
||||||
|
-- Instead of true it can also be a list of languages
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
vim.opt.runtimepath:append("/some/path/to/store/parsers")
|
||||||
|
<
|
||||||
|
|
||||||
|
See |nvim-treesitter-modules| for a list of all available modules and its options.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
MODULES *nvim-treesitter-modules*
|
||||||
|
|
||||||
|
|nvim-treesitter| provides several functionalities via modules (and submodules),
|
||||||
|
each module makes use of the query files defined for each language,
|
||||||
|
|
||||||
|
All modules are disabled by default, and some provide default keymaps.
|
||||||
|
Each module corresponds to an entry in the dictionary passed to the
|
||||||
|
`nvim-treesitter.configs.setup` function, this should be in your `init.lua` file.
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
-- Modules and its options go here
|
||||||
|
highlight = { enable = true },
|
||||||
|
incremental_selection = { enable = true },
|
||||||
|
textobjects = { enable = true },
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
All modules share some common options, like `enable` and `disable`.
|
||||||
|
When `enable` is `true` this will enable the module for all supported languages,
|
||||||
|
if you want to disable the module for some languages you can pass a list to the `disable` option.
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
disable = { "cpp", "lua" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
For more fine-grained control, `disable` can also take a function and
|
||||||
|
whenever it returns `true`, the module is disabled for that buffer.
|
||||||
|
The function is called once when a module starts in a buffer and receives the
|
||||||
|
language and buffer number as arguments:
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
disable = function(lang, bufnr) -- Disable in large C++ buffers
|
||||||
|
return lang == "cpp" and vim.api.nvim_buf_line_count(bufnr) > 50000
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
Options that define or accept a keymap use the same format you use to define
|
||||||
|
keymaps in Neovim, so you can write keymaps as `gd`, `<space>a`, `<leader>a`
|
||||||
|
`<C-a>` (control + a), `<A-n>` (alt + n), `<CR>` (enter), etc.
|
||||||
|
|
||||||
|
External plugins can provide their own modules with their own options,
|
||||||
|
those can also be configured using the `nvim-treesitter.configs.setup`
|
||||||
|
function.
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
HIGHLIGHT *nvim-treesitter-highlight-mod*
|
||||||
|
|
||||||
|
Consistent syntax highlighting.
|
||||||
|
|
||||||
|
Query files: `highlights.scm`.
|
||||||
|
Supported options:
|
||||||
|
|
||||||
|
- enable: `true` or `false`.
|
||||||
|
- disable: list of languages.
|
||||||
|
- additional_vim_regex_highlighting: `true` or `false`, or a list of languages.
|
||||||
|
Set this to `true` if you depend on 'syntax' being enabled
|
||||||
|
(like for indentation). Using this option may slow down your editor,
|
||||||
|
and you may see some duplicate highlights.
|
||||||
|
Defaults to `false`.
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
highlight = {
|
||||||
|
enable = true,
|
||||||
|
custom_captures = {
|
||||||
|
-- Highlight the @foo.bar capture group with the "Identifier" highlight group.
|
||||||
|
["foo.bar"] = "Identifier",
|
||||||
|
},
|
||||||
|
-- Setting this to true or a list of languages will run `:h syntax` and tree-sitter at the same time.
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
You can also set custom highlight captures
|
||||||
|
>
|
||||||
|
lua <<EOF
|
||||||
|
require"nvim-treesitter.highlight".set_custom_captures {
|
||||||
|
-- Highlight the @foo.bar capture group with the "Identifier" highlight group.
|
||||||
|
["foo.bar"] = "Identifier",
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
<
|
||||||
|
Note: The api is not stable yet.
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
INCREMENTAL SELECTION *nvim-treesitter-incremental-selection-mod*
|
||||||
|
|
||||||
|
Incremental selection based on the named nodes from the grammar.
|
||||||
|
|
||||||
|
Query files: `locals.scm`.
|
||||||
|
Supported options:
|
||||||
|
- enable: `true` or `false`.
|
||||||
|
- disable: list of languages.
|
||||||
|
- keymaps:
|
||||||
|
- init_selection: in normal mode, start incremental selection.
|
||||||
|
Defaults to `gnn`.
|
||||||
|
- node_incremental: in visual mode, increment to the upper named parent.
|
||||||
|
Defaults to `grn`.
|
||||||
|
- scope_incremental: in visual mode, increment to the upper scope
|
||||||
|
(as defined in `locals.scm`). Defaults to `grc`.
|
||||||
|
- node_decremental: in visual mode, decrement to the previous named node.
|
||||||
|
Defaults to `grm`.
|
||||||
|
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
incremental_selection = {
|
||||||
|
enable = true,
|
||||||
|
keymaps = {
|
||||||
|
init_selection = "gnn",
|
||||||
|
node_incremental = "grn",
|
||||||
|
scope_incremental = "grc",
|
||||||
|
node_decremental = "grm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
INDENTATION *nvim-treesitter-indentation-mod*
|
||||||
|
|
||||||
|
Indentation based on treesitter for the |=| operator.
|
||||||
|
NOTE: this is an experimental feature.
|
||||||
|
|
||||||
|
Query files: `indents.scm`.
|
||||||
|
Supported options:
|
||||||
|
- enable: `true` or `false`.
|
||||||
|
- disable: list of languages.
|
||||||
|
>
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
indent = {
|
||||||
|
enable = true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
`@indent` *nvim-treesitter-indentation-queries*
|
||||||
|
Queries can use the following captures: `@indent.begin` and `@indent.dedent`,
|
||||||
|
`@indent.branch`, `@indent.end` or `@indent.align`. An `@indent.ignore` capture tells
|
||||||
|
treesitter to ignore indentation and a `@indent.zero` capture sets
|
||||||
|
the indentation to 0.
|
||||||
|
|
||||||
|
`@indent.begin` *nvim-treesitter-indentation-indent.begin*
|
||||||
|
The `@indent.begin` specifies that the next line should be indented. Multiple
|
||||||
|
indents on the same line get collapsed. Eg.
|
||||||
|
|
||||||
|
>
|
||||||
|
(
|
||||||
|
(if_statement)
|
||||||
|
(ERROR "else") @indent.begin
|
||||||
|
)
|
||||||
|
<
|
||||||
|
Indent can also have `indent.immediate` set using a `#set!` directive, which
|
||||||
|
permits the next line to indent even when the block intended to be indented
|
||||||
|
has no content yet, improving interactive typing.
|
||||||
|
|
||||||
|
eg for python:
|
||||||
|
>
|
||||||
|
((if_statement) @indent.begin
|
||||||
|
(#set! indent.immediate 1))
|
||||||
|
<
|
||||||
|
|
||||||
|
Will allow:
|
||||||
|
>
|
||||||
|
if True:<CR>
|
||||||
|
# Auto indent to here
|
||||||
|
|
||||||
|
`@indent.end` *nvim-treesitter-indentation-indent.end*
|
||||||
|
An `@indent.end` capture is used to specify that the indented region ends and
|
||||||
|
any text subsequent to the capture should be dedented.
|
||||||
|
|
||||||
|
`@indent.branch` *nvim-treesitter-indentation-indent.branch*
|
||||||
|
An `@indent.branch` capture is used to specify that a dedented region starts
|
||||||
|
at the line including the captured nodes.
|
||||||
|
|
||||||
|
`@indent.dedent` *nvim-treesitter-indentation-indent.dedent*
|
||||||
|
A `@indent.dedent` capture specifies dedenting starting on the next line.
|
||||||
|
>
|
||||||
|
`@indent.align` *nvim-treesitter-indentation-aligned_indent.align*
|
||||||
|
Aligned indent blocks may be specified with the `@indent.align` capture.
|
||||||
|
This permits
|
||||||
|
|
||||||
|
>
|
||||||
|
foo(a,
|
||||||
|
b,
|
||||||
|
c)
|
||||||
|
<
|
||||||
|
As well as
|
||||||
|
>
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c)
|
||||||
|
<
|
||||||
|
and finally
|
||||||
|
>
|
||||||
|
foo(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c
|
||||||
|
)
|
||||||
|
<
|
||||||
|
To specify the delimiters to use `indent.open_delimiter` and
|
||||||
|
`indent.close_delimiter` should be used. Eg.
|
||||||
|
>
|
||||||
|
((argument_list) @indent.align
|
||||||
|
(#set! indent.open_delimiter "(")
|
||||||
|
(#set! indent.close_delimiter ")"))
|
||||||
|
<
|
||||||
|
|
||||||
|
For some languages the last line of an `indent.align` block must not be
|
||||||
|
the same indent as the natural next line.
|
||||||
|
|
||||||
|
For example in python:
|
||||||
|
|
||||||
|
>
|
||||||
|
if (a > b and
|
||||||
|
c < d):
|
||||||
|
pass
|
||||||
|
|
||||||
|
Is not correct, whereas
|
||||||
|
>
|
||||||
|
if (a > b and
|
||||||
|
c < d):
|
||||||
|
pass
|
||||||
|
|
||||||
|
Would be correctly indented. This behavior may be chosen using
|
||||||
|
`indent.avoid_last_matching_next`. Eg.
|
||||||
|
|
||||||
|
>
|
||||||
|
(if_statement
|
||||||
|
condition: (parenthesized_expression) @indent.align
|
||||||
|
(#set! indent.open_delimiter "(")
|
||||||
|
(#set! indent.close_delimiter ")")
|
||||||
|
(#set! indent.avoid_last_matching_next 1)
|
||||||
|
)
|
||||||
|
<
|
||||||
|
Could be used to specify that the last line of an `@indent.align` capture
|
||||||
|
should be additionally indented to avoid clashing with the indent of the first
|
||||||
|
line of the block inside an if.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
COMMANDS *nvim-treesitter-commands*
|
||||||
|
|
||||||
|
*:TSInstall*
|
||||||
|
:TSInstall {language} ...~
|
||||||
|
|
||||||
|
Install one or more treesitter parsers.
|
||||||
|
You can use |:TSInstall| `all` to install all parsers. Use |:TSInstall!| to
|
||||||
|
force the reinstallation of already installed parsers.
|
||||||
|
*:TSInstallSync*
|
||||||
|
:TSInstallSync {language} ...~
|
||||||
|
|
||||||
|
Perform the |:TSInstall| operation synchronously.
|
||||||
|
|
||||||
|
*:TSInstallInfo*
|
||||||
|
:TSInstallInfo~
|
||||||
|
|
||||||
|
List information about currently installed parsers
|
||||||
|
|
||||||
|
*:TSUpdate*
|
||||||
|
:TSUpdate {language} ...~
|
||||||
|
|
||||||
|
Update the installed parser for one more {language} or all installed parsers
|
||||||
|
if {language} is omitted. The specified parser is installed if it is not already
|
||||||
|
installed.
|
||||||
|
|
||||||
|
*:TSUpdateSync*
|
||||||
|
:TSUpdateSync {language} ...~
|
||||||
|
|
||||||
|
Perform the |:TSUpdate| operation synchronously.
|
||||||
|
|
||||||
|
*:TSUninstall*
|
||||||
|
:TSUninstall {language} ...~
|
||||||
|
|
||||||
|
Deletes the parser for one or more {language}. You can use 'all' for language
|
||||||
|
to uninstall all parsers.
|
||||||
|
|
||||||
|
*:TSBufEnable*
|
||||||
|
:TSBufEnable {module}~
|
||||||
|
|
||||||
|
Enable {module} on the current buffer.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
|
||||||
|
*:TSBufDisable*
|
||||||
|
:TSBufDisable {module}~
|
||||||
|
|
||||||
|
Disable {module} on the current buffer.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
|
||||||
|
*:TSBufToggle*
|
||||||
|
:TSBufToggle {module}~
|
||||||
|
|
||||||
|
Toggle (enable if disabled, disable if enabled) {module} on the current
|
||||||
|
buffer.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
|
||||||
|
*:TSEnable*
|
||||||
|
:TSEnable {module} [{language}]~
|
||||||
|
|
||||||
|
Enable {module} for the session.
|
||||||
|
If {language} is specified, enable module for the session only for this
|
||||||
|
particular language.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
A list of languages can be found at |:TSInstallInfo|
|
||||||
|
|
||||||
|
*:TSDisable*
|
||||||
|
:TSDisable {module} [{language}]~
|
||||||
|
|
||||||
|
Disable {module} for the session.
|
||||||
|
If {language} is specified, disable module for the session only for this
|
||||||
|
particular language.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
A list of languages can be found at |:TSInstallInfo|
|
||||||
|
|
||||||
|
*:TSToggle*
|
||||||
|
:TSToggle {module} [{language}]~
|
||||||
|
|
||||||
|
Toggle (enable if disabled, disable if enabled) {module} for the session.
|
||||||
|
If {language} is specified, toggle module for the session only for this
|
||||||
|
particular language.
|
||||||
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
A list of languages can be found at |:TSInstallInfo|
|
||||||
|
|
||||||
|
*:TSModuleInfo*
|
||||||
|
:TSModuleInfo [{module}]~
|
||||||
|
|
||||||
|
List the state for the given module or all modules for the current session in
|
||||||
|
a new buffer.
|
||||||
|
|
||||||
|
These highlight groups are used by default:
|
||||||
|
>
|
||||||
|
highlight default TSModuleInfoGood guifg=LightGreen gui=bold
|
||||||
|
highlight default TSModuleInfoBad guifg=Crimson
|
||||||
|
highlight default link TSModuleInfoHeader Type
|
||||||
|
highlight default link TSModuleInfoNamespace Statement
|
||||||
|
highlight default link TSModuleInfoParser Identifier
|
||||||
|
<
|
||||||
|
|
||||||
|
*:TSEditQuery*
|
||||||
|
:TSEditQuery {query-group} [{lang}]~
|
||||||
|
|
||||||
|
Edit the query file for a {query-group} (e.g. highlights, locals) for given
|
||||||
|
{lang}. If there are multiple files, the user is prompted to select one of them.
|
||||||
|
If no such file exists, a buffer for a new file in the user's config directory
|
||||||
|
is created. If {lang} is not specified, the language of the current buffer
|
||||||
|
is used.
|
||||||
|
|
||||||
|
*:TSEditQueryUserAfter*
|
||||||
|
:TSEditQueryUserAfter {query-group} [{lang}]~
|
||||||
|
|
||||||
|
Same as |:TSEditQuery| but edits a file in the `after` directory of the
|
||||||
|
user's config directory. Useful to add custom extensions for the queries
|
||||||
|
provided by a plugin.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
UTILS *nvim-treesitter-utils*
|
||||||
|
|
||||||
|
Nvim treesitter has some wrapper functions that you can retrieve with:
|
||||||
|
>
|
||||||
|
local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||||
|
<
|
||||||
|
Methods
|
||||||
|
*ts_utils.get_node_at_cursor*
|
||||||
|
get_node_at_cursor(winnr)~
|
||||||
|
|
||||||
|
`winnr` will be 0 if nil.
|
||||||
|
Returns the node under the cursor.
|
||||||
|
|
||||||
|
*ts_utils.is_parent*
|
||||||
|
is_parent(dest, source)~
|
||||||
|
|
||||||
|
Determines whether `dest` is a parent of `source`.
|
||||||
|
Returns a boolean.
|
||||||
|
|
||||||
|
*ts_utils.get_named_children*
|
||||||
|
get_named_children(node)~
|
||||||
|
|
||||||
|
Returns a table of named children of `node`.
|
||||||
|
|
||||||
|
*ts_utils.get_next_node*
|
||||||
|
get_next_node(node, allow_switch_parent, allow_next_parent)~
|
||||||
|
|
||||||
|
Returns the next node within the same parent.
|
||||||
|
If no node is found, returns `nil`.
|
||||||
|
If `allow_switch_parent` is true, it will allow switching parent
|
||||||
|
when the node is the last node.
|
||||||
|
If `allow_next_parent` is true, it will allow next parent if
|
||||||
|
the node is the last node and the next parent doesn't have children.
|
||||||
|
|
||||||
|
*ts_utils.get_previous_node*
|
||||||
|
get_previous_node(node, allow_switch_parents, allow_prev_parent)~
|
||||||
|
|
||||||
|
Returns the previous node within the same parent.
|
||||||
|
`allow_switch_parent` and `allow_prev_parent` follow the same rule
|
||||||
|
as |ts_utils.get_next_node| but if the node is the first node.
|
||||||
|
|
||||||
|
*ts_utils.goto_node*
|
||||||
|
goto_node(node, goto_end, avoid_set_jump)~
|
||||||
|
|
||||||
|
Sets cursor to the position of `node` in the current windows.
|
||||||
|
If `goto_end` is truthy, the cursor is set to the end the node range.
|
||||||
|
Setting `avoid_set_jump` to `true`, avoids setting the current cursor position
|
||||||
|
to the jump list.
|
||||||
|
|
||||||
|
*ts_utils.swap_nodes*
|
||||||
|
swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)~
|
||||||
|
|
||||||
|
Swaps the nodes or ranges.
|
||||||
|
set `cursor_to_second` to true to move the cursor to the second node
|
||||||
|
|
||||||
|
*ts_utils.memoize_by_buf_tick*
|
||||||
|
memoize_by_buf_tick(fn, options)~
|
||||||
|
|
||||||
|
Caches the return value for a function and returns the cache value if the tick
|
||||||
|
of the buffer has not changed from the previous.
|
||||||
|
|
||||||
|
`fn`: a function that takes any arguments
|
||||||
|
and returns a value to store.
|
||||||
|
`options?`: <table>
|
||||||
|
- `bufnr`: a function/value that extracts the bufnr from the given arguments.
|
||||||
|
- `key`: a function/value that extracts the cache key from the given arguments.
|
||||||
|
`returns`: a function to call with bufnr as argument to
|
||||||
|
retrieve the value from the cache
|
||||||
|
|
||||||
|
*ts_utils.node_to_lsp_range*
|
||||||
|
node_to_lsp_range(node)~
|
||||||
|
|
||||||
|
Get an lsp formatted range from a node range
|
||||||
|
|
||||||
|
*ts_utils.node_length*
|
||||||
|
node_length(node)~
|
||||||
|
|
||||||
|
Get the byte length of node range
|
||||||
|
|
||||||
|
*ts_utils.update_selection*
|
||||||
|
update_selection(buf, node)~
|
||||||
|
|
||||||
|
Set the selection to the node range
|
||||||
|
|
||||||
|
*ts_utils.highlight_range*
|
||||||
|
highlight_range(range, buf, hl_namespace, hl_group)~
|
||||||
|
|
||||||
|
Set a highlight that spans the given range
|
||||||
|
|
||||||
|
*ts_utils.highlight_node*
|
||||||
|
highlight_node(node, buf, hl_namespace, hl_group)~
|
||||||
|
|
||||||
|
Set a highlight that spans the given node's range
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
FUNCTIONS *nvim-treesitter-functions*
|
||||||
|
|
||||||
|
*nvim_treesitter#statusline()*
|
||||||
|
nvim_treesitter#statusline(opts)~
|
||||||
|
|
||||||
|
Returns a string describing the current position in the file. This
|
||||||
|
could be used as a statusline indicator.
|
||||||
|
Default options (lua syntax):
|
||||||
|
>
|
||||||
|
{
|
||||||
|
indicator_size = 100,
|
||||||
|
type_patterns = {'class', 'function', 'method'},
|
||||||
|
transform_fn = function(line, _node) return line:gsub('%s*[%[%(%{]*%s*$', '') end,
|
||||||
|
separator = ' -> ',
|
||||||
|
allow_duplicates = false
|
||||||
|
}
|
||||||
|
<
|
||||||
|
- `indicator_size` - How long should the string be. If longer, it is cut from
|
||||||
|
the beginning.
|
||||||
|
- `type_patterns` - Which node type patterns to match.
|
||||||
|
- `transform_fn` - Function used to transform the single item in line. By
|
||||||
|
default it removes opening brackets and spaces from end. Takes two arguments:
|
||||||
|
the text of the line in question, and the corresponding treesitter node.
|
||||||
|
- `separator` - Separator between nodes.
|
||||||
|
- `allow_duplicates` - Whether or not to remove duplicate components.
|
||||||
|
|
||||||
|
*nvim_treesitter#foldexpr()*
|
||||||
|
nvim_treesitter#foldexpr()~
|
||||||
|
|
||||||
|
Functions to be used to determine the fold level at a given line number.
|
||||||
|
To use it: >
|
||||||
|
set foldmethod=expr
|
||||||
|
set foldexpr=nvim_treesitter#foldexpr()
|
||||||
|
<
|
||||||
|
|
||||||
|
This will respect your 'foldminlines' and 'foldnestmax' settings.
|
||||||
|
|
||||||
|
Note: This is highly experimental, and folding can break on some types of
|
||||||
|
edits. If you encounter such breakage, hitting `zx` should fix folding.
|
||||||
|
In any case, feel free to open an issue with the reproducing steps.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
PERFORMANCE *nvim-treesitter-performance*
|
||||||
|
|
||||||
|
`nvim-treesitter` checks the 'runtimepath' on startup in order to discover
|
||||||
|
available parsers and queries and index them. As a consequence, a very long
|
||||||
|
'runtimepath' might result in delayed startup times.
|
||||||
|
|
||||||
|
|
||||||
|
vim:tw=78:ts=8:expandtab:noet:ft=help:norl:
|
905
pack/ant/start/nvim-treesitter/lockfile.json
Normal file
905
pack/ant/start/nvim-treesitter/lockfile.json
Normal file
|
@ -0,0 +1,905 @@
|
||||||
|
{
|
||||||
|
"ada": {
|
||||||
|
"revision": "e8e2515465cc2d7c444498e68bdb9f1d86767f95"
|
||||||
|
},
|
||||||
|
"agda": {
|
||||||
|
"revision": "6516cfec35479d62c0ad3c8e7e546a9774b489fd"
|
||||||
|
},
|
||||||
|
"angular": {
|
||||||
|
"revision": "745d3c65c2294aca1110b6b6ad6805124be605c9"
|
||||||
|
},
|
||||||
|
"apex": {
|
||||||
|
"revision": "46d4a12e4e90b10a575b7b16ea3b6ead50322074"
|
||||||
|
},
|
||||||
|
"arduino": {
|
||||||
|
"revision": "415ebc8f75eb02a748faa03f5af199f08ced120f"
|
||||||
|
},
|
||||||
|
"asm": {
|
||||||
|
"revision": "55b2b913f1e71136027d6fce8212e760c64f3532"
|
||||||
|
},
|
||||||
|
"astro": {
|
||||||
|
"revision": "4be180759ec13651f72bacee65fa477c64222a1a"
|
||||||
|
},
|
||||||
|
"authzed": {
|
||||||
|
"revision": "1dec7e1af96c56924e3322cd85fdce15d0a31d00"
|
||||||
|
},
|
||||||
|
"awk": {
|
||||||
|
"revision": "553fdc4afb3b603332c3f4baf50c711506f4e797"
|
||||||
|
},
|
||||||
|
"bash": {
|
||||||
|
"revision": "597a5ed6ed4d932fd44697feec988f977081ae59"
|
||||||
|
},
|
||||||
|
"bass": {
|
||||||
|
"revision": "28dc7059722be090d04cd751aed915b2fee2f89a"
|
||||||
|
},
|
||||||
|
"beancount": {
|
||||||
|
"revision": "01c0da29e0fc7130420a09d939ecc524e09b6ba6"
|
||||||
|
},
|
||||||
|
"bibtex": {
|
||||||
|
"revision": "ccfd77db0ed799b6c22c214fe9d2937f47bc8b34"
|
||||||
|
},
|
||||||
|
"bicep": {
|
||||||
|
"revision": "0092c7d1bd6bb22ce0a6f78497d50ea2b87f19c0"
|
||||||
|
},
|
||||||
|
"bitbake": {
|
||||||
|
"revision": "a5d04fdb5a69a02b8fa8eb5525a60dfb5309b73b"
|
||||||
|
},
|
||||||
|
"blueprint": {
|
||||||
|
"revision": "60ba73739c6083c693d86a1a7cf039c07eb4ed59"
|
||||||
|
},
|
||||||
|
"bp": {
|
||||||
|
"revision": "4e60cf3c2e613625c06f6f85540b3631e2d06cd3"
|
||||||
|
},
|
||||||
|
"c": {
|
||||||
|
"revision": "79284a14a0d7e4495b095b38acdd8a27acbe870e"
|
||||||
|
},
|
||||||
|
"c_sharp": {
|
||||||
|
"revision": "3a85187e0a9e8db01dec6b3eb2f4e7cdfecc9d88"
|
||||||
|
},
|
||||||
|
"cairo": {
|
||||||
|
"revision": "6238f609bea233040fe927858156dee5515a0745"
|
||||||
|
},
|
||||||
|
"capnp": {
|
||||||
|
"revision": "7b0883c03e5edd34ef7bcf703194204299d7099f"
|
||||||
|
},
|
||||||
|
"chatito": {
|
||||||
|
"revision": "a461f20dedb43905febb12c1635bc7d2e43e96f0"
|
||||||
|
},
|
||||||
|
"clojure": {
|
||||||
|
"revision": "f4236d4da8aa92bc105d9c118746474c608e6af7"
|
||||||
|
},
|
||||||
|
"cmake": {
|
||||||
|
"revision": "e409ae33f00e04cde30f2bcffb979caf1a33562a"
|
||||||
|
},
|
||||||
|
"comment": {
|
||||||
|
"revision": "3555706cef8b98d3e4c7379d7260548ff03ad363"
|
||||||
|
},
|
||||||
|
"commonlisp": {
|
||||||
|
"revision": "bf2a65b1c119898a1a17389e07f2a399c05cdc0c"
|
||||||
|
},
|
||||||
|
"cooklang": {
|
||||||
|
"revision": "4ebe237c1cf64cf3826fc249e9ec0988fe07e58e"
|
||||||
|
},
|
||||||
|
"corn": {
|
||||||
|
"revision": "464654742cbfd3a3de560aba120998f1d5dfa844"
|
||||||
|
},
|
||||||
|
"cpon": {
|
||||||
|
"revision": "594289eadfec719198e560f9d7fd243c4db678d5"
|
||||||
|
},
|
||||||
|
"cpp": {
|
||||||
|
"revision": "16bf9d2c451957aee976c982c2c668b1c0d12014"
|
||||||
|
},
|
||||||
|
"css": {
|
||||||
|
"revision": "ccc4e2c4b30ddabc4b41c577ad0550b3cac4a74a"
|
||||||
|
},
|
||||||
|
"csv": {
|
||||||
|
"revision": "7eb7297823605392d2bbcc4c09b1cd18d6fa9529"
|
||||||
|
},
|
||||||
|
"cuda": {
|
||||||
|
"revision": "635e8aa3747823a0c4e9660c07cef76fe8d3ef93"
|
||||||
|
},
|
||||||
|
"cue": {
|
||||||
|
"revision": "8a5f273bfa281c66354da562f2307c2d394b6c81"
|
||||||
|
},
|
||||||
|
"d": {
|
||||||
|
"revision": "45e5f1e9d6de2c68591bc8e5ec662cf18e950b4a"
|
||||||
|
},
|
||||||
|
"dart": {
|
||||||
|
"revision": "9ac03bb2154316624fb4c41fe0f372a5f1597b43"
|
||||||
|
},
|
||||||
|
"devicetree": {
|
||||||
|
"revision": "16c9cb959675bc9bc4f4e5bebe473d511a12a06d"
|
||||||
|
},
|
||||||
|
"dhall": {
|
||||||
|
"revision": "affb6ee38d629c9296749767ab832d69bb0d9ea8"
|
||||||
|
},
|
||||||
|
"diff": {
|
||||||
|
"revision": "63439b5e6e35750aff1e53d9eecc663d369c54bc"
|
||||||
|
},
|
||||||
|
"disassembly": {
|
||||||
|
"revision": "0229c0211dba909c5d45129ac784a3f4d49c243a"
|
||||||
|
},
|
||||||
|
"djot": {
|
||||||
|
"revision": "886601b67d1f4690173a4925c214343c30704d32"
|
||||||
|
},
|
||||||
|
"dockerfile": {
|
||||||
|
"revision": "087daa20438a6cc01fa5e6fe6906d77c869d19fe"
|
||||||
|
},
|
||||||
|
"dot": {
|
||||||
|
"revision": "9ab85550c896d8b294d9b9ca1e30698736f08cea"
|
||||||
|
},
|
||||||
|
"doxygen": {
|
||||||
|
"revision": "ccd998f378c3f9345ea4eeb223f56d7b84d16687"
|
||||||
|
},
|
||||||
|
"dtd": {
|
||||||
|
"revision": "cd1316e476ec40da6ce1fb5749c9d7e6b4f1090c"
|
||||||
|
},
|
||||||
|
"earthfile": {
|
||||||
|
"revision": "1d637f2002bb8b22d4c08d26ad2bfbc22916f3ce"
|
||||||
|
},
|
||||||
|
"ebnf": {
|
||||||
|
"revision": "8e635b0b723c620774dfb8abf382a7f531894b40"
|
||||||
|
},
|
||||||
|
"editorconfig": {
|
||||||
|
"revision": "777f774d6381f1bb84adffa02a4e476fb61486ae"
|
||||||
|
},
|
||||||
|
"eds": {
|
||||||
|
"revision": "26d529e6cfecde391a03c21d1474eb51e0285805"
|
||||||
|
},
|
||||||
|
"eex": {
|
||||||
|
"revision": "f742f2fe327463335e8671a87c0b9b396905d1d1"
|
||||||
|
},
|
||||||
|
"elixir": {
|
||||||
|
"revision": "2ac7a0f81f0731d83068b2872c4a8fee39263a85"
|
||||||
|
},
|
||||||
|
"elm": {
|
||||||
|
"revision": "27f502ed0a1cbd3c5912d284cc7934ee0d4cdddc"
|
||||||
|
},
|
||||||
|
"elsa": {
|
||||||
|
"revision": "0a66b2b3f3c1915e67ad2ef9f7dbd2a84820d9d7"
|
||||||
|
},
|
||||||
|
"elvish": {
|
||||||
|
"revision": "5e7210d945425b77f82cbaebc5af4dd3e1ad40f5"
|
||||||
|
},
|
||||||
|
"embedded_template": {
|
||||||
|
"revision": "7e319b065c5864bac2fb68f7e14a338b919e8bb3"
|
||||||
|
},
|
||||||
|
"erlang": {
|
||||||
|
"revision": "4095e9993acc89cb311ab1be8614c21b1cf768a4"
|
||||||
|
},
|
||||||
|
"facility": {
|
||||||
|
"revision": "2d037f2f2bf668737f72e6be6eda4b7918b68d86"
|
||||||
|
},
|
||||||
|
"faust": {
|
||||||
|
"revision": "f3b9274514b5f9bf6b0dd4a01c30f9cc15c58bc4"
|
||||||
|
},
|
||||||
|
"fennel": {
|
||||||
|
"revision": "cfbfa478dc2dbef267ee94ae4323d9c886f45e94"
|
||||||
|
},
|
||||||
|
"fidl": {
|
||||||
|
"revision": "0a8910f293268e27ff554357c229ba172b0eaed2"
|
||||||
|
},
|
||||||
|
"firrtl": {
|
||||||
|
"revision": "8503d3a0fe0f9e427863cb0055699ff2d29ae5f5"
|
||||||
|
},
|
||||||
|
"fish": {
|
||||||
|
"revision": "a78aef9abc395c600c38a037ac779afc7e3cc9e0"
|
||||||
|
},
|
||||||
|
"foam": {
|
||||||
|
"revision": "04664b40c0dadb7ef37028acf3422c63271d377b"
|
||||||
|
},
|
||||||
|
"forth": {
|
||||||
|
"revision": "90189238385cf636b9ee99ce548b9e5b5e569d48"
|
||||||
|
},
|
||||||
|
"fortran": {
|
||||||
|
"revision": "4a593dda9cbc050a6686187249f8350ceea292ce"
|
||||||
|
},
|
||||||
|
"fsh": {
|
||||||
|
"revision": "fad2e175099a45efbc98f000cc196d3674cc45e0"
|
||||||
|
},
|
||||||
|
"fsharp": {
|
||||||
|
"revision": "971da5ff0266bfe4a6ecfb94616548032d6d1ba0"
|
||||||
|
},
|
||||||
|
"func": {
|
||||||
|
"revision": "f780ca55e65e7d7360d0229331763e16c452fc98"
|
||||||
|
},
|
||||||
|
"fusion": {
|
||||||
|
"revision": "19db2f47ba4c3a0f6238d4ae0e2abfca16e61dd6"
|
||||||
|
},
|
||||||
|
"gap": {
|
||||||
|
"revision": "141b063335e85299bde3f61b4888d02d674a1abc"
|
||||||
|
},
|
||||||
|
"gaptst": {
|
||||||
|
"revision": "e0723dc6136309b3d5904dad2c73ef71267428c1"
|
||||||
|
},
|
||||||
|
"gdscript": {
|
||||||
|
"revision": "1f1e782fe2600f50ae57b53876505b8282388d77"
|
||||||
|
},
|
||||||
|
"gdshader": {
|
||||||
|
"revision": "ffd9f958df13cae04593781d7d2562295a872455"
|
||||||
|
},
|
||||||
|
"git_config": {
|
||||||
|
"revision": "9c2a1b7894e6d9eedfe99805b829b4ecd871375e"
|
||||||
|
},
|
||||||
|
"git_rebase": {
|
||||||
|
"revision": "bff4b66b44b020d918d67e2828eada1974a966aa"
|
||||||
|
},
|
||||||
|
"gitattributes": {
|
||||||
|
"revision": "41940e199ba5763abea1d21b4f717014b45f01ea"
|
||||||
|
},
|
||||||
|
"gitcommit": {
|
||||||
|
"revision": "db0e0c4fb9095fdc42a7af34019c0616c071e9eb"
|
||||||
|
},
|
||||||
|
"gitignore": {
|
||||||
|
"revision": "f4685bf11ac466dd278449bcfe5fd014e94aa504"
|
||||||
|
},
|
||||||
|
"gleam": {
|
||||||
|
"revision": "57c9951b290c8084d7c60b0aee7a2b30986ea031"
|
||||||
|
},
|
||||||
|
"glimmer": {
|
||||||
|
"revision": "da605af8c5999b43e6839b575eae5e6cafabb06f"
|
||||||
|
},
|
||||||
|
"glimmer_javascript": {
|
||||||
|
"revision": "7e8ea8cf39fc360cb97bd253442cd48e4f7a9ce3"
|
||||||
|
},
|
||||||
|
"glimmer_typescript": {
|
||||||
|
"revision": "4006128790efb58ca82a4492d8ef0983b260fc6a"
|
||||||
|
},
|
||||||
|
"glsl": {
|
||||||
|
"revision": "66aec57f7119c7e8e40665b723cd7af5594f15ee"
|
||||||
|
},
|
||||||
|
"gn": {
|
||||||
|
"revision": "bc06955bc1e3c9ff8e9b2b2a55b38b94da923c05"
|
||||||
|
},
|
||||||
|
"gnuplot": {
|
||||||
|
"revision": "3c895f5d9c0b3a3c7e02383766b462c21913c000"
|
||||||
|
},
|
||||||
|
"go": {
|
||||||
|
"revision": "df2ce2e206d2810bf010d73055055bfcff1b55aa"
|
||||||
|
},
|
||||||
|
"goctl": {
|
||||||
|
"revision": "49c43532689fe1f53e8b9e009d0521cab02c432b"
|
||||||
|
},
|
||||||
|
"godot_resource": {
|
||||||
|
"revision": "2ffb90de47417018651fc3b970e5f6b67214dc9d"
|
||||||
|
},
|
||||||
|
"gomod": {
|
||||||
|
"revision": "3b01edce2b9ea6766ca19328d1850e456fde3103"
|
||||||
|
},
|
||||||
|
"gosum": {
|
||||||
|
"revision": "e2ac513b2240c7ff1069ae33b2df29ce90777c11"
|
||||||
|
},
|
||||||
|
"gotmpl": {
|
||||||
|
"revision": "ca52fbfc98366c585b84f4cb3745df49f33cd140"
|
||||||
|
},
|
||||||
|
"gowork": {
|
||||||
|
"revision": "949a8a470559543857a62102c84700d291fc984c"
|
||||||
|
},
|
||||||
|
"gpg": {
|
||||||
|
"revision": "f99323fb8f3f10b6c69db0c2f6d0a14bd7330675"
|
||||||
|
},
|
||||||
|
"graphql": {
|
||||||
|
"revision": "5e66e961eee421786bdda8495ed1db045e06b5fe"
|
||||||
|
},
|
||||||
|
"gren": {
|
||||||
|
"revision": "c06e272341363c5d8e19ac34bc7c56258a37e71b"
|
||||||
|
},
|
||||||
|
"groovy": {
|
||||||
|
"revision": "0d8884514fe10c4fa47527d9a0284d207f38ddea"
|
||||||
|
},
|
||||||
|
"gstlaunch": {
|
||||||
|
"revision": "549aef253fd38a53995cda1bf55c501174372bf7"
|
||||||
|
},
|
||||||
|
"hack": {
|
||||||
|
"revision": "fca1e294f6dce8ec5659233a6a21f5bd0ed5b4f2"
|
||||||
|
},
|
||||||
|
"hare": {
|
||||||
|
"revision": "4af5d82cf9ec39f67cb1db5b7a9269d337406592"
|
||||||
|
},
|
||||||
|
"haskell": {
|
||||||
|
"revision": "70ea0757986ea58a0d39ddfcd9d791beadeb0f43"
|
||||||
|
},
|
||||||
|
"haskell_persistent": {
|
||||||
|
"revision": "577259b4068b2c281c9ebf94c109bd50a74d5857"
|
||||||
|
},
|
||||||
|
"hcl": {
|
||||||
|
"revision": "9e3ec9848f28d26845ba300fd73c740459b83e9b"
|
||||||
|
},
|
||||||
|
"heex": {
|
||||||
|
"revision": "6dd0303acf7138dd2b9b432a229e16539581c701"
|
||||||
|
},
|
||||||
|
"helm": {
|
||||||
|
"revision": "ca52fbfc98366c585b84f4cb3745df49f33cd140"
|
||||||
|
},
|
||||||
|
"hjson": {
|
||||||
|
"revision": "02fa3b79b3ff9a296066da6277adfc3f26cbc9e0"
|
||||||
|
},
|
||||||
|
"hlsl": {
|
||||||
|
"revision": "b309425a7ab4456605cfe78774b80f7e275ca87d"
|
||||||
|
},
|
||||||
|
"hlsplaylist": {
|
||||||
|
"revision": "3bfda9271e3adb08d35f47a2102fe957009e1c55"
|
||||||
|
},
|
||||||
|
"hocon": {
|
||||||
|
"revision": "c390f10519ae69fdb03b3e5764f5592fb6924bcc"
|
||||||
|
},
|
||||||
|
"hoon": {
|
||||||
|
"revision": "a24c5a39d1d7e993a8bee913c8e8b6a652ca5ae8"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"revision": "c30792dee70aaa1910e66a39557a841b6e4386d5"
|
||||||
|
},
|
||||||
|
"htmldjango": {
|
||||||
|
"revision": "ea71012d3fe14dd0b69f36be4f96bdfe9155ebae"
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"revision": "231f1b1bafd12e46c8ed8c21dbbdd940d9f15e94"
|
||||||
|
},
|
||||||
|
"hurl": {
|
||||||
|
"revision": "ff07a42d9ec95443b5c1b57ed793414bf7b79be5"
|
||||||
|
},
|
||||||
|
"hyprlang": {
|
||||||
|
"revision": "6858695eba0e63b9e0fceef081d291eb352abce8"
|
||||||
|
},
|
||||||
|
"idl": {
|
||||||
|
"revision": "5573b295410201ed22771776b34d636900eba368"
|
||||||
|
},
|
||||||
|
"ini": {
|
||||||
|
"revision": "962568c9efa71d25720ab42c5d36e222626ef3a6"
|
||||||
|
},
|
||||||
|
"inko": {
|
||||||
|
"revision": "6f9c072d023c3886aabcd8012274461b35d2d0a9"
|
||||||
|
},
|
||||||
|
"ispc": {
|
||||||
|
"revision": "9b2f9aec2106b94b4e099fe75e73ebd8ae707c04"
|
||||||
|
},
|
||||||
|
"janet_simple": {
|
||||||
|
"revision": "12bfab7db8a5f5b1d774ef84b5831acd34936071"
|
||||||
|
},
|
||||||
|
"java": {
|
||||||
|
"revision": "b864ed97b9675e86de7c15a70c12e4c1ca85fbf9"
|
||||||
|
},
|
||||||
|
"javascript": {
|
||||||
|
"revision": "c4ce9dc8e7e98ea25757ea26bfe9a022043ccd77"
|
||||||
|
},
|
||||||
|
"jq": {
|
||||||
|
"revision": "13990f530e8e6709b7978503da9bc8701d366791"
|
||||||
|
},
|
||||||
|
"jsdoc": {
|
||||||
|
"revision": "b2237872e528b8372ed008068f717db66c16a725"
|
||||||
|
},
|
||||||
|
"json": {
|
||||||
|
"revision": "f2503f1c437fe24560876557868ac94c9cfd3216"
|
||||||
|
},
|
||||||
|
"json5": {
|
||||||
|
"revision": "ab0ba8229d639ec4f3fa5f674c9133477f4b77bd"
|
||||||
|
},
|
||||||
|
"jsonc": {
|
||||||
|
"revision": "02b01653c8a1c198ae7287d566efa86a135b30d5"
|
||||||
|
},
|
||||||
|
"jsonnet": {
|
||||||
|
"revision": "ddd075f1939aed8147b7aa67f042eda3fce22790"
|
||||||
|
},
|
||||||
|
"julia": {
|
||||||
|
"revision": "19f62656dc7f2ff3756a8ef3dcf9ab1c01a9eb58"
|
||||||
|
},
|
||||||
|
"just": {
|
||||||
|
"revision": "6aee3d2f5b3a47286bae0916daaa6c7a217f6fa4"
|
||||||
|
},
|
||||||
|
"kconfig": {
|
||||||
|
"revision": "486fea71f61ad9f3fd4072a118402e97fe88d26c"
|
||||||
|
},
|
||||||
|
"kdl": {
|
||||||
|
"revision": "b37e3d58e5c5cf8d739b315d6114e02d42e66664"
|
||||||
|
},
|
||||||
|
"kotlin": {
|
||||||
|
"revision": "76f53c48d29e8588934fb55b0240d7bdfe00bfe5"
|
||||||
|
},
|
||||||
|
"koto": {
|
||||||
|
"revision": "cbf637e5163065934c827d254b293f4d2f08f523"
|
||||||
|
},
|
||||||
|
"kusto": {
|
||||||
|
"revision": "8353a1296607d6ba33db7c7e312226e5fc83e8ce"
|
||||||
|
},
|
||||||
|
"lalrpop": {
|
||||||
|
"revision": "194c25539f435de415ee0551a5f07058833da915"
|
||||||
|
},
|
||||||
|
"latex": {
|
||||||
|
"revision": "87e4059f01bed363230dc349f794ce4cc580e862"
|
||||||
|
},
|
||||||
|
"ledger": {
|
||||||
|
"revision": "a2eff7fee59ee6adfc4a3646e2f41ba3b340a97d"
|
||||||
|
},
|
||||||
|
"leo": {
|
||||||
|
"revision": "6ca11a96fc2cab51217e0cf4a2f9ed3ea63e28fb"
|
||||||
|
},
|
||||||
|
"linkerscript": {
|
||||||
|
"revision": "f99011a3554213b654985a4b0a65b3b032ec4621"
|
||||||
|
},
|
||||||
|
"liquid": {
|
||||||
|
"revision": "23ac814111e2b4b4b083e2c92219af2d5b74d13d"
|
||||||
|
},
|
||||||
|
"liquidsoap": {
|
||||||
|
"revision": "14feafa91630afb1ab9988cf9b738b7ea29f3f89"
|
||||||
|
},
|
||||||
|
"llvm": {
|
||||||
|
"revision": "c14cb839003348692158b845db9edda201374548"
|
||||||
|
},
|
||||||
|
"lua": {
|
||||||
|
"revision": "34e60e7f45fc313463c68090d88d742a55d1bd7a"
|
||||||
|
},
|
||||||
|
"luadoc": {
|
||||||
|
"revision": "873612aadd3f684dd4e631bdf42ea8990c57634e"
|
||||||
|
},
|
||||||
|
"luap": {
|
||||||
|
"revision": "c134aaec6acf4fa95fe4aa0dc9aba3eacdbbe55a"
|
||||||
|
},
|
||||||
|
"luau": {
|
||||||
|
"revision": "fbadc96272f718dba267628ba7b0e694c368cef3"
|
||||||
|
},
|
||||||
|
"m68k": {
|
||||||
|
"revision": "e128454c2210c0e0c10b68fe45ddb8fee80182a3"
|
||||||
|
},
|
||||||
|
"make": {
|
||||||
|
"revision": "a4b9187417d6be349ee5fd4b6e77b4172c6827dd"
|
||||||
|
},
|
||||||
|
"markdown": {
|
||||||
|
"revision": "5cdc549ab8f461aff876c5be9741027189299cec"
|
||||||
|
},
|
||||||
|
"markdown_inline": {
|
||||||
|
"revision": "5cdc549ab8f461aff876c5be9741027189299cec"
|
||||||
|
},
|
||||||
|
"matlab": {
|
||||||
|
"revision": "306c43ab28b7b8a4976e40ff0a7c26b019ad52df"
|
||||||
|
},
|
||||||
|
"menhir": {
|
||||||
|
"revision": "be8866a6bcc2b563ab0de895af69daeffa88fe70"
|
||||||
|
},
|
||||||
|
"mermaid": {
|
||||||
|
"revision": "90ae195b31933ceb9d079abfa8a3ad0a36fee4cc"
|
||||||
|
},
|
||||||
|
"meson": {
|
||||||
|
"revision": "c5fffb8edd39f22644084ab3f73a924a75721ee3"
|
||||||
|
},
|
||||||
|
"mlir": {
|
||||||
|
"revision": "0238b7fb6a630f77b3fc8b8a48285ef6ed45cbcc"
|
||||||
|
},
|
||||||
|
"muttrc": {
|
||||||
|
"revision": "173b0ab53a9c07962c9777189c4c70e90f1c1837"
|
||||||
|
},
|
||||||
|
"nasm": {
|
||||||
|
"revision": "570f3d7be01fffc751237f4cfcf52d04e20532d1"
|
||||||
|
},
|
||||||
|
"nginx": {
|
||||||
|
"revision": "281d184b8240b2b22670b8907b57b6d6842db6f3"
|
||||||
|
},
|
||||||
|
"nickel": {
|
||||||
|
"revision": "ddaa2bc22355effd97c0d6b09ff5962705c6368d"
|
||||||
|
},
|
||||||
|
"nim": {
|
||||||
|
"revision": "897e5d346f0b59ed62b517cfb0f1a845ad8f0ab7"
|
||||||
|
},
|
||||||
|
"nim_format_string": {
|
||||||
|
"revision": "d45f75022d147cda056e98bfba68222c9c8eca3a"
|
||||||
|
},
|
||||||
|
"ninja": {
|
||||||
|
"revision": "0a95cfdc0745b6ae82f60d3a339b37f19b7b9267"
|
||||||
|
},
|
||||||
|
"nix": {
|
||||||
|
"revision": "456b14a2fa6315abc7e02fcffaf4a1f35d4955d3"
|
||||||
|
},
|
||||||
|
"norg": {
|
||||||
|
"revision": "d89d95af13d409f30a6c7676387bde311ec4a2c8"
|
||||||
|
},
|
||||||
|
"nqc": {
|
||||||
|
"revision": "14e6da1627aaef21d2b2aa0c37d04269766dcc1d"
|
||||||
|
},
|
||||||
|
"objc": {
|
||||||
|
"revision": "62e61b6f5c0289c376d61a8c91faf6435cde9012"
|
||||||
|
},
|
||||||
|
"objdump": {
|
||||||
|
"revision": "28d3b2e25a0b1881d1b47ed1924ca276c7003d45"
|
||||||
|
},
|
||||||
|
"ocaml": {
|
||||||
|
"revision": "5f7a97e9757d8afe6c0b0b5dd8734cf59f35456e"
|
||||||
|
},
|
||||||
|
"ocaml_interface": {
|
||||||
|
"revision": "5f7a97e9757d8afe6c0b0b5dd8734cf59f35456e"
|
||||||
|
},
|
||||||
|
"ocamllex": {
|
||||||
|
"revision": "4b9898ccbf198602bb0dec9cd67cc1d2c0a4fad2"
|
||||||
|
},
|
||||||
|
"odin": {
|
||||||
|
"revision": "3fee7964bbfb2554deef12c224344f3870d15375"
|
||||||
|
},
|
||||||
|
"org": {
|
||||||
|
"revision": "64cfbc213f5a83da17632c95382a5a0a2f3357c1"
|
||||||
|
},
|
||||||
|
"pascal": {
|
||||||
|
"revision": "d0ebabefaea9ac3f6fc3004cf08cd121b66da9e4"
|
||||||
|
},
|
||||||
|
"passwd": {
|
||||||
|
"revision": "20239395eacdc2e0923a7e5683ad3605aee7b716"
|
||||||
|
},
|
||||||
|
"pem": {
|
||||||
|
"revision": "217ff2af3f2db15a79ab7e3d21ea1e0c17e71a1a"
|
||||||
|
},
|
||||||
|
"perl": {
|
||||||
|
"revision": "76ab9a52b9dd2a1758aae3da8286519d995037e9"
|
||||||
|
},
|
||||||
|
"php": {
|
||||||
|
"revision": "2bce5a6588ad6d53ffe5effaf9708682f0fbfc9b"
|
||||||
|
},
|
||||||
|
"php_only": {
|
||||||
|
"revision": "2bce5a6588ad6d53ffe5effaf9708682f0fbfc9b"
|
||||||
|
},
|
||||||
|
"phpdoc": {
|
||||||
|
"revision": "fe3202e468bc17332bec8969f2b50ff1f1da3a46"
|
||||||
|
},
|
||||||
|
"pioasm": {
|
||||||
|
"revision": "afece58efdb30440bddd151ef1347fa8d6f744a9"
|
||||||
|
},
|
||||||
|
"po": {
|
||||||
|
"revision": "bd860a0f57f697162bf28e576674be9c1500db5e"
|
||||||
|
},
|
||||||
|
"pod": {
|
||||||
|
"revision": "0bf8387987c21bf2f8ed41d2575a8f22b139687f"
|
||||||
|
},
|
||||||
|
"poe_filter": {
|
||||||
|
"revision": "592476d81f95d2451f2ca107dc872224c76fecdf"
|
||||||
|
},
|
||||||
|
"pony": {
|
||||||
|
"revision": "73ff874ae4c9e9b45462673cbc0a1e350e2522a7"
|
||||||
|
},
|
||||||
|
"powershell": {
|
||||||
|
"revision": "ebe2ab2f642eda2072c68c8de02e83973c26f33c"
|
||||||
|
},
|
||||||
|
"printf": {
|
||||||
|
"revision": "0e0aceabbf607ea09e03562f5d8a56f048ddea3d"
|
||||||
|
},
|
||||||
|
"prisma": {
|
||||||
|
"revision": "eca2596a355b1a9952b4f80f8f9caed300a272b5"
|
||||||
|
},
|
||||||
|
"problog": {
|
||||||
|
"revision": "93c69d2f84d8a167c0a3f4a8d51ccefe365a4dc8"
|
||||||
|
},
|
||||||
|
"prolog": {
|
||||||
|
"revision": "93c69d2f84d8a167c0a3f4a8d51ccefe365a4dc8"
|
||||||
|
},
|
||||||
|
"promql": {
|
||||||
|
"revision": "77625d78eebc3ffc44d114a07b2f348dff3061b0"
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"revision": "9d09f5f200c356c50c4103d36441309fd61b48d1"
|
||||||
|
},
|
||||||
|
"proto": {
|
||||||
|
"revision": "e9f6b43f6844bd2189b50a422d4e2094313f6aa3"
|
||||||
|
},
|
||||||
|
"prql": {
|
||||||
|
"revision": "09e158cd3650581c0af4c49c2e5b10c4834c8646"
|
||||||
|
},
|
||||||
|
"psv": {
|
||||||
|
"revision": "7eb7297823605392d2bbcc4c09b1cd18d6fa9529"
|
||||||
|
},
|
||||||
|
"pug": {
|
||||||
|
"revision": "a7ff31a38908df9b9f34828d21d6ca5e12413e18"
|
||||||
|
},
|
||||||
|
"puppet": {
|
||||||
|
"revision": "584522f32495d648b18a53ccb52d988e60de127d"
|
||||||
|
},
|
||||||
|
"purescript": {
|
||||||
|
"revision": "daf9b3e2be18b0b2996a1281f7783e0d041d8b80"
|
||||||
|
},
|
||||||
|
"pymanifest": {
|
||||||
|
"revision": "be062582956165019d3253794b4d712f66dfeaaa"
|
||||||
|
},
|
||||||
|
"python": {
|
||||||
|
"revision": "7f4b9c2d8039701b0579b7c060a918f8548aa7cd"
|
||||||
|
},
|
||||||
|
"ql": {
|
||||||
|
"revision": "1d3e2ff34f1113fadc0ff174c8a01cd4227af7fd"
|
||||||
|
},
|
||||||
|
"qmldir": {
|
||||||
|
"revision": "6b2b5e41734bd6f07ea4c36ac20fb6f14061c841"
|
||||||
|
},
|
||||||
|
"qmljs": {
|
||||||
|
"revision": "6d4db242185721e1f5ef21fde613ca90c743ec47"
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"revision": "f767fb0ac5e711b6d44c5e0c8d1f349687a86ce0"
|
||||||
|
},
|
||||||
|
"r": {
|
||||||
|
"revision": "2097fa502efa21349d26af0ffee55d773015e481"
|
||||||
|
},
|
||||||
|
"racket": {
|
||||||
|
"revision": "5b211bf93021d1c45f39aa96898be9f794f087e4"
|
||||||
|
},
|
||||||
|
"ralph": {
|
||||||
|
"revision": "f6d81bf7a4599c77388035439cf5801cd461ff77"
|
||||||
|
},
|
||||||
|
"rasi": {
|
||||||
|
"revision": "6c9bbcfdf5f0f553d9ebc01750a3aa247a37b8aa"
|
||||||
|
},
|
||||||
|
"rbs": {
|
||||||
|
"revision": "8d8e65ac3f77fbc9e15b1cdb9f980a3e0ac3ab99"
|
||||||
|
},
|
||||||
|
"re2c": {
|
||||||
|
"revision": "c18a3c2f4b6665e35b7e50d6048ea3cff770c572"
|
||||||
|
},
|
||||||
|
"readline": {
|
||||||
|
"revision": "74addc90fc539d31d413c0c7cf7581997a7fa46e"
|
||||||
|
},
|
||||||
|
"regex": {
|
||||||
|
"revision": "58f4caf9db12db3b38b81c77d274aa73c9e85aca"
|
||||||
|
},
|
||||||
|
"rego": {
|
||||||
|
"revision": "20b5a5958c837bc9f74b231022a68a594a313f6d"
|
||||||
|
},
|
||||||
|
"requirements": {
|
||||||
|
"revision": "5ad9b7581b3334f6ad492847d007f2fac6e6e5f2"
|
||||||
|
},
|
||||||
|
"rescript": {
|
||||||
|
"revision": "4606cd81c4c31d1d02390fee530858323410a74c"
|
||||||
|
},
|
||||||
|
"rnoweb": {
|
||||||
|
"revision": "1a74dc0ed731ad07db39f063e2c5a6fe528cae7f"
|
||||||
|
},
|
||||||
|
"robot": {
|
||||||
|
"revision": "322e4cc65754d2b3fdef4f2f8a71e0762e3d13af"
|
||||||
|
},
|
||||||
|
"robots": {
|
||||||
|
"revision": "8e3a4205b76236bb6dbebdbee5afc262ce38bb62"
|
||||||
|
},
|
||||||
|
"roc": {
|
||||||
|
"revision": "ef46edd0c03ea30a22f7e92bc68628fb7231dc8a"
|
||||||
|
},
|
||||||
|
"ron": {
|
||||||
|
"revision": "78938553b93075e638035f624973083451b29055"
|
||||||
|
},
|
||||||
|
"rst": {
|
||||||
|
"revision": "5120f6e59284cb8b85b450bd2db0bd352635ba9f"
|
||||||
|
},
|
||||||
|
"ruby": {
|
||||||
|
"revision": "83aec5f7d1659aaa79e6f24b406a9cd49b87e8e8"
|
||||||
|
},
|
||||||
|
"rust": {
|
||||||
|
"revision": "2ace7a922a755960f44d73a7bb1efffeb4cc5501"
|
||||||
|
},
|
||||||
|
"scala": {
|
||||||
|
"revision": "a9af6356f8e31f04e870587bca79bc2b15808ff5"
|
||||||
|
},
|
||||||
|
"scfg": {
|
||||||
|
"revision": "a5512800ea0220da4abbae61b8aea8423d1549aa"
|
||||||
|
},
|
||||||
|
"scheme": {
|
||||||
|
"revision": "63e25a4a84142ae7ee0ee01fe3a32c985ca16745"
|
||||||
|
},
|
||||||
|
"scss": {
|
||||||
|
"revision": "c478c6868648eff49eb04a4df90d703dc45b312a"
|
||||||
|
},
|
||||||
|
"sflog": {
|
||||||
|
"revision": "46d4a12e4e90b10a575b7b16ea3b6ead50322074"
|
||||||
|
},
|
||||||
|
"slang": {
|
||||||
|
"revision": "3ed23c04a412a0559162d9cadf96dfff7cb36079"
|
||||||
|
},
|
||||||
|
"slint": {
|
||||||
|
"revision": "4e2765d4cac1f03ada6f635eeb6008d1d0aff5a3"
|
||||||
|
},
|
||||||
|
"smali": {
|
||||||
|
"revision": "fdfa6a1febc43c7467aa7e937b87b607956f2346"
|
||||||
|
},
|
||||||
|
"smithy": {
|
||||||
|
"revision": "fa898ac0885d1da9a253695c3e0e91f5efc587cd"
|
||||||
|
},
|
||||||
|
"snakemake": {
|
||||||
|
"revision": "e909815acdbe37e69440261ebb1091ed52e1dec6"
|
||||||
|
},
|
||||||
|
"solidity": {
|
||||||
|
"revision": "ee5a2d2ba30b487c4bbf613d2ef310a454c09c7c"
|
||||||
|
},
|
||||||
|
"soql": {
|
||||||
|
"revision": "46d4a12e4e90b10a575b7b16ea3b6ead50322074"
|
||||||
|
},
|
||||||
|
"sosl": {
|
||||||
|
"revision": "46d4a12e4e90b10a575b7b16ea3b6ead50322074"
|
||||||
|
},
|
||||||
|
"sourcepawn": {
|
||||||
|
"revision": "6b9bf9cbab91443380d2ca8a2f6c491cc7fac5bf"
|
||||||
|
},
|
||||||
|
"sparql": {
|
||||||
|
"revision": "d853661ca680d8ff7f8d800182d5782b61d0dd58"
|
||||||
|
},
|
||||||
|
"sql": {
|
||||||
|
"revision": "f551a8fa69dc9aea479b93fae34c3ea7be15f931"
|
||||||
|
},
|
||||||
|
"squirrel": {
|
||||||
|
"revision": "072c969749e66f000dba35a33c387650e203e96e"
|
||||||
|
},
|
||||||
|
"ssh_config": {
|
||||||
|
"revision": "77450e8bce8853921512348f83c73c168c71fdfb"
|
||||||
|
},
|
||||||
|
"starlark": {
|
||||||
|
"revision": "018d0e09d9d0f0dd6740a37682b8ee4512e8b2ac"
|
||||||
|
},
|
||||||
|
"strace": {
|
||||||
|
"revision": "d819cdd5dbe455bd3c859193633c8d91c0df7c36"
|
||||||
|
},
|
||||||
|
"styled": {
|
||||||
|
"revision": "764af55fc6b8e5ae177eb272f5c5de6238db23e6"
|
||||||
|
},
|
||||||
|
"supercollider": {
|
||||||
|
"revision": "1a8ee0da9a4f2df5a8a22f4d637ac863623a78a7"
|
||||||
|
},
|
||||||
|
"superhtml": {
|
||||||
|
"revision": "3325bbb2dda260131a8db0cae1f1f557d17ebced"
|
||||||
|
},
|
||||||
|
"surface": {
|
||||||
|
"revision": "f4586b35ac8548667a9aaa4eae44456c1f43d032"
|
||||||
|
},
|
||||||
|
"svelte": {
|
||||||
|
"revision": "ae5199db47757f785e43a14b332118a5474de1a2"
|
||||||
|
},
|
||||||
|
"swift": {
|
||||||
|
"revision": "d351cb321c28f0a3e66242ef2f61b1f890ec4b44"
|
||||||
|
},
|
||||||
|
"sxhkdrc": {
|
||||||
|
"revision": "440d5f913d9465c9c776a1bd92334d32febcf065"
|
||||||
|
},
|
||||||
|
"systemtap": {
|
||||||
|
"revision": "f2b378a9af0b7e1192cff67a5fb45508c927205d"
|
||||||
|
},
|
||||||
|
"t32": {
|
||||||
|
"revision": "0f6a5b1e031c97ebf58d3c76eadb2c6bf1e4f780"
|
||||||
|
},
|
||||||
|
"tablegen": {
|
||||||
|
"revision": "b1170880c61355aaf38fc06f4af7d3c55abdabc4"
|
||||||
|
},
|
||||||
|
"tact": {
|
||||||
|
"revision": "83e264928fa194b7283428527259e88e54205264"
|
||||||
|
},
|
||||||
|
"tcl": {
|
||||||
|
"revision": "cdba4ab96a9896492d0d5219b70300c8783ca4e7"
|
||||||
|
},
|
||||||
|
"teal": {
|
||||||
|
"revision": "485fbdc00d811b01b2090dff4d0469fd1d0350f5"
|
||||||
|
},
|
||||||
|
"templ": {
|
||||||
|
"revision": "4519e3ec9ca92754ca25659bb1fd410d5e0f8d88"
|
||||||
|
},
|
||||||
|
"terraform": {
|
||||||
|
"revision": "9e3ec9848f28d26845ba300fd73c740459b83e9b"
|
||||||
|
},
|
||||||
|
"textproto": {
|
||||||
|
"revision": "568471b80fd8793d37ed01865d8c2208a9fefd1b"
|
||||||
|
},
|
||||||
|
"thrift": {
|
||||||
|
"revision": "68fd0d80943a828d9e6f49c58a74be1e9ca142cf"
|
||||||
|
},
|
||||||
|
"tiger": {
|
||||||
|
"revision": "a7f11d946b44244f71df41d2a78af0665d618dae"
|
||||||
|
},
|
||||||
|
"tlaplus": {
|
||||||
|
"revision": "8a8413f1d08e7ee40b347206d26eac4324db9fd9"
|
||||||
|
},
|
||||||
|
"tmux": {
|
||||||
|
"revision": "0252ecd080016e45e6305ef1a943388f5ae2f4b4"
|
||||||
|
},
|
||||||
|
"todotxt": {
|
||||||
|
"revision": "3937c5cd105ec4127448651a21aef45f52d19609"
|
||||||
|
},
|
||||||
|
"toml": {
|
||||||
|
"revision": "16a30c83ce427385b8d14939c45c137fcfca6c42"
|
||||||
|
},
|
||||||
|
"tsv": {
|
||||||
|
"revision": "7eb7297823605392d2bbcc4c09b1cd18d6fa9529"
|
||||||
|
},
|
||||||
|
"tsx": {
|
||||||
|
"revision": "73c4447796b251295b498227bad028d88dc1918b"
|
||||||
|
},
|
||||||
|
"turtle": {
|
||||||
|
"revision": "7f789ea7ef765080f71a298fc96b7c957fa24422"
|
||||||
|
},
|
||||||
|
"twig": {
|
||||||
|
"revision": "085648e01d1422163a1702a44e72303b4e2a0bd1"
|
||||||
|
},
|
||||||
|
"typescript": {
|
||||||
|
"revision": "73c4447796b251295b498227bad028d88dc1918b"
|
||||||
|
},
|
||||||
|
"typespec": {
|
||||||
|
"revision": "0ee05546d73d8eb64635ed8125de6f35c77759fe"
|
||||||
|
},
|
||||||
|
"typoscript": {
|
||||||
|
"revision": "43b221c0b76e77244efdaa9963e402a17c930fbc"
|
||||||
|
},
|
||||||
|
"typst": {
|
||||||
|
"revision": "8b8b16ef1b40cbecbe3f754b1c1c966b5a0904fe"
|
||||||
|
},
|
||||||
|
"udev": {
|
||||||
|
"revision": "8f58696e79092b4ad6bf197415bbd0970acf15cd"
|
||||||
|
},
|
||||||
|
"ungrammar": {
|
||||||
|
"revision": "debd26fed283d80456ebafa33a06957b0c52e451"
|
||||||
|
},
|
||||||
|
"unison": {
|
||||||
|
"revision": "bc06e1eb100e1c0fab9bd89a9ca55d646ac80fc4"
|
||||||
|
},
|
||||||
|
"usd": {
|
||||||
|
"revision": "4e0875f724d94d0c2ff36f9b8cb0b12f8b20d216"
|
||||||
|
},
|
||||||
|
"uxntal": {
|
||||||
|
"revision": "ad9b638b914095320de85d59c49ab271603af048"
|
||||||
|
},
|
||||||
|
"v": {
|
||||||
|
"revision": "ea538758a1273b59774dc9179cde460d9c73fd89"
|
||||||
|
},
|
||||||
|
"vala": {
|
||||||
|
"revision": "8f690bfa639f2b83d1fb938ed3dd98a7ba453e8b"
|
||||||
|
},
|
||||||
|
"vento": {
|
||||||
|
"revision": "3321077d7446c1b3b017c294fd56ce028ed817fe"
|
||||||
|
},
|
||||||
|
"verilog": {
|
||||||
|
"revision": "0dacb911daa9614a7c7e79a594d4cb9f478e6554"
|
||||||
|
},
|
||||||
|
"vhdl": {
|
||||||
|
"revision": "d6e8301999336b47d663052d43f983c3edeb01dd"
|
||||||
|
},
|
||||||
|
"vhs": {
|
||||||
|
"revision": "09f8fbfe40a3a699b200daca7d92e65fbbe9f9e6"
|
||||||
|
},
|
||||||
|
"vim": {
|
||||||
|
"revision": "f3cd62d8bd043ef20507e84bb6b4b53731ccf3a7"
|
||||||
|
},
|
||||||
|
"vimdoc": {
|
||||||
|
"revision": "59c539286e7487b267bc7808b16833f9e3ad6793"
|
||||||
|
},
|
||||||
|
"vrl": {
|
||||||
|
"revision": "274b3ce63f72aa8ffea18e7fc280d3062d28f0ba"
|
||||||
|
},
|
||||||
|
"vue": {
|
||||||
|
"revision": "22bdfa6c9fc0f5ffa44c6e938ec46869ac8a99ff"
|
||||||
|
},
|
||||||
|
"wgsl": {
|
||||||
|
"revision": "40259f3c77ea856841a4e0c4c807705f3e4a2b65"
|
||||||
|
},
|
||||||
|
"wgsl_bevy": {
|
||||||
|
"revision": "47c1818d245a6156a488c4c4d06e9336714bae9b"
|
||||||
|
},
|
||||||
|
"wing": {
|
||||||
|
"revision": "76e0c25844a66ebc6e866d690fcc5f4e90698947"
|
||||||
|
},
|
||||||
|
"wit": {
|
||||||
|
"revision": "81490b4e74c792369e005f72b0d46fe082d3fed2"
|
||||||
|
},
|
||||||
|
"xcompose": {
|
||||||
|
"revision": "fff3e72242aa110ebba6441946ea4d12d200fa68"
|
||||||
|
},
|
||||||
|
"xml": {
|
||||||
|
"revision": "cd1316e476ec40da6ce1fb5749c9d7e6b4f1090c"
|
||||||
|
},
|
||||||
|
"xresources": {
|
||||||
|
"revision": "630af80f563ede09a652a808277950c36306e3a3"
|
||||||
|
},
|
||||||
|
"yaml": {
|
||||||
|
"revision": "7b03feefd36b5f155465ca736c6304aca983b267"
|
||||||
|
},
|
||||||
|
"yang": {
|
||||||
|
"revision": "2c0e6be8dd4dcb961c345fa35c309ad4f5bd3502"
|
||||||
|
},
|
||||||
|
"yuck": {
|
||||||
|
"revision": "e877f6ade4b77d5ef8787075141053631ba12318"
|
||||||
|
},
|
||||||
|
"zathurarc": {
|
||||||
|
"revision": "0554b4a5d313244b7fc000cbb41c04afae4f4e31"
|
||||||
|
},
|
||||||
|
"zig": {
|
||||||
|
"revision": "eb7d58c2dc4fbeea4745019dee8df013034ae66b"
|
||||||
|
},
|
||||||
|
"ziggy": {
|
||||||
|
"revision": "42b6f5d7320340bc5903c4c29d34065e8517a549"
|
||||||
|
},
|
||||||
|
"ziggy_schema": {
|
||||||
|
"revision": "42b6f5d7320340bc5903c4c29d34065e8517a549"
|
||||||
|
}
|
||||||
|
}
|
22
pack/ant/start/nvim-treesitter/lua/nvim-treesitter.lua
Normal file
22
pack/ant/start/nvim-treesitter/lua/nvim-treesitter.lua
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
local install = require "nvim-treesitter.install"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local info = require "nvim-treesitter.info"
|
||||||
|
local configs = require "nvim-treesitter.configs"
|
||||||
|
local statusline = require "nvim-treesitter.statusline"
|
||||||
|
|
||||||
|
-- Registers all query predicates
|
||||||
|
require "nvim-treesitter.query_predicates"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
utils.setup_commands("install", install.commands)
|
||||||
|
utils.setup_commands("info", info.commands)
|
||||||
|
utils.setup_commands("configs", configs.commands)
|
||||||
|
configs.init()
|
||||||
|
end
|
||||||
|
|
||||||
|
M.define_modules = configs.define_modules
|
||||||
|
M.statusline = statusline.statusline
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,71 @@
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Creates a cache table for buffers keyed by a type name.
|
||||||
|
-- Cache entries attach to the buffer and cleanup entries
|
||||||
|
-- as buffers are detached.
|
||||||
|
function M.create_buffer_cache()
|
||||||
|
local cache = {}
|
||||||
|
|
||||||
|
---@type table<integer, table<string, any>>
|
||||||
|
local items = setmetatable({}, {
|
||||||
|
__index = function(tbl, key)
|
||||||
|
rawset(tbl, key, {})
|
||||||
|
return rawget(tbl, key)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
---@type table<integer, boolean>
|
||||||
|
local loaded_buffers = {}
|
||||||
|
|
||||||
|
---@param type_name string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param value any
|
||||||
|
function cache.set(type_name, bufnr, value)
|
||||||
|
if not loaded_buffers[bufnr] then
|
||||||
|
loaded_buffers[bufnr] = true
|
||||||
|
-- Clean up the cache if the buffer is detached
|
||||||
|
-- to avoid memory leaks
|
||||||
|
api.nvim_buf_attach(bufnr, false, {
|
||||||
|
on_detach = function()
|
||||||
|
cache.clear_buffer(bufnr)
|
||||||
|
loaded_buffers[bufnr] = nil
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
on_reload = function() end, -- this is needed to prevent on_detach being called on buffer reload
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
items[bufnr][type_name] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type_name string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return any
|
||||||
|
function cache.get(type_name, bufnr)
|
||||||
|
return items[bufnr][type_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type_name string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return boolean
|
||||||
|
function cache.has(type_name, bufnr)
|
||||||
|
return cache.get(type_name, bufnr) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param type_name string
|
||||||
|
---@param bufnr integer
|
||||||
|
function cache.remove(type_name, bufnr)
|
||||||
|
items[bufnr][type_name] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
function cache.clear_buffer(bufnr)
|
||||||
|
items[bufnr] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return cache
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,39 @@
|
||||||
|
-- Shim module to address deprecations across nvim versions
|
||||||
|
local ts = vim.treesitter
|
||||||
|
local tsq = ts.query
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.get_query_files(lang, query_group, is_included)
|
||||||
|
return (tsq.get_files or tsq.get_query_files)(lang, query_group, is_included)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_query(lang, query_name)
|
||||||
|
return (tsq.get or tsq.get_query)(lang, query_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.parse_query(lang, query)
|
||||||
|
return (tsq.parse or tsq.parse_query)(lang, query)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_range(node, source, metadata)
|
||||||
|
return (ts.get_range or tsq.get_range)(node, source, metadata)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_node_text(node, bufnr)
|
||||||
|
return (ts.get_node_text or tsq.get_node_text)(node, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.require_language(lang, opts)
|
||||||
|
return (ts.language.add or ts.language.require_language)(lang, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.flatten(t)
|
||||||
|
if vim.fn.has "nvim-0.11" == 1 then
|
||||||
|
return vim.iter(t):flatten():totable()
|
||||||
|
else
|
||||||
|
return vim.tbl_flatten(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
616
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/configs.lua
Normal file
616
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/configs.lua
Normal file
|
@ -0,0 +1,616 @@
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local queries = require "nvim-treesitter.query"
|
||||||
|
local ts = require "nvim-treesitter.compat"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local caching = require "nvim-treesitter.caching"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@class TSConfig
|
||||||
|
---@field modules {[string]:TSModule}
|
||||||
|
---@field sync_install boolean
|
||||||
|
---@field ensure_installed string[]|string
|
||||||
|
---@field ignore_install string[]
|
||||||
|
---@field auto_install boolean
|
||||||
|
---@field parser_install_dir string|nil
|
||||||
|
|
||||||
|
---@type TSConfig
|
||||||
|
local config = {
|
||||||
|
modules = {},
|
||||||
|
sync_install = false,
|
||||||
|
ensure_installed = {},
|
||||||
|
auto_install = false,
|
||||||
|
ignore_install = {},
|
||||||
|
parser_install_dir = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- List of modules that need to be setup on initialization.
|
||||||
|
---@type TSModule[][]
|
||||||
|
local queued_modules_defs = {}
|
||||||
|
-- Whether we've initialized the plugin yet.
|
||||||
|
local is_initialized = false
|
||||||
|
|
||||||
|
---@class TSModule
|
||||||
|
---@field module_path string
|
||||||
|
---@field enable boolean|string[]|function(string): boolean
|
||||||
|
---@field disable boolean|string[]|function(string): boolean
|
||||||
|
---@field keymaps table<string, string>
|
||||||
|
---@field is_supported function(string): boolean
|
||||||
|
---@field attach function(string)
|
||||||
|
---@field detach function(string)
|
||||||
|
---@field enabled_buffers table<integer, boolean>
|
||||||
|
---@field additional_vim_regex_highlighting boolean|string[]
|
||||||
|
|
||||||
|
---@type {[string]: TSModule}
|
||||||
|
local builtin_modules = {
|
||||||
|
highlight = {
|
||||||
|
module_path = "nvim-treesitter.highlight",
|
||||||
|
-- @deprecated: use `highlight.set_custom_captures` instead
|
||||||
|
custom_captures = {},
|
||||||
|
enable = false,
|
||||||
|
is_supported = function(lang)
|
||||||
|
return queries.has_highlights(lang)
|
||||||
|
end,
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
incremental_selection = {
|
||||||
|
module_path = "nvim-treesitter.incremental_selection",
|
||||||
|
enable = false,
|
||||||
|
keymaps = {
|
||||||
|
init_selection = "gnn", -- set to `false` to disable one of the mappings
|
||||||
|
node_incremental = "grn",
|
||||||
|
scope_incremental = "grc",
|
||||||
|
node_decremental = "grm",
|
||||||
|
},
|
||||||
|
is_supported = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
indent = {
|
||||||
|
module_path = "nvim-treesitter.indent",
|
||||||
|
enable = false,
|
||||||
|
is_supported = queries.has_indents,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local attached_buffers_by_module = caching.create_buffer_cache()
|
||||||
|
|
||||||
|
---Resolves a module by requiring the `module_path` or using the module definition.
|
||||||
|
---@param mod_name string
|
||||||
|
---@return TSModule|nil
|
||||||
|
local function resolve_module(mod_name)
|
||||||
|
local config_mod = M.get_module(mod_name)
|
||||||
|
|
||||||
|
if not config_mod then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(config_mod.attach) == "function" and type(config_mod.detach) == "function" then
|
||||||
|
return config_mod
|
||||||
|
elseif type(config_mod.module_path) == "string" then
|
||||||
|
return require(config_mod.module_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Enables and attaches the module to a buffer for lang.
|
||||||
|
---@param mod string path to module
|
||||||
|
---@param bufnr integer|nil buffer number, defaults to current buffer
|
||||||
|
---@param lang string|nil language, defaults to current language
|
||||||
|
local function enable_module(mod, bufnr, lang)
|
||||||
|
local module = M.get_module(mod)
|
||||||
|
if not module then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
lang = lang or parsers.get_buf_lang(bufnr)
|
||||||
|
|
||||||
|
if not module.enable then
|
||||||
|
if module.enabled_buffers then
|
||||||
|
module.enabled_buffers[bufnr] = true
|
||||||
|
else
|
||||||
|
module.enabled_buffers = { [bufnr] = true }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.attach_module(mod, bufnr, lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Enables autocomands for the module.
|
||||||
|
---After the module is loaded `loaded` will be set to true for the module.
|
||||||
|
---@param mod string path to module
|
||||||
|
local function enable_mod_conf_autocmd(mod)
|
||||||
|
local config_mod = M.get_module(mod)
|
||||||
|
if not config_mod or config_mod.loaded then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("FileType", {
|
||||||
|
group = api.nvim_create_augroup("NvimTreesitter-" .. mod, {}),
|
||||||
|
callback = function(args)
|
||||||
|
require("nvim-treesitter.configs").reattach_module(mod, args.buf)
|
||||||
|
end,
|
||||||
|
desc = "Reattach module",
|
||||||
|
})
|
||||||
|
|
||||||
|
config_mod.loaded = true
|
||||||
|
end
|
||||||
|
|
||||||
|
---Enables the module globally and for all current buffers.
|
||||||
|
---After enabled, `enable` will be set to true for the module.
|
||||||
|
---@param mod string path to module
|
||||||
|
local function enable_all(mod)
|
||||||
|
local config_mod = M.get_module(mod)
|
||||||
|
if not config_mod then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
enable_mod_conf_autocmd(mod)
|
||||||
|
config_mod.enable = true
|
||||||
|
config_mod.enabled_buffers = nil
|
||||||
|
|
||||||
|
for _, bufnr in pairs(api.nvim_list_bufs()) do
|
||||||
|
enable_module(mod, bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Disables and detaches the module for a buffer.
|
||||||
|
---@param mod string path to module
|
||||||
|
---@param bufnr integer buffer number, defaults to current buffer
|
||||||
|
local function disable_module(mod, bufnr)
|
||||||
|
local module = M.get_module(mod)
|
||||||
|
if not module then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
if module.enabled_buffers then
|
||||||
|
module.enabled_buffers[bufnr] = false
|
||||||
|
end
|
||||||
|
M.detach_module(mod, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Disables autocomands for the module.
|
||||||
|
---After the module is unloaded `loaded` will be set to false for the module.
|
||||||
|
---@param mod string path to module
|
||||||
|
local function disable_mod_conf_autocmd(mod)
|
||||||
|
local config_mod = M.get_module(mod)
|
||||||
|
if not config_mod or not config_mod.loaded then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
api.nvim_clear_autocmds { event = "FileType", group = "NvimTreesitter-" .. mod }
|
||||||
|
config_mod.loaded = false
|
||||||
|
end
|
||||||
|
|
||||||
|
---Disables the module globally and for all current buffers.
|
||||||
|
---After disabled, `enable` will be set to false for the module.
|
||||||
|
---@param mod string path to module
|
||||||
|
local function disable_all(mod)
|
||||||
|
local config_mod = M.get_module(mod)
|
||||||
|
if not config_mod then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
config_mod.enabled_buffers = nil
|
||||||
|
disable_mod_conf_autocmd(mod)
|
||||||
|
config_mod.enable = false
|
||||||
|
|
||||||
|
for _, bufnr in pairs(api.nvim_list_bufs()) do
|
||||||
|
disable_module(mod, bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Toggles a module for a buffer
|
||||||
|
---@param mod string path to module
|
||||||
|
---@param bufnr integer buffer number, defaults to current buffer
|
||||||
|
---@param lang string language, defaults to current language
|
||||||
|
local function toggle_module(mod, bufnr, lang)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
lang = lang or parsers.get_buf_lang(bufnr)
|
||||||
|
|
||||||
|
if attached_buffers_by_module.has(mod, bufnr) then
|
||||||
|
disable_module(mod, bufnr)
|
||||||
|
else
|
||||||
|
enable_module(mod, bufnr, lang)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Toggles the module globally and for all current buffers.
|
||||||
|
-- @param mod path to module
|
||||||
|
local function toggle_all(mod)
|
||||||
|
local config_mod = M.get_module(mod)
|
||||||
|
if not config_mod then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if config_mod.enable then
|
||||||
|
disable_all(mod)
|
||||||
|
else
|
||||||
|
enable_all(mod)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Recurses through all modules including submodules
|
||||||
|
---@param accumulator function called for each module
|
||||||
|
---@param root {[string]: TSModule}|nil root configuration table to start at
|
||||||
|
---@param path string|nil prefix path
|
||||||
|
local function recurse_modules(accumulator, root, path)
|
||||||
|
root = root or config.modules
|
||||||
|
|
||||||
|
for name, module in pairs(root) do
|
||||||
|
local new_path = path and (path .. "." .. name) or name
|
||||||
|
|
||||||
|
if M.is_module(module) then
|
||||||
|
accumulator(name, module, new_path, root)
|
||||||
|
elseif type(module) == "table" then
|
||||||
|
recurse_modules(accumulator, module, new_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Shows current configuration of all nvim-treesitter modules
|
||||||
|
---@param process_function function used as the `process` parameter
|
||||||
|
--- for vim.inspect (https://github.com/kikito/inspect.lua#optionsprocess)
|
||||||
|
local function config_info(process_function)
|
||||||
|
process_function = process_function
|
||||||
|
or function(item, path)
|
||||||
|
if path[#path] == vim.inspect.METATABLE then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if path[#path] == "is_supported" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return item
|
||||||
|
end
|
||||||
|
print(vim.inspect(config, { process = process_function }))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param query_group string
|
||||||
|
---@param lang string
|
||||||
|
function M.edit_query_file(query_group, lang)
|
||||||
|
lang = lang or parsers.get_buf_lang()
|
||||||
|
local files = ts.get_query_files(lang, query_group, true)
|
||||||
|
if #files == 0 then
|
||||||
|
utils.notify "No query file found! Creating a new one!"
|
||||||
|
M.edit_query_file_user_after(query_group, lang)
|
||||||
|
elseif #files == 1 then
|
||||||
|
vim.cmd(":edit " .. files[1])
|
||||||
|
else
|
||||||
|
vim.ui.select(files, { prompt = "Select a file:" }, function(file)
|
||||||
|
if file then
|
||||||
|
vim.cmd(":edit " .. file)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param query_group string
|
||||||
|
---@param lang string
|
||||||
|
function M.edit_query_file_user_after(query_group, lang)
|
||||||
|
lang = lang or parsers.get_buf_lang()
|
||||||
|
local folder = utils.join_path(vim.fn.stdpath "config", "after", "queries", lang)
|
||||||
|
local file = utils.join_path(folder, query_group .. ".scm")
|
||||||
|
if vim.fn.isdirectory(folder) ~= 1 then
|
||||||
|
vim.ui.select({ "Yes", "No" }, { prompt = '"' .. folder .. '" does not exist. Create it?' }, function(choice)
|
||||||
|
if choice == "Yes" then
|
||||||
|
vim.fn.mkdir(folder, "p", "0755")
|
||||||
|
vim.cmd(":edit " .. file)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
vim.cmd(":edit " .. file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.commands = {
|
||||||
|
TSBufEnable = {
|
||||||
|
run = enable_module,
|
||||||
|
args = {
|
||||||
|
"-nargs=1",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSBufDisable = {
|
||||||
|
run = disable_module,
|
||||||
|
args = {
|
||||||
|
"-nargs=1",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSBufToggle = {
|
||||||
|
run = toggle_module,
|
||||||
|
args = {
|
||||||
|
"-nargs=1",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSEnable = {
|
||||||
|
run = enable_all,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSDisable = {
|
||||||
|
run = disable_all,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSToggle = {
|
||||||
|
run = toggle_all,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSConfigInfo = {
|
||||||
|
run = config_info,
|
||||||
|
args = {
|
||||||
|
"-nargs=0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSEditQuery = {
|
||||||
|
run = M.edit_query_file,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_query_groups",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSEditQueryUserAfter = {
|
||||||
|
run = M.edit_query_file_user_after,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#available_query_groups",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param mod string module
|
||||||
|
---@param lang string the language of the buffer
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
function M.is_enabled(mod, lang, bufnr)
|
||||||
|
if not parsers.has_parser(lang) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local module_config = M.get_module(mod)
|
||||||
|
if not module_config then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local buffer_enabled = module_config.enabled_buffers and module_config.enabled_buffers[bufnr]
|
||||||
|
local config_enabled = module_config.enable or buffer_enabled
|
||||||
|
if not config_enabled or not module_config.is_supported(lang) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local disable = module_config.disable
|
||||||
|
if type(disable) == "function" then
|
||||||
|
if disable(lang, bufnr) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif type(disable) == "table" then
|
||||||
|
-- Otherwise it's a list of languages
|
||||||
|
for _, parser in pairs(disable) do
|
||||||
|
if lang == parser then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---Setup call for users to override module configurations.
|
||||||
|
---@param user_data TSConfig module overrides
|
||||||
|
function M.setup(user_data)
|
||||||
|
config.modules = vim.tbl_deep_extend("force", config.modules, user_data)
|
||||||
|
config.ignore_install = user_data.ignore_install or {}
|
||||||
|
config.parser_install_dir = user_data.parser_install_dir or nil
|
||||||
|
if config.parser_install_dir then
|
||||||
|
config.parser_install_dir = vim.fn.expand(config.parser_install_dir, ":p")
|
||||||
|
end
|
||||||
|
|
||||||
|
config.auto_install = user_data.auto_install or false
|
||||||
|
if config.auto_install then
|
||||||
|
require("nvim-treesitter.install").setup_auto_install()
|
||||||
|
end
|
||||||
|
|
||||||
|
local ensure_installed = user_data.ensure_installed or {}
|
||||||
|
if #ensure_installed > 0 then
|
||||||
|
if user_data.sync_install then
|
||||||
|
require("nvim-treesitter.install").ensure_installed_sync(ensure_installed)
|
||||||
|
else
|
||||||
|
require("nvim-treesitter.install").ensure_installed(ensure_installed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config.modules.ensure_installed = nil
|
||||||
|
config.ensure_installed = ensure_installed
|
||||||
|
|
||||||
|
recurse_modules(function(_, _, new_path)
|
||||||
|
local data = utils.get_at_path(config.modules, new_path)
|
||||||
|
if data.enable then
|
||||||
|
enable_all(new_path)
|
||||||
|
end
|
||||||
|
end, config.modules)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Defines a table of modules that can be attached/detached to buffers
|
||||||
|
-- based on language support. A module consist of the following properties:
|
||||||
|
---* @enable Whether the modules is enabled. Can be true or false.
|
||||||
|
---* @disable A list of languages to disable the module for. Only relevant if enable is true.
|
||||||
|
---* @keymaps A list of user mappings for a given module if relevant.
|
||||||
|
---* @is_supported A function which, given a ft, will return true if the ft works on the module.
|
||||||
|
---* @module_path A string path to a module file using `require`. The exported module must contain
|
||||||
|
--- an `attach` and `detach` function. This path is not required if `attach` and `detach`
|
||||||
|
--- functions are provided directly on the module definition.
|
||||||
|
---* @attach An attach function that is called for each buffer that the module is enabled for. This is required
|
||||||
|
--- if a `module_path` is not specified.
|
||||||
|
---* @detach A detach function that is called for each buffer that the module is enabled for. This is required
|
||||||
|
--- if a `module_path` is not specified.
|
||||||
|
--
|
||||||
|
-- Modules are not setup until `init` is invoked by the plugin. This allows modules to be defined in any order
|
||||||
|
-- and can be loaded lazily.
|
||||||
|
--
|
||||||
|
---* @example
|
||||||
|
---require"nvim-treesitter".define_modules {
|
||||||
|
--- my_cool_module = {
|
||||||
|
--- attach = function()
|
||||||
|
--- do_some_cool_setup()
|
||||||
|
--- end,
|
||||||
|
--- detach = function()
|
||||||
|
--- do_some_cool_teardown()
|
||||||
|
--- end
|
||||||
|
--- }
|
||||||
|
---}
|
||||||
|
---@param mod_defs TSModule[]
|
||||||
|
function M.define_modules(mod_defs)
|
||||||
|
if not is_initialized then
|
||||||
|
table.insert(queued_modules_defs, mod_defs)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
recurse_modules(function(key, mod, _, group)
|
||||||
|
group[key] = vim.tbl_extend("keep", mod, {
|
||||||
|
enable = false,
|
||||||
|
disable = {},
|
||||||
|
is_supported = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end, mod_defs)
|
||||||
|
|
||||||
|
config.modules = vim.tbl_deep_extend("keep", config.modules, mod_defs)
|
||||||
|
|
||||||
|
for _, mod in ipairs(M.available_modules(mod_defs)) do
|
||||||
|
local module_config = M.get_module(mod)
|
||||||
|
if module_config and module_config.enable then
|
||||||
|
enable_mod_conf_autocmd(mod)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Attaches a module to a buffer
|
||||||
|
---@param mod_name string the module name
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
---@param lang string the language of the buffer
|
||||||
|
function M.attach_module(mod_name, bufnr, lang)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
lang = lang or parsers.get_buf_lang(bufnr)
|
||||||
|
local resolved_mod = resolve_module(mod_name)
|
||||||
|
|
||||||
|
if resolved_mod and not attached_buffers_by_module.has(mod_name, bufnr) and M.is_enabled(mod_name, lang, bufnr) then
|
||||||
|
attached_buffers_by_module.set(mod_name, bufnr, true)
|
||||||
|
resolved_mod.attach(bufnr, lang)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Detaches a module to a buffer
|
||||||
|
---@param mod_name string the module name
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
function M.detach_module(mod_name, bufnr)
|
||||||
|
local resolved_mod = resolve_module(mod_name)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
if resolved_mod and attached_buffers_by_module.has(mod_name, bufnr) then
|
||||||
|
attached_buffers_by_module.remove(mod_name, bufnr)
|
||||||
|
resolved_mod.detach(bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Same as attach_module, but if the module is already attached, detach it first.
|
||||||
|
---@param mod_name string the module name
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
---@param lang string the language of the buffer
|
||||||
|
function M.reattach_module(mod_name, bufnr, lang)
|
||||||
|
M.detach_module(mod_name, bufnr)
|
||||||
|
M.attach_module(mod_name, bufnr, lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets available modules
|
||||||
|
---@param root {[string]:TSModule}|nil table to find modules
|
||||||
|
---@return string[] modules list of module paths
|
||||||
|
function M.available_modules(root)
|
||||||
|
local modules = {}
|
||||||
|
|
||||||
|
recurse_modules(function(_, _, path)
|
||||||
|
table.insert(modules, path)
|
||||||
|
end, root)
|
||||||
|
|
||||||
|
return modules
|
||||||
|
end
|
||||||
|
|
||||||
|
---Gets a module config by path
|
||||||
|
---@param mod_path string path to the module
|
||||||
|
---@return TSModule|nil: the module or nil
|
||||||
|
function M.get_module(mod_path)
|
||||||
|
local mod = utils.get_at_path(config.modules, mod_path)
|
||||||
|
|
||||||
|
return M.is_module(mod) and mod or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Determines whether the provided table is a module.
|
||||||
|
-- A module should contain an attach and detach function.
|
||||||
|
---@param mod table|nil the module table
|
||||||
|
---@return boolean
|
||||||
|
function M.is_module(mod)
|
||||||
|
return type(mod) == "table"
|
||||||
|
and ((type(mod.attach) == "function" and type(mod.detach) == "function") or type(mod.module_path) == "string")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Initializes built-in modules and any queued modules
|
||||||
|
-- registered by plugins or the user.
|
||||||
|
function M.init()
|
||||||
|
is_initialized = true
|
||||||
|
M.define_modules(builtin_modules)
|
||||||
|
|
||||||
|
for _, mod_def in ipairs(queued_modules_defs) do
|
||||||
|
M.define_modules(mod_def)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If parser_install_dir is not nil is used or created.
|
||||||
|
-- If parser_install_dir is nil try the package dir of the nvim-treesitter
|
||||||
|
-- plugin first, followed by the "site" dir from "runtimepath". "site" dir will
|
||||||
|
-- be created if it doesn't exist. Using only the package dir won't work when
|
||||||
|
-- the plugin is installed with Nix, since the "/nix/store" is read-only.
|
||||||
|
---@param folder_name string|nil
|
||||||
|
---@return string|nil, string|nil
|
||||||
|
function M.get_parser_install_dir(folder_name)
|
||||||
|
folder_name = folder_name or "parser"
|
||||||
|
|
||||||
|
local install_dir = config.parser_install_dir or utils.get_package_path()
|
||||||
|
local parser_dir = utils.join_path(install_dir, folder_name)
|
||||||
|
|
||||||
|
return utils.create_or_reuse_writable_dir(
|
||||||
|
parser_dir,
|
||||||
|
utils.join_space("Could not create parser dir '", parser_dir, "': "),
|
||||||
|
utils.join_space(
|
||||||
|
"Parser dir '",
|
||||||
|
parser_dir,
|
||||||
|
"' should be read/write (see README on how to configure an alternative install location)"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_parser_info_dir()
|
||||||
|
return M.get_parser_install_dir "parser-info"
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_ignored_parser_installs()
|
||||||
|
return config.ignore_install or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_ensure_installed_parsers()
|
||||||
|
if type(config.ensure_installed) == "string" then
|
||||||
|
return { config.ensure_installed }
|
||||||
|
end
|
||||||
|
return config.ensure_installed or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
123
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/fold.lua
Normal file
123
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/fold.lua
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
local api = vim.api
|
||||||
|
local tsutils = require "nvim-treesitter.ts_utils"
|
||||||
|
local query = require "nvim-treesitter.query"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- This is cached on buf tick to avoid computing that multiple times
|
||||||
|
-- Especially not for every line in the file when `zx` is hit
|
||||||
|
local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr)
|
||||||
|
local max_fold_level = api.nvim_win_get_option(0, "foldnestmax")
|
||||||
|
local trim_level = function(level)
|
||||||
|
if level > max_fold_level then
|
||||||
|
return max_fold_level
|
||||||
|
end
|
||||||
|
return level
|
||||||
|
end
|
||||||
|
|
||||||
|
local parser = parsers.get_parser(bufnr)
|
||||||
|
|
||||||
|
if not parser then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local matches = query.get_capture_matches_recursively(bufnr, function(lang)
|
||||||
|
if query.has_folds(lang) then
|
||||||
|
return "@fold", "folds"
|
||||||
|
elseif query.has_locals(lang) then
|
||||||
|
return "@scope", "locals"
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- start..stop is an inclusive range
|
||||||
|
|
||||||
|
---@type table<number, number>
|
||||||
|
local start_counts = {}
|
||||||
|
---@type table<number, number>
|
||||||
|
local stop_counts = {}
|
||||||
|
|
||||||
|
local prev_start = -1
|
||||||
|
local prev_stop = -1
|
||||||
|
|
||||||
|
local min_fold_lines = api.nvim_win_get_option(0, "foldminlines")
|
||||||
|
|
||||||
|
for _, match in ipairs(matches) do
|
||||||
|
local start, stop, stop_col ---@type integer, integer, integer
|
||||||
|
if match.metadata and match.metadata.range then
|
||||||
|
start, _, stop, stop_col = unpack(match.metadata.range) ---@type integer, integer, integer, integer
|
||||||
|
else
|
||||||
|
start, _, stop, stop_col = match.node:range() ---@type integer, integer, integer, integer
|
||||||
|
end
|
||||||
|
|
||||||
|
if stop_col == 0 then
|
||||||
|
stop = stop - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local fold_length = stop - start + 1
|
||||||
|
local should_fold = fold_length > min_fold_lines
|
||||||
|
|
||||||
|
-- Fold only multiline nodes that are not exactly the same as previously met folds
|
||||||
|
-- Checking against just the previously found fold is sufficient if nodes
|
||||||
|
-- are returned in preorder or postorder when traversing tree
|
||||||
|
if should_fold and not (start == prev_start and stop == prev_stop) then
|
||||||
|
start_counts[start] = (start_counts[start] or 0) + 1
|
||||||
|
stop_counts[stop] = (stop_counts[stop] or 0) + 1
|
||||||
|
prev_start = start
|
||||||
|
prev_stop = stop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type string[]
|
||||||
|
local levels = {}
|
||||||
|
local current_level = 0
|
||||||
|
|
||||||
|
-- We now have the list of fold opening and closing, fill the gaps and mark where fold start
|
||||||
|
for lnum = 0, api.nvim_buf_line_count(bufnr) do
|
||||||
|
local prefix = ""
|
||||||
|
|
||||||
|
local last_trimmed_level = trim_level(current_level)
|
||||||
|
current_level = current_level + (start_counts[lnum] or 0)
|
||||||
|
local trimmed_level = trim_level(current_level)
|
||||||
|
current_level = current_level - (stop_counts[lnum] or 0)
|
||||||
|
local next_trimmed_level = trim_level(current_level)
|
||||||
|
|
||||||
|
-- Determine if it's the start/end of a fold
|
||||||
|
-- NB: vim's fold-expr interface does not have a mechanism to indicate that
|
||||||
|
-- two (or more) folds start at this line, so it cannot distinguish between
|
||||||
|
-- ( \n ( \n )) \n (( \n ) \n )
|
||||||
|
-- versus
|
||||||
|
-- ( \n ( \n ) \n ( \n ) \n )
|
||||||
|
-- If it did have such a mechanism, (trimmed_level - last_trimmed_level)
|
||||||
|
-- would be the correct number of starts to pass on.
|
||||||
|
if trimmed_level - last_trimmed_level > 0 then
|
||||||
|
prefix = ">"
|
||||||
|
elseif trimmed_level - next_trimmed_level > 0 then
|
||||||
|
-- Ending marks tend to confuse vim more than it helps, particularly when
|
||||||
|
-- the fold level changes by at least 2; we can uncomment this if
|
||||||
|
-- vim's behavior gets fixed.
|
||||||
|
-- prefix = "<"
|
||||||
|
prefix = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
levels[lnum + 1] = prefix .. tostring(trimmed_level)
|
||||||
|
end
|
||||||
|
|
||||||
|
return levels
|
||||||
|
end)
|
||||||
|
|
||||||
|
---@param lnum integer
|
||||||
|
---@return string
|
||||||
|
function M.get_fold_indic(lnum)
|
||||||
|
if not parsers.has_parser() or not lnum then
|
||||||
|
return "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local levels = folds_levels(buf) or {}
|
||||||
|
|
||||||
|
return levels[lnum] or "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
176
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/health.lua
Normal file
176
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/health.lua
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
local api = vim.api
|
||||||
|
local fn = vim.fn
|
||||||
|
|
||||||
|
local queries = require "nvim-treesitter.query"
|
||||||
|
local info = require "nvim-treesitter.info"
|
||||||
|
local shell = require "nvim-treesitter.shell_command_selectors"
|
||||||
|
local install = require "nvim-treesitter.install"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local ts = require "nvim-treesitter.compat"
|
||||||
|
|
||||||
|
local health = vim.health or require "health"
|
||||||
|
|
||||||
|
-- "report_" prefix has been deprecated, use the recommended replacements if they exist.
|
||||||
|
local _start = health.start or health.report_start
|
||||||
|
local _ok = health.ok or health.report_ok
|
||||||
|
local _warn = health.warn or health.report_warn
|
||||||
|
local _error = health.error or health.report_error
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local NVIM_TREESITTER_MINIMUM_ABI = 13
|
||||||
|
|
||||||
|
local function install_health()
|
||||||
|
_start "Installation"
|
||||||
|
|
||||||
|
if fn.has "nvim-0.9.2" ~= 1 then
|
||||||
|
_error "Nvim-treesitter requires Nvim 0.9.2 or newer"
|
||||||
|
end
|
||||||
|
|
||||||
|
if fn.executable "tree-sitter" == 0 then
|
||||||
|
_warn(
|
||||||
|
"`tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar,"
|
||||||
|
.. " not required for :TSInstall)"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_ok(
|
||||||
|
"`tree-sitter` found "
|
||||||
|
.. (utils.ts_cli_version() or "(unknown version)")
|
||||||
|
.. " (parser generator, only needed for :TSInstallFromGrammar)"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if fn.executable "node" == 0 then
|
||||||
|
_warn("`node` executable not found (only needed for :TSInstallFromGrammar," .. " not required for :TSInstall)")
|
||||||
|
else
|
||||||
|
local handle = io.popen "node --version"
|
||||||
|
local result = handle:read "*a"
|
||||||
|
handle:close()
|
||||||
|
local version = vim.split(result, "\n")[1]
|
||||||
|
_ok("`node` found " .. version .. " (only needed for :TSInstallFromGrammar)")
|
||||||
|
end
|
||||||
|
|
||||||
|
if fn.executable "git" == 0 then
|
||||||
|
_error("`git` executable not found.", {
|
||||||
|
"Install it with your package manager.",
|
||||||
|
"Check that your `$PATH` is set correctly.",
|
||||||
|
})
|
||||||
|
else
|
||||||
|
_ok "`git` executable found."
|
||||||
|
end
|
||||||
|
|
||||||
|
local cc = shell.select_executable(install.compilers)
|
||||||
|
if not cc then
|
||||||
|
_error("`cc` executable not found.", {
|
||||||
|
"Check that any of "
|
||||||
|
.. vim.inspect(install.compilers)
|
||||||
|
.. " is in your $PATH"
|
||||||
|
.. ' or set the environment variable CC or `require"nvim-treesitter.install".compilers` explicitly!',
|
||||||
|
})
|
||||||
|
else
|
||||||
|
local version = vim.fn.systemlist(cc .. (cc == "cl" and "" or " --version"))[1]
|
||||||
|
_ok(
|
||||||
|
"`"
|
||||||
|
.. cc
|
||||||
|
.. "` executable found. Selected from "
|
||||||
|
.. vim.inspect(install.compilers)
|
||||||
|
.. (version and ("\nVersion: " .. version) or "")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if vim.treesitter.language_version then
|
||||||
|
if vim.treesitter.language_version >= NVIM_TREESITTER_MINIMUM_ABI then
|
||||||
|
_ok(
|
||||||
|
"Neovim was compiled with tree-sitter runtime ABI version "
|
||||||
|
.. vim.treesitter.language_version
|
||||||
|
.. " (required >="
|
||||||
|
.. NVIM_TREESITTER_MINIMUM_ABI
|
||||||
|
.. "). Parsers must be compatible with runtime ABI."
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_error(
|
||||||
|
"Neovim was compiled with tree-sitter runtime ABI version "
|
||||||
|
.. vim.treesitter.language_version
|
||||||
|
.. ".\n"
|
||||||
|
.. "nvim-treesitter expects at least ABI version "
|
||||||
|
.. NVIM_TREESITTER_MINIMUM_ABI
|
||||||
|
.. "\n"
|
||||||
|
.. "Please make sure that Neovim is linked against are recent tree-sitter runtime when building"
|
||||||
|
.. " or raise an issue at your Neovim packager. Parsers must be compatible with runtime ABI."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
_start("OS Info:\n" .. vim.inspect(vim.loop.os_uname()))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function query_status(lang, query_group)
|
||||||
|
local ok, err = pcall(queries.get_query, lang, query_group)
|
||||||
|
if not ok then
|
||||||
|
return "x", err
|
||||||
|
elseif not err then
|
||||||
|
return "."
|
||||||
|
else
|
||||||
|
return "✓"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.check()
|
||||||
|
local error_collection = {}
|
||||||
|
-- Installation dependency checks
|
||||||
|
install_health()
|
||||||
|
queries.invalidate_query_cache()
|
||||||
|
-- Parser installation checks
|
||||||
|
local parser_installation = { "Parser/Features" .. string.rep(" ", 9) .. "H L F I J" }
|
||||||
|
for _, parser_name in pairs(info.installed_parsers()) do
|
||||||
|
local installed = #api.nvim_get_runtime_file("parser/" .. parser_name .. ".so", false)
|
||||||
|
|
||||||
|
-- Only append information about installed parsers
|
||||||
|
if installed >= 1 then
|
||||||
|
local multiple_parsers = installed > 1 and "+" or ""
|
||||||
|
local out = " - " .. parser_name .. multiple_parsers .. string.rep(" ", 20 - (#parser_name + #multiple_parsers))
|
||||||
|
for _, query_group in pairs(queries.built_in_query_groups) do
|
||||||
|
local status, err = query_status(parser_name, query_group)
|
||||||
|
out = out .. status .. " "
|
||||||
|
if err then
|
||||||
|
table.insert(error_collection, { parser_name, query_group, err })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(parser_installation, vim.fn.trim(out, " ", 2))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local legend = [[
|
||||||
|
|
||||||
|
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
|
||||||
|
+) multiple parsers found, only one will be used
|
||||||
|
x) errors found in the query, try to run :TSUpdate {lang}]]
|
||||||
|
table.insert(parser_installation, legend)
|
||||||
|
-- Finally call the report function
|
||||||
|
_start(table.concat(parser_installation, "\n"))
|
||||||
|
if #error_collection > 0 then
|
||||||
|
_start "The following errors have been detected:"
|
||||||
|
for _, p in ipairs(error_collection) do
|
||||||
|
local lang, type, err = unpack(p)
|
||||||
|
local lines = {}
|
||||||
|
table.insert(lines, lang .. "(" .. type .. "): " .. err)
|
||||||
|
local files = ts.get_query_files(lang, type)
|
||||||
|
if #files > 0 then
|
||||||
|
table.insert(lines, lang .. "(" .. type .. ") is concatenated from the following files:")
|
||||||
|
for _, file in ipairs(files) do
|
||||||
|
local fd = io.open(file, "r")
|
||||||
|
if fd then
|
||||||
|
local ok, file_err = pcall(ts.parse_query, lang, fd:read "*a")
|
||||||
|
if ok then
|
||||||
|
table.insert(lines, '| [OK]:"' .. file .. '"')
|
||||||
|
else
|
||||||
|
table.insert(lines, '| [ERROR]:"' .. file .. '", failed to load: ' .. file_err)
|
||||||
|
end
|
||||||
|
fd:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
_error(table.concat(lines, "\n"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,49 @@
|
||||||
|
local configs = require "nvim-treesitter.configs"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param config TSModule
|
||||||
|
---@param lang string
|
||||||
|
---@return boolean
|
||||||
|
local function should_enable_vim_regex(config, lang)
|
||||||
|
local additional_hl = config.additional_vim_regex_highlighting
|
||||||
|
local is_table = type(additional_hl) == "table"
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
|
return additional_hl and (not is_table or vim.tbl_contains(additional_hl, lang))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param lang string
|
||||||
|
function M.attach(bufnr, lang)
|
||||||
|
local config = configs.get_module "highlight"
|
||||||
|
vim.treesitter.start(bufnr, lang)
|
||||||
|
if config and should_enable_vim_regex(config, lang) then
|
||||||
|
vim.bo[bufnr].syntax = "ON"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
function M.detach(bufnr)
|
||||||
|
vim.treesitter.stop(bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@deprecated
|
||||||
|
function M.start(...)
|
||||||
|
vim.notify(
|
||||||
|
"`nvim-treesitter.highlight.start` is deprecated: use `nvim-treesitter.highlight.attach` or `vim.treesitter.start`",
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
M.attach(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@deprecated
|
||||||
|
function M.stop(...)
|
||||||
|
vim.notify(
|
||||||
|
"`nvim-treesitter.highlight.stop` is deprecated: use `nvim-treesitter.highlight.detach` or `vim.treesitter.stop`",
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
M.detach(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,167 @@
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local configs = require "nvim-treesitter.configs"
|
||||||
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
|
local locals = require "nvim-treesitter.locals"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local queries = require "nvim-treesitter.query"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@type table<integer, table<TSNode|nil>>
|
||||||
|
local selections = {}
|
||||||
|
|
||||||
|
function M.init_selection()
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
local node = ts_utils.get_node_at_cursor()
|
||||||
|
selections[buf] = { [1] = node }
|
||||||
|
ts_utils.update_selection(buf, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get the range of the current visual selection.
|
||||||
|
--
|
||||||
|
-- The range starts with 1 and the ending is inclusive.
|
||||||
|
---@return integer, integer, integer, integer
|
||||||
|
local function visual_selection_range()
|
||||||
|
local _, csrow, cscol, _ = unpack(vim.fn.getpos "v") ---@type integer, integer, integer, integer
|
||||||
|
local _, cerow, cecol, _ = unpack(vim.fn.getpos ".") ---@type integer, integer, integer, integer
|
||||||
|
|
||||||
|
local start_row, start_col, end_row, end_col ---@type integer, integer, integer, integer
|
||||||
|
|
||||||
|
if csrow < cerow or (csrow == cerow and cscol <= cecol) then
|
||||||
|
start_row = csrow
|
||||||
|
start_col = cscol
|
||||||
|
end_row = cerow
|
||||||
|
end_col = cecol
|
||||||
|
else
|
||||||
|
start_row = cerow
|
||||||
|
start_col = cecol
|
||||||
|
end_row = csrow
|
||||||
|
end_col = cscol
|
||||||
|
end
|
||||||
|
|
||||||
|
return start_row, start_col, end_row, end_col
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@return boolean
|
||||||
|
local function range_matches(node)
|
||||||
|
local csrow, cscol, cerow, cecol = visual_selection_range()
|
||||||
|
local srow, scol, erow, ecol = ts_utils.get_vim_range { node:range() }
|
||||||
|
return srow == csrow and scol == cscol and erow == cerow and ecol == cecol
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param get_parent fun(node: TSNode): TSNode|nil
|
||||||
|
---@return fun():nil
|
||||||
|
local function select_incremental(get_parent)
|
||||||
|
return function()
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
local nodes = selections[buf]
|
||||||
|
|
||||||
|
local csrow, cscol, cerow, cecol = visual_selection_range()
|
||||||
|
-- Initialize incremental selection with current selection
|
||||||
|
if not nodes or #nodes == 0 or not range_matches(nodes[#nodes]) then
|
||||||
|
local root = parsers.get_parser():parse()[1]:root()
|
||||||
|
local node = root:named_descendant_for_range(csrow - 1, cscol - 1, cerow - 1, cecol)
|
||||||
|
ts_utils.update_selection(buf, node)
|
||||||
|
if nodes and #nodes > 0 then
|
||||||
|
table.insert(selections[buf], node)
|
||||||
|
else
|
||||||
|
selections[buf] = { [1] = node }
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Find a node that changes the current selection.
|
||||||
|
local node = nodes[#nodes] ---@type TSNode
|
||||||
|
while true do
|
||||||
|
local parent = get_parent(node)
|
||||||
|
if not parent or parent == node then
|
||||||
|
-- Keep searching in the main tree
|
||||||
|
-- TODO: we should search on the parent tree of the current node.
|
||||||
|
local root = parsers.get_parser():parse()[1]:root()
|
||||||
|
parent = root:named_descendant_for_range(csrow - 1, cscol - 1, cerow - 1, cecol)
|
||||||
|
if not parent or root == node or parent == node then
|
||||||
|
ts_utils.update_selection(buf, node)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
node = parent
|
||||||
|
local srow, scol, erow, ecol = ts_utils.get_vim_range { node:range() }
|
||||||
|
local same_range = (srow == csrow and scol == cscol and erow == cerow and ecol == cecol)
|
||||||
|
if not same_range then
|
||||||
|
table.insert(selections[buf], node)
|
||||||
|
if node ~= nodes[#nodes] then
|
||||||
|
table.insert(nodes, node)
|
||||||
|
end
|
||||||
|
ts_utils.update_selection(buf, node)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.node_incremental = select_incremental(function(node)
|
||||||
|
return node:parent() or node
|
||||||
|
end)
|
||||||
|
|
||||||
|
M.scope_incremental = select_incremental(function(node)
|
||||||
|
local lang = parsers.get_buf_lang()
|
||||||
|
if queries.has_locals(lang) then
|
||||||
|
return locals.containing_scope(node:parent() or node)
|
||||||
|
else
|
||||||
|
return node
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function M.node_decremental()
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
local nodes = selections[buf]
|
||||||
|
if not nodes or #nodes < 2 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
table.remove(selections[buf])
|
||||||
|
local node = nodes[#nodes] ---@type TSNode
|
||||||
|
ts_utils.update_selection(buf, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
local FUNCTION_DESCRIPTIONS = {
|
||||||
|
init_selection = "Start selecting nodes with nvim-treesitter",
|
||||||
|
node_incremental = "Increment selection to named node",
|
||||||
|
scope_incremental = "Increment selection to surrounding scope",
|
||||||
|
node_decremental = "Shrink selection to previous named node",
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
function M.attach(bufnr)
|
||||||
|
local config = configs.get_module "incremental_selection"
|
||||||
|
for funcname, mapping in pairs(config.keymaps) do
|
||||||
|
if mapping then
|
||||||
|
local mode = funcname == "init_selection" and "n" or "x"
|
||||||
|
local rhs = M[funcname] ---@type function
|
||||||
|
|
||||||
|
if not rhs then
|
||||||
|
utils.notify("Unknown keybinding: " .. funcname .. debug.traceback(), vim.log.levels.ERROR)
|
||||||
|
else
|
||||||
|
vim.keymap.set(mode, mapping, rhs, { buffer = bufnr, silent = true, desc = FUNCTION_DESCRIPTIONS[funcname] })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.detach(bufnr)
|
||||||
|
local config = configs.get_module "incremental_selection"
|
||||||
|
for f, mapping in pairs(config.keymaps) do
|
||||||
|
if mapping then
|
||||||
|
local mode = f == "init_selection" and "n" or "x"
|
||||||
|
local ok, err = pcall(vim.keymap.del, mode, mapping, { buffer = bufnr })
|
||||||
|
if not ok then
|
||||||
|
utils.notify(string.format('%s "%s" for mode %s', err, mapping, mode), vim.log.levels.ERROR)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
366
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/indent.lua
Normal file
366
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/indent.lua
Normal file
|
@ -0,0 +1,366 @@
|
||||||
|
local ts = vim.treesitter
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.avoid_force_reparsing = {
|
||||||
|
yaml = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
M.comment_parsers = {
|
||||||
|
comment = true,
|
||||||
|
jsdoc = true,
|
||||||
|
phpdoc = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function getline(lnum)
|
||||||
|
return vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1] or ""
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lnum integer
|
||||||
|
---@return integer
|
||||||
|
local function get_indentcols_at_line(lnum)
|
||||||
|
local _, indentcols = getline(lnum):find "^%s*"
|
||||||
|
return indentcols or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param root TSNode
|
||||||
|
---@param lnum integer
|
||||||
|
---@param col? integer
|
||||||
|
---@return TSNode
|
||||||
|
local function get_first_node_at_line(root, lnum, col)
|
||||||
|
col = col or get_indentcols_at_line(lnum)
|
||||||
|
return root:descendant_for_range(lnum - 1, col, lnum - 1, col + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param root TSNode
|
||||||
|
---@param lnum integer
|
||||||
|
---@param col? integer
|
||||||
|
---@return TSNode
|
||||||
|
local function get_last_node_at_line(root, lnum, col)
|
||||||
|
col = col or (#getline(lnum) - 1)
|
||||||
|
return root:descendant_for_range(lnum - 1, col, lnum - 1, col + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@return number
|
||||||
|
local function node_length(node)
|
||||||
|
local _, _, start_byte = node:start()
|
||||||
|
local _, _, end_byte = node:end_()
|
||||||
|
return end_byte - start_byte
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param node TSNode
|
||||||
|
---@param delimiter string
|
||||||
|
---@return TSNode|nil child
|
||||||
|
---@return boolean|nil is_end
|
||||||
|
local function find_delimiter(bufnr, node, delimiter)
|
||||||
|
for child, _ in node:iter_children() do
|
||||||
|
if child:type() == delimiter then
|
||||||
|
local linenr = child:start()
|
||||||
|
local line = vim.api.nvim_buf_get_lines(bufnr, linenr, linenr + 1, false)[1]
|
||||||
|
local end_char = { child:end_() }
|
||||||
|
local trimmed_after_delim
|
||||||
|
local escaped_delimiter = delimiter:gsub("[%-%.%+%[%]%(%)%$%^%%%?%*]", "%%%1")
|
||||||
|
trimmed_after_delim, _ = line:sub(end_char[2] + 1):gsub("[%s" .. escaped_delimiter .. "]*", "")
|
||||||
|
return child, #trimmed_after_delim == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Memoize a function using hash_fn to hash the arguments.
|
||||||
|
---@generic F: function
|
||||||
|
---@param fn F
|
||||||
|
---@param hash_fn fun(...): any
|
||||||
|
---@return F
|
||||||
|
local function memoize(fn, hash_fn)
|
||||||
|
local cache = setmetatable({}, { __mode = "kv" }) ---@type table<any,any>
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
local key = hash_fn(...)
|
||||||
|
if cache[key] == nil then
|
||||||
|
local v = fn(...) ---@type any
|
||||||
|
cache[key] = v ~= nil and v or vim.NIL
|
||||||
|
end
|
||||||
|
|
||||||
|
local v = cache[key]
|
||||||
|
return v ~= vim.NIL and v or nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_indents = memoize(function(bufnr, root, lang)
|
||||||
|
local map = {
|
||||||
|
["indent.auto"] = {},
|
||||||
|
["indent.begin"] = {},
|
||||||
|
["indent.end"] = {},
|
||||||
|
["indent.dedent"] = {},
|
||||||
|
["indent.branch"] = {},
|
||||||
|
["indent.ignore"] = {},
|
||||||
|
["indent.align"] = {},
|
||||||
|
["indent.zero"] = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
--TODO(clason): remove when dropping Nvim 0.8 compat
|
||||||
|
local query = (ts.query.get or ts.get_query)(lang, "indents")
|
||||||
|
if not query then
|
||||||
|
return map
|
||||||
|
end
|
||||||
|
for id, node, metadata in query:iter_captures(root, bufnr) do
|
||||||
|
if query.captures[id]:sub(1, 1) ~= "_" then
|
||||||
|
map[query.captures[id]][node:id()] = metadata or {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return map
|
||||||
|
end, function(bufnr, root, lang)
|
||||||
|
return tostring(bufnr) .. root:id() .. "_" .. lang
|
||||||
|
end)
|
||||||
|
|
||||||
|
---@param lnum number (1-indexed)
|
||||||
|
function M.get_indent(lnum)
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
local parser = parsers.get_parser(bufnr)
|
||||||
|
if not parser or not lnum then
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
--TODO(clason): replace when dropping Nvim 0.8 compat
|
||||||
|
local root_lang = parsers.get_buf_lang(bufnr)
|
||||||
|
|
||||||
|
-- some languages like Python will actually have worse results when re-parsing at opened new line
|
||||||
|
if not M.avoid_force_reparsing[root_lang] then
|
||||||
|
-- Reparse in case we got triggered by ":h indentkeys"
|
||||||
|
parser:parse { vim.fn.line "w0" - 1, vim.fn.line "w$" }
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get language tree with smallest range around node that's not a comment parser
|
||||||
|
local root, lang_tree ---@type TSNode, LanguageTree
|
||||||
|
parser:for_each_tree(function(tstree, tree)
|
||||||
|
if not tstree or M.comment_parsers[tree:lang()] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local local_root = tstree:root()
|
||||||
|
if ts.is_in_node_range(local_root, lnum - 1, 0) then
|
||||||
|
if not root or node_length(root) >= node_length(local_root) then
|
||||||
|
root = local_root
|
||||||
|
lang_tree = tree
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Not likely, but just in case...
|
||||||
|
if not root then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local q = get_indents(vim.api.nvim_get_current_buf(), root, lang_tree:lang())
|
||||||
|
local is_empty_line = string.match(getline(lnum), "^%s*$") ~= nil
|
||||||
|
local node ---@type TSNode
|
||||||
|
if is_empty_line then
|
||||||
|
local prevlnum = vim.fn.prevnonblank(lnum)
|
||||||
|
local indentcols = get_indentcols_at_line(prevlnum)
|
||||||
|
local prevline = vim.trim(getline(prevlnum))
|
||||||
|
-- The final position can be trailing spaces, which should not affect indentation
|
||||||
|
node = get_last_node_at_line(root, prevlnum, indentcols + #prevline - 1)
|
||||||
|
if node:type():match "comment" then
|
||||||
|
-- The final node we capture of the previous line can be a comment node, which should also be ignored
|
||||||
|
-- Unless the last line is an entire line of comment, ignore the comment range and find the last node again
|
||||||
|
local first_node = get_first_node_at_line(root, prevlnum, indentcols)
|
||||||
|
local _, scol, _, _ = node:range()
|
||||||
|
if first_node:id() ~= node:id() then
|
||||||
|
-- In case the last captured node is a trailing comment node, re-trim the string
|
||||||
|
prevline = vim.trim(prevline:sub(1, scol - indentcols))
|
||||||
|
-- Add back indent as indent of prevline was trimmed away
|
||||||
|
local col = indentcols + #prevline - 1
|
||||||
|
node = get_last_node_at_line(root, prevlnum, col)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if q["indent.end"][node:id()] then
|
||||||
|
node = get_first_node_at_line(root, lnum)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
node = get_first_node_at_line(root, lnum)
|
||||||
|
end
|
||||||
|
|
||||||
|
local indent_size = vim.fn.shiftwidth()
|
||||||
|
local indent = 0
|
||||||
|
local _, _, root_start = root:start()
|
||||||
|
if root_start ~= 0 then
|
||||||
|
-- injected tree
|
||||||
|
indent = vim.fn.indent(root:start() + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- tracks to ensure multiple indent levels are not applied for same line
|
||||||
|
local is_processed_by_row = {}
|
||||||
|
|
||||||
|
if q["indent.zero"][node:id()] then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
while node do
|
||||||
|
-- do 'autoindent' if not marked as @indent
|
||||||
|
if
|
||||||
|
not q["indent.begin"][node:id()]
|
||||||
|
and not q["indent.align"][node:id()]
|
||||||
|
and q["indent.auto"][node:id()]
|
||||||
|
and node:start() < lnum - 1
|
||||||
|
and lnum - 1 <= node:end_()
|
||||||
|
then
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Do not indent if we are inside an @ignore block.
|
||||||
|
-- If a node spans from L1,C1 to L2,C2, we know that lines where L1 < line <= L2 would
|
||||||
|
-- have their indentations contained by the node.
|
||||||
|
if
|
||||||
|
not q["indent.begin"][node:id()]
|
||||||
|
and q["indent.ignore"][node:id()]
|
||||||
|
and node:start() < lnum - 1
|
||||||
|
and lnum - 1 <= node:end_()
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local srow, _, erow = node:range()
|
||||||
|
|
||||||
|
local is_processed = false
|
||||||
|
|
||||||
|
if
|
||||||
|
not is_processed_by_row[srow]
|
||||||
|
and ((q["indent.branch"][node:id()] and srow == lnum - 1) or (q["indent.dedent"][node:id()] and srow ~= lnum - 1))
|
||||||
|
then
|
||||||
|
indent = indent - indent_size
|
||||||
|
is_processed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
|
||||||
|
local should_process = not is_processed_by_row[srow]
|
||||||
|
local is_in_err = false
|
||||||
|
if should_process then
|
||||||
|
local parent = node:parent()
|
||||||
|
is_in_err = parent and parent:has_error()
|
||||||
|
end
|
||||||
|
if
|
||||||
|
should_process
|
||||||
|
and (
|
||||||
|
q["indent.begin"][node:id()]
|
||||||
|
and (srow ~= erow or is_in_err or q["indent.begin"][node:id()]["indent.immediate"])
|
||||||
|
and (srow ~= lnum - 1 or q["indent.begin"][node:id()]["indent.start_at_same_line"])
|
||||||
|
)
|
||||||
|
then
|
||||||
|
indent = indent + indent_size
|
||||||
|
is_processed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if is_in_err and not q["indent.align"][node:id()] then
|
||||||
|
-- only when the node is in error, promote the
|
||||||
|
-- first child's aligned indent to the error node
|
||||||
|
-- to work around ((ERROR "X" . (_)) @aligned_indent (#set! "delimiter" "AB"))
|
||||||
|
-- matching for all X, instead set do
|
||||||
|
-- (ERROR "X" @aligned_indent (#set! "delimiter" "AB") . (_))
|
||||||
|
-- and we will fish it out here.
|
||||||
|
for c in node:iter_children() do
|
||||||
|
if q["indent.align"][c:id()] then
|
||||||
|
q["indent.align"][node:id()] = q["indent.align"][c:id()]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
|
||||||
|
if should_process and q["indent.align"][node:id()] and (srow ~= erow or is_in_err) and (srow ~= lnum - 1) then
|
||||||
|
local metadata = q["indent.align"][node:id()]
|
||||||
|
local o_delim_node, o_is_last_in_line ---@type TSNode|nil, boolean|nil
|
||||||
|
local c_delim_node, c_is_last_in_line ---@type TSNode|nil, boolean|nil, boolean|nil
|
||||||
|
local indent_is_absolute = false
|
||||||
|
if metadata["indent.open_delimiter"] then
|
||||||
|
o_delim_node, o_is_last_in_line = find_delimiter(bufnr, node, metadata["indent.open_delimiter"])
|
||||||
|
else
|
||||||
|
o_delim_node = node
|
||||||
|
end
|
||||||
|
if metadata["indent.close_delimiter"] then
|
||||||
|
c_delim_node, c_is_last_in_line = find_delimiter(bufnr, node, metadata["indent.close_delimiter"])
|
||||||
|
else
|
||||||
|
c_delim_node = node
|
||||||
|
end
|
||||||
|
|
||||||
|
if o_delim_node then
|
||||||
|
local o_srow, o_scol = o_delim_node:start()
|
||||||
|
local c_srow = nil
|
||||||
|
if c_delim_node then
|
||||||
|
c_srow, _ = c_delim_node:start()
|
||||||
|
end
|
||||||
|
if o_is_last_in_line then
|
||||||
|
-- hanging indent (previous line ended with starting delimiter)
|
||||||
|
-- should be processed like indent
|
||||||
|
if should_process then
|
||||||
|
indent = indent + indent_size * 1
|
||||||
|
if c_is_last_in_line then
|
||||||
|
-- If current line is outside the range of a node marked with `@aligned_indent`
|
||||||
|
-- Then its indent level shouldn't be affected by `@aligned_indent` node
|
||||||
|
if c_srow and c_srow < lnum - 1 then
|
||||||
|
indent = math.max(indent - indent_size, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- aligned indent
|
||||||
|
if c_is_last_in_line and c_srow and o_srow ~= c_srow and c_srow < lnum - 1 then
|
||||||
|
-- If current line is outside the range of a node marked with `@aligned_indent`
|
||||||
|
-- Then its indent level shouldn't be affected by `@aligned_indent` node
|
||||||
|
indent = math.max(indent - indent_size, 0)
|
||||||
|
else
|
||||||
|
indent = o_scol + (metadata["indent.increment"] or 1)
|
||||||
|
indent_is_absolute = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- deal with the final line
|
||||||
|
local avoid_last_matching_next = false
|
||||||
|
if c_srow and c_srow ~= o_srow and c_srow == lnum - 1 then
|
||||||
|
-- delims end on current line, and are not open and closed same line.
|
||||||
|
-- then this last line may need additional indent to avoid clashes
|
||||||
|
-- with the next. `indent.avoid_last_matching_next` controls this behavior,
|
||||||
|
-- for example this is needed for function parameters.
|
||||||
|
avoid_last_matching_next = metadata["indent.avoid_last_matching_next"] or false
|
||||||
|
end
|
||||||
|
if avoid_last_matching_next then
|
||||||
|
-- last line must be indented more in cases where
|
||||||
|
-- it would be same indent as next line (we determine this as one
|
||||||
|
-- width more than the open indent to avoid confusing with any
|
||||||
|
-- hanging indents)
|
||||||
|
if indent <= vim.fn.indent(o_srow + 1) + indent_size then
|
||||||
|
indent = indent + indent_size * 1
|
||||||
|
else
|
||||||
|
indent = indent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
is_processed = true
|
||||||
|
if indent_is_absolute then
|
||||||
|
-- don't allow further indenting by parent nodes, this is an absolute position
|
||||||
|
return indent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
is_processed_by_row[srow] = is_processed_by_row[srow] or is_processed
|
||||||
|
|
||||||
|
node = node:parent()
|
||||||
|
end
|
||||||
|
|
||||||
|
return indent
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type table<integer, string>
|
||||||
|
local indent_funcs = {}
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
function M.attach(bufnr)
|
||||||
|
indent_funcs[bufnr] = vim.bo.indentexpr
|
||||||
|
vim.bo.indentexpr = "nvim_treesitter#indent()"
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.detach(bufnr)
|
||||||
|
vim.bo.indentexpr = indent_funcs[bufnr]
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
190
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/info.lua
Normal file
190
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/info.lua
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
local api = vim.api
|
||||||
|
local configs = require "nvim-treesitter.configs"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function install_info()
|
||||||
|
local max_len = 0
|
||||||
|
for _, ft in pairs(parsers.available_parsers()) do
|
||||||
|
if #ft > max_len then
|
||||||
|
max_len = #ft
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local parser_list = parsers.available_parsers()
|
||||||
|
table.sort(parser_list)
|
||||||
|
for _, lang in pairs(parser_list) do
|
||||||
|
local is_installed = #api.nvim_get_runtime_file("parser/" .. lang .. ".so", false) > 0
|
||||||
|
api.nvim_out_write(lang .. string.rep(" ", max_len - #lang + 1))
|
||||||
|
if is_installed then
|
||||||
|
api.nvim_out_write "[✓] installed\n"
|
||||||
|
elseif pcall(vim.treesitter.inspect_lang, lang) then
|
||||||
|
api.nvim_out_write "[✗] not installed (but still loaded. Restart Neovim!)\n"
|
||||||
|
else
|
||||||
|
api.nvim_out_write "[✗] not installed\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Sort a list of modules into namespaces.
|
||||||
|
-- {'mod1', 'mod2.sub1', 'mod2.sub2', 'mod3'}
|
||||||
|
-- ->
|
||||||
|
-- { default = {'mod1', 'mod3'}, mod2 = {'sub1', 'sub2'}}
|
||||||
|
---@param modulelist string[]
|
||||||
|
---@return table
|
||||||
|
local function namespace_modules(modulelist)
|
||||||
|
local modules = {}
|
||||||
|
for _, module in ipairs(modulelist) do
|
||||||
|
if module:find "%." then
|
||||||
|
local namespace, submodule = module:match "^(.*)%.(.*)$"
|
||||||
|
if not modules[namespace] then
|
||||||
|
modules[namespace] = {}
|
||||||
|
end
|
||||||
|
table.insert(modules[namespace], submodule)
|
||||||
|
else
|
||||||
|
if not modules.default then
|
||||||
|
modules.default = {}
|
||||||
|
end
|
||||||
|
table.insert(modules.default, module)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return modules
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param list string[]
|
||||||
|
---@return integer length
|
||||||
|
local function longest_string_length(list)
|
||||||
|
local length = 0
|
||||||
|
for _, value in ipairs(list) do
|
||||||
|
if #value > length then
|
||||||
|
length = #value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return length
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param curbuf integer
|
||||||
|
---@param origbuf integer
|
||||||
|
---@param parserlist string[]
|
||||||
|
---@param namespace string
|
||||||
|
---@param modulelist string[]
|
||||||
|
local function append_module_table(curbuf, origbuf, parserlist, namespace, modulelist)
|
||||||
|
local maxlen_parser = longest_string_length(parserlist)
|
||||||
|
table.sort(modulelist)
|
||||||
|
|
||||||
|
-- header
|
||||||
|
local header = ">> " .. namespace .. string.rep(" ", maxlen_parser - #namespace - 1)
|
||||||
|
for _, module in pairs(modulelist) do
|
||||||
|
header = header .. module .. " "
|
||||||
|
end
|
||||||
|
api.nvim_buf_set_lines(curbuf, -1, -1, true, { header })
|
||||||
|
|
||||||
|
-- actual table
|
||||||
|
for _, parser in ipairs(parserlist) do
|
||||||
|
local padding = string.rep(" ", maxlen_parser - #parser + 2)
|
||||||
|
local line = parser .. padding
|
||||||
|
local namespace_prefix = (namespace == "default") and "" or namespace .. "."
|
||||||
|
for _, module in pairs(modulelist) do
|
||||||
|
local modlen = #module
|
||||||
|
module = namespace_prefix .. module
|
||||||
|
if configs.is_enabled(module, parser, origbuf) then
|
||||||
|
line = line .. "✓"
|
||||||
|
else
|
||||||
|
line = line .. "✗"
|
||||||
|
end
|
||||||
|
line = line .. string.rep(" ", modlen + 1)
|
||||||
|
end
|
||||||
|
api.nvim_buf_set_lines(curbuf, -1, -1, true, { line })
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_buf_set_lines(curbuf, -1, -1, true, { "" })
|
||||||
|
end
|
||||||
|
|
||||||
|
local function print_info_modules(parserlist, module)
|
||||||
|
local origbuf = api.nvim_get_current_buf()
|
||||||
|
api.nvim_command "enew"
|
||||||
|
local curbuf = api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local modules
|
||||||
|
if module then
|
||||||
|
modules = namespace_modules { module }
|
||||||
|
else
|
||||||
|
modules = namespace_modules(configs.available_modules())
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type string[]
|
||||||
|
local namespaces = {}
|
||||||
|
for k, _ in pairs(modules) do
|
||||||
|
table.insert(namespaces, k)
|
||||||
|
end
|
||||||
|
table.sort(namespaces)
|
||||||
|
|
||||||
|
table.sort(parserlist)
|
||||||
|
for _, namespace in ipairs(namespaces) do
|
||||||
|
append_module_table(curbuf, origbuf, parserlist, namespace, modules[namespace])
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_buf_set_option(curbuf, "modified", false)
|
||||||
|
api.nvim_buf_set_option(curbuf, "buftype", "nofile")
|
||||||
|
vim.cmd [[
|
||||||
|
syntax match TSModuleInfoGood /✓/
|
||||||
|
syntax match TSModuleInfoBad /✗/
|
||||||
|
syntax match TSModuleInfoHeader /^>>.*$/ contains=TSModuleInfoNamespace
|
||||||
|
syntax match TSModuleInfoNamespace /^>> \w*/ contained
|
||||||
|
syntax match TSModuleInfoParser /^[^> ]*\ze /
|
||||||
|
]]
|
||||||
|
|
||||||
|
local highlights = {
|
||||||
|
TSModuleInfoGood = { fg = "LightGreen", bold = true, default = true },
|
||||||
|
TSModuleInfoBad = { fg = "Crimson", default = true },
|
||||||
|
TSModuleInfoHeader = { link = "Type", default = true },
|
||||||
|
TSModuleInfoNamespace = { link = "Statement", default = true },
|
||||||
|
TSModuleInfoParser = { link = "Identifier", default = true },
|
||||||
|
}
|
||||||
|
for k, v in pairs(highlights) do
|
||||||
|
api.nvim_set_hl(0, k, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function module_info(module)
|
||||||
|
if module and not configs.get_module(module) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local parserlist = parsers.available_parsers()
|
||||||
|
if module then
|
||||||
|
print_info_modules(parserlist, module)
|
||||||
|
else
|
||||||
|
print_info_modules(parserlist)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return string[]
|
||||||
|
function M.installed_parsers()
|
||||||
|
local installed = {}
|
||||||
|
for _, p in pairs(parsers.available_parsers()) do
|
||||||
|
if parsers.has_parser(p) then
|
||||||
|
table.insert(installed, p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return installed
|
||||||
|
end
|
||||||
|
|
||||||
|
M.commands = {
|
||||||
|
TSInstallInfo = {
|
||||||
|
run = install_info,
|
||||||
|
args = {
|
||||||
|
"-nargs=0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSModuleInfo = {
|
||||||
|
run = module_info,
|
||||||
|
args = {
|
||||||
|
"-nargs=?",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
781
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/install.lua
Normal file
781
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/install.lua
Normal file
|
@ -0,0 +1,781 @@
|
||||||
|
local api = vim.api
|
||||||
|
local fn = vim.fn
|
||||||
|
local luv = vim.loop
|
||||||
|
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local info = require "nvim-treesitter.info"
|
||||||
|
local configs = require "nvim-treesitter.configs"
|
||||||
|
local shell = require "nvim-treesitter.shell_command_selectors"
|
||||||
|
local compat = require "nvim-treesitter.compat"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@class LockfileInfo
|
||||||
|
---@field revision string
|
||||||
|
|
||||||
|
---@type table<string, LockfileInfo>
|
||||||
|
local lockfile = {}
|
||||||
|
|
||||||
|
M.compilers = { vim.fn.getenv "CC", "cc", "gcc", "clang", "cl", "zig" }
|
||||||
|
M.prefer_git = fn.has "win32" == 1
|
||||||
|
M.command_extra_args = {}
|
||||||
|
M.ts_generate_args = nil
|
||||||
|
|
||||||
|
local started_commands = 0
|
||||||
|
local finished_commands = 0
|
||||||
|
local failed_commands = 0
|
||||||
|
local complete_std_output = {}
|
||||||
|
local complete_error_output = {}
|
||||||
|
|
||||||
|
local function reset_progress_counter()
|
||||||
|
if started_commands ~= finished_commands then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
started_commands = 0
|
||||||
|
finished_commands = 0
|
||||||
|
failed_commands = 0
|
||||||
|
complete_std_output = {}
|
||||||
|
complete_error_output = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_job_status()
|
||||||
|
return "[nvim-treesitter] ["
|
||||||
|
.. finished_commands
|
||||||
|
.. "/"
|
||||||
|
.. started_commands
|
||||||
|
.. (failed_commands > 0 and ", failed: " .. failed_commands or "")
|
||||||
|
.. "]"
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return function
|
||||||
|
local function reattach_if_possible_fn(lang, error_on_fail)
|
||||||
|
return function()
|
||||||
|
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if parsers.get_buf_lang(buf) == lang then
|
||||||
|
vim._ts_remove_language(lang)
|
||||||
|
local ok, err
|
||||||
|
if vim.treesitter.language.add then
|
||||||
|
local ft = vim.bo[buf].filetype
|
||||||
|
ok, err = pcall(vim.treesitter.language.add, lang, { filetype = ft })
|
||||||
|
else
|
||||||
|
ok, err = pcall(compat.require_language, lang)
|
||||||
|
end
|
||||||
|
if not ok and error_on_fail then
|
||||||
|
vim.notify("Could not load parser for " .. lang .. ": " .. vim.inspect(err))
|
||||||
|
end
|
||||||
|
for _, mod in ipairs(require("nvim-treesitter.configs").available_modules()) do
|
||||||
|
if ok then
|
||||||
|
require("nvim-treesitter.configs").reattach_module(mod, buf, lang)
|
||||||
|
else
|
||||||
|
require("nvim-treesitter.configs").detach_module(mod, buf)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@param validate boolean|nil
|
||||||
|
---@return InstallInfo
|
||||||
|
local function get_parser_install_info(lang, validate)
|
||||||
|
local parser_config = parsers.get_parser_configs()[lang]
|
||||||
|
|
||||||
|
if not parser_config then
|
||||||
|
error('Parser not available for language "' .. lang .. '"')
|
||||||
|
end
|
||||||
|
|
||||||
|
local install_info = parser_config.install_info
|
||||||
|
|
||||||
|
if validate then
|
||||||
|
vim.validate {
|
||||||
|
url = { install_info.url, "string" },
|
||||||
|
files = { install_info.files, "table" },
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return install_info
|
||||||
|
end
|
||||||
|
|
||||||
|
local function load_lockfile()
|
||||||
|
local filename = utils.join_path(utils.get_package_path(), "lockfile.json")
|
||||||
|
lockfile = vim.fn.filereadable(filename) == 1 and vim.fn.json_decode(vim.fn.readfile(filename)) or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_ignored_parser(lang)
|
||||||
|
return vim.tbl_contains(configs.get_ignored_parser_installs(), lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return string|nil
|
||||||
|
local function get_revision(lang)
|
||||||
|
if #lockfile == 0 then
|
||||||
|
load_lockfile()
|
||||||
|
end
|
||||||
|
|
||||||
|
local install_info = get_parser_install_info(lang)
|
||||||
|
if install_info.revision then
|
||||||
|
return install_info.revision
|
||||||
|
end
|
||||||
|
|
||||||
|
if lockfile[lang] then
|
||||||
|
return lockfile[lang].revision
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return string|nil
|
||||||
|
local function get_installed_revision(lang)
|
||||||
|
local lang_file = utils.join_path(configs.get_parser_info_dir(), lang .. ".revision")
|
||||||
|
if vim.fn.filereadable(lang_file) == 1 then
|
||||||
|
return vim.fn.readfile(lang_file)[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clean path for use in a prefix comparison
|
||||||
|
---@param input string
|
||||||
|
---@return string
|
||||||
|
local function clean_path(input)
|
||||||
|
local pth = vim.fn.fnamemodify(input, ":p")
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
pth = pth:gsub("/", "\\")
|
||||||
|
end
|
||||||
|
return pth
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checks if parser is installed with nvim-treesitter
|
||||||
|
---@param lang string
|
||||||
|
---@return boolean
|
||||||
|
local function is_installed(lang)
|
||||||
|
local matched_parsers = vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", true) or {}
|
||||||
|
local install_dir = configs.get_parser_install_dir()
|
||||||
|
if not install_dir then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
install_dir = clean_path(install_dir)
|
||||||
|
for _, path in ipairs(matched_parsers) do
|
||||||
|
local abspath = clean_path(path)
|
||||||
|
if vim.startswith(abspath, install_dir) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@return boolean
|
||||||
|
local function needs_update(lang)
|
||||||
|
local revision = get_revision(lang)
|
||||||
|
return not revision or revision ~= get_installed_revision(lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return string[]
|
||||||
|
local function outdated_parsers()
|
||||||
|
return vim.tbl_filter(function(lang) ---@param lang string
|
||||||
|
return is_installed(lang) and needs_update(lang)
|
||||||
|
end, info.installed_parsers())
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param handle userdata
|
||||||
|
---@param is_stderr boolean
|
||||||
|
local function onread(handle, is_stderr)
|
||||||
|
return function(_, data)
|
||||||
|
if data then
|
||||||
|
if is_stderr then
|
||||||
|
complete_error_output[handle] = (complete_error_output[handle] or "") .. data
|
||||||
|
else
|
||||||
|
complete_std_output[handle] = (complete_std_output[handle] or "") .. data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.iter_cmd(cmd_list, i, lang, success_message)
|
||||||
|
if i == 1 then
|
||||||
|
started_commands = started_commands + 1
|
||||||
|
end
|
||||||
|
if i == #cmd_list + 1 then
|
||||||
|
finished_commands = finished_commands + 1
|
||||||
|
return print(get_job_status() .. " " .. success_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
local attr = cmd_list[i]
|
||||||
|
if attr.info then
|
||||||
|
print(get_job_status() .. " " .. attr.info)
|
||||||
|
end
|
||||||
|
|
||||||
|
if attr.opts and attr.opts.args and M.command_extra_args[attr.cmd] then
|
||||||
|
vim.list_extend(attr.opts.args, M.command_extra_args[attr.cmd])
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(attr.cmd) == "function" then
|
||||||
|
local ok, err = pcall(attr.cmd)
|
||||||
|
if ok then
|
||||||
|
M.iter_cmd(cmd_list, i + 1, lang, success_message)
|
||||||
|
else
|
||||||
|
failed_commands = failed_commands + 1
|
||||||
|
finished_commands = finished_commands + 1
|
||||||
|
return api.nvim_err_writeln(
|
||||||
|
(attr.err or ("Failed to execute the following command:\n" .. vim.inspect(attr))) .. "\n" .. vim.inspect(err)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local handle
|
||||||
|
local stdout = luv.new_pipe(false)
|
||||||
|
local stderr = luv.new_pipe(false)
|
||||||
|
attr.opts.stdio = { nil, stdout, stderr }
|
||||||
|
---@type userdata
|
||||||
|
handle = luv.spawn(
|
||||||
|
attr.cmd,
|
||||||
|
attr.opts,
|
||||||
|
vim.schedule_wrap(function(code)
|
||||||
|
if code ~= 0 then
|
||||||
|
stdout:read_stop()
|
||||||
|
stderr:read_stop()
|
||||||
|
end
|
||||||
|
stdout:close()
|
||||||
|
stderr:close()
|
||||||
|
handle:close()
|
||||||
|
if code ~= 0 then
|
||||||
|
failed_commands = failed_commands + 1
|
||||||
|
finished_commands = finished_commands + 1
|
||||||
|
if complete_std_output[handle] and complete_std_output[handle] ~= "" then
|
||||||
|
print(complete_std_output[handle])
|
||||||
|
end
|
||||||
|
|
||||||
|
local err_msg = complete_error_output[handle] or ""
|
||||||
|
api.nvim_err_writeln(
|
||||||
|
"nvim-treesitter["
|
||||||
|
.. lang
|
||||||
|
.. "]: "
|
||||||
|
.. (attr.err or ("Failed to execute the following command:\n" .. vim.inspect(attr)))
|
||||||
|
.. "\n"
|
||||||
|
.. err_msg
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
M.iter_cmd(cmd_list, i + 1, lang, success_message)
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
luv.read_start(stdout, onread(handle, false))
|
||||||
|
luv.read_start(stderr, onread(handle, true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param cmd Command
|
||||||
|
---@return string command
|
||||||
|
local function get_command(cmd)
|
||||||
|
local options = ""
|
||||||
|
if cmd.opts and cmd.opts.args then
|
||||||
|
if M.command_extra_args[cmd.cmd] then
|
||||||
|
vim.list_extend(cmd.opts.args, M.command_extra_args[cmd.cmd])
|
||||||
|
end
|
||||||
|
for _, opt in ipairs(cmd.opts.args) do
|
||||||
|
options = string.format("%s %s", options, opt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local command = string.format("%s %s", cmd.cmd, options)
|
||||||
|
if cmd.opts and cmd.opts.cwd then
|
||||||
|
command = shell.make_directory_change_for_command(cmd.opts.cwd, command)
|
||||||
|
end
|
||||||
|
return command
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param cmd_list Command[]
|
||||||
|
---@return boolean
|
||||||
|
local function iter_cmd_sync(cmd_list)
|
||||||
|
for _, cmd in ipairs(cmd_list) do
|
||||||
|
if cmd.info then
|
||||||
|
print(cmd.info)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(cmd.cmd) == "function" then
|
||||||
|
cmd.cmd()
|
||||||
|
else
|
||||||
|
local ret = vim.fn.system(get_command(cmd))
|
||||||
|
if vim.v.shell_error ~= 0 then
|
||||||
|
print(ret)
|
||||||
|
api.nvim_err_writeln(
|
||||||
|
(cmd.err and cmd.err .. "\n" or "") .. "Failed to execute the following command:\n" .. vim.inspect(cmd)
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param cache_folder string
|
||||||
|
---@param install_folder string
|
||||||
|
---@param lang string
|
||||||
|
---@param repo InstallInfo
|
||||||
|
---@param with_sync boolean
|
||||||
|
---@param generate_from_grammar boolean
|
||||||
|
local function run_install(cache_folder, install_folder, lang, repo, with_sync, generate_from_grammar)
|
||||||
|
parsers.reset_cache()
|
||||||
|
|
||||||
|
local path_sep = utils.get_path_sep()
|
||||||
|
|
||||||
|
local project_name = "tree-sitter-" .. lang
|
||||||
|
local maybe_local_path = vim.fn.expand(repo.url)
|
||||||
|
local from_local_path = vim.fn.isdirectory(maybe_local_path) == 1
|
||||||
|
if from_local_path then
|
||||||
|
repo.url = maybe_local_path
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type string compile_location only needed for typescript installs.
|
||||||
|
local compile_location
|
||||||
|
if from_local_path then
|
||||||
|
compile_location = repo.url
|
||||||
|
if repo.location then
|
||||||
|
compile_location = utils.join_path(compile_location, repo.location)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local repo_location = project_name
|
||||||
|
if repo.location then
|
||||||
|
repo_location = repo_location .. "/" .. repo.location
|
||||||
|
end
|
||||||
|
repo_location = repo_location:gsub("/", path_sep)
|
||||||
|
compile_location = utils.join_path(cache_folder, repo_location)
|
||||||
|
end
|
||||||
|
local parser_lib_name = utils.join_path(install_folder, lang) .. ".so"
|
||||||
|
|
||||||
|
generate_from_grammar = repo.requires_generate_from_grammar or generate_from_grammar
|
||||||
|
|
||||||
|
if generate_from_grammar and vim.fn.executable "tree-sitter" ~= 1 then
|
||||||
|
api.nvim_err_writeln "tree-sitter CLI not found: `tree-sitter` is not executable!"
|
||||||
|
if repo.requires_generate_from_grammar then
|
||||||
|
api.nvim_err_writeln(
|
||||||
|
"tree-sitter CLI is needed because `"
|
||||||
|
.. lang
|
||||||
|
.. "` is marked that it needs "
|
||||||
|
.. "to be generated from the grammar definitions to be compatible with nvim!"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
else
|
||||||
|
if not M.ts_generate_args then
|
||||||
|
local ts_cli_version = utils.ts_cli_version()
|
||||||
|
if ts_cli_version and vim.split(ts_cli_version, " ")[1] > "0.20.2" then
|
||||||
|
M.ts_generate_args = { "generate", "--no-bindings", "--abi", vim.treesitter.language_version }
|
||||||
|
else
|
||||||
|
M.ts_generate_args = { "generate", "--no-bindings" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if generate_from_grammar and vim.fn.executable "node" ~= 1 then
|
||||||
|
api.nvim_err_writeln "Node JS not found: `node` is not executable!"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local cc = shell.select_executable(M.compilers)
|
||||||
|
if not cc then
|
||||||
|
api.nvim_err_writeln('No C compiler found! "' .. table.concat(
|
||||||
|
vim.tbl_filter(function(c) ---@param c string
|
||||||
|
return type(c) == "string"
|
||||||
|
end, M.compilers),
|
||||||
|
'", "'
|
||||||
|
) .. '" are not executable.')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local revision = repo.revision
|
||||||
|
if not revision then
|
||||||
|
revision = get_revision(lang)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class Command
|
||||||
|
---@field cmd string
|
||||||
|
---@field info string
|
||||||
|
---@field err string
|
||||||
|
---@field opts CmdOpts
|
||||||
|
|
||||||
|
---@class CmdOpts
|
||||||
|
---@field args string[]
|
||||||
|
---@field cwd string
|
||||||
|
|
||||||
|
---@type Command[]
|
||||||
|
local command_list = {}
|
||||||
|
if not from_local_path then
|
||||||
|
vim.list_extend(command_list, { shell.select_install_rm_cmd(cache_folder, project_name) })
|
||||||
|
vim.list_extend(
|
||||||
|
command_list,
|
||||||
|
shell.select_download_commands(repo, project_name, cache_folder, revision, M.prefer_git)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if generate_from_grammar then
|
||||||
|
if repo.generate_requires_npm then
|
||||||
|
if vim.fn.executable "npm" ~= 1 then
|
||||||
|
api.nvim_err_writeln("`" .. lang .. "` requires NPM to be installed from grammar.js")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.list_extend(command_list, {
|
||||||
|
{
|
||||||
|
cmd = "npm",
|
||||||
|
info = "Installing NPM dependencies of " .. lang .. " parser",
|
||||||
|
err = "Error during `npm install` (required for parser generation of " .. lang .. " with npm dependencies)",
|
||||||
|
opts = {
|
||||||
|
args = { "install" },
|
||||||
|
cwd = compile_location,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
vim.list_extend(command_list, {
|
||||||
|
{
|
||||||
|
cmd = vim.fn.exepath "tree-sitter",
|
||||||
|
info = "Generating source files from grammar.js...",
|
||||||
|
err = 'Error during "tree-sitter generate"',
|
||||||
|
opts = {
|
||||||
|
args = M.ts_generate_args,
|
||||||
|
cwd = compile_location,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
vim.list_extend(command_list, {
|
||||||
|
shell.select_compile_command(repo, cc, compile_location),
|
||||||
|
shell.select_mv_cmd("parser.so", parser_lib_name, compile_location),
|
||||||
|
{
|
||||||
|
cmd = function()
|
||||||
|
vim.fn.writefile({ revision or "" }, utils.join_path(configs.get_parser_info_dir() or "", lang .. ".revision"))
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{ -- auto-attach modules after installation
|
||||||
|
cmd = reattach_if_possible_fn(lang, true),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if not from_local_path then
|
||||||
|
vim.list_extend(command_list, { shell.select_install_rm_cmd(cache_folder, project_name) })
|
||||||
|
end
|
||||||
|
|
||||||
|
if with_sync then
|
||||||
|
if iter_cmd_sync(command_list) == true then
|
||||||
|
print("Treesitter parser for " .. lang .. " has been installed")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been installed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@param ask_reinstall boolean|string
|
||||||
|
---@param cache_folder string
|
||||||
|
---@param install_folder string
|
||||||
|
---@param with_sync boolean
|
||||||
|
---@param generate_from_grammar boolean
|
||||||
|
local function install_lang(lang, ask_reinstall, cache_folder, install_folder, with_sync, generate_from_grammar)
|
||||||
|
if is_installed(lang) and ask_reinstall ~= "force" then
|
||||||
|
if not ask_reinstall then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local yesno = fn.input(lang .. " parser already available: would you like to reinstall ? y/n: ")
|
||||||
|
print "\n "
|
||||||
|
if not string.match(yesno, "^y.*") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, install_info = pcall(get_parser_install_info, lang, true)
|
||||||
|
if not ok then
|
||||||
|
vim.notify("Installation not possible: " .. install_info, vim.log.levels.ERROR)
|
||||||
|
if not parsers.get_parser_configs()[lang] then
|
||||||
|
vim.notify(
|
||||||
|
"See https://github.com/nvim-treesitter/nvim-treesitter/#adding-parsers on how to add a new parser!",
|
||||||
|
vim.log.levels.INFO
|
||||||
|
)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class InstallOptions
|
||||||
|
---@field with_sync boolean
|
||||||
|
---@field ask_reinstall boolean|string
|
||||||
|
---@field generate_from_grammar boolean
|
||||||
|
---@field exclude_configured_parsers boolean
|
||||||
|
|
||||||
|
-- Install a parser
|
||||||
|
---@param options? InstallOptions
|
||||||
|
---@return function
|
||||||
|
local function install(options)
|
||||||
|
options = options or {}
|
||||||
|
local with_sync = options.with_sync
|
||||||
|
local ask_reinstall = options.ask_reinstall
|
||||||
|
local generate_from_grammar = options.generate_from_grammar
|
||||||
|
local exclude_configured_parsers = options.exclude_configured_parsers
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
if fn.executable "git" == 0 then
|
||||||
|
return api.nvim_err_writeln "Git is required on your system to run this command"
|
||||||
|
end
|
||||||
|
|
||||||
|
local cache_folder, err = utils.get_cache_dir()
|
||||||
|
if err then
|
||||||
|
return api.nvim_err_writeln(err)
|
||||||
|
end
|
||||||
|
assert(cache_folder)
|
||||||
|
|
||||||
|
local install_folder
|
||||||
|
install_folder, err = configs.get_parser_install_dir()
|
||||||
|
if err then
|
||||||
|
return api.nvim_err_writeln(err)
|
||||||
|
end
|
||||||
|
install_folder = install_folder and clean_path(install_folder)
|
||||||
|
assert(install_folder)
|
||||||
|
|
||||||
|
local languages ---@type string[]
|
||||||
|
local ask ---@type boolean|string
|
||||||
|
if ... == "all" then
|
||||||
|
languages = parsers.available_parsers()
|
||||||
|
ask = false
|
||||||
|
else
|
||||||
|
languages = compat.flatten { ... }
|
||||||
|
ask = ask_reinstall
|
||||||
|
end
|
||||||
|
|
||||||
|
if exclude_configured_parsers then
|
||||||
|
languages = utils.difference(languages, configs.get_ignored_parser_installs())
|
||||||
|
end
|
||||||
|
|
||||||
|
if #languages > 1 then
|
||||||
|
reset_progress_counter()
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, lang in ipairs(languages) do
|
||||||
|
install_lang(lang, ask, cache_folder, install_folder, with_sync, generate_from_grammar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.setup_auto_install()
|
||||||
|
local function try_install_curr_lang()
|
||||||
|
local lang = parsers.get_buf_lang()
|
||||||
|
if parsers.get_parser_configs()[lang] and not is_installed(lang) and not is_ignored_parser(lang) then
|
||||||
|
install() { lang }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
try_install_curr_lang()
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = { "*" },
|
||||||
|
group = vim.api.nvim_create_augroup("NvimTreesitter-auto_install", { clear = true }),
|
||||||
|
callback = try_install_curr_lang,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.update(options)
|
||||||
|
options = options or {}
|
||||||
|
return function(...)
|
||||||
|
M.lockfile = {}
|
||||||
|
reset_progress_counter()
|
||||||
|
if ... and ... ~= "all" then
|
||||||
|
---@type string[]
|
||||||
|
local languages = compat.flatten { ... }
|
||||||
|
local installed = 0
|
||||||
|
for _, lang in ipairs(languages) do
|
||||||
|
if (not is_installed(lang)) or (needs_update(lang)) then
|
||||||
|
installed = installed + 1
|
||||||
|
install {
|
||||||
|
ask_reinstall = "force",
|
||||||
|
with_sync = options.with_sync,
|
||||||
|
}(lang)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if installed == 0 then
|
||||||
|
utils.notify "Parsers are up-to-date!"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local parsers_to_update = outdated_parsers() or info.installed_parsers()
|
||||||
|
if #parsers_to_update == 0 then
|
||||||
|
utils.notify "All parsers are up-to-date!"
|
||||||
|
end
|
||||||
|
for _, lang in pairs(parsers_to_update) do
|
||||||
|
install {
|
||||||
|
ask_reinstall = "force",
|
||||||
|
exclude_configured_parsers = true,
|
||||||
|
with_sync = options.with_sync,
|
||||||
|
}(lang)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.uninstall(...)
|
||||||
|
if vim.tbl_contains({ "all" }, ...) then
|
||||||
|
reset_progress_counter()
|
||||||
|
local installed = info.installed_parsers()
|
||||||
|
M.uninstall(installed)
|
||||||
|
elseif ... then
|
||||||
|
local ensure_installed_parsers = configs.get_ensure_installed_parsers()
|
||||||
|
if ensure_installed_parsers == "all" then
|
||||||
|
ensure_installed_parsers = parsers.available_parsers()
|
||||||
|
end
|
||||||
|
ensure_installed_parsers = utils.difference(ensure_installed_parsers, configs.get_ignored_parser_installs())
|
||||||
|
|
||||||
|
---@type string[]
|
||||||
|
local languages = compat.flatten { ... }
|
||||||
|
for _, lang in ipairs(languages) do
|
||||||
|
local install_dir, err = configs.get_parser_install_dir()
|
||||||
|
if err then
|
||||||
|
return api.nvim_err_writeln(err)
|
||||||
|
end
|
||||||
|
install_dir = install_dir and clean_path(install_dir)
|
||||||
|
|
||||||
|
if vim.tbl_contains(ensure_installed_parsers, lang) then
|
||||||
|
vim.notify(
|
||||||
|
"Uninstalling "
|
||||||
|
.. lang
|
||||||
|
.. '. But the parser is still configured in "ensure_installed" setting of nvim-treesitter.'
|
||||||
|
.. " Please consider updating your config!",
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local parser_lib = utils.join_path(install_dir, lang) .. ".so"
|
||||||
|
local all_parsers = vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", true)
|
||||||
|
if vim.fn.filereadable(parser_lib) == 1 then
|
||||||
|
local command_list = {
|
||||||
|
shell.select_rm_file_cmd(parser_lib, "Uninstalling parser for " .. lang),
|
||||||
|
{
|
||||||
|
cmd = function()
|
||||||
|
local all_parsers_after_deletion = vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", true)
|
||||||
|
if #all_parsers_after_deletion > 0 then
|
||||||
|
vim.notify(
|
||||||
|
"Tried to uninstall parser for "
|
||||||
|
.. lang
|
||||||
|
.. "! But the parser is still installed (not by nvim-treesitter):"
|
||||||
|
.. table.concat(all_parsers_after_deletion, ", "),
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{ -- auto-reattach or detach modules after uninstallation
|
||||||
|
cmd = reattach_if_possible_fn(lang, false),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been uninstalled")
|
||||||
|
elseif #all_parsers > 0 then
|
||||||
|
vim.notify(
|
||||||
|
"Parser for "
|
||||||
|
.. lang
|
||||||
|
.. " is installed! But not by nvim-treesitter! Please manually remove the following files: "
|
||||||
|
.. table.concat(all_parsers, ", "),
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.write_lockfile(verbose, skip_langs)
|
||||||
|
local sorted_parsers = {} ---@type Parser[]
|
||||||
|
-- Load previous lockfile
|
||||||
|
load_lockfile()
|
||||||
|
skip_langs = skip_langs or {}
|
||||||
|
|
||||||
|
for k, v in pairs(parsers.get_parser_configs()) do
|
||||||
|
table.insert(sorted_parsers, { name = k, parser = v })
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param a Parser
|
||||||
|
---@param b Parser
|
||||||
|
table.sort(sorted_parsers, function(a, b)
|
||||||
|
return a.name < b.name
|
||||||
|
end)
|
||||||
|
|
||||||
|
for _, v in ipairs(sorted_parsers) do
|
||||||
|
if not vim.tbl_contains(skip_langs, v.name) then
|
||||||
|
-- I'm sure this can be done in aync way with iter_cmd
|
||||||
|
local sha ---@type string
|
||||||
|
if v.parser.install_info.branch then
|
||||||
|
sha = vim.split(
|
||||||
|
vim.fn.systemlist(
|
||||||
|
"git ls-remote " .. v.parser.install_info.url .. " | grep refs/heads/" .. v.parser.install_info.branch
|
||||||
|
)[1],
|
||||||
|
"\t"
|
||||||
|
)[1]
|
||||||
|
else
|
||||||
|
sha = vim.split(vim.fn.systemlist("git ls-remote " .. v.parser.install_info.url)[1], "\t")[1]
|
||||||
|
end
|
||||||
|
lockfile[v.name] = { revision = sha }
|
||||||
|
if verbose then
|
||||||
|
print(v.name .. ": " .. sha)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("Skipping " .. v.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if verbose then
|
||||||
|
print(vim.inspect(lockfile))
|
||||||
|
end
|
||||||
|
vim.fn.writefile(
|
||||||
|
vim.fn.split(vim.fn.json_encode(lockfile), "\n"),
|
||||||
|
utils.join_path(utils.get_package_path(), "lockfile.json")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.ensure_installed = install { exclude_configured_parsers = true }
|
||||||
|
M.ensure_installed_sync = install { with_sync = true, exclude_configured_parsers = true }
|
||||||
|
|
||||||
|
M.commands = {
|
||||||
|
TSInstall = {
|
||||||
|
run = install { ask_reinstall = true },
|
||||||
|
["run!"] = install { ask_reinstall = "force" },
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSInstallFromGrammar = {
|
||||||
|
run = install { generate_from_grammar = true, ask_reinstall = true },
|
||||||
|
["run!"] = install { generate_from_grammar = true, ask_reinstall = "force" },
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSInstallSync = {
|
||||||
|
run = install { with_sync = true, ask_reinstall = true },
|
||||||
|
["run!"] = install { with_sync = true, ask_reinstall = "force" },
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-bang",
|
||||||
|
"-complete=custom,nvim_treesitter#installable_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSUpdate = {
|
||||||
|
run = M.update {},
|
||||||
|
args = {
|
||||||
|
"-nargs=*",
|
||||||
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSUpdateSync = {
|
||||||
|
run = M.update { with_sync = true },
|
||||||
|
args = {
|
||||||
|
"-nargs=*",
|
||||||
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TSUninstall = {
|
||||||
|
run = M.uninstall,
|
||||||
|
args = {
|
||||||
|
"-nargs=+",
|
||||||
|
"-complete=custom,nvim_treesitter#installed_parsers",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
365
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/locals.lua
Normal file
365
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/locals.lua
Normal file
|
@ -0,0 +1,365 @@
|
||||||
|
-- Functions to handle locals
|
||||||
|
-- Locals are a generalization of definition and scopes
|
||||||
|
-- its the way nvim-treesitter uses to "understand" the code
|
||||||
|
|
||||||
|
local queries = require "nvim-treesitter.query"
|
||||||
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
|
local ts = vim.treesitter
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.collect_locals(bufnr)
|
||||||
|
return queries.collect_group_results(bufnr, "locals")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Iterates matches from a locals query file.
|
||||||
|
-- @param bufnr the buffer
|
||||||
|
-- @param root the root node
|
||||||
|
function M.iter_locals(bufnr, root)
|
||||||
|
return queries.iter_group_results(bufnr, "locals", root)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return any
|
||||||
|
function M.get_locals(bufnr)
|
||||||
|
return queries.get_matches(bufnr, "locals")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Creates unique id for a node based on text and range
|
||||||
|
---@param scope TSNode: the scope node of the definition
|
||||||
|
---@param node_text string: the node text to use
|
||||||
|
---@return string: a string id
|
||||||
|
function M.get_definition_id(scope, node_text)
|
||||||
|
-- Add a valid starting character in case node text doesn't start with a valid one.
|
||||||
|
return table.concat({ "k", node_text or "", scope:range() }, "_")
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_definitions(bufnr)
|
||||||
|
local locals = M.get_locals(bufnr)
|
||||||
|
|
||||||
|
local defs = {}
|
||||||
|
|
||||||
|
for _, loc in ipairs(locals) do
|
||||||
|
if loc["local"]["definition"] then
|
||||||
|
table.insert(defs, loc["local"]["definition"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return defs
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_scopes(bufnr)
|
||||||
|
local locals = M.get_locals(bufnr)
|
||||||
|
|
||||||
|
local scopes = {}
|
||||||
|
|
||||||
|
for _, loc in ipairs(locals) do
|
||||||
|
if loc["local"]["scope"] and loc["local"]["scope"].node then
|
||||||
|
table.insert(scopes, loc["local"]["scope"].node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return scopes
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_references(bufnr)
|
||||||
|
local locals = M.get_locals(bufnr)
|
||||||
|
|
||||||
|
local refs = {}
|
||||||
|
|
||||||
|
for _, loc in ipairs(locals) do
|
||||||
|
if loc["local"]["reference"] and loc["local"]["reference"].node then
|
||||||
|
table.insert(refs, loc["local"]["reference"].node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return refs
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets a table with all the scopes containing a node
|
||||||
|
-- The order is from most specific to least (bottom up)
|
||||||
|
---@param node TSNode
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return TSNode[]
|
||||||
|
function M.get_scope_tree(node, bufnr)
|
||||||
|
local scopes = {} ---@type TSNode[]
|
||||||
|
|
||||||
|
for scope in M.iter_scope_tree(node, bufnr) do
|
||||||
|
table.insert(scopes, scope)
|
||||||
|
end
|
||||||
|
|
||||||
|
return scopes
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Iterates over a nodes scopes moving from the bottom up
|
||||||
|
---@param node TSNode
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return fun(): TSNode|nil
|
||||||
|
function M.iter_scope_tree(node, bufnr)
|
||||||
|
local last_node = node
|
||||||
|
return function()
|
||||||
|
if not last_node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local scope = M.containing_scope(last_node, bufnr, false) or ts_utils.get_root_for_node(node)
|
||||||
|
|
||||||
|
last_node = scope:parent()
|
||||||
|
|
||||||
|
return scope
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets a table of all nodes and their 'kinds' from a locals list
|
||||||
|
---@param local_def any: the local list result
|
||||||
|
---@return table: a list of node entries
|
||||||
|
function M.get_local_nodes(local_def)
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
M.recurse_local_nodes(local_def, function(def, _node, kind)
|
||||||
|
table.insert(result, vim.tbl_extend("keep", { kind = kind }, def))
|
||||||
|
end)
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Recurse locals results until a node is found.
|
||||||
|
-- The accumulator function is given
|
||||||
|
-- * The table of the node
|
||||||
|
-- * The node
|
||||||
|
-- * The full definition match `@definition.var.something` -> 'var.something'
|
||||||
|
-- * The last definition match `@definition.var.something` -> 'something'
|
||||||
|
---@param local_def any The locals result
|
||||||
|
---@param accumulator function The accumulator function
|
||||||
|
---@param full_match? string The full match path to append to
|
||||||
|
---@param last_match? string The last match
|
||||||
|
function M.recurse_local_nodes(local_def, accumulator, full_match, last_match)
|
||||||
|
if type(local_def) ~= "table" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if local_def.node then
|
||||||
|
accumulator(local_def, local_def.node, full_match, last_match)
|
||||||
|
else
|
||||||
|
for match_key, def in pairs(local_def) do
|
||||||
|
M.recurse_local_nodes(def, accumulator, full_match and (full_match .. "." .. match_key) or match_key, match_key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get a single dimension table to look definition nodes.
|
||||||
|
-- Keys are generated by using the range of the containing scope and the text of the definition node.
|
||||||
|
-- This makes looking up a definition for a given scope a simple key lookup.
|
||||||
|
--
|
||||||
|
-- This is memoized by buffer tick. If the function is called in succession
|
||||||
|
-- without the buffer tick changing, then the previous result will be used
|
||||||
|
-- since the syntax tree hasn't changed.
|
||||||
|
--
|
||||||
|
-- Usage lookups require finding the definition of the node, so `find_definition`
|
||||||
|
-- is called very frequently, which is why this lookup must be fast as possible.
|
||||||
|
--
|
||||||
|
---@param bufnr integer: the buffer
|
||||||
|
---@return table result: a table for looking up definitions
|
||||||
|
M.get_definitions_lookup_table = ts_utils.memoize_by_buf_tick(function(bufnr)
|
||||||
|
local definitions = M.get_definitions(bufnr)
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
for _, definition in ipairs(definitions) do
|
||||||
|
for _, node_entry in ipairs(M.get_local_nodes(definition)) do
|
||||||
|
local scopes = M.get_definition_scopes(node_entry.node, bufnr, node_entry.scope)
|
||||||
|
-- Always use the highest valid scope
|
||||||
|
local scope = scopes[#scopes]
|
||||||
|
local node_text = ts.get_node_text(node_entry.node, bufnr)
|
||||||
|
local id = M.get_definition_id(scope, node_text)
|
||||||
|
|
||||||
|
result[id] = node_entry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Gets all the scopes of a definition based on the scope type
|
||||||
|
-- Scope types can be
|
||||||
|
--
|
||||||
|
-- "parent": Uses the parent of the containing scope, basically, skipping a scope
|
||||||
|
-- "global": Uses the top most scope
|
||||||
|
-- "local": Uses the containing scope of the definition. This is the default
|
||||||
|
--
|
||||||
|
---@param node TSNode: the definition node
|
||||||
|
---@param bufnr integer: the buffer
|
||||||
|
---@param scope_type string: the scope type
|
||||||
|
function M.get_definition_scopes(node, bufnr, scope_type)
|
||||||
|
local scopes = {}
|
||||||
|
local scope_count = 1 ---@type integer|nil
|
||||||
|
|
||||||
|
-- Definition is valid for the containing scope
|
||||||
|
-- and the containing scope of that scope
|
||||||
|
if scope_type == "parent" then
|
||||||
|
scope_count = 2
|
||||||
|
-- Definition is valid in all parent scopes
|
||||||
|
elseif scope_type == "global" then
|
||||||
|
scope_count = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local i = 0
|
||||||
|
for scope in M.iter_scope_tree(node, bufnr) do
|
||||||
|
table.insert(scopes, scope)
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
if scope_count and i >= scope_count then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return scopes
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return TSNode node
|
||||||
|
---@return TSNode scope
|
||||||
|
---@return string|nil kind
|
||||||
|
function M.find_definition(node, bufnr)
|
||||||
|
local def_lookup = M.get_definitions_lookup_table(bufnr)
|
||||||
|
local node_text = ts.get_node_text(node, bufnr)
|
||||||
|
|
||||||
|
for scope in M.iter_scope_tree(node, bufnr) do
|
||||||
|
local id = M.get_definition_id(scope, node_text)
|
||||||
|
|
||||||
|
if def_lookup[id] then
|
||||||
|
local entry = def_lookup[id]
|
||||||
|
|
||||||
|
return entry.node, scope, entry.kind
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return node, ts_utils.get_root_for_node(node), nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Finds usages of a node in a given scope.
|
||||||
|
---@param node TSNode the node to find usages for
|
||||||
|
---@param scope_node TSNode the node to look within
|
||||||
|
---@return TSNode[]: a list of nodes
|
||||||
|
function M.find_usages(node, scope_node, bufnr)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
local node_text = ts.get_node_text(node, bufnr)
|
||||||
|
|
||||||
|
if not node_text or #node_text < 1 then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local scope_node = scope_node or ts_utils.get_root_for_node(node)
|
||||||
|
local usages = {}
|
||||||
|
|
||||||
|
for match in M.iter_locals(bufnr, scope_node) do
|
||||||
|
match = match["local"]
|
||||||
|
if match.reference and match.reference.node and ts.get_node_text(match.reference.node, bufnr) == node_text then
|
||||||
|
local def_node, _, kind = M.find_definition(match.reference.node, bufnr)
|
||||||
|
|
||||||
|
if kind == nil or def_node == node then
|
||||||
|
table.insert(usages, match.reference.node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return usages
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@param bufnr? integer
|
||||||
|
---@param allow_scope? boolean
|
||||||
|
---@return TSNode|nil
|
||||||
|
function M.containing_scope(node, bufnr, allow_scope)
|
||||||
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
local allow_scope = allow_scope == nil or allow_scope == true
|
||||||
|
|
||||||
|
local scopes = M.get_scopes(bufnr)
|
||||||
|
if not node or not scopes then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local iter_node = node
|
||||||
|
|
||||||
|
while iter_node ~= nil and not vim.tbl_contains(scopes, iter_node) do
|
||||||
|
iter_node = iter_node:parent()
|
||||||
|
end
|
||||||
|
|
||||||
|
return iter_node or (allow_scope and node or nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.nested_scope(node, cursor_pos)
|
||||||
|
local bufnr = api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local scopes = M.get_scopes(bufnr)
|
||||||
|
if not node or not scopes then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local row = cursor_pos.row ---@type integer
|
||||||
|
local col = cursor_pos.col ---@type integer
|
||||||
|
local scope = M.containing_scope(node)
|
||||||
|
|
||||||
|
for _, child in ipairs(ts_utils.get_named_children(scope)) do
|
||||||
|
local row_, col_ = child:start()
|
||||||
|
if vim.tbl_contains(scopes, child) and ((row_ + 1 == row and col_ > col) or row_ + 1 > row) then
|
||||||
|
return child
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.next_scope(node)
|
||||||
|
local bufnr = api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local scopes = M.get_scopes(bufnr)
|
||||||
|
if not node or not scopes then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local scope = M.containing_scope(node)
|
||||||
|
|
||||||
|
local parent = scope:parent()
|
||||||
|
if not parent then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_prev = true
|
||||||
|
for _, child in ipairs(ts_utils.get_named_children(parent)) do
|
||||||
|
if child == scope then
|
||||||
|
is_prev = false
|
||||||
|
elseif not is_prev and vim.tbl_contains(scopes, child) then
|
||||||
|
return child
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@return TSNode|nil
|
||||||
|
function M.previous_scope(node)
|
||||||
|
local bufnr = api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local scopes = M.get_scopes(bufnr)
|
||||||
|
if not node or not scopes then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local scope = M.containing_scope(node)
|
||||||
|
|
||||||
|
local parent = scope:parent()
|
||||||
|
if not parent then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_prev = true
|
||||||
|
local children = ts_utils.get_named_children(parent)
|
||||||
|
for i = #children, 1, -1 do
|
||||||
|
if children[i] == scope then
|
||||||
|
is_prev = false
|
||||||
|
elseif not is_prev and vim.tbl_contains(scopes, children[i]) then
|
||||||
|
return children[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
2693
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/parsers.lua
Normal file
2693
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/parsers.lua
Normal file
File diff suppressed because it is too large
Load diff
453
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/query.lua
Normal file
453
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/query.lua
Normal file
|
@ -0,0 +1,453 @@
|
||||||
|
local api = vim.api
|
||||||
|
local ts = require "nvim-treesitter.compat"
|
||||||
|
local tsrange = require "nvim-treesitter.tsrange"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local caching = require "nvim-treesitter.caching"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local EMPTY_ITER = function() end
|
||||||
|
|
||||||
|
M.built_in_query_groups = { "highlights", "locals", "folds", "indents", "injections" }
|
||||||
|
|
||||||
|
-- Creates a function that checks whether a given query exists
|
||||||
|
-- for a specific language.
|
||||||
|
---@param query string
|
||||||
|
---@return fun(string): boolean
|
||||||
|
local function get_query_guard(query)
|
||||||
|
return function(lang)
|
||||||
|
return M.has_query_files(lang, query)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, query in ipairs(M.built_in_query_groups) do
|
||||||
|
M["has_" .. query] = get_query_guard(query)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return string[]
|
||||||
|
function M.available_query_groups()
|
||||||
|
local query_files = api.nvim_get_runtime_file("queries/*/*.scm", true)
|
||||||
|
local groups = {}
|
||||||
|
for _, f in ipairs(query_files) do
|
||||||
|
groups[vim.fn.fnamemodify(f, ":t:r")] = true
|
||||||
|
end
|
||||||
|
local list = {}
|
||||||
|
for k, _ in pairs(groups) do
|
||||||
|
table.insert(list, k)
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local query_cache = caching.create_buffer_cache()
|
||||||
|
|
||||||
|
local function update_cached_matches(bufnr, changed_tick, query_group)
|
||||||
|
query_cache.set(query_group, bufnr, {
|
||||||
|
tick = changed_tick,
|
||||||
|
cache = M.collect_group_results(bufnr, query_group) or {},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param query_group string
|
||||||
|
---@return any
|
||||||
|
function M.get_matches(bufnr, query_group)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
local cached_local = query_cache.get(query_group, bufnr)
|
||||||
|
if not cached_local or api.nvim_buf_get_changedtick(bufnr) > cached_local.tick then
|
||||||
|
update_cached_matches(bufnr, api.nvim_buf_get_changedtick(bufnr), query_group)
|
||||||
|
end
|
||||||
|
|
||||||
|
return query_cache.get(query_group, bufnr).cache
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@param query_name string
|
||||||
|
---@return string[]
|
||||||
|
local function runtime_queries(lang, query_name)
|
||||||
|
return api.nvim_get_runtime_file(string.format("queries/%s/%s.scm", lang, query_name), true) or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type table<string, table<string, boolean>>
|
||||||
|
local query_files_cache = {}
|
||||||
|
|
||||||
|
---@param lang string
|
||||||
|
---@param query_name string
|
||||||
|
---@return boolean
|
||||||
|
function M.has_query_files(lang, query_name)
|
||||||
|
if not query_files_cache[lang] then
|
||||||
|
query_files_cache[lang] = {}
|
||||||
|
end
|
||||||
|
if query_files_cache[lang][query_name] == nil then
|
||||||
|
local files = runtime_queries(lang, query_name)
|
||||||
|
query_files_cache[lang][query_name] = files and #files > 0
|
||||||
|
end
|
||||||
|
return query_files_cache[lang][query_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local mt = {}
|
||||||
|
mt.__index = function(tbl, key)
|
||||||
|
if rawget(tbl, key) == nil then
|
||||||
|
rawset(tbl, key, {})
|
||||||
|
end
|
||||||
|
return rawget(tbl, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- cache will auto set the table for each lang if it is nil
|
||||||
|
---@type table<string, table<string, Query>>
|
||||||
|
local cache = setmetatable({}, mt)
|
||||||
|
|
||||||
|
-- Same as `vim.treesitter.query` except will return cached values
|
||||||
|
---@param lang string
|
||||||
|
---@param query_name string
|
||||||
|
function M.get_query(lang, query_name)
|
||||||
|
if cache[lang][query_name] == nil then
|
||||||
|
cache[lang][query_name] = ts.get_query(lang, query_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
return cache[lang][query_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Invalidates the query file cache.
|
||||||
|
--
|
||||||
|
-- If lang and query_name is both present, will reload for only the lang and query_name.
|
||||||
|
-- If only lang is present, will reload all query_names for that lang
|
||||||
|
-- If none are present, will reload everything
|
||||||
|
---@param lang? string
|
||||||
|
---@param query_name? string
|
||||||
|
function M.invalidate_query_cache(lang, query_name)
|
||||||
|
if lang and query_name then
|
||||||
|
cache[lang][query_name] = nil
|
||||||
|
if query_files_cache[lang] then
|
||||||
|
query_files_cache[lang][query_name] = nil
|
||||||
|
end
|
||||||
|
elseif lang and not query_name then
|
||||||
|
query_files_cache[lang] = nil
|
||||||
|
for query_name0, _ in pairs(cache[lang]) do
|
||||||
|
M.invalidate_query_cache(lang, query_name0)
|
||||||
|
end
|
||||||
|
elseif not lang and not query_name then
|
||||||
|
query_files_cache = {}
|
||||||
|
for lang0, _ in pairs(cache) do
|
||||||
|
for query_name0, _ in pairs(cache[lang0]) do
|
||||||
|
M.invalidate_query_cache(lang0, query_name0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error "Cannot have query_name by itself!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- This function is meant for an autocommand and not to be used. Only use if file is a query file.
|
||||||
|
---@param fname string
|
||||||
|
function M.invalidate_query_file(fname)
|
||||||
|
local fnamemodify = vim.fn.fnamemodify
|
||||||
|
M.invalidate_query_cache(fnamemodify(fname, ":p:h:t"), fnamemodify(fname, ":t:r"))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class QueryInfo
|
||||||
|
---@field root TSNode
|
||||||
|
---@field source integer
|
||||||
|
---@field start integer
|
||||||
|
---@field stop integer
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param query_name string
|
||||||
|
---@param root TSNode
|
||||||
|
---@param root_lang string|nil
|
||||||
|
---@return Query|nil, QueryInfo|nil
|
||||||
|
local function prepare_query(bufnr, query_name, root, root_lang)
|
||||||
|
local buf_lang = parsers.get_buf_lang(bufnr)
|
||||||
|
|
||||||
|
if not buf_lang then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local parser = parsers.get_parser(bufnr, buf_lang)
|
||||||
|
if not parser then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not root then
|
||||||
|
local first_tree = parser:trees()[1]
|
||||||
|
|
||||||
|
if first_tree then
|
||||||
|
root = first_tree:root()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not root then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local range = { root:range() }
|
||||||
|
|
||||||
|
if not root_lang then
|
||||||
|
local lang_tree = parser:language_for_range(range)
|
||||||
|
|
||||||
|
if lang_tree then
|
||||||
|
root_lang = lang_tree:lang()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not root_lang then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local query = M.get_query(root_lang, query_name)
|
||||||
|
if not query then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return query,
|
||||||
|
{
|
||||||
|
root = root,
|
||||||
|
source = bufnr,
|
||||||
|
start = range[1],
|
||||||
|
-- The end row is exclusive so we need to add 1 to it.
|
||||||
|
stop = range[3] + 1,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Given a path (i.e. a List(String)) this functions inserts value at path
|
||||||
|
---@param object any
|
||||||
|
---@param path string[]
|
||||||
|
---@param value any
|
||||||
|
function M.insert_to_path(object, path, value)
|
||||||
|
local curr_obj = object
|
||||||
|
|
||||||
|
for index = 1, (#path - 1) do
|
||||||
|
if curr_obj[path[index]] == nil then
|
||||||
|
curr_obj[path[index]] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
curr_obj = curr_obj[path[index]]
|
||||||
|
end
|
||||||
|
|
||||||
|
curr_obj[path[#path]] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param query Query
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param start_row integer
|
||||||
|
---@param end_row integer
|
||||||
|
function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row)
|
||||||
|
-- A function that splits a string on '.'
|
||||||
|
---@param to_split string
|
||||||
|
---@return string[]
|
||||||
|
local function split(to_split)
|
||||||
|
local t = {}
|
||||||
|
for str in string.gmatch(to_split, "([^.]+)") do
|
||||||
|
table.insert(t, str)
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local matches = query:iter_matches(qnode, bufnr, start_row, end_row, { all = false })
|
||||||
|
|
||||||
|
local function iterator()
|
||||||
|
local pattern, match, metadata = matches()
|
||||||
|
if pattern ~= nil then
|
||||||
|
local prepared_match = {}
|
||||||
|
|
||||||
|
-- Extract capture names from each match
|
||||||
|
for id, node in pairs(match) do
|
||||||
|
local name = query.captures[id] -- name of the capture in the query
|
||||||
|
if name ~= nil then
|
||||||
|
local path = split(name .. ".node")
|
||||||
|
M.insert_to_path(prepared_match, path, node)
|
||||||
|
local metadata_path = split(name .. ".metadata")
|
||||||
|
M.insert_to_path(prepared_match, metadata_path, metadata[id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add some predicates for testing
|
||||||
|
---@type string[][] ( TODO: make pred type so this can be pred[])
|
||||||
|
local preds = query.info.patterns[pattern]
|
||||||
|
if preds then
|
||||||
|
for _, pred in pairs(preds) do
|
||||||
|
-- functions
|
||||||
|
if pred[1] == "set!" and type(pred[2]) == "string" then
|
||||||
|
M.insert_to_path(prepared_match, split(pred[2]), pred[3])
|
||||||
|
end
|
||||||
|
if pred[1] == "make-range!" and type(pred[2]) == "string" and #pred == 4 then
|
||||||
|
M.insert_to_path(
|
||||||
|
prepared_match,
|
||||||
|
split(pred[2] .. ".node"),
|
||||||
|
tsrange.TSRange.from_nodes(bufnr, match[pred[3]], match[pred[4]])
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return prepared_match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return iterator
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Return all nodes corresponding to a specific capture path (like @definition.var, @reference.type)
|
||||||
|
-- Works like M.get_references or M.get_scopes except you can choose the capture
|
||||||
|
-- Can also be a nested capture like @definition.function to get all nodes defining a function.
|
||||||
|
--
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
---@param captures string|string[]
|
||||||
|
---@param query_group string the name of query group (highlights or injections for example)
|
||||||
|
---@param root TSNode|nil node from where to start the search
|
||||||
|
---@param lang string|nil the language from where to get the captures.
|
||||||
|
--- Root nodes can have several languages.
|
||||||
|
---@return table|nil
|
||||||
|
function M.get_capture_matches(bufnr, captures, query_group, root, lang)
|
||||||
|
if type(captures) == "string" then
|
||||||
|
captures = { captures }
|
||||||
|
end
|
||||||
|
local strip_captures = {} ---@type string[]
|
||||||
|
for i, capture in ipairs(captures) do
|
||||||
|
if capture:sub(1, 1) ~= "@" then
|
||||||
|
error 'Captures must start with "@"'
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- Remove leading "@".
|
||||||
|
strip_captures[i] = capture:sub(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local matches = {}
|
||||||
|
for match in M.iter_group_results(bufnr, query_group, root, lang) do
|
||||||
|
for _, capture in ipairs(strip_captures) do
|
||||||
|
local insert = utils.get_at_path(match, capture)
|
||||||
|
if insert then
|
||||||
|
table.insert(matches, insert)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return matches
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.iter_captures(bufnr, query_name, root, lang)
|
||||||
|
local query, params = prepare_query(bufnr, query_name, root, lang)
|
||||||
|
if not query then
|
||||||
|
return EMPTY_ITER
|
||||||
|
end
|
||||||
|
assert(params)
|
||||||
|
|
||||||
|
local iter = query:iter_captures(params.root, params.source, params.start, params.stop)
|
||||||
|
|
||||||
|
local function wrapped_iter()
|
||||||
|
local id, node, metadata = iter()
|
||||||
|
if not id then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local name = query.captures[id]
|
||||||
|
if string.sub(name, 1, 1) == "_" then
|
||||||
|
return wrapped_iter()
|
||||||
|
end
|
||||||
|
|
||||||
|
return name, node, metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
return wrapped_iter
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param capture_string string
|
||||||
|
---@param query_group string
|
||||||
|
---@param filter_predicate fun(match: table): boolean
|
||||||
|
---@param scoring_function fun(match: table): number
|
||||||
|
---@param root TSNode
|
||||||
|
---@return table|unknown
|
||||||
|
function M.find_best_match(bufnr, capture_string, query_group, filter_predicate, scoring_function, root)
|
||||||
|
if string.sub(capture_string, 1, 1) == "@" then
|
||||||
|
--remove leading "@"
|
||||||
|
capture_string = string.sub(capture_string, 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local best ---@type table|nil
|
||||||
|
local best_score ---@type number
|
||||||
|
|
||||||
|
for maybe_match in M.iter_group_results(bufnr, query_group, root) do
|
||||||
|
local match = utils.get_at_path(maybe_match, capture_string)
|
||||||
|
|
||||||
|
if match and filter_predicate(match) then
|
||||||
|
local current_score = scoring_function(match)
|
||||||
|
if not best then
|
||||||
|
best = match
|
||||||
|
best_score = current_score
|
||||||
|
end
|
||||||
|
if current_score > best_score then
|
||||||
|
best = match
|
||||||
|
best_score = current_score
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return best
|
||||||
|
end
|
||||||
|
|
||||||
|
---Iterates matches from a query file.
|
||||||
|
---@param bufnr integer the buffer
|
||||||
|
---@param query_group string the query file to use
|
||||||
|
---@param root TSNode the root node
|
||||||
|
---@param root_lang? string the root node lang, if known
|
||||||
|
function M.iter_group_results(bufnr, query_group, root, root_lang)
|
||||||
|
local query, params = prepare_query(bufnr, query_group, root, root_lang)
|
||||||
|
if not query then
|
||||||
|
return EMPTY_ITER
|
||||||
|
end
|
||||||
|
assert(params)
|
||||||
|
|
||||||
|
return M.iter_prepared_matches(query, params.root, params.source, params.start, params.stop)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.collect_group_results(bufnr, query_group, root, lang)
|
||||||
|
local matches = {}
|
||||||
|
|
||||||
|
for prepared_match in M.iter_group_results(bufnr, query_group, root, lang) do
|
||||||
|
table.insert(matches, prepared_match)
|
||||||
|
end
|
||||||
|
|
||||||
|
return matches
|
||||||
|
end
|
||||||
|
|
||||||
|
---@alias CaptureResFn function(string, LanguageTree, LanguageTree): string, string
|
||||||
|
|
||||||
|
-- Same as get_capture_matches except this will recursively get matches for every language in the tree.
|
||||||
|
---@param bufnr integer The buffer
|
||||||
|
---@param capture_or_fn string|CaptureResFn The capture to get. If a function is provided then that
|
||||||
|
--- function will be used to resolve both the capture and query argument.
|
||||||
|
--- The function can return `nil` to ignore that tree.
|
||||||
|
---@param query_type string? The query to get the capture from. This is ignored if a function is provided
|
||||||
|
--- for the capture argument.
|
||||||
|
---@return table[]
|
||||||
|
function M.get_capture_matches_recursively(bufnr, capture_or_fn, query_type)
|
||||||
|
---@type CaptureResFn
|
||||||
|
local type_fn
|
||||||
|
if type(capture_or_fn) == "function" then
|
||||||
|
type_fn = capture_or_fn
|
||||||
|
else
|
||||||
|
type_fn = function(_, _, _)
|
||||||
|
return capture_or_fn, query_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local parser = parsers.get_parser(bufnr)
|
||||||
|
local matches = {}
|
||||||
|
|
||||||
|
if parser then
|
||||||
|
parser:for_each_tree(function(tree, lang_tree)
|
||||||
|
local lang = lang_tree:lang()
|
||||||
|
local capture, type_ = type_fn(lang, tree, lang_tree)
|
||||||
|
|
||||||
|
if capture then
|
||||||
|
vim.list_extend(matches, M.get_capture_matches(bufnr, capture, type_, tree:root(), lang) or {})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return matches
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,241 @@
|
||||||
|
local query = require "vim.treesitter.query"
|
||||||
|
|
||||||
|
local html_script_type_languages = {
|
||||||
|
["importmap"] = "json",
|
||||||
|
["module"] = "javascript",
|
||||||
|
["application/ecmascript"] = "javascript",
|
||||||
|
["text/ecmascript"] = "javascript",
|
||||||
|
}
|
||||||
|
|
||||||
|
local non_filetype_match_injection_language_aliases = {
|
||||||
|
ex = "elixir",
|
||||||
|
pl = "perl",
|
||||||
|
sh = "bash",
|
||||||
|
uxn = "uxntal",
|
||||||
|
ts = "typescript",
|
||||||
|
}
|
||||||
|
|
||||||
|
-- compatibility shim for breaking change on nightly/0.11
|
||||||
|
local opts = vim.fn.has "nvim-0.10" == 1 and { force = true, all = false } or true
|
||||||
|
|
||||||
|
local function get_parser_from_markdown_info_string(injection_alias)
|
||||||
|
local match = vim.filetype.match { filename = "a." .. injection_alias }
|
||||||
|
return match or non_filetype_match_injection_language_aliases[injection_alias] or injection_alias
|
||||||
|
end
|
||||||
|
|
||||||
|
local function error(str)
|
||||||
|
vim.api.nvim_err_writeln(str)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function valid_args(name, pred, count, strict_count)
|
||||||
|
local arg_count = #pred - 1
|
||||||
|
|
||||||
|
if strict_count then
|
||||||
|
if arg_count ~= count then
|
||||||
|
error(string.format("%s must have exactly %d arguments", name, count))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
elseif arg_count < count then
|
||||||
|
error(string.format("%s must have at least %d arguments", name, count))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _pattern string
|
||||||
|
---@param _bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_predicate("nth?", function(match, _pattern, _bufnr, pred)
|
||||||
|
if not valid_args("nth?", pred, 2, true) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = match[pred[2]] ---@type TSNode
|
||||||
|
local n = tonumber(pred[3])
|
||||||
|
if node and node:parent() and node:parent():named_child_count() > n then
|
||||||
|
return node:parent():named_child(n) == node
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _pattern string
|
||||||
|
---@param _bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
local function has_ancestor(match, _pattern, _bufnr, pred)
|
||||||
|
if not valid_args(pred[1], pred, 2) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = match[pred[2]]
|
||||||
|
local ancestor_types = { unpack(pred, 3) }
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local just_direct_parent = pred[1]:find("has-parent", 1, true)
|
||||||
|
|
||||||
|
node = node:parent()
|
||||||
|
while node do
|
||||||
|
if vim.tbl_contains(ancestor_types, node:type()) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if just_direct_parent then
|
||||||
|
node = nil
|
||||||
|
else
|
||||||
|
node = node:parent()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
query.add_predicate("has-ancestor?", has_ancestor, opts)
|
||||||
|
|
||||||
|
query.add_predicate("has-parent?", has_ancestor, opts)
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _pattern string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_predicate("is?", function(match, _pattern, bufnr, pred)
|
||||||
|
if not valid_args("is?", pred, 2) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Avoid circular dependencies
|
||||||
|
local locals = require "nvim-treesitter.locals"
|
||||||
|
local node = match[pred[2]]
|
||||||
|
local types = { unpack(pred, 3) }
|
||||||
|
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local _, _, kind = locals.find_definition(node, bufnr)
|
||||||
|
|
||||||
|
return vim.tbl_contains(types, kind)
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _pattern string
|
||||||
|
---@param _bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_predicate("kind-eq?", function(match, _pattern, _bufnr, pred)
|
||||||
|
if not valid_args(pred[1], pred, 2) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = match[pred[2]]
|
||||||
|
local types = { unpack(pred, 3) }
|
||||||
|
|
||||||
|
if not node then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return vim.tbl_contains(types, node:type())
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _ string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, metadata)
|
||||||
|
local capture_id = pred[2]
|
||||||
|
local node = match[capture_id]
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local type_attr_value = vim.treesitter.get_node_text(node, bufnr)
|
||||||
|
local configured = html_script_type_languages[type_attr_value]
|
||||||
|
if configured then
|
||||||
|
metadata["injection.language"] = configured
|
||||||
|
else
|
||||||
|
local parts = vim.split(type_attr_value, "/", {})
|
||||||
|
metadata["injection.language"] = parts[#parts]
|
||||||
|
end
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _ string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred, metadata)
|
||||||
|
local capture_id = pred[2]
|
||||||
|
local node = match[capture_id]
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local injection_alias = vim.treesitter.get_node_text(node, bufnr):lower()
|
||||||
|
metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
-- Just avoid some annoying warnings for this directive
|
||||||
|
query.add_directive("make-range!", function() end, opts)
|
||||||
|
|
||||||
|
--- transform node text to lower case (e.g., to make @injection.language case insensitive)
|
||||||
|
---
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _ string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@return boolean|nil
|
||||||
|
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
||||||
|
local id = pred[2]
|
||||||
|
local node = match[id]
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or ""
|
||||||
|
if not metadata[id] then
|
||||||
|
metadata[id] = {}
|
||||||
|
end
|
||||||
|
metadata[id].text = string.lower(text)
|
||||||
|
end, opts)
|
||||||
|
|
||||||
|
-- Trim blank lines from end of the region
|
||||||
|
-- Arguments are the captures to trim.
|
||||||
|
---@param match (TSNode|nil)[]
|
||||||
|
---@param _ string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@param pred string[]
|
||||||
|
---@param metadata table
|
||||||
|
query.add_directive("trim!", function(match, _, bufnr, pred, metadata)
|
||||||
|
for _, id in ipairs { select(2, unpack(pred)) } do
|
||||||
|
local node = match[id]
|
||||||
|
local start_row, start_col, end_row, end_col = node:range()
|
||||||
|
|
||||||
|
-- Don't trim if region ends in middle of a line
|
||||||
|
if end_col ~= 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
-- As we only care when end_col == 0, always inspect one line above end_row.
|
||||||
|
local end_line = vim.api.nvim_buf_get_lines(bufnr, end_row - 1, end_row, true)[1]
|
||||||
|
|
||||||
|
if end_line ~= "" then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
end_row = end_row - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If this produces an invalid range, we just skip it.
|
||||||
|
if start_row < end_row or (start_row == end_row and start_col <= end_col) then
|
||||||
|
if not metadata[id] then
|
||||||
|
metadata[id] = {}
|
||||||
|
end
|
||||||
|
metadata[id].range = { start_row, start_col, end_row, end_col }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, opts)
|
|
@ -0,0 +1,365 @@
|
||||||
|
local fn = vim.fn
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local uv = vim.uv or vim.loop
|
||||||
|
|
||||||
|
-- Convert path for cmd.exe on Windows.
|
||||||
|
-- This is needed when vim.opt.shellslash is in use.
|
||||||
|
---@param p string
|
||||||
|
---@return string
|
||||||
|
local function cmdpath(p)
|
||||||
|
if vim.opt.shellslash:get() then
|
||||||
|
local r = p:gsub("/", "\\")
|
||||||
|
return r
|
||||||
|
else
|
||||||
|
return p
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Returns the mkdir command based on the OS
|
||||||
|
---@param directory string
|
||||||
|
---@param cwd string
|
||||||
|
---@param info_msg string
|
||||||
|
---@return table
|
||||||
|
function M.select_mkdir_cmd(directory, cwd, info_msg)
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
return {
|
||||||
|
cmd = "cmd",
|
||||||
|
opts = {
|
||||||
|
args = { "/C", "mkdir", cmdpath(directory) },
|
||||||
|
cwd = cwd,
|
||||||
|
},
|
||||||
|
info = info_msg,
|
||||||
|
err = "Could not create " .. directory,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = "mkdir",
|
||||||
|
opts = {
|
||||||
|
args = { directory },
|
||||||
|
cwd = cwd,
|
||||||
|
},
|
||||||
|
info = info_msg,
|
||||||
|
err = "Could not create " .. directory,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the remove command based on the OS
|
||||||
|
---@param file string
|
||||||
|
---@param info_msg string
|
||||||
|
---@return table
|
||||||
|
function M.select_rm_file_cmd(file, info_msg)
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
return {
|
||||||
|
cmd = "cmd",
|
||||||
|
opts = {
|
||||||
|
args = { "/C", "if", "exist", cmdpath(file), "del", cmdpath(file) },
|
||||||
|
},
|
||||||
|
info = info_msg,
|
||||||
|
err = "Could not delete " .. file,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = "rm",
|
||||||
|
opts = {
|
||||||
|
args = { file },
|
||||||
|
},
|
||||||
|
info = info_msg,
|
||||||
|
err = "Could not delete " .. file,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param executables string[]
|
||||||
|
---@return string|nil
|
||||||
|
function M.select_executable(executables)
|
||||||
|
return vim.tbl_filter(function(c) ---@param c string
|
||||||
|
return c ~= vim.NIL and fn.executable(c) == 1
|
||||||
|
end, executables)[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the compiler arguments based on the compiler and OS
|
||||||
|
---@param repo InstallInfo
|
||||||
|
---@param compiler string
|
||||||
|
---@return string[]
|
||||||
|
function M.select_compiler_args(repo, compiler)
|
||||||
|
if string.match(compiler, "cl$") or string.match(compiler, "cl.exe$") then
|
||||||
|
return {
|
||||||
|
"/Fe:",
|
||||||
|
"parser.so",
|
||||||
|
"/Isrc",
|
||||||
|
repo.files,
|
||||||
|
"-Os",
|
||||||
|
"/utf-8",
|
||||||
|
"/LD",
|
||||||
|
}
|
||||||
|
elseif string.match(compiler, "zig$") or string.match(compiler, "zig.exe$") then
|
||||||
|
return {
|
||||||
|
"c++",
|
||||||
|
"-o",
|
||||||
|
"parser.so",
|
||||||
|
repo.files,
|
||||||
|
"-lc",
|
||||||
|
"-Isrc",
|
||||||
|
"-shared",
|
||||||
|
"-Os",
|
||||||
|
}
|
||||||
|
else
|
||||||
|
local args = {
|
||||||
|
"-o",
|
||||||
|
"parser.so",
|
||||||
|
"-I./src",
|
||||||
|
repo.files,
|
||||||
|
"-Os",
|
||||||
|
}
|
||||||
|
if fn.has "mac" == 1 then
|
||||||
|
table.insert(args, "-bundle")
|
||||||
|
else
|
||||||
|
table.insert(args, "-shared")
|
||||||
|
end
|
||||||
|
if
|
||||||
|
#vim.tbl_filter(function(file) ---@param file string
|
||||||
|
local ext = vim.fn.fnamemodify(file, ":e")
|
||||||
|
return ext == "cc" or ext == "cpp" or ext == "cxx"
|
||||||
|
end, repo.files) > 0
|
||||||
|
then
|
||||||
|
table.insert(args, "-lstdc++")
|
||||||
|
end
|
||||||
|
if fn.has "win32" == 0 then
|
||||||
|
table.insert(args, "-fPIC")
|
||||||
|
end
|
||||||
|
return args
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the compile command based on the OS and user options
|
||||||
|
---@param repo InstallInfo
|
||||||
|
---@param cc string
|
||||||
|
---@param compile_location string
|
||||||
|
---@return Command
|
||||||
|
function M.select_compile_command(repo, cc, compile_location)
|
||||||
|
local make = M.select_executable { "gmake", "make" }
|
||||||
|
if
|
||||||
|
string.match(cc, "cl$")
|
||||||
|
or string.match(cc, "cl.exe$")
|
||||||
|
or not repo.use_makefile
|
||||||
|
or fn.has "win32" == 1
|
||||||
|
or not make
|
||||||
|
then
|
||||||
|
return {
|
||||||
|
cmd = cc,
|
||||||
|
info = "Compiling...",
|
||||||
|
err = "Error during compilation",
|
||||||
|
opts = {
|
||||||
|
args = require("nvim-treesitter.compat").flatten(M.select_compiler_args(repo, cc)),
|
||||||
|
cwd = compile_location,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = make,
|
||||||
|
info = "Compiling...",
|
||||||
|
err = "Error during compilation",
|
||||||
|
opts = {
|
||||||
|
args = {
|
||||||
|
"--makefile=" .. utils.join_path(utils.get_package_path(), "scripts", "compile_parsers.makefile"),
|
||||||
|
"CC=" .. cc,
|
||||||
|
"CXX_STANDARD=" .. (repo.cxx_standard or "c++14"),
|
||||||
|
},
|
||||||
|
cwd = compile_location,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the remove command based on the OS
|
||||||
|
---@param cache_folder string
|
||||||
|
---@param project_name string
|
||||||
|
---@return Command
|
||||||
|
function M.select_install_rm_cmd(cache_folder, project_name)
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
local dir = cache_folder .. "\\" .. project_name
|
||||||
|
return {
|
||||||
|
cmd = "cmd",
|
||||||
|
opts = {
|
||||||
|
args = { "/C", "if", "exist", cmdpath(dir), "rmdir", "/s", "/q", cmdpath(dir) },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = "rm",
|
||||||
|
opts = {
|
||||||
|
args = { "-rf", cache_folder .. "/" .. project_name },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the move command based on the OS
|
||||||
|
---@param from string
|
||||||
|
---@param to string
|
||||||
|
---@param cwd string
|
||||||
|
---@return Command
|
||||||
|
function M.select_mv_cmd(from, to, cwd)
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
return {
|
||||||
|
cmd = "cmd",
|
||||||
|
opts = {
|
||||||
|
args = { "/C", "move", "/Y", cmdpath(from), cmdpath(to) },
|
||||||
|
cwd = cwd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
cmd = "mv",
|
||||||
|
opts = {
|
||||||
|
args = { "-f", from, to },
|
||||||
|
cwd = cwd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param repo InstallInfo
|
||||||
|
---@param project_name string
|
||||||
|
---@param cache_folder string
|
||||||
|
---@param revision string|nil
|
||||||
|
---@param prefer_git boolean
|
||||||
|
---@return table
|
||||||
|
function M.select_download_commands(repo, project_name, cache_folder, revision, prefer_git)
|
||||||
|
local can_use_tar = vim.fn.executable "tar" == 1 and vim.fn.executable "curl" == 1
|
||||||
|
local is_github = repo.url:find("github.com", 1, true)
|
||||||
|
local is_gitlab = repo.url:find("gitlab.com", 1, true)
|
||||||
|
|
||||||
|
revision = revision or repo.branch or "master"
|
||||||
|
|
||||||
|
if can_use_tar and (is_github or is_gitlab) and not prefer_git then
|
||||||
|
local path_sep = utils.get_path_sep()
|
||||||
|
local url = repo.url:gsub(".git$", "")
|
||||||
|
|
||||||
|
local folder_rev = revision
|
||||||
|
if is_github and revision:match "^v%d" then
|
||||||
|
folder_rev = revision:sub(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
M.select_install_rm_cmd(cache_folder, project_name .. "-tmp"),
|
||||||
|
{
|
||||||
|
cmd = "curl",
|
||||||
|
info = "Downloading " .. project_name .. "...",
|
||||||
|
err = "Error during download, please verify your internet connection",
|
||||||
|
opts = {
|
||||||
|
args = {
|
||||||
|
"--silent",
|
||||||
|
"--show-error",
|
||||||
|
"-L", -- follow redirects
|
||||||
|
is_github and url .. "/archive/" .. revision .. ".tar.gz"
|
||||||
|
or url .. "/-/archive/" .. revision .. "/" .. project_name .. "-" .. revision .. ".tar.gz",
|
||||||
|
"--output",
|
||||||
|
project_name .. ".tar.gz",
|
||||||
|
},
|
||||||
|
cwd = cache_folder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
M.select_mkdir_cmd(project_name .. "-tmp", cache_folder, "Creating temporary directory"),
|
||||||
|
{
|
||||||
|
cmd = "tar",
|
||||||
|
info = "Extracting " .. project_name .. "...",
|
||||||
|
err = "Error during tarball extraction.",
|
||||||
|
opts = {
|
||||||
|
args = {
|
||||||
|
"-xvzf",
|
||||||
|
project_name .. ".tar.gz",
|
||||||
|
"-C",
|
||||||
|
project_name .. "-tmp",
|
||||||
|
},
|
||||||
|
cwd = cache_folder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
M.select_rm_file_cmd(cache_folder .. path_sep .. project_name .. ".tar.gz"),
|
||||||
|
M.select_mv_cmd(
|
||||||
|
utils.join_path(project_name .. "-tmp", url:match "[^/]-$" .. "-" .. folder_rev),
|
||||||
|
project_name,
|
||||||
|
cache_folder
|
||||||
|
),
|
||||||
|
M.select_install_rm_cmd(cache_folder, project_name .. "-tmp"),
|
||||||
|
}
|
||||||
|
else
|
||||||
|
local git_folder = utils.join_path(cache_folder, project_name)
|
||||||
|
local clone_error = "Error during download, please verify your internet connection"
|
||||||
|
|
||||||
|
-- Running `git clone` or `git checkout` while running under Git (such as
|
||||||
|
-- editing a `git commit` message) will likely fail to install parsers
|
||||||
|
-- (such as 'gitcommit') and can also corrupt the index file of the current
|
||||||
|
-- Git repository. Check for typical git environment variables and abort if found.
|
||||||
|
for _, k in pairs {
|
||||||
|
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
||||||
|
"GIT_CEILING_DIRECTORIES",
|
||||||
|
"GIT_DIR",
|
||||||
|
"GIT_INDEX",
|
||||||
|
"GIT_INDEX_FILE",
|
||||||
|
"GIT_OBJECT_DIRECTORY",
|
||||||
|
"GIT_PREFIX",
|
||||||
|
"GIT_WORK_TREE",
|
||||||
|
} do
|
||||||
|
if uv.os_getenv(k) then
|
||||||
|
vim.api.nvim_err_writeln(
|
||||||
|
string.format(
|
||||||
|
"Cannot install %s with git in an active git session. Exit the session and run ':TSInstall %s' manually",
|
||||||
|
project_name,
|
||||||
|
project_name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
cmd = "git",
|
||||||
|
info = "Downloading " .. project_name .. "...",
|
||||||
|
err = clone_error,
|
||||||
|
opts = {
|
||||||
|
args = {
|
||||||
|
"clone",
|
||||||
|
repo.url,
|
||||||
|
project_name,
|
||||||
|
"--filter=blob:none",
|
||||||
|
},
|
||||||
|
cwd = cache_folder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd = "git",
|
||||||
|
info = "Checking out locked revision",
|
||||||
|
err = "Error while checking out revision",
|
||||||
|
opts = {
|
||||||
|
args = {
|
||||||
|
"checkout",
|
||||||
|
revision,
|
||||||
|
},
|
||||||
|
cwd = git_folder,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param dir string
|
||||||
|
---@param command string
|
||||||
|
---@return string command
|
||||||
|
function M.make_directory_change_for_command(dir, command)
|
||||||
|
if fn.has "win32" == 1 then
|
||||||
|
if string.find(vim.o.shell, "cmd") ~= nil then
|
||||||
|
return string.format("pushd %s & %s & popd", cmdpath(dir), command)
|
||||||
|
else
|
||||||
|
return string.format("pushd %s ; %s ; popd", cmdpath(dir), command)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return string.format("cd %s;\n%s", dir, command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -0,0 +1,53 @@
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Trim spaces and opening brackets from end
|
||||||
|
local transform_line = function(line)
|
||||||
|
return line:gsub("%s*[%[%(%{]*%s*$", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.statusline(opts)
|
||||||
|
if not parsers.has_parser() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local options = opts or {}
|
||||||
|
if type(opts) == "number" then
|
||||||
|
options = { indicator_size = opts }
|
||||||
|
end
|
||||||
|
local bufnr = options.bufnr or 0
|
||||||
|
local indicator_size = options.indicator_size or 100
|
||||||
|
local type_patterns = options.type_patterns or { "class", "function", "method" }
|
||||||
|
local transform_fn = options.transform_fn or transform_line
|
||||||
|
local separator = options.separator or " -> "
|
||||||
|
local allow_duplicates = options.allow_duplicates or false
|
||||||
|
|
||||||
|
local current_node = ts_utils.get_node_at_cursor()
|
||||||
|
if not current_node then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local lines = {}
|
||||||
|
local expr = current_node
|
||||||
|
|
||||||
|
while expr do
|
||||||
|
local line = ts_utils._get_line_for_node(expr, type_patterns, transform_fn, bufnr)
|
||||||
|
if line ~= "" then
|
||||||
|
if allow_duplicates or not vim.tbl_contains(lines, line) then
|
||||||
|
table.insert(lines, 1, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expr = expr:parent()
|
||||||
|
end
|
||||||
|
|
||||||
|
local text = table.concat(lines, separator)
|
||||||
|
local text_len = #text
|
||||||
|
if text_len > indicator_size then
|
||||||
|
return "..." .. text:sub(text_len - indicator_size, text_len)
|
||||||
|
end
|
||||||
|
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
468
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua
Normal file
468
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua
Normal file
|
@ -0,0 +1,468 @@
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
local ts = vim.treesitter
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function get_node_text(node, bufnr)
|
||||||
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
|
if not node then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We have to remember that end_col is end-exclusive
|
||||||
|
local start_row, start_col, end_row, end_col = ts.get_node_range(node)
|
||||||
|
|
||||||
|
if start_row ~= end_row then
|
||||||
|
local lines = api.nvim_buf_get_lines(bufnr, start_row, end_row + 1, false)
|
||||||
|
if next(lines) == nil then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
lines[1] = string.sub(lines[1], start_col + 1)
|
||||||
|
-- end_row might be just after the last line. In this case the last line is not truncated.
|
||||||
|
if #lines == end_row - start_row + 1 then
|
||||||
|
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
||||||
|
end
|
||||||
|
return lines
|
||||||
|
else
|
||||||
|
local line = api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1]
|
||||||
|
-- If line is nil then the line is empty
|
||||||
|
return line and { string.sub(line, start_col + 1, end_col) } or {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@private
|
||||||
|
---@param node TSNode
|
||||||
|
---@param type_patterns string[]
|
||||||
|
---@param transform_fn fun(line: string): string
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return string
|
||||||
|
function M._get_line_for_node(node, type_patterns, transform_fn, bufnr)
|
||||||
|
local node_type = node:type()
|
||||||
|
local is_valid = false
|
||||||
|
for _, rgx in ipairs(type_patterns) do
|
||||||
|
if node_type:find(rgx) then
|
||||||
|
is_valid = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not is_valid then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
local line = transform_fn(vim.trim(get_node_text(node, bufnr)[1] or ""), node)
|
||||||
|
-- Escape % to avoid statusline to evaluate content as expression
|
||||||
|
return line:gsub("%%", "%%%%")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets the actual text content of a node
|
||||||
|
-- @deprecated Use vim.treesitter.get_node_text
|
||||||
|
-- @param node the node to get the text from
|
||||||
|
-- @param bufnr the buffer containing the node
|
||||||
|
-- @return list of lines of text of the node
|
||||||
|
function M.get_node_text(node, bufnr)
|
||||||
|
vim.notify_once(
|
||||||
|
"nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.get_node_text",
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
return get_node_text(node, bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Determines whether a node is the parent of another
|
||||||
|
-- @param dest the possible parent
|
||||||
|
-- @param source the possible child node
|
||||||
|
function M.is_parent(dest, source)
|
||||||
|
if not (dest and source) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local current = source
|
||||||
|
while current ~= nil do
|
||||||
|
if current == dest then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
current = current:parent()
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get next node with same parent
|
||||||
|
---@param node TSNode
|
||||||
|
---@param allow_switch_parents? boolean allow switching parents if last node
|
||||||
|
---@param allow_next_parent? boolean allow next parent if last node and next parent without children
|
||||||
|
function M.get_next_node(node, allow_switch_parents, allow_next_parent)
|
||||||
|
local destination_node ---@type TSNode
|
||||||
|
local parent = node:parent()
|
||||||
|
|
||||||
|
if not parent then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local found_pos = 0
|
||||||
|
for i = 0, parent:named_child_count() - 1, 1 do
|
||||||
|
if parent:named_child(i) == node then
|
||||||
|
found_pos = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if parent:named_child_count() > found_pos + 1 then
|
||||||
|
destination_node = parent:named_child(found_pos + 1)
|
||||||
|
elseif allow_switch_parents then
|
||||||
|
local next_node = M.get_next_node(node:parent())
|
||||||
|
if next_node and next_node:named_child_count() > 0 then
|
||||||
|
destination_node = next_node:named_child(0)
|
||||||
|
elseif next_node and allow_next_parent then
|
||||||
|
destination_node = next_node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return destination_node
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get previous node with same parent
|
||||||
|
---@param node TSNode
|
||||||
|
---@param allow_switch_parents? boolean allow switching parents if first node
|
||||||
|
---@param allow_previous_parent? boolean allow previous parent if first node and previous parent without children
|
||||||
|
function M.get_previous_node(node, allow_switch_parents, allow_previous_parent)
|
||||||
|
local destination_node ---@type TSNode
|
||||||
|
local parent = node:parent()
|
||||||
|
if not parent then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local found_pos = 0
|
||||||
|
for i = 0, parent:named_child_count() - 1, 1 do
|
||||||
|
if parent:named_child(i) == node then
|
||||||
|
found_pos = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if 0 < found_pos then
|
||||||
|
destination_node = parent:named_child(found_pos - 1)
|
||||||
|
elseif allow_switch_parents then
|
||||||
|
local previous_node = M.get_previous_node(node:parent())
|
||||||
|
if previous_node and previous_node:named_child_count() > 0 then
|
||||||
|
destination_node = previous_node:named_child(previous_node:named_child_count() - 1)
|
||||||
|
elseif previous_node and allow_previous_parent then
|
||||||
|
destination_node = previous_node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return destination_node
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_named_children(node)
|
||||||
|
local nodes = {} ---@type TSNode[]
|
||||||
|
for i = 0, node:named_child_count() - 1, 1 do
|
||||||
|
nodes[i + 1] = node:named_child(i)
|
||||||
|
end
|
||||||
|
return nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_node_at_cursor(winnr, ignore_injected_langs)
|
||||||
|
winnr = winnr or 0
|
||||||
|
local cursor = api.nvim_win_get_cursor(winnr)
|
||||||
|
local cursor_range = { cursor[1] - 1, cursor[2] }
|
||||||
|
|
||||||
|
local buf = vim.api.nvim_win_get_buf(winnr)
|
||||||
|
local root_lang_tree = parsers.get_parser(buf)
|
||||||
|
if not root_lang_tree then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local root ---@type TSNode|nil
|
||||||
|
if ignore_injected_langs then
|
||||||
|
for _, tree in pairs(root_lang_tree:trees()) do
|
||||||
|
local tree_root = tree:root()
|
||||||
|
if tree_root and ts.is_in_node_range(tree_root, cursor_range[1], cursor_range[2]) then
|
||||||
|
root = tree_root
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not root then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return root:named_descendant_for_range(cursor_range[1], cursor_range[2], cursor_range[1], cursor_range[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_root_for_position(line, col, root_lang_tree)
|
||||||
|
if not root_lang_tree then
|
||||||
|
if not parsers.has_parser() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
root_lang_tree = parsers.get_parser()
|
||||||
|
end
|
||||||
|
|
||||||
|
local lang_tree = root_lang_tree:language_for_range { line, col, line, col }
|
||||||
|
|
||||||
|
for _, tree in pairs(lang_tree:trees()) do
|
||||||
|
local root = tree:root()
|
||||||
|
|
||||||
|
if root and ts.is_in_node_range(root, line, col) then
|
||||||
|
return root, tree, lang_tree
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- This isn't a likely scenario, since the position must belong to a tree somewhere.
|
||||||
|
return nil, nil, lang_tree
|
||||||
|
end
|
||||||
|
|
||||||
|
---comment
|
||||||
|
---@param node TSNode
|
||||||
|
---@return TSNode result
|
||||||
|
function M.get_root_for_node(node)
|
||||||
|
local parent = node
|
||||||
|
local result = node
|
||||||
|
|
||||||
|
while parent ~= nil do
|
||||||
|
result = parent
|
||||||
|
parent = result:parent()
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.highlight_node(node, buf, hl_namespace, hl_group)
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
M.highlight_range({ node:range() }, buf, hl_namespace, hl_group)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get a compatible vim range (1 index based) from a TS node range.
|
||||||
|
--
|
||||||
|
-- TS nodes start with 0 and the end col is ending exclusive.
|
||||||
|
-- They also treat a EOF/EOL char as a char ending in the first
|
||||||
|
-- col of the next row.
|
||||||
|
---comment
|
||||||
|
---@param range integer[]
|
||||||
|
---@param buf integer|nil
|
||||||
|
---@return integer, integer, integer, integer
|
||||||
|
function M.get_vim_range(range, buf)
|
||||||
|
---@type integer, integer, integer, integer
|
||||||
|
local srow, scol, erow, ecol = unpack(range)
|
||||||
|
srow = srow + 1
|
||||||
|
scol = scol + 1
|
||||||
|
erow = erow + 1
|
||||||
|
|
||||||
|
if ecol == 0 then
|
||||||
|
-- Use the value of the last col of the previous row instead.
|
||||||
|
erow = erow - 1
|
||||||
|
if not buf or buf == 0 then
|
||||||
|
ecol = vim.fn.col { erow, "$" } - 1
|
||||||
|
else
|
||||||
|
ecol = #api.nvim_buf_get_lines(buf, erow - 1, erow, false)[1]
|
||||||
|
end
|
||||||
|
ecol = math.max(ecol, 1)
|
||||||
|
end
|
||||||
|
return srow, scol, erow, ecol
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.highlight_range(range, buf, hl_namespace, hl_group)
|
||||||
|
---@type integer, integer, integer, integer
|
||||||
|
local start_row, start_col, end_row, end_col = unpack(range)
|
||||||
|
---@diagnostic disable-next-line: missing-parameter
|
||||||
|
vim.highlight.range(buf, hl_namespace, hl_group, { start_row, start_col }, { end_row, end_col })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set visual selection to node
|
||||||
|
-- @param selection_mode One of "charwise" (default) or "v", "linewise" or "V",
|
||||||
|
-- "blockwise" or "<C-v>" (as a string with 5 characters or a single character)
|
||||||
|
function M.update_selection(buf, node, selection_mode)
|
||||||
|
local start_row, start_col, end_row, end_col = M.get_vim_range({ ts.get_node_range(node) }, buf)
|
||||||
|
|
||||||
|
local v_table = { charwise = "v", linewise = "V", blockwise = "<C-v>" }
|
||||||
|
selection_mode = selection_mode or "charwise"
|
||||||
|
|
||||||
|
-- Normalise selection_mode
|
||||||
|
if vim.tbl_contains(vim.tbl_keys(v_table), selection_mode) then
|
||||||
|
selection_mode = v_table[selection_mode]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- enter visual mode if normal or operator-pending (no) mode
|
||||||
|
-- Why? According to https://learnvimscriptthehardway.stevelosh.com/chapters/15.html
|
||||||
|
-- If your operator-pending mapping ends with some text visually selected, Vim will operate on that text.
|
||||||
|
-- Otherwise, Vim will operate on the text between the original cursor position and the new position.
|
||||||
|
local mode = api.nvim_get_mode()
|
||||||
|
if mode.mode ~= selection_mode then
|
||||||
|
-- Call to `nvim_replace_termcodes()` is needed for sending appropriate command to enter blockwise mode
|
||||||
|
selection_mode = vim.api.nvim_replace_termcodes(selection_mode, true, true, true)
|
||||||
|
api.nvim_cmd({ cmd = "normal", bang = true, args = { selection_mode } }, {})
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_win_set_cursor(0, { start_row, start_col - 1 })
|
||||||
|
vim.cmd "normal! o"
|
||||||
|
api.nvim_win_set_cursor(0, { end_row, end_col - 1 })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Byte length of node range
|
||||||
|
---@param node TSNode
|
||||||
|
---@return number
|
||||||
|
function M.node_length(node)
|
||||||
|
local _, _, start_byte = node:start()
|
||||||
|
local _, _, end_byte = node:end_()
|
||||||
|
return end_byte - start_byte
|
||||||
|
end
|
||||||
|
|
||||||
|
---@deprecated Use `vim.treesitter.is_in_node_range()` instead
|
||||||
|
function M.is_in_node_range(node, line, col)
|
||||||
|
vim.notify_once(
|
||||||
|
"nvim-treesitter.ts_utils.is_in_node_range is deprecated: use vim.treesitter.is_in_node_range",
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
return ts.is_in_node_range(node, line, col)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@deprecated Use `vim.treesitter.get_node_range()` instead
|
||||||
|
function M.get_node_range(node_or_range)
|
||||||
|
vim.notify_once(
|
||||||
|
"nvim-treesitter.ts_utils.get_node_range is deprecated: use vim.treesitter.get_node_range",
|
||||||
|
vim.log.levels.WARN
|
||||||
|
)
|
||||||
|
return ts.get_node_range(node_or_range)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param node TSNode
|
||||||
|
---@return table
|
||||||
|
function M.node_to_lsp_range(node)
|
||||||
|
local start_line, start_col, end_line, end_col = ts.get_node_range(node)
|
||||||
|
local rtn = {}
|
||||||
|
rtn.start = { line = start_line, character = start_col }
|
||||||
|
rtn["end"] = { line = end_line, character = end_col }
|
||||||
|
return rtn
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Memoizes a function based on the buffer tick of the provided bufnr.
|
||||||
|
-- The cache entry is cleared when the buffer is detached to avoid memory leaks.
|
||||||
|
-- The options argument is a table with two optional values:
|
||||||
|
-- - bufnr: extracts a bufnr from the given arguments.
|
||||||
|
-- - key: extracts the cache key from the given arguments.
|
||||||
|
---@param fn function the fn to memoize, taking the buffer as first argument
|
||||||
|
---@param options? {bufnr: integer?, key: string|fun(...): string?} the memoization options
|
||||||
|
---@return function: a memoized function
|
||||||
|
function M.memoize_by_buf_tick(fn, options)
|
||||||
|
options = options or {}
|
||||||
|
|
||||||
|
---@type table<string, {result: any, last_tick: integer}>
|
||||||
|
local cache = setmetatable({}, { __mode = "kv" })
|
||||||
|
local bufnr_fn = utils.to_func(options.bufnr or utils.identity)
|
||||||
|
local key_fn = utils.to_func(options.key or utils.identity)
|
||||||
|
|
||||||
|
return function(...)
|
||||||
|
local bufnr = bufnr_fn(...)
|
||||||
|
local key = key_fn(...)
|
||||||
|
local tick = api.nvim_buf_get_changedtick(bufnr)
|
||||||
|
|
||||||
|
if cache[key] then
|
||||||
|
if cache[key].last_tick == tick then
|
||||||
|
return cache[key].result
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local function detach_handler()
|
||||||
|
cache[key] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clean up logic only!
|
||||||
|
api.nvim_buf_attach(bufnr, false, {
|
||||||
|
on_detach = detach_handler,
|
||||||
|
on_reload = detach_handler,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
cache[key] = {
|
||||||
|
result = fn(...),
|
||||||
|
last_tick = tick,
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache[key].result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.swap_nodes(node_or_range1, node_or_range2, bufnr, cursor_to_second)
|
||||||
|
if not node_or_range1 or not node_or_range2 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local range1 = M.node_to_lsp_range(node_or_range1)
|
||||||
|
local range2 = M.node_to_lsp_range(node_or_range2)
|
||||||
|
|
||||||
|
local text1 = get_node_text(node_or_range1, bufnr)
|
||||||
|
local text2 = get_node_text(node_or_range2, bufnr)
|
||||||
|
|
||||||
|
local edit1 = { range = range1, newText = table.concat(text2, "\n") }
|
||||||
|
local edit2 = { range = range2, newText = table.concat(text1, "\n") }
|
||||||
|
bufnr = bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr
|
||||||
|
vim.lsp.util.apply_text_edits({ edit1, edit2 }, bufnr, "utf-8")
|
||||||
|
|
||||||
|
if cursor_to_second then
|
||||||
|
utils.set_jump()
|
||||||
|
|
||||||
|
local char_delta = 0
|
||||||
|
local line_delta = 0
|
||||||
|
if
|
||||||
|
range1["end"].line < range2.start.line
|
||||||
|
or (range1["end"].line == range2.start.line and range1["end"].character <= range2.start.character)
|
||||||
|
then
|
||||||
|
line_delta = #text2 - #text1
|
||||||
|
end
|
||||||
|
|
||||||
|
if range1["end"].line == range2.start.line and range1["end"].character <= range2.start.character then
|
||||||
|
if line_delta ~= 0 then
|
||||||
|
--- why?
|
||||||
|
--correction_after_line_change = -range2.start.character
|
||||||
|
--text_now_before_range2 = #(text2[#text2])
|
||||||
|
--space_between_ranges = range2.start.character - range1["end"].character
|
||||||
|
--char_delta = correction_after_line_change + text_now_before_range2 + space_between_ranges
|
||||||
|
--- Equivalent to:
|
||||||
|
char_delta = #text2[#text2] - range1["end"].character
|
||||||
|
|
||||||
|
-- add range1.start.character if last line of range1 (now text2) does not start at 0
|
||||||
|
if range1.start.line == range2.start.line + line_delta then
|
||||||
|
char_delta = char_delta + range1.start.character
|
||||||
|
end
|
||||||
|
else
|
||||||
|
char_delta = #text2[#text2] - #text1[#text1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_win_set_cursor(
|
||||||
|
api.nvim_get_current_win(),
|
||||||
|
{ range2.start.line + 1 + line_delta, range2.start.character + char_delta }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.goto_node(node, goto_end, avoid_set_jump)
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not avoid_set_jump then
|
||||||
|
utils.set_jump()
|
||||||
|
end
|
||||||
|
local range = { M.get_vim_range { node:range() } }
|
||||||
|
---@type table<number>
|
||||||
|
local position
|
||||||
|
if not goto_end then
|
||||||
|
position = { range[1], range[2] }
|
||||||
|
else
|
||||||
|
position = { range[3], range[4] }
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Enter visual mode if we are in operator pending mode
|
||||||
|
-- If we don't do this, it will miss the last character.
|
||||||
|
local mode = vim.api.nvim_get_mode()
|
||||||
|
if mode.mode == "no" then
|
||||||
|
vim.cmd "normal! v"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Position is 1, 0 indexed.
|
||||||
|
api.nvim_win_set_cursor(0, { position[1], position[2] - 1 })
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
154
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/tsrange.lua
Normal file
154
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/tsrange.lua
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
local M = {}
|
||||||
|
local TSRange = {}
|
||||||
|
TSRange.__index = TSRange
|
||||||
|
|
||||||
|
local api = vim.api
|
||||||
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
|
|
||||||
|
local function get_byte_offset(buf, row, col)
|
||||||
|
return api.nvim_buf_get_offset(buf, row) + vim.fn.byteidx(api.nvim_buf_get_lines(buf, row, row + 1, false)[1], col)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange.new(buf, start_row, start_col, end_row, end_col)
|
||||||
|
return setmetatable({
|
||||||
|
start_pos = { start_row, start_col, get_byte_offset(buf, start_row, start_col) },
|
||||||
|
end_pos = { end_row, end_col, get_byte_offset(buf, end_row, end_col) },
|
||||||
|
buf = buf,
|
||||||
|
[1] = start_row,
|
||||||
|
[2] = start_col,
|
||||||
|
[3] = end_row,
|
||||||
|
[4] = end_col,
|
||||||
|
}, TSRange)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange.from_nodes(buf, start_node, end_node)
|
||||||
|
TSRange.__index = TSRange
|
||||||
|
local start_pos = start_node and { start_node:start() } or { end_node:start() }
|
||||||
|
local end_pos = end_node and { end_node:end_() } or { start_node:end_() }
|
||||||
|
return setmetatable({
|
||||||
|
start_pos = { start_pos[1], start_pos[2], start_pos[3] },
|
||||||
|
end_pos = { end_pos[1], end_pos[2], end_pos[3] },
|
||||||
|
buf = buf,
|
||||||
|
[1] = start_pos[1],
|
||||||
|
[2] = start_pos[2],
|
||||||
|
[3] = end_pos[1],
|
||||||
|
[4] = end_pos[2],
|
||||||
|
}, TSRange)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange.from_table(buf, range)
|
||||||
|
return setmetatable({
|
||||||
|
start_pos = { range[1], range[2], get_byte_offset(buf, range[1], range[2]) },
|
||||||
|
end_pos = { range[3], range[4], get_byte_offset(buf, range[3], range[4]) },
|
||||||
|
buf = buf,
|
||||||
|
[1] = range[1],
|
||||||
|
[2] = range[2],
|
||||||
|
[3] = range[3],
|
||||||
|
[4] = range[4],
|
||||||
|
}, TSRange)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:parent()
|
||||||
|
local root_lang_tree = parsers.get_parser(self.buf)
|
||||||
|
local root = ts_utils.get_root_for_position(self[1], self[2], root_lang_tree)
|
||||||
|
|
||||||
|
return root
|
||||||
|
and root:named_descendant_for_range(self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2])
|
||||||
|
or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:field() end
|
||||||
|
|
||||||
|
function TSRange:child_count()
|
||||||
|
return #self:collect_children()
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:named_child_count()
|
||||||
|
return #self:collect_children(function(c)
|
||||||
|
return c:named()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:iter_children()
|
||||||
|
local raw_iterator = self:parent().iter_children()
|
||||||
|
return function()
|
||||||
|
while true do
|
||||||
|
local node = raw_iterator()
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local _, _, start_byte = node:start()
|
||||||
|
local _, _, end_byte = node:end_()
|
||||||
|
if start_byte >= self.start_pos[3] and end_byte <= self.end_pos[3] then
|
||||||
|
return node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:collect_children(filter_fun)
|
||||||
|
local children = {}
|
||||||
|
for _, c in self:iter_children() do
|
||||||
|
if not filter_fun or filter_fun(c) then
|
||||||
|
table.insert(children, c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return children
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:child(index)
|
||||||
|
return self:collect_children()[index + 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:named_child(index)
|
||||||
|
return self:collect_children(function(c)
|
||||||
|
return c.named()
|
||||||
|
end)[index + 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:start()
|
||||||
|
return unpack(self.start_pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:end_()
|
||||||
|
return unpack(self.end_pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:range()
|
||||||
|
return self.start_pos[1], self.start_pos[2], self.end_pos[1], self.end_pos[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:type()
|
||||||
|
return "nvim-treesitter-range"
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:symbol()
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:named()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:missing()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:has_error()
|
||||||
|
return #self:collect_children(function(c)
|
||||||
|
return c:has_error()
|
||||||
|
end) > 0 and true or false
|
||||||
|
end
|
||||||
|
|
||||||
|
function TSRange:sexpr()
|
||||||
|
return table.concat(
|
||||||
|
vim.tbl_map(function(c)
|
||||||
|
return c:sexpr()
|
||||||
|
end, self:collect_children()),
|
||||||
|
" "
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.TSRange = TSRange
|
||||||
|
return M
|
237
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/utils.lua
Normal file
237
pack/ant/start/nvim-treesitter/lua/nvim-treesitter/utils.lua
Normal file
|
@ -0,0 +1,237 @@
|
||||||
|
local api = vim.api
|
||||||
|
local fn = vim.fn
|
||||||
|
local luv = vim.loop
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Wrapper around vim.notify with common options set.
|
||||||
|
---@param msg string
|
||||||
|
---@param log_level number|nil
|
||||||
|
---@param opts table|nil
|
||||||
|
function M.notify(msg, log_level, opts)
|
||||||
|
local default_opts = { title = "nvim-treesitter" }
|
||||||
|
vim.notify(msg, log_level, vim.tbl_extend("force", default_opts, opts or {}))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns the system-specific path separator.
|
||||||
|
---@return string
|
||||||
|
function M.get_path_sep()
|
||||||
|
return (fn.has "win32" == 1 and not vim.opt.shellslash:get()) and "\\" or "/"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a function that joins the given arguments with separator. Arguments
|
||||||
|
-- can't be nil. Example:
|
||||||
|
--
|
||||||
|
--[[
|
||||||
|
print(M.generate_join(" ")("foo", "bar"))
|
||||||
|
--]]
|
||||||
|
--prints "foo bar"
|
||||||
|
---@param separator string
|
||||||
|
---@return fun(...: string): string
|
||||||
|
function M.generate_join(separator)
|
||||||
|
return function(...)
|
||||||
|
return table.concat({ ... }, separator)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.join_path = M.generate_join(M.get_path_sep())
|
||||||
|
|
||||||
|
M.join_space = M.generate_join " "
|
||||||
|
|
||||||
|
---@class Command
|
||||||
|
---@field run function
|
||||||
|
---@field f_args string
|
||||||
|
---@field args string
|
||||||
|
|
||||||
|
-- Define user defined vim command which calls nvim-treesitter module function
|
||||||
|
-- - If module name is 'mod', it should be defined in hierarchy 'nvim-treesitter.mod'
|
||||||
|
-- - A table with name 'commands' should be defined in 'mod' which needs to be passed as
|
||||||
|
-- the commands param of this function
|
||||||
|
--
|
||||||
|
---@param mod string Name of the module that resides in the hierarchy - nvim-treesitter.module
|
||||||
|
---@param commands table<string, Command> Command list for the module
|
||||||
|
--- - {command_name} Name of the vim user defined command, Keys:
|
||||||
|
--- - {run}: (function) callback function that needs to be executed
|
||||||
|
--- - {f_args}: (string, default <f-args>)
|
||||||
|
--- - type of arguments that needs to be passed to the vim command
|
||||||
|
--- - {args}: (string, optional)
|
||||||
|
--- - vim command attributes
|
||||||
|
---
|
||||||
|
---* @example
|
||||||
|
--- If module is nvim-treesitter.custom_mod
|
||||||
|
--- <pre>
|
||||||
|
--- M.commands = {
|
||||||
|
--- custom_command = {
|
||||||
|
--- run = M.module_function,
|
||||||
|
--- f_args = "<f-args>",
|
||||||
|
--- args = {
|
||||||
|
--- "-range"
|
||||||
|
--- }
|
||||||
|
--- }
|
||||||
|
--- }
|
||||||
|
---
|
||||||
|
--- utils.setup_commands("custom_mod", require("nvim-treesitter.custom_mod").commands)
|
||||||
|
--- </pre>
|
||||||
|
---
|
||||||
|
--- Will generate command :
|
||||||
|
--- <pre>
|
||||||
|
--- command! -range custom_command \
|
||||||
|
--- lua require'nvim-treesitter.custom_mod'.commands.custom_command['run<bang>'](<f-args>)
|
||||||
|
--- </pre>
|
||||||
|
function M.setup_commands(mod, commands)
|
||||||
|
for command_name, def in pairs(commands) do
|
||||||
|
local f_args = def.f_args or "<f-args>"
|
||||||
|
local call_fn =
|
||||||
|
string.format("lua require'nvim-treesitter.%s'.commands.%s['run<bang>'](%s)", mod, command_name, f_args)
|
||||||
|
local parts = require("nvim-treesitter.compat").flatten {
|
||||||
|
"command!",
|
||||||
|
"-bar",
|
||||||
|
def.args,
|
||||||
|
command_name,
|
||||||
|
call_fn,
|
||||||
|
}
|
||||||
|
api.nvim_command(table.concat(parts, " "))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param dir string
|
||||||
|
---@param create_err string
|
||||||
|
---@param writeable_err string
|
||||||
|
---@return string|nil, string|nil
|
||||||
|
function M.create_or_reuse_writable_dir(dir, create_err, writeable_err)
|
||||||
|
create_err = create_err or M.join_space("Could not create dir '", dir, "': ")
|
||||||
|
writeable_err = writeable_err or M.join_space("Invalid rights, '", dir, "' should be read/write")
|
||||||
|
-- Try creating and using parser_dir if it doesn't exist
|
||||||
|
if not luv.fs_stat(dir) then
|
||||||
|
local ok, error = pcall(vim.fn.mkdir, dir, "p", "0755")
|
||||||
|
if not ok then
|
||||||
|
return nil, M.join_space(create_err, error)
|
||||||
|
end
|
||||||
|
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
|
||||||
|
-- parser_dir exists, use it if it's read/write
|
||||||
|
if luv.fs_access(dir, "RW") then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
|
||||||
|
-- parser_dir exists but isn't read/write, give up
|
||||||
|
return nil, M.join_space(writeable_err, dir, "'")
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_package_path()
|
||||||
|
-- Path to this source file, removing the leading '@'
|
||||||
|
local source = string.sub(debug.getinfo(1, "S").source, 2)
|
||||||
|
|
||||||
|
-- Path to the package root
|
||||||
|
return fn.fnamemodify(source, ":p:h:h:h")
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_cache_dir()
|
||||||
|
local cache_dir = fn.stdpath "data"
|
||||||
|
|
||||||
|
if luv.fs_access(cache_dir, "RW") then
|
||||||
|
return cache_dir
|
||||||
|
elseif luv.fs_access("/tmp", "RW") then
|
||||||
|
return "/tmp"
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil, M.join_space("Invalid cache rights,", fn.stdpath "data", "or /tmp should be read/write")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns $XDG_DATA_HOME/nvim/site, but could use any directory that is in
|
||||||
|
-- runtimepath
|
||||||
|
function M.get_site_dir()
|
||||||
|
return M.join_path(fn.stdpath "data", "site")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets a property at path
|
||||||
|
---@param tbl table the table to access
|
||||||
|
---@param path string the '.' separated path
|
||||||
|
---@return table|nil result the value at path or nil
|
||||||
|
function M.get_at_path(tbl, path)
|
||||||
|
if path == "" then
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
local segments = vim.split(path, ".", true)
|
||||||
|
---@type table[]|table
|
||||||
|
local result = tbl
|
||||||
|
|
||||||
|
for _, segment in ipairs(segments) do
|
||||||
|
if type(result) == "table" then
|
||||||
|
---@type table
|
||||||
|
-- TODO: figure out the actual type of tbl
|
||||||
|
result = result[segment]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.set_jump()
|
||||||
|
vim.cmd "normal! m'"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Filters a list based on the given predicate
|
||||||
|
---@param tbl any[] The list to filter
|
||||||
|
---@param predicate fun(v:any, i:number):boolean The predicate to filter with
|
||||||
|
function M.filter(tbl, predicate)
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
for i, v in ipairs(tbl) do
|
||||||
|
if predicate(v, i) then
|
||||||
|
table.insert(result, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a list of all values from the first list
|
||||||
|
-- that are not present in the second list.
|
||||||
|
---@param tbl1 any[] The first table
|
||||||
|
---@param tbl2 any[] The second table
|
||||||
|
---@return table
|
||||||
|
function M.difference(tbl1, tbl2)
|
||||||
|
return M.filter(tbl1, function(v)
|
||||||
|
return not vim.tbl_contains(tbl2, v)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.identity(a)
|
||||||
|
return a
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a function returning the given value
|
||||||
|
---@param a any
|
||||||
|
---@return fun():any
|
||||||
|
function M.constant(a)
|
||||||
|
return function()
|
||||||
|
return a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a function that returns the given value if it is a function,
|
||||||
|
-- otherwise returns a function that returns the given value.
|
||||||
|
---@param a any
|
||||||
|
---@return fun(...):any
|
||||||
|
function M.to_func(a)
|
||||||
|
return type(a) == "function" and a or M.constant(a)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return string|nil
|
||||||
|
function M.ts_cli_version()
|
||||||
|
if fn.executable "tree-sitter" == 1 then
|
||||||
|
local handle = io.popen "tree-sitter -V"
|
||||||
|
if not handle then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local result = handle:read "*a"
|
||||||
|
handle:close()
|
||||||
|
return vim.split(result, "\n")[1]:match "[^tree%psitter ].*"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
2
pack/ant/start/nvim-treesitter/parser-info/.gitignore
vendored
Normal file
2
pack/ant/start/nvim-treesitter/parser-info/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!.gitignore
|
2
pack/ant/start/nvim-treesitter/parser/.gitignore
vendored
Normal file
2
pack/ant/start/nvim-treesitter/parser/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*
|
||||||
|
!.gitignore
|
34
pack/ant/start/nvim-treesitter/plugin/nvim-treesitter.lua
Normal file
34
pack/ant/start/nvim-treesitter/plugin/nvim-treesitter.lua
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
-- Last Change: 2022 Apr 16
|
||||||
|
|
||||||
|
if vim.g.loaded_nvim_treesitter then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.g.loaded_nvim_treesitter = true
|
||||||
|
|
||||||
|
-- setup modules
|
||||||
|
require("nvim-treesitter").setup()
|
||||||
|
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
-- define autocommands
|
||||||
|
local augroup = api.nvim_create_augroup("NvimTreesitter", {})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("Filetype", {
|
||||||
|
pattern = "query",
|
||||||
|
group = augroup,
|
||||||
|
callback = function()
|
||||||
|
api.nvim_clear_autocmds {
|
||||||
|
group = augroup,
|
||||||
|
event = "BufWritePost",
|
||||||
|
}
|
||||||
|
api.nvim_create_autocmd("BufWritePost", {
|
||||||
|
group = augroup,
|
||||||
|
buffer = 0,
|
||||||
|
callback = function(opts)
|
||||||
|
require("nvim-treesitter.query").invalidate_query_file(opts.file)
|
||||||
|
end,
|
||||||
|
desc = "Invalidate query file",
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
desc = "Reload query",
|
||||||
|
})
|
13
pack/ant/start/nvim-treesitter/queries/ada/folds.scm
Normal file
13
pack/ant/start/nvim-treesitter/queries/ada/folds.scm
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
; Support for folding in Ada
|
||||||
|
; za toggles folding a package, subprogram, if statement or loop
|
||||||
|
[
|
||||||
|
(package_declaration)
|
||||||
|
(generic_package_declaration)
|
||||||
|
(package_body)
|
||||||
|
(subprogram_body)
|
||||||
|
(block_statement)
|
||||||
|
(if_statement)
|
||||||
|
(loop_statement)
|
||||||
|
(gnatprep_declarative_if_statement)
|
||||||
|
(gnatprep_if_statement)
|
||||||
|
] @fold
|
286
pack/ant/start/nvim-treesitter/queries/ada/highlights.scm
Normal file
286
pack/ant/start/nvim-treesitter/queries/ada/highlights.scm
Normal file
|
@ -0,0 +1,286 @@
|
||||||
|
; highlight queries.
|
||||||
|
; See the syntax at https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries
|
||||||
|
; See also https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md#parser-configurations
|
||||||
|
; for a list of recommended @ tags, though not all of them have matching
|
||||||
|
; highlights in neovim.
|
||||||
|
[
|
||||||
|
"abort"
|
||||||
|
"abs"
|
||||||
|
"abstract"
|
||||||
|
"accept"
|
||||||
|
"access"
|
||||||
|
"all"
|
||||||
|
"array"
|
||||||
|
"at"
|
||||||
|
"begin"
|
||||||
|
"body"
|
||||||
|
"declare"
|
||||||
|
"delay"
|
||||||
|
"delta"
|
||||||
|
"digits"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
"entry"
|
||||||
|
"exit"
|
||||||
|
"generic"
|
||||||
|
"interface"
|
||||||
|
"is"
|
||||||
|
"limited"
|
||||||
|
"mod"
|
||||||
|
"new"
|
||||||
|
"null"
|
||||||
|
"of"
|
||||||
|
"others"
|
||||||
|
"out"
|
||||||
|
"overriding"
|
||||||
|
"package"
|
||||||
|
"pragma"
|
||||||
|
"private"
|
||||||
|
"protected"
|
||||||
|
"range"
|
||||||
|
"separate"
|
||||||
|
"subtype"
|
||||||
|
"synchronized"
|
||||||
|
"tagged"
|
||||||
|
"task"
|
||||||
|
"terminate"
|
||||||
|
"type"
|
||||||
|
"until"
|
||||||
|
"when"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"record" @keyword.type
|
||||||
|
|
||||||
|
[
|
||||||
|
"aliased"
|
||||||
|
"constant"
|
||||||
|
"renames"
|
||||||
|
] @keyword.modifier
|
||||||
|
|
||||||
|
[
|
||||||
|
"with"
|
||||||
|
"use"
|
||||||
|
] @keyword.import
|
||||||
|
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"procedure"
|
||||||
|
] @keyword.function
|
||||||
|
|
||||||
|
[
|
||||||
|
"and"
|
||||||
|
"in"
|
||||||
|
"not"
|
||||||
|
"or"
|
||||||
|
"xor"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"while"
|
||||||
|
"loop"
|
||||||
|
"for"
|
||||||
|
"parallel"
|
||||||
|
"reverse"
|
||||||
|
"some"
|
||||||
|
] @keyword.repeat
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
[
|
||||||
|
"case"
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"then"
|
||||||
|
"elsif"
|
||||||
|
"select"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"exception"
|
||||||
|
"raise"
|
||||||
|
] @keyword.exception
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
(string_literal) @string
|
||||||
|
|
||||||
|
(character_literal) @string
|
||||||
|
|
||||||
|
(numeric_literal) @number
|
||||||
|
|
||||||
|
; Highlight the name of subprograms
|
||||||
|
(procedure_specification
|
||||||
|
name: (_) @function)
|
||||||
|
|
||||||
|
(function_specification
|
||||||
|
name: (_) @function)
|
||||||
|
|
||||||
|
(package_declaration
|
||||||
|
name: (_) @function)
|
||||||
|
|
||||||
|
(package_body
|
||||||
|
name: (_) @function)
|
||||||
|
|
||||||
|
(generic_instantiation
|
||||||
|
name: (_) @function)
|
||||||
|
|
||||||
|
(entry_declaration
|
||||||
|
.
|
||||||
|
(identifier) @function)
|
||||||
|
|
||||||
|
; Some keywords should take different categories depending on the context
|
||||||
|
(use_clause
|
||||||
|
"use" @keyword.import
|
||||||
|
"type" @keyword.import)
|
||||||
|
|
||||||
|
(with_clause
|
||||||
|
"private" @keyword.import)
|
||||||
|
|
||||||
|
(with_clause
|
||||||
|
"limited" @keyword.import)
|
||||||
|
|
||||||
|
(use_clause
|
||||||
|
(_) @module)
|
||||||
|
|
||||||
|
(with_clause
|
||||||
|
(_) @module)
|
||||||
|
|
||||||
|
(loop_statement
|
||||||
|
"end" @keyword.repeat)
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
"end" @keyword.conditional)
|
||||||
|
|
||||||
|
(loop_parameter_specification
|
||||||
|
"in" @keyword.repeat)
|
||||||
|
|
||||||
|
(loop_parameter_specification
|
||||||
|
"in" @keyword.repeat)
|
||||||
|
|
||||||
|
(iterator_specification
|
||||||
|
[
|
||||||
|
"in"
|
||||||
|
"of"
|
||||||
|
] @keyword.repeat)
|
||||||
|
|
||||||
|
(range_attribute_designator
|
||||||
|
"range" @keyword.repeat)
|
||||||
|
|
||||||
|
(raise_statement
|
||||||
|
"with" @keyword.exception)
|
||||||
|
|
||||||
|
(gnatprep_declarative_if_statement) @keyword.directive
|
||||||
|
|
||||||
|
(gnatprep_if_statement) @keyword.directive
|
||||||
|
|
||||||
|
(gnatprep_identifier) @keyword.directive
|
||||||
|
|
||||||
|
(subprogram_declaration
|
||||||
|
"is" @keyword.function
|
||||||
|
"abstract" @keyword.function)
|
||||||
|
|
||||||
|
(aspect_specification
|
||||||
|
"with" @keyword.function)
|
||||||
|
|
||||||
|
(full_type_declaration
|
||||||
|
"is" @keyword.type)
|
||||||
|
|
||||||
|
(subtype_declaration
|
||||||
|
"is" @keyword.type)
|
||||||
|
|
||||||
|
(record_definition
|
||||||
|
"end" @keyword.type)
|
||||||
|
|
||||||
|
(full_type_declaration
|
||||||
|
(_
|
||||||
|
"access" @keyword.type))
|
||||||
|
|
||||||
|
(array_type_definition
|
||||||
|
"array" @keyword.type
|
||||||
|
"of" @keyword.type)
|
||||||
|
|
||||||
|
(access_to_object_definition
|
||||||
|
"access" @keyword.type)
|
||||||
|
|
||||||
|
(access_to_object_definition
|
||||||
|
"access" @keyword.type
|
||||||
|
[
|
||||||
|
(general_access_modifier
|
||||||
|
"constant" @keyword.type)
|
||||||
|
(general_access_modifier
|
||||||
|
"all" @keyword.type)
|
||||||
|
])
|
||||||
|
|
||||||
|
(range_constraint
|
||||||
|
"range" @keyword.type)
|
||||||
|
|
||||||
|
(signed_integer_type_definition
|
||||||
|
"range" @keyword.type)
|
||||||
|
|
||||||
|
(index_subtype_definition
|
||||||
|
"range" @keyword.type)
|
||||||
|
|
||||||
|
(record_type_definition
|
||||||
|
"abstract" @keyword.type)
|
||||||
|
|
||||||
|
(record_type_definition
|
||||||
|
"tagged" @keyword.type)
|
||||||
|
|
||||||
|
(record_type_definition
|
||||||
|
"limited" @keyword.type)
|
||||||
|
|
||||||
|
(record_type_definition
|
||||||
|
(record_definition
|
||||||
|
"null" @keyword.type))
|
||||||
|
|
||||||
|
(private_type_declaration
|
||||||
|
"is" @keyword.type
|
||||||
|
"private" @keyword.type)
|
||||||
|
|
||||||
|
(private_type_declaration
|
||||||
|
"tagged" @keyword.type)
|
||||||
|
|
||||||
|
(private_type_declaration
|
||||||
|
"limited" @keyword.type)
|
||||||
|
|
||||||
|
(task_type_declaration
|
||||||
|
"task" @keyword.type
|
||||||
|
"is" @keyword.type)
|
||||||
|
|
||||||
|
; Gray the body of expression functions
|
||||||
|
(expression_function_declaration
|
||||||
|
(function_specification)
|
||||||
|
"is"
|
||||||
|
(_) @attribute)
|
||||||
|
|
||||||
|
(subprogram_declaration
|
||||||
|
(aspect_specification) @attribute)
|
||||||
|
|
||||||
|
; Highlight full subprogram specifications
|
||||||
|
;(subprogram_body
|
||||||
|
; [
|
||||||
|
; (procedure_specification)
|
||||||
|
; (function_specification)
|
||||||
|
; ] @function.spec
|
||||||
|
;)
|
||||||
|
((comment) @comment.documentation
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(entry_declaration)
|
||||||
|
(subprogram_declaration)
|
||||||
|
(parameter_specification)
|
||||||
|
])
|
||||||
|
|
||||||
|
(compilation_unit
|
||||||
|
.
|
||||||
|
(comment) @comment.documentation)
|
||||||
|
|
||||||
|
(component_list
|
||||||
|
(component_declaration)
|
||||||
|
.
|
||||||
|
(comment) @comment.documentation)
|
||||||
|
|
||||||
|
(enumeration_type_definition
|
||||||
|
(identifier)
|
||||||
|
.
|
||||||
|
(comment) @comment.documentation)
|
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
91
pack/ant/start/nvim-treesitter/queries/ada/locals.scm
Normal file
91
pack/ant/start/nvim-treesitter/queries/ada/locals.scm
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
; Better highlighting by referencing to the definition, for variable
|
||||||
|
; references. However, this is not yet supported by neovim
|
||||||
|
; See https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables
|
||||||
|
(compilation) @local.scope
|
||||||
|
|
||||||
|
(package_declaration) @local.scope
|
||||||
|
|
||||||
|
(package_body) @local.scope
|
||||||
|
|
||||||
|
(subprogram_declaration) @local.scope
|
||||||
|
|
||||||
|
(subprogram_body) @local.scope
|
||||||
|
|
||||||
|
(block_statement) @local.scope
|
||||||
|
|
||||||
|
(with_clause
|
||||||
|
(identifier) @local.definition.import)
|
||||||
|
|
||||||
|
(procedure_specification
|
||||||
|
name: (_) @local.definition.function)
|
||||||
|
|
||||||
|
(function_specification
|
||||||
|
name: (_) @local.definition.function)
|
||||||
|
|
||||||
|
(package_declaration
|
||||||
|
name: (_) @local.definition.var)
|
||||||
|
|
||||||
|
(package_body
|
||||||
|
name: (_) @local.definition.var)
|
||||||
|
|
||||||
|
(generic_instantiation
|
||||||
|
.
|
||||||
|
name: (_) @local.definition.var)
|
||||||
|
|
||||||
|
(component_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(exception_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(formal_object_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(object_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(parameter_specification
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(full_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(private_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(private_extension_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(incomplete_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(protected_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(formal_complete_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(formal_incomplete_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(task_type_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(subtype_declaration
|
||||||
|
.
|
||||||
|
(identifier) @local.definition.type)
|
||||||
|
|
||||||
|
(identifier) @local.reference
|
4
pack/ant/start/nvim-treesitter/queries/agda/folds.scm
Normal file
4
pack/ant/start/nvim-treesitter/queries/agda/folds.scm
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[
|
||||||
|
(record)
|
||||||
|
(module)
|
||||||
|
] @fold
|
87
pack/ant/start/nvim-treesitter/queries/agda/highlights.scm
Normal file
87
pack/ant/start/nvim-treesitter/queries/agda/highlights.scm
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
; Constants
|
||||||
|
(integer) @number
|
||||||
|
|
||||||
|
; Variables and Symbols
|
||||||
|
(typed_binding
|
||||||
|
(atom
|
||||||
|
(qid) @variable))
|
||||||
|
|
||||||
|
(untyped_binding) @variable
|
||||||
|
|
||||||
|
(typed_binding
|
||||||
|
(expr) @type)
|
||||||
|
|
||||||
|
(id) @function
|
||||||
|
|
||||||
|
(bid) @function
|
||||||
|
|
||||||
|
(function_name
|
||||||
|
(atom
|
||||||
|
(qid) @function))
|
||||||
|
|
||||||
|
(field_name) @function
|
||||||
|
|
||||||
|
[
|
||||||
|
(data_name)
|
||||||
|
(record_name)
|
||||||
|
] @constructor
|
||||||
|
|
||||||
|
; Set
|
||||||
|
(SetN) @type.builtin
|
||||||
|
|
||||||
|
(expr
|
||||||
|
.
|
||||||
|
(atom) @function)
|
||||||
|
|
||||||
|
((atom) @boolean
|
||||||
|
(#any-of? @boolean "true" "false" "True" "False"))
|
||||||
|
|
||||||
|
; Imports and Module Declarations
|
||||||
|
"import" @keyword.import
|
||||||
|
|
||||||
|
(module_name) @module
|
||||||
|
|
||||||
|
; Pragmas and comments
|
||||||
|
(pragma) @keyword.directive
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
; Keywords
|
||||||
|
[
|
||||||
|
"where"
|
||||||
|
"data"
|
||||||
|
"rewrite"
|
||||||
|
"postulate"
|
||||||
|
"public"
|
||||||
|
"private"
|
||||||
|
"tactic"
|
||||||
|
"Prop"
|
||||||
|
"quote"
|
||||||
|
"renaming"
|
||||||
|
"open"
|
||||||
|
"in"
|
||||||
|
"hiding"
|
||||||
|
"constructor"
|
||||||
|
"abstract"
|
||||||
|
"let"
|
||||||
|
"field"
|
||||||
|
"mutual"
|
||||||
|
"module"
|
||||||
|
"infix"
|
||||||
|
"infixl"
|
||||||
|
"infixr"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"record" @keyword.type
|
||||||
|
|
||||||
|
;(expr
|
||||||
|
; f_name: (atom) @function)
|
||||||
|
; Brackets
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
"=" @operator
|
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
1
pack/ant/start/nvim-treesitter/queries/angular/folds.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/angular/folds.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html
|
146
pack/ant/start/nvim-treesitter/queries/angular/highlights.scm
Normal file
146
pack/ant/start/nvim-treesitter/queries/angular/highlights.scm
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
; inherits: html_tags
|
||||||
|
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
(pipe_operator) @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
(string)
|
||||||
|
(static_member_expression)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(pipe_call
|
||||||
|
name: (identifier) @function)
|
||||||
|
|
||||||
|
(pipe_call
|
||||||
|
arguments: (pipe_arguments
|
||||||
|
(identifier) @variable.parameter))
|
||||||
|
|
||||||
|
(structural_directive
|
||||||
|
"*" @keyword
|
||||||
|
(identifier) @keyword)
|
||||||
|
|
||||||
|
(attribute
|
||||||
|
(attribute_name) @variable.member
|
||||||
|
(#lua-match? @variable.member "#.*"))
|
||||||
|
|
||||||
|
(binding_name
|
||||||
|
(identifier) @keyword)
|
||||||
|
|
||||||
|
(event_binding
|
||||||
|
(binding_name
|
||||||
|
(identifier) @keyword))
|
||||||
|
|
||||||
|
(event_binding
|
||||||
|
"\"" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(property_binding
|
||||||
|
"\"" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(structural_assignment
|
||||||
|
operator: (identifier) @keyword)
|
||||||
|
|
||||||
|
(member_expression
|
||||||
|
property: (identifier) @property)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @function)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: ((identifier) @function.builtin
|
||||||
|
(#eq? @function.builtin "$any")))
|
||||||
|
|
||||||
|
(pair
|
||||||
|
key: ((identifier) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "$implicit")))
|
||||||
|
|
||||||
|
[
|
||||||
|
(control_keyword)
|
||||||
|
(special_keyword)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
((control_keyword) @keyword.repeat
|
||||||
|
(#any-of? @keyword.repeat "for" "empty"))
|
||||||
|
|
||||||
|
((control_keyword) @keyword.conditional
|
||||||
|
(#any-of? @keyword.conditional "if" "else" "switch" "case" "default"))
|
||||||
|
|
||||||
|
((control_keyword) @keyword.coroutine
|
||||||
|
(#any-of? @keyword.coroutine "defer" "placeholder" "loading"))
|
||||||
|
|
||||||
|
((control_keyword) @keyword.exception
|
||||||
|
(#eq? @keyword.exception "error"))
|
||||||
|
|
||||||
|
((identifier) @boolean
|
||||||
|
(#any-of? @boolean "true" "false"))
|
||||||
|
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#any-of? @variable.builtin "this" "$event"))
|
||||||
|
|
||||||
|
((identifier) @constant.builtin
|
||||||
|
(#eq? @constant.builtin "null"))
|
||||||
|
|
||||||
|
[
|
||||||
|
(ternary_operator)
|
||||||
|
(conditional_operator)
|
||||||
|
] @keyword.conditional.ternary
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"@"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
(two_way_binding
|
||||||
|
[
|
||||||
|
"[("
|
||||||
|
")]"
|
||||||
|
] @punctuation.bracket)
|
||||||
|
|
||||||
|
[
|
||||||
|
"{{"
|
||||||
|
"}}"
|
||||||
|
] @punctuation.special
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
"."
|
||||||
|
","
|
||||||
|
"?."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
(nullish_coalescing_expression
|
||||||
|
(coalescing_operator) @operator)
|
||||||
|
|
||||||
|
(concatenation_expression
|
||||||
|
"+" @operator)
|
||||||
|
|
||||||
|
(icu_clause) @keyword.operator
|
||||||
|
|
||||||
|
(icu_category) @keyword.conditional
|
||||||
|
|
||||||
|
(binary_expression
|
||||||
|
[
|
||||||
|
"-"
|
||||||
|
"&&"
|
||||||
|
"+"
|
||||||
|
"<"
|
||||||
|
"<="
|
||||||
|
"="
|
||||||
|
"=="
|
||||||
|
"==="
|
||||||
|
"!="
|
||||||
|
"!=="
|
||||||
|
">"
|
||||||
|
">="
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"||"
|
||||||
|
"%"
|
||||||
|
] @operator)
|
16
pack/ant/start/nvim-treesitter/queries/angular/indents.scm
Normal file
16
pack/ant/start/nvim-treesitter/queries/angular/indents.scm
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
; inherits: html_tags
|
||||||
|
|
||||||
|
[
|
||||||
|
(statement_block)
|
||||||
|
(switch_statement)
|
||||||
|
] @indent.begin
|
||||||
|
|
||||||
|
(statement_block
|
||||||
|
"{" @indent.branch)
|
||||||
|
|
||||||
|
(statement_block
|
||||||
|
"}" @indent.end)
|
||||||
|
|
||||||
|
"}" @indent.branch
|
||||||
|
|
||||||
|
"}" @indent.end
|
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html_tags
|
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html
|
6
pack/ant/start/nvim-treesitter/queries/apex/folds.scm
Normal file
6
pack/ant/start/nvim-treesitter/queries/apex/folds.scm
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[
|
||||||
|
(class_body)
|
||||||
|
(constructor_declaration)
|
||||||
|
(argument_list)
|
||||||
|
(annotation_argument_list)
|
||||||
|
] @fold
|
257
pack/ant/start/nvim-treesitter/queries/apex/highlights.scm
Normal file
257
pack/ant/start/nvim-treesitter/queries/apex/highlights.scm
Normal file
|
@ -0,0 +1,257 @@
|
||||||
|
; inherits: soql
|
||||||
|
|
||||||
|
; Apex + SOQL
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
":"
|
||||||
|
"?"
|
||||||
|
";"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
; Default general color definition
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
(type_identifier) @type
|
||||||
|
|
||||||
|
; Methods
|
||||||
|
(method_declaration
|
||||||
|
name: (identifier) @function.method)
|
||||||
|
|
||||||
|
(method_invocation
|
||||||
|
name: (identifier) @function.method.call)
|
||||||
|
|
||||||
|
(super) @function.builtin
|
||||||
|
|
||||||
|
; Annotations
|
||||||
|
(annotation
|
||||||
|
name: (identifier) @attribute)
|
||||||
|
|
||||||
|
; Types
|
||||||
|
(interface_declaration
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
(superclass) @type)
|
||||||
|
|
||||||
|
(enum_declaration
|
||||||
|
name: (identifier) @type)
|
||||||
|
|
||||||
|
(enum_constant
|
||||||
|
name: (identifier) @constant)
|
||||||
|
|
||||||
|
(type_arguments
|
||||||
|
"<" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(type_arguments
|
||||||
|
">" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(field_access
|
||||||
|
object: (identifier) @type)
|
||||||
|
|
||||||
|
(field_access
|
||||||
|
field: (identifier) @property)
|
||||||
|
|
||||||
|
((scoped_identifier
|
||||||
|
scope: (identifier) @type)
|
||||||
|
(#match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
((method_invocation
|
||||||
|
object: (identifier) @type)
|
||||||
|
(#match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
(formal_parameters
|
||||||
|
(formal_parameter
|
||||||
|
name: (identifier) @variable.parameter)))
|
||||||
|
|
||||||
|
(constructor_declaration
|
||||||
|
name: (identifier) @constructor)
|
||||||
|
|
||||||
|
(dml_type) @function.builtin
|
||||||
|
|
||||||
|
(assignment_operator) @operator
|
||||||
|
|
||||||
|
(update_operator) @operator
|
||||||
|
|
||||||
|
(trigger_declaration
|
||||||
|
name: (identifier) @type
|
||||||
|
object: (identifier) @type
|
||||||
|
(trigger_event) @keyword
|
||||||
|
(","
|
||||||
|
(trigger_event) @keyword)*)
|
||||||
|
|
||||||
|
[
|
||||||
|
"@"
|
||||||
|
"="
|
||||||
|
"!="
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
(binary_expression
|
||||||
|
operator: [
|
||||||
|
">"
|
||||||
|
"<"
|
||||||
|
"=="
|
||||||
|
"==="
|
||||||
|
"!=="
|
||||||
|
"&&"
|
||||||
|
"||"
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"&"
|
||||||
|
"|"
|
||||||
|
"^"
|
||||||
|
"%"
|
||||||
|
"<<"
|
||||||
|
">>"
|
||||||
|
">>>"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(unary_expression
|
||||||
|
operator: [
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"!"
|
||||||
|
"~"
|
||||||
|
]) @operator
|
||||||
|
|
||||||
|
"=>" @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
(boolean_type)
|
||||||
|
(void_type)
|
||||||
|
] @type.builtin
|
||||||
|
|
||||||
|
; Fields
|
||||||
|
(field_declaration
|
||||||
|
declarator: (variable_declarator
|
||||||
|
name: (identifier) @variable.member))
|
||||||
|
|
||||||
|
(field_access
|
||||||
|
field: (identifier) @variable.member)
|
||||||
|
|
||||||
|
; Variables
|
||||||
|
(variable_declarator
|
||||||
|
(identifier) @property)
|
||||||
|
|
||||||
|
(field_declaration
|
||||||
|
(modifiers
|
||||||
|
(modifier
|
||||||
|
[
|
||||||
|
(final)
|
||||||
|
(static)
|
||||||
|
])
|
||||||
|
(modifier
|
||||||
|
[
|
||||||
|
(final)
|
||||||
|
(static)
|
||||||
|
]))
|
||||||
|
(variable_declarator
|
||||||
|
name: (identifier) @constant))
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) ; SCREAM SNAKE CASE
|
||||||
|
|
||||||
|
(this) @variable.builtin
|
||||||
|
|
||||||
|
; Literals
|
||||||
|
[
|
||||||
|
(int)
|
||||||
|
(decimal)
|
||||||
|
(currency_literal)
|
||||||
|
] @number
|
||||||
|
|
||||||
|
(string_literal) @string
|
||||||
|
|
||||||
|
[
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
|
(null_literal) @constant.builtin
|
||||||
|
|
||||||
|
; ;; Keywords
|
||||||
|
[
|
||||||
|
"abstract"
|
||||||
|
"final"
|
||||||
|
"private"
|
||||||
|
"protected"
|
||||||
|
"public"
|
||||||
|
"static"
|
||||||
|
] @keyword.modifier
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"switch"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"while"
|
||||||
|
"do"
|
||||||
|
"break"
|
||||||
|
] @keyword.repeat
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
[
|
||||||
|
"throw"
|
||||||
|
"finally"
|
||||||
|
"try"
|
||||||
|
"catch"
|
||||||
|
] @keyword.exception
|
||||||
|
|
||||||
|
"new" @keyword.operator
|
||||||
|
|
||||||
|
[
|
||||||
|
(abstract)
|
||||||
|
(all_rows_clause)
|
||||||
|
"continue"
|
||||||
|
"extends"
|
||||||
|
(final)
|
||||||
|
"get"
|
||||||
|
(global)
|
||||||
|
"implements"
|
||||||
|
"instanceof"
|
||||||
|
"on"
|
||||||
|
(override)
|
||||||
|
(private)
|
||||||
|
(protected)
|
||||||
|
(public)
|
||||||
|
"set"
|
||||||
|
(static)
|
||||||
|
(testMethod)
|
||||||
|
(webservice)
|
||||||
|
(transient)
|
||||||
|
"trigger"
|
||||||
|
(virtual)
|
||||||
|
"when"
|
||||||
|
(with_sharing)
|
||||||
|
(without_sharing)
|
||||||
|
(inherited_sharing)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
|
"interface"
|
||||||
|
"class"
|
||||||
|
"enum"
|
||||||
|
] @keyword.type
|
||||||
|
|
||||||
|
"System.runAs" @function.builtin
|
|
@ -0,0 +1,5 @@
|
||||||
|
([
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
70
pack/ant/start/nvim-treesitter/queries/apex/locals.scm
Normal file
70
pack/ant/start/nvim-treesitter/queries/apex/locals.scm
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
; declarations
|
||||||
|
(class_declaration) @local.scope
|
||||||
|
|
||||||
|
(method_declaration) @local.scope
|
||||||
|
|
||||||
|
(constructor_declaration) @local.scope
|
||||||
|
|
||||||
|
(enum_declaration) @local.scope
|
||||||
|
|
||||||
|
(enhanced_for_statement) @local.scope
|
||||||
|
|
||||||
|
; if/else
|
||||||
|
(if_statement) @local.scope
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
consequence: (_) @local.scope) ; if body in case there are no braces
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
alternative: (_) @local.scope) ; else body in case there are no braces
|
||||||
|
|
||||||
|
; try/catch
|
||||||
|
(try_statement) @local.scope ; covers try+catch, individual try and catch are covered by (block)
|
||||||
|
|
||||||
|
(catch_clause) @local.scope ; needed because `Exception` variable
|
||||||
|
|
||||||
|
; loops
|
||||||
|
(for_statement) @local.scope
|
||||||
|
|
||||||
|
(for_statement ; "for" body in case there are no braces
|
||||||
|
body: (_) @local.scope)
|
||||||
|
|
||||||
|
(do_statement
|
||||||
|
body: (_) @local.scope)
|
||||||
|
|
||||||
|
(while_statement
|
||||||
|
body: (_) @local.scope)
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
(constructor_declaration) @local.scope
|
||||||
|
|
||||||
|
(method_declaration) @local.scope
|
||||||
|
|
||||||
|
; definitions
|
||||||
|
(enum_declaration
|
||||||
|
name: (identifier) @local.definition.enum)
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (identifier) @local.definition.method)
|
||||||
|
|
||||||
|
(local_variable_declaration
|
||||||
|
declarator: (variable_declarator
|
||||||
|
name: (identifier) @local.definition.var))
|
||||||
|
|
||||||
|
(enhanced_for_statement
|
||||||
|
name: (identifier) @local.definition.var)
|
||||||
|
|
||||||
|
(formal_parameter
|
||||||
|
name: (identifier) @local.definition.parameter)
|
||||||
|
|
||||||
|
(catch_formal_parameter
|
||||||
|
name: (identifier) @local.definition.parameter)
|
||||||
|
|
||||||
|
(field_declaration
|
||||||
|
declarator: (variable_declarator
|
||||||
|
name: (identifier) @local.definition.field))
|
||||||
|
|
||||||
|
; REFERENCES
|
||||||
|
(identifier) @local.reference
|
||||||
|
|
||||||
|
(type_identifier) @local.reference
|
1
pack/ant/start/nvim-treesitter/queries/arduino/folds.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/arduino/folds.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: cpp
|
|
@ -0,0 +1,53 @@
|
||||||
|
; inherits: cpp
|
||||||
|
|
||||||
|
((identifier) @function.builtin
|
||||||
|
(#any-of? @function.builtin
|
||||||
|
; Digital I/O
|
||||||
|
"digitalRead" "digitalWrite" "pinMode"
|
||||||
|
; Analog I/O
|
||||||
|
"analogRead" "analogReference" "analogWrite"
|
||||||
|
; Zero, Due & MKR Family
|
||||||
|
"analogReadResolution" "analogWriteResolution"
|
||||||
|
; Advanced I/O
|
||||||
|
"noTone" "pulseIn" "pulseInLong" "shiftIn" "shiftOut" "tone"
|
||||||
|
; Time
|
||||||
|
"delay" "delayMicroseconds" "micros" "millis"
|
||||||
|
; Math
|
||||||
|
"abs" "constrain" "map" "max" "min" "pow" "sq" "sqrt"
|
||||||
|
; Trigonometry
|
||||||
|
"cos" "sin" "tan"
|
||||||
|
; Characters
|
||||||
|
"isAlpha" "isAlphaNumeric" "isAscii" "isControl" "isDigit" "isGraph" "isHexadecimalDigit"
|
||||||
|
"isLowerCase" "isPrintable" "isPunct" "isSpace" "isUpperCase" "isWhitespace"
|
||||||
|
; Random Numbers
|
||||||
|
"random" "randomSeed"
|
||||||
|
; Bits and Bytes
|
||||||
|
"bit" "bitClear" "bitRead" "bitSet" "bitWrite" "highByte" "lowByte"
|
||||||
|
; External Interrupts
|
||||||
|
"attachInterrupt" "detachInterrupt"
|
||||||
|
; Interrupts
|
||||||
|
"interrupts" "noInterrupts"))
|
||||||
|
|
||||||
|
((identifier) @type.builtin
|
||||||
|
(#any-of? @type.builtin "Serial" "SPI" "Stream" "Wire" "Keyboard" "Mouse" "String"))
|
||||||
|
|
||||||
|
((identifier) @constant.builtin
|
||||||
|
(#any-of? @constant.builtin "HIGH" "LOW" "INPUT" "OUTPUT" "INPUT_PULLUP" "LED_BUILTIN"))
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
(function_declarator
|
||||||
|
declarator: (identifier) @function.builtin)
|
||||||
|
(#any-of? @function.builtin "loop" "setup"))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (primitive_type) @function.builtin)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @constructor
|
||||||
|
(#any-of? @constructor "SPISettings" "String"))
|
||||||
|
|
||||||
|
(declaration
|
||||||
|
(type_identifier) @type.builtin
|
||||||
|
(function_declarator
|
||||||
|
declarator: (identifier) @constructor)
|
||||||
|
(#eq? @type.builtin "SPISettings"))
|
|
@ -0,0 +1 @@
|
||||||
|
; inherits: cpp
|
|
@ -0,0 +1,5 @@
|
||||||
|
((preproc_arg) @injection.content
|
||||||
|
(#set! injection.language "arduino"))
|
||||||
|
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
|
@ -0,0 +1 @@
|
||||||
|
; inherits: cpp
|
66
pack/ant/start/nvim-treesitter/queries/asm/highlights.scm
Normal file
66
pack/ant/start/nvim-treesitter/queries/asm/highlights.scm
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
; General
|
||||||
|
(label
|
||||||
|
[
|
||||||
|
(ident)
|
||||||
|
(word)
|
||||||
|
] @label)
|
||||||
|
|
||||||
|
(reg) @variable.builtin
|
||||||
|
|
||||||
|
(meta
|
||||||
|
kind: (_) @function.builtin)
|
||||||
|
|
||||||
|
(instruction
|
||||||
|
kind: (_) @function.builtin)
|
||||||
|
|
||||||
|
(const
|
||||||
|
name: (word) @constant)
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
[
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @comment @spell
|
||||||
|
|
||||||
|
; Literals
|
||||||
|
(int) @number
|
||||||
|
|
||||||
|
(float) @number.float
|
||||||
|
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
; Keywords
|
||||||
|
[
|
||||||
|
"byte"
|
||||||
|
"word"
|
||||||
|
"dword"
|
||||||
|
"qword"
|
||||||
|
"ptr"
|
||||||
|
"rel"
|
||||||
|
"label"
|
||||||
|
"const"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
; Operators & Punctuation
|
||||||
|
[
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"|"
|
||||||
|
"^"
|
||||||
|
"&"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
","
|
||||||
|
":"
|
||||||
|
] @punctuation.delimiter
|
|
@ -0,0 +1,5 @@
|
||||||
|
([
|
||||||
|
(line_comment)
|
||||||
|
(block_comment)
|
||||||
|
] @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
1
pack/ant/start/nvim-treesitter/queries/astro/folds.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/astro/folds.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html
|
25
pack/ant/start/nvim-treesitter/queries/astro/highlights.scm
Normal file
25
pack/ant/start/nvim-treesitter/queries/astro/highlights.scm
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
; inherits: html_tags
|
||||||
|
|
||||||
|
(doctype) @constant
|
||||||
|
|
||||||
|
"<!" @tag.delimiter
|
||||||
|
|
||||||
|
"---" @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.special
|
||||||
|
|
||||||
|
; custom components get `@type` highlighting
|
||||||
|
((start_tag
|
||||||
|
(tag_name) @type)
|
||||||
|
(#lua-match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
((end_tag
|
||||||
|
(tag_name) @type)
|
||||||
|
(#lua-match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
((erroneous_end_tag
|
||||||
|
(erroneous_end_tag_name) @type)
|
||||||
|
(#lua-match? @type "^[A-Z]"))
|
1
pack/ant/start/nvim-treesitter/queries/astro/indents.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/astro/indents.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html
|
32
pack/ant/start/nvim-treesitter/queries/astro/injections.scm
Normal file
32
pack/ant/start/nvim-treesitter/queries/astro/injections.scm
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
; inherits: html_tags
|
||||||
|
|
||||||
|
(frontmatter
|
||||||
|
(frontmatter_js_block) @injection.content
|
||||||
|
(#set! injection.language "typescript"))
|
||||||
|
|
||||||
|
(attribute_interpolation
|
||||||
|
(attribute_js_expr) @injection.content
|
||||||
|
(#set! injection.language "typescript"))
|
||||||
|
|
||||||
|
(attribute
|
||||||
|
(attribute_backtick_string) @injection.content
|
||||||
|
(#set! injection.language "typescript"))
|
||||||
|
|
||||||
|
(html_interpolation
|
||||||
|
(permissible_text) @injection.content
|
||||||
|
(#set! injection.language "typescript"))
|
||||||
|
|
||||||
|
(script_element
|
||||||
|
(raw_text) @injection.content
|
||||||
|
(#set! injection.language "typescript"))
|
||||||
|
|
||||||
|
(style_element
|
||||||
|
(start_tag
|
||||||
|
(attribute
|
||||||
|
(attribute_name) @_lang_attr
|
||||||
|
(quoted_attribute_value
|
||||||
|
(attribute_value) @_lang_value)))
|
||||||
|
(raw_text) @injection.content
|
||||||
|
(#eq? @_lang_attr "lang")
|
||||||
|
(#eq? @_lang_value "scss")
|
||||||
|
(#set! injection.language "scss"))
|
1
pack/ant/start/nvim-treesitter/queries/astro/locals.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/astro/locals.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
; inherits: html
|
|
@ -0,0 +1,60 @@
|
||||||
|
(identifier) @function
|
||||||
|
|
||||||
|
(block
|
||||||
|
(relation
|
||||||
|
(relation_literal) @function.builtin
|
||||||
|
(identifier) @constant))
|
||||||
|
|
||||||
|
(block
|
||||||
|
(permission
|
||||||
|
(permission_literal) @variable.builtin
|
||||||
|
(identifier) @type))
|
||||||
|
|
||||||
|
; relations
|
||||||
|
(rel_expression
|
||||||
|
(identifier) @property)
|
||||||
|
|
||||||
|
(relation
|
||||||
|
(rel_expression
|
||||||
|
(hash_literal)
|
||||||
|
.
|
||||||
|
(identifier) @constant))
|
||||||
|
|
||||||
|
; permissions
|
||||||
|
(perm_expression
|
||||||
|
(identifier) @property)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (selector_expression
|
||||||
|
operand: (identifier) @constant
|
||||||
|
field: (field_identifier) @function.method))
|
||||||
|
|
||||||
|
(perm_expression
|
||||||
|
(stabby) @operator
|
||||||
|
.
|
||||||
|
(identifier) @function)
|
||||||
|
|
||||||
|
; misc
|
||||||
|
[
|
||||||
|
(plus_literal)
|
||||||
|
(minus_literal)
|
||||||
|
(amp_literal)
|
||||||
|
(pipe_literal)
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
[
|
||||||
|
(true)
|
||||||
|
(false)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(caveat_literal)
|
||||||
|
(definition_literal)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
|
(hash_literal)
|
||||||
|
(comment)
|
||||||
|
] @comment
|
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
199
pack/ant/start/nvim-treesitter/queries/awk/highlights.scm
Normal file
199
pack/ant/start/nvim-treesitter/queries/awk/highlights.scm
Normal file
|
@ -0,0 +1,199 @@
|
||||||
|
; adapted from https://github.com/Beaglefoot/tree-sitter-awk
|
||||||
|
[
|
||||||
|
(identifier)
|
||||||
|
(field_ref)
|
||||||
|
] @variable
|
||||||
|
|
||||||
|
(field_ref
|
||||||
|
(_) @variable)
|
||||||
|
|
||||||
|
; https://www.gnu.org/software/gawk/manual/html_node/Auto_002dset.html
|
||||||
|
((identifier) @constant.builtin
|
||||||
|
(#any-of? @constant.builtin
|
||||||
|
"ARGC" "ARGV" "ARGIND" "ENVIRON" "ERRNO" "FILENAME" "FNR" "NF" "FUNCTAB" "NR" "PROCINFO"
|
||||||
|
"RLENGTH" "RSTART" "RT" "SYMTAB"))
|
||||||
|
|
||||||
|
; https://www.gnu.org/software/gawk/manual/html_node/User_002dmodified.html
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#any-of? @variable.builtin
|
||||||
|
"BINMODE" "CONVFMT" "FIELDWIDTHS" "FPAT" "FS" "IGNORECASE" "LINT" "OFMT" "OFS" "ORS" "PREC"
|
||||||
|
"ROUNDMODE" "RS" "SUBSEP" "TEXTDOMAIN"))
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
(regex) @string.regexp
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
((program
|
||||||
|
.
|
||||||
|
(comment) @keyword.directive @nospell)
|
||||||
|
(#lua-match? @keyword.directive "^#!/"))
|
||||||
|
|
||||||
|
(ns_qualified_name
|
||||||
|
(namespace) @module)
|
||||||
|
|
||||||
|
(ns_qualified_name
|
||||||
|
"::" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(func_def
|
||||||
|
name: (_
|
||||||
|
(identifier) @function) @function)
|
||||||
|
|
||||||
|
(func_call
|
||||||
|
name: (_
|
||||||
|
(identifier) @function) @function)
|
||||||
|
|
||||||
|
(func_def
|
||||||
|
(param_list
|
||||||
|
(identifier) @variable.parameter))
|
||||||
|
|
||||||
|
[
|
||||||
|
"print"
|
||||||
|
"printf"
|
||||||
|
"getline"
|
||||||
|
] @function.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(delete_statement)
|
||||||
|
(break_statement)
|
||||||
|
(continue_statement)
|
||||||
|
(next_statement)
|
||||||
|
(nextfile_statement)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
|
"func"
|
||||||
|
"function"
|
||||||
|
] @keyword.function
|
||||||
|
|
||||||
|
[
|
||||||
|
"return"
|
||||||
|
"exit"
|
||||||
|
] @keyword.return
|
||||||
|
|
||||||
|
[
|
||||||
|
"do"
|
||||||
|
"while"
|
||||||
|
"for"
|
||||||
|
"in"
|
||||||
|
] @keyword.repeat
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"else"
|
||||||
|
"switch"
|
||||||
|
"case"
|
||||||
|
"default"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"@include"
|
||||||
|
"@load"
|
||||||
|
] @keyword.import
|
||||||
|
|
||||||
|
"@namespace" @keyword.directive
|
||||||
|
|
||||||
|
[
|
||||||
|
"BEGIN"
|
||||||
|
"END"
|
||||||
|
"BEGINFILE"
|
||||||
|
"ENDFILE"
|
||||||
|
] @label
|
||||||
|
|
||||||
|
(binary_exp
|
||||||
|
[
|
||||||
|
"^"
|
||||||
|
"**"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
"=="
|
||||||
|
"!="
|
||||||
|
"~"
|
||||||
|
"!~"
|
||||||
|
"in"
|
||||||
|
"&&"
|
||||||
|
"||"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(unary_exp
|
||||||
|
[
|
||||||
|
"!"
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(assignment_exp
|
||||||
|
[
|
||||||
|
"="
|
||||||
|
"+="
|
||||||
|
"-="
|
||||||
|
"*="
|
||||||
|
"/="
|
||||||
|
"%="
|
||||||
|
"^="
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(ternary_exp
|
||||||
|
[
|
||||||
|
"?"
|
||||||
|
":"
|
||||||
|
] @keyword.conditional.ternary)
|
||||||
|
|
||||||
|
(update_exp
|
||||||
|
[
|
||||||
|
"++"
|
||||||
|
"--"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(redirected_io_statement
|
||||||
|
[
|
||||||
|
">"
|
||||||
|
">>"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(piped_io_statement
|
||||||
|
[
|
||||||
|
"|"
|
||||||
|
"|&"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(piped_io_exp
|
||||||
|
[
|
||||||
|
"|"
|
||||||
|
"|&"
|
||||||
|
] @operator)
|
||||||
|
|
||||||
|
(field_ref
|
||||||
|
"$" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(regex
|
||||||
|
"/" @punctuation.delimiter)
|
||||||
|
|
||||||
|
(regex_constant
|
||||||
|
"@" @punctuation.delimiter)
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
","
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
17
pack/ant/start/nvim-treesitter/queries/awk/injections.scm
Normal file
17
pack/ant/start/nvim-treesitter/queries/awk/injections.scm
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
||||||
|
|
||||||
|
((regex) @injection.content
|
||||||
|
(#set! injection.language "regex"))
|
||||||
|
|
||||||
|
((print_statement
|
||||||
|
(exp_list
|
||||||
|
.
|
||||||
|
(string) @injection.content))
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
((printf_statement
|
||||||
|
(exp_list
|
||||||
|
.
|
||||||
|
(string) @injection.content))
|
||||||
|
(#set! injection.language "printf"))
|
9
pack/ant/start/nvim-treesitter/queries/bash/folds.scm
Normal file
9
pack/ant/start/nvim-treesitter/queries/bash/folds.scm
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[
|
||||||
|
(function_definition)
|
||||||
|
(if_statement)
|
||||||
|
(case_statement)
|
||||||
|
(for_statement)
|
||||||
|
(while_statement)
|
||||||
|
(c_style_for_statement)
|
||||||
|
(heredoc_redirect)
|
||||||
|
] @fold
|
239
pack/ant/start/nvim-treesitter/queries/bash/highlights.scm
Normal file
239
pack/ant/start/nvim-treesitter/queries/bash/highlights.scm
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"[["
|
||||||
|
"]]"
|
||||||
|
"(("
|
||||||
|
"))"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
";;"
|
||||||
|
";&"
|
||||||
|
";;&"
|
||||||
|
"&"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
">"
|
||||||
|
">>"
|
||||||
|
"<"
|
||||||
|
"<<"
|
||||||
|
"&&"
|
||||||
|
"|"
|
||||||
|
"|&"
|
||||||
|
"||"
|
||||||
|
"="
|
||||||
|
"+="
|
||||||
|
"=~"
|
||||||
|
"=="
|
||||||
|
"!="
|
||||||
|
"&>"
|
||||||
|
"&>>"
|
||||||
|
"<&"
|
||||||
|
">&"
|
||||||
|
">|"
|
||||||
|
"<&-"
|
||||||
|
">&-"
|
||||||
|
"<<-"
|
||||||
|
"<<<"
|
||||||
|
".."
|
||||||
|
"!"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
; Do *not* spell check strings since they typically have some sort of
|
||||||
|
; interpolation in them, or, are typically used for things like filenames, URLs,
|
||||||
|
; flags and file content.
|
||||||
|
[
|
||||||
|
(string)
|
||||||
|
(raw_string)
|
||||||
|
(ansi_c_string)
|
||||||
|
(heredoc_body)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
[
|
||||||
|
(heredoc_start)
|
||||||
|
(heredoc_end)
|
||||||
|
] @label
|
||||||
|
|
||||||
|
(variable_assignment
|
||||||
|
(word) @string)
|
||||||
|
|
||||||
|
(command
|
||||||
|
argument: "$" @string) ; bare dollar
|
||||||
|
|
||||||
|
(concatenation
|
||||||
|
(word) @string)
|
||||||
|
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"then"
|
||||||
|
"else"
|
||||||
|
"elif"
|
||||||
|
"fi"
|
||||||
|
"case"
|
||||||
|
"in"
|
||||||
|
"esac"
|
||||||
|
] @keyword.conditional
|
||||||
|
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"do"
|
||||||
|
"done"
|
||||||
|
"select"
|
||||||
|
"until"
|
||||||
|
"while"
|
||||||
|
] @keyword.repeat
|
||||||
|
|
||||||
|
[
|
||||||
|
"declare"
|
||||||
|
"typeset"
|
||||||
|
"readonly"
|
||||||
|
"local"
|
||||||
|
"unset"
|
||||||
|
"unsetenv"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"export" @keyword.import
|
||||||
|
|
||||||
|
"function" @keyword.function
|
||||||
|
|
||||||
|
(special_variable_name) @constant
|
||||||
|
|
||||||
|
; trap -l
|
||||||
|
((word) @constant.builtin
|
||||||
|
(#any-of? @constant.builtin
|
||||||
|
"SIGHUP" "SIGINT" "SIGQUIT" "SIGILL" "SIGTRAP" "SIGABRT" "SIGBUS" "SIGFPE" "SIGKILL" "SIGUSR1"
|
||||||
|
"SIGSEGV" "SIGUSR2" "SIGPIPE" "SIGALRM" "SIGTERM" "SIGSTKFLT" "SIGCHLD" "SIGCONT" "SIGSTOP"
|
||||||
|
"SIGTSTP" "SIGTTIN" "SIGTTOU" "SIGURG" "SIGXCPU" "SIGXFSZ" "SIGVTALRM" "SIGPROF" "SIGWINCH"
|
||||||
|
"SIGIO" "SIGPWR" "SIGSYS" "SIGRTMIN" "SIGRTMIN+1" "SIGRTMIN+2" "SIGRTMIN+3" "SIGRTMIN+4"
|
||||||
|
"SIGRTMIN+5" "SIGRTMIN+6" "SIGRTMIN+7" "SIGRTMIN+8" "SIGRTMIN+9" "SIGRTMIN+10" "SIGRTMIN+11"
|
||||||
|
"SIGRTMIN+12" "SIGRTMIN+13" "SIGRTMIN+14" "SIGRTMIN+15" "SIGRTMAX-14" "SIGRTMAX-13"
|
||||||
|
"SIGRTMAX-12" "SIGRTMAX-11" "SIGRTMAX-10" "SIGRTMAX-9" "SIGRTMAX-8" "SIGRTMAX-7" "SIGRTMAX-6"
|
||||||
|
"SIGRTMAX-5" "SIGRTMAX-4" "SIGRTMAX-3" "SIGRTMAX-2" "SIGRTMAX-1" "SIGRTMAX"))
|
||||||
|
|
||||||
|
((word) @boolean
|
||||||
|
(#any-of? @boolean "true" "false"))
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
(test_operator) @operator
|
||||||
|
|
||||||
|
(command_substitution
|
||||||
|
"$(" @punctuation.special
|
||||||
|
")" @punctuation.special)
|
||||||
|
|
||||||
|
(process_substitution
|
||||||
|
[
|
||||||
|
"<("
|
||||||
|
">("
|
||||||
|
] @punctuation.special
|
||||||
|
")" @punctuation.special)
|
||||||
|
|
||||||
|
(arithmetic_expansion
|
||||||
|
[
|
||||||
|
"$(("
|
||||||
|
"(("
|
||||||
|
] @punctuation.special
|
||||||
|
"))" @punctuation.special)
|
||||||
|
|
||||||
|
(arithmetic_expansion
|
||||||
|
"," @punctuation.delimiter)
|
||||||
|
|
||||||
|
(ternary_expression
|
||||||
|
[
|
||||||
|
"?"
|
||||||
|
":"
|
||||||
|
] @keyword.conditional.ternary)
|
||||||
|
|
||||||
|
(binary_expression
|
||||||
|
operator: _ @operator)
|
||||||
|
|
||||||
|
(unary_expression
|
||||||
|
operator: _ @operator)
|
||||||
|
|
||||||
|
(postfix_expression
|
||||||
|
operator: _ @operator)
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (word) @function)
|
||||||
|
|
||||||
|
(command_name
|
||||||
|
(word) @function.call)
|
||||||
|
|
||||||
|
(command_name
|
||||||
|
(word) @function.builtin
|
||||||
|
(#any-of? @function.builtin
|
||||||
|
"alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete" "compopt"
|
||||||
|
"continue" "coproc" "dirs" "disown" "echo" "enable" "eval" "exec" "exit" "fc" "fg" "getopts"
|
||||||
|
"hash" "help" "history" "jobs" "kill" "let" "logout" "mapfile" "popd" "printf" "pushd" "pwd"
|
||||||
|
"read" "readarray" "return" "set" "shift" "shopt" "source" "suspend" "test" "time" "times"
|
||||||
|
"trap" "type" "typeset" "ulimit" "umask" "unalias" "wait"))
|
||||||
|
|
||||||
|
(command
|
||||||
|
argument: [
|
||||||
|
(word) @variable.parameter
|
||||||
|
(concatenation
|
||||||
|
(word) @variable.parameter)
|
||||||
|
])
|
||||||
|
|
||||||
|
(declaration_command
|
||||||
|
(word) @variable.parameter)
|
||||||
|
|
||||||
|
(unset_command
|
||||||
|
(word) @variable.parameter)
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
((word) @number
|
||||||
|
(#lua-match? @number "^[0-9]+$"))
|
||||||
|
|
||||||
|
(file_redirect
|
||||||
|
destination: (word) @variable.parameter)
|
||||||
|
|
||||||
|
(file_descriptor) @operator
|
||||||
|
|
||||||
|
(simple_expansion
|
||||||
|
"$" @punctuation.special) @none
|
||||||
|
|
||||||
|
(expansion
|
||||||
|
"${" @punctuation.special
|
||||||
|
"}" @punctuation.special) @none
|
||||||
|
|
||||||
|
(expansion
|
||||||
|
operator: _ @punctuation.special)
|
||||||
|
|
||||||
|
(expansion
|
||||||
|
"@"
|
||||||
|
.
|
||||||
|
operator: _ @character.special)
|
||||||
|
|
||||||
|
((expansion
|
||||||
|
(subscript
|
||||||
|
index: (word) @character.special))
|
||||||
|
(#any-of? @character.special "@" "*"))
|
||||||
|
|
||||||
|
"``" @punctuation.special
|
||||||
|
|
||||||
|
(variable_name) @variable
|
||||||
|
|
||||||
|
((variable_name) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
|
(case_item
|
||||||
|
value: (word) @variable.parameter)
|
||||||
|
|
||||||
|
[
|
||||||
|
(regex)
|
||||||
|
(extglob_pattern)
|
||||||
|
] @string.regexp
|
||||||
|
|
||||||
|
((program
|
||||||
|
.
|
||||||
|
(comment) @keyword.directive @nospell)
|
||||||
|
(#lua-match? @keyword.directive "^#!/"))
|
79
pack/ant/start/nvim-treesitter/queries/bash/injections.scm
Normal file
79
pack/ant/start/nvim-treesitter/queries/bash/injections.scm
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
||||||
|
|
||||||
|
((regex) @injection.content
|
||||||
|
(#set! injection.language "regex"))
|
||||||
|
|
||||||
|
((heredoc_redirect
|
||||||
|
(heredoc_body) @injection.content
|
||||||
|
(heredoc_end) @injection.language)
|
||||||
|
(#downcase! @injection.language))
|
||||||
|
|
||||||
|
; printf 'format'
|
||||||
|
((command
|
||||||
|
name: (command_name) @_command
|
||||||
|
.
|
||||||
|
argument: [
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenation
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content))
|
||||||
|
(raw_string) @injection.content
|
||||||
|
(concatenation
|
||||||
|
(raw_string) @injection.content)
|
||||||
|
])
|
||||||
|
(#eq? @_command "printf")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
; printf -v var 'format'
|
||||||
|
((command
|
||||||
|
name: (command_name) @_command
|
||||||
|
argument: (word) @_arg
|
||||||
|
.
|
||||||
|
(_)
|
||||||
|
.
|
||||||
|
argument: [
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenation
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content))
|
||||||
|
(raw_string) @injection.content
|
||||||
|
(concatenation
|
||||||
|
(raw_string) @injection.content)
|
||||||
|
])
|
||||||
|
(#eq? @_command "printf")
|
||||||
|
(#eq? @_arg "-v")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
; printf -- 'format'
|
||||||
|
((command
|
||||||
|
name: (command_name) @_command
|
||||||
|
argument: (word) @_arg
|
||||||
|
.
|
||||||
|
argument: [
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content)
|
||||||
|
(concatenation
|
||||||
|
(string
|
||||||
|
(string_content) @injection.content))
|
||||||
|
(raw_string) @injection.content
|
||||||
|
(concatenation
|
||||||
|
(raw_string) @injection.content)
|
||||||
|
])
|
||||||
|
(#eq? @_command "printf")
|
||||||
|
(#eq? @_arg "--")
|
||||||
|
(#set! injection.language "printf"))
|
||||||
|
|
||||||
|
((command
|
||||||
|
name: (command_name) @_command
|
||||||
|
.
|
||||||
|
argument: [
|
||||||
|
(string)
|
||||||
|
(raw_string)
|
||||||
|
] @injection.content)
|
||||||
|
(#eq? @_command "bind")
|
||||||
|
(#offset! @injection.content 0 1 0 -1)
|
||||||
|
(#set! injection.include-children)
|
||||||
|
(#set! injection.language "readline"))
|
14
pack/ant/start/nvim-treesitter/queries/bash/locals.scm
Normal file
14
pack/ant/start/nvim-treesitter/queries/bash/locals.scm
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
; Scopes
|
||||||
|
(function_definition) @local.scope
|
||||||
|
|
||||||
|
; Definitions
|
||||||
|
(variable_assignment
|
||||||
|
name: (variable_name) @local.definition.var)
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (word) @local.definition.function)
|
||||||
|
|
||||||
|
; References
|
||||||
|
(variable_name) @local.reference
|
||||||
|
|
||||||
|
(word) @local.reference
|
5
pack/ant/start/nvim-treesitter/queries/bass/folds.scm
Normal file
5
pack/ant/start/nvim-treesitter/queries/bass/folds.scm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[
|
||||||
|
(list)
|
||||||
|
(scope)
|
||||||
|
(cons)
|
||||||
|
] @fold
|
126
pack/ant/start/nvim-treesitter/queries/bass/highlights.scm
Normal file
126
pack/ant/start/nvim-treesitter/queries/bass/highlights.scm
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
; Variables
|
||||||
|
(list
|
||||||
|
(symbol) @variable)
|
||||||
|
|
||||||
|
(cons
|
||||||
|
(symbol) @variable)
|
||||||
|
|
||||||
|
(scope
|
||||||
|
(symbol) @variable)
|
||||||
|
|
||||||
|
(symbind
|
||||||
|
(symbol) @variable)
|
||||||
|
|
||||||
|
; Constants
|
||||||
|
((symbol) @constant
|
||||||
|
(#lua-match? @constant "^_*[A-Z][A-Z0-9_]*$"))
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
(list
|
||||||
|
.
|
||||||
|
(symbol) @function)
|
||||||
|
|
||||||
|
; Namespaces
|
||||||
|
(symbind
|
||||||
|
(symbol) @module
|
||||||
|
.
|
||||||
|
(keyword))
|
||||||
|
|
||||||
|
; Includes
|
||||||
|
((symbol) @keyword.import
|
||||||
|
(#any-of? @keyword.import "use" "import" "load"))
|
||||||
|
|
||||||
|
; Keywords
|
||||||
|
((symbol) @keyword
|
||||||
|
(#any-of? @keyword "do" "doc"))
|
||||||
|
|
||||||
|
; Special Functions
|
||||||
|
; Keywords construct a symbol
|
||||||
|
(keyword) @constructor
|
||||||
|
|
||||||
|
((list
|
||||||
|
.
|
||||||
|
(symbol) @keyword.function
|
||||||
|
.
|
||||||
|
(symbol) @function
|
||||||
|
(symbol)? @variable.parameter)
|
||||||
|
(#any-of? @keyword.function "def" "defop" "defn" "fn"))
|
||||||
|
|
||||||
|
((cons
|
||||||
|
.
|
||||||
|
(symbol) @keyword.function
|
||||||
|
.
|
||||||
|
(symbol) @function
|
||||||
|
(symbol)? @variable.parameter)
|
||||||
|
(#any-of? @keyword.function "def" "defop" "defn" "fn"))
|
||||||
|
|
||||||
|
((symbol) @function.builtin
|
||||||
|
(#any-of? @function.builtin
|
||||||
|
"dump" "mkfs" "json" "log" "error" "now" "cons" "wrap" "unwrap" "eval" "make-scope" "bind"
|
||||||
|
"meta" "with-meta" "null?" "ignore?" "boolean?" "number?" "string?" "symbol?" "scope?" "sink?"
|
||||||
|
"source?" "list?" "pair?" "applicative?" "operative?" "combiner?" "path?" "empty?" "thunk?" "+"
|
||||||
|
"*" "quot" "-" "max" "min" "=" ">" ">=" "<" "<=" "list->source" "across" "emit" "next"
|
||||||
|
"reduce-kv" "assoc" "symbol->string" "string->symbol" "str" "substring" "trim" "scope->list"
|
||||||
|
"string->fs-path" "string->cmd-path" "string->dir" "subpath" "path-name" "path-stem"
|
||||||
|
"with-image" "with-dir" "with-args" "with-cmd" "with-stdin" "with-env" "with-insecure"
|
||||||
|
"with-label" "with-port" "with-tls" "with-mount" "thunk-cmd" "thunk-args" "resolve" "start"
|
||||||
|
"addr" "wait" "read" "cache-dir" "binds?" "recall-memo" "store-memo" "mask" "list" "list*"
|
||||||
|
"first" "rest" "length" "second" "third" "map" "map-pairs" "foldr" "foldl" "append" "filter"
|
||||||
|
"conj" "list->scope" "merge" "apply" "id" "always" "vals" "keys" "memo" "succeeds?" "run" "last"
|
||||||
|
"take" "take-all" "insecure!" "from" "cd" "wrap-cmd" "mkfile" "path-base" "not"))
|
||||||
|
|
||||||
|
((symbol) @function.macro
|
||||||
|
(#any-of? @function.macro
|
||||||
|
"op" "current-scope" "quote" "let" "provide" "module" "or" "and" "curryfn" "for" "$" "linux"))
|
||||||
|
|
||||||
|
; Conditionals
|
||||||
|
((symbol) @keyword.conditional
|
||||||
|
(#any-of? @keyword.conditional "if" "case" "cond" "when"))
|
||||||
|
|
||||||
|
; Repeats
|
||||||
|
((symbol) @keyword.repeat
|
||||||
|
(#any-of? @keyword.repeat "each"))
|
||||||
|
|
||||||
|
; Operators
|
||||||
|
((symbol) @operator
|
||||||
|
(#any-of? @operator "&" "*" "+" "-" "<" "<=" "=" ">" ">="))
|
||||||
|
|
||||||
|
; Punctuation
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
((symbol) @punctuation.delimiter
|
||||||
|
(#eq? @punctuation.delimiter "->"))
|
||||||
|
|
||||||
|
; Literals
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
(path) @string.special.url
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(boolean) @boolean
|
||||||
|
|
||||||
|
[
|
||||||
|
(ignore)
|
||||||
|
(null)
|
||||||
|
] @constant.builtin
|
||||||
|
|
||||||
|
"^" @character.special
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
(comment) @comment @spell
|
31
pack/ant/start/nvim-treesitter/queries/bass/indents.scm
Normal file
31
pack/ant/start/nvim-treesitter/queries/bass/indents.scm
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
[
|
||||||
|
(list)
|
||||||
|
(scope)
|
||||||
|
(cons)
|
||||||
|
] @indent.begin
|
||||||
|
|
||||||
|
[
|
||||||
|
")"
|
||||||
|
"}"
|
||||||
|
"]"
|
||||||
|
] @indent.end
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
(ERROR)
|
||||||
|
(comment)
|
||||||
|
] @indent.auto
|
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
26
pack/ant/start/nvim-treesitter/queries/bass/locals.scm
Normal file
26
pack/ant/start/nvim-treesitter/queries/bass/locals.scm
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
; Scopes
|
||||||
|
[
|
||||||
|
(list)
|
||||||
|
(scope)
|
||||||
|
(cons)
|
||||||
|
] @local.scope
|
||||||
|
|
||||||
|
; References
|
||||||
|
(symbol) @local.reference
|
||||||
|
|
||||||
|
; Definitions
|
||||||
|
((list
|
||||||
|
.
|
||||||
|
(symbol) @_fnkw
|
||||||
|
.
|
||||||
|
(symbol) @local.definition.function
|
||||||
|
(symbol)? @local.definition.parameter)
|
||||||
|
(#any-of? @_fnkw "def" "defop" "defn" "fn"))
|
||||||
|
|
||||||
|
((cons
|
||||||
|
.
|
||||||
|
(symbol) @_fnkw
|
||||||
|
.
|
||||||
|
(symbol) @local.definition.function
|
||||||
|
(symbol)? @local.definition.parameter)
|
||||||
|
(#any-of? @_fnkw "def" "defop" "defn" "fn"))
|
|
@ -0,0 +1,4 @@
|
||||||
|
[
|
||||||
|
(transaction)
|
||||||
|
(section)
|
||||||
|
] @fold
|
|
@ -0,0 +1,57 @@
|
||||||
|
(date) @variable.member
|
||||||
|
|
||||||
|
(txn) @attribute
|
||||||
|
|
||||||
|
(account) @type
|
||||||
|
|
||||||
|
(amount) @number
|
||||||
|
|
||||||
|
(incomplete_amount) @number
|
||||||
|
|
||||||
|
(compound_amount) @number
|
||||||
|
|
||||||
|
(amount_tolerance) @number
|
||||||
|
|
||||||
|
(currency) @property
|
||||||
|
|
||||||
|
(key) @label
|
||||||
|
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
(narration) @string @spell
|
||||||
|
|
||||||
|
(payee) @string @spell
|
||||||
|
|
||||||
|
(tag) @constant
|
||||||
|
|
||||||
|
(link) @constant
|
||||||
|
|
||||||
|
[
|
||||||
|
(minus)
|
||||||
|
(plus)
|
||||||
|
(slash)
|
||||||
|
(asterisk)
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
[
|
||||||
|
(balance)
|
||||||
|
(open)
|
||||||
|
(close)
|
||||||
|
(commodity)
|
||||||
|
(pad)
|
||||||
|
(event)
|
||||||
|
(price)
|
||||||
|
(note)
|
||||||
|
(document)
|
||||||
|
(query)
|
||||||
|
(custom)
|
||||||
|
(pushtag)
|
||||||
|
(poptag)
|
||||||
|
(pushmeta)
|
||||||
|
(popmeta)
|
||||||
|
(option)
|
||||||
|
(include)
|
||||||
|
(plugin)
|
||||||
|
] @keyword
|
|
@ -0,0 +1,2 @@
|
||||||
|
((comment) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
1
pack/ant/start/nvim-treesitter/queries/bibtex/folds.scm
Normal file
1
pack/ant/start/nvim-treesitter/queries/bibtex/folds.scm
Normal file
|
@ -0,0 +1 @@
|
||||||
|
(entry) @fold
|
50
pack/ant/start/nvim-treesitter/queries/bibtex/highlights.scm
Normal file
50
pack/ant/start/nvim-treesitter/queries/bibtex/highlights.scm
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
; CREDITS @pfoerster (adapted from https://github.com/latex-lsp/tree-sitter-bibtex)
|
||||||
|
[
|
||||||
|
(string_type)
|
||||||
|
(preamble_type)
|
||||||
|
(entry_type)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
[
|
||||||
|
(junk)
|
||||||
|
(comment)
|
||||||
|
] @comment
|
||||||
|
|
||||||
|
(comment) @spell
|
||||||
|
|
||||||
|
[
|
||||||
|
"="
|
||||||
|
"#"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
(command) @function.builtin
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(field
|
||||||
|
name: (identifier) @variable.member)
|
||||||
|
|
||||||
|
(token
|
||||||
|
(identifier) @variable.parameter)
|
||||||
|
|
||||||
|
[
|
||||||
|
(brace_word)
|
||||||
|
(quote_word)
|
||||||
|
] @string
|
||||||
|
|
||||||
|
[
|
||||||
|
(key_brace)
|
||||||
|
(key_paren)
|
||||||
|
] @string.special.symbol
|
||||||
|
|
||||||
|
(string
|
||||||
|
name: (identifier) @constant)
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
"," @punctuation.delimiter
|
|
@ -0,0 +1,8 @@
|
||||||
|
(entry) @indent.begin
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
(comment) @indent.ignore
|
|
@ -0,0 +1,2 @@
|
||||||
|
((junk) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
19
pack/ant/start/nvim-treesitter/queries/bicep/folds.scm
Normal file
19
pack/ant/start/nvim-treesitter/queries/bicep/folds.scm
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[
|
||||||
|
(module_declaration)
|
||||||
|
(metadata_declaration)
|
||||||
|
(output_declaration)
|
||||||
|
(parameter_declaration)
|
||||||
|
(resource_declaration)
|
||||||
|
(type_declaration)
|
||||||
|
(variable_declaration)
|
||||||
|
(parenthesized_expression)
|
||||||
|
(decorators)
|
||||||
|
(array)
|
||||||
|
(object)
|
||||||
|
(if_statement)
|
||||||
|
(for_statement)
|
||||||
|
(subscript_expression)
|
||||||
|
(ternary_expression)
|
||||||
|
(string)
|
||||||
|
(comment)
|
||||||
|
] @fold
|
234
pack/ant/start/nvim-treesitter/queries/bicep/highlights.scm
Normal file
234
pack/ant/start/nvim-treesitter/queries/bicep/highlights.scm
Normal file
|
@ -0,0 +1,234 @@
|
||||||
|
; Includes
|
||||||
|
[
|
||||||
|
"import"
|
||||||
|
"provider"
|
||||||
|
"with"
|
||||||
|
"as"
|
||||||
|
"from"
|
||||||
|
] @keyword.import
|
||||||
|
|
||||||
|
; Namespaces
|
||||||
|
(module_declaration
|
||||||
|
(identifier) @module)
|
||||||
|
|
||||||
|
; Builtins
|
||||||
|
(primitive_type) @type.builtin
|
||||||
|
|
||||||
|
((member_expression
|
||||||
|
object: (identifier) @type.builtin)
|
||||||
|
(#eq? @type.builtin "sys"))
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @function.call)
|
||||||
|
|
||||||
|
(user_defined_function
|
||||||
|
name: (identifier) @function)
|
||||||
|
|
||||||
|
; Properties
|
||||||
|
(object_property
|
||||||
|
(identifier) @property
|
||||||
|
":" @punctuation.delimiter
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(object_property
|
||||||
|
(compatible_identifier) @property
|
||||||
|
":" @punctuation.delimiter
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(property_identifier) @property
|
||||||
|
|
||||||
|
; Attributes
|
||||||
|
(decorator
|
||||||
|
"@" @attribute)
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(call_expression
|
||||||
|
(identifier) @attribute))
|
||||||
|
|
||||||
|
(decorator
|
||||||
|
(call_expression
|
||||||
|
(member_expression
|
||||||
|
object: (identifier) @attribute
|
||||||
|
property: (property_identifier) @attribute)))
|
||||||
|
|
||||||
|
; Types
|
||||||
|
(type_declaration
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(type_declaration
|
||||||
|
(identifier)
|
||||||
|
"="
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(type
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(resource_declaration
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
(resource_expression
|
||||||
|
(identifier) @type)
|
||||||
|
|
||||||
|
; Parameters
|
||||||
|
(parameter_declaration
|
||||||
|
(identifier) @variable.parameter
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (_)
|
||||||
|
(arguments
|
||||||
|
(identifier) @variable.parameter))
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (_)
|
||||||
|
(arguments
|
||||||
|
(member_expression
|
||||||
|
object: (identifier) @variable.parameter)))
|
||||||
|
|
||||||
|
(parameter
|
||||||
|
.
|
||||||
|
(identifier) @variable.parameter)
|
||||||
|
|
||||||
|
; Variables
|
||||||
|
(variable_declaration
|
||||||
|
(identifier) @variable
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(metadata_declaration
|
||||||
|
(identifier) @variable
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(output_declaration
|
||||||
|
(identifier) @variable
|
||||||
|
(_))
|
||||||
|
|
||||||
|
(object_property
|
||||||
|
(_)
|
||||||
|
":"
|
||||||
|
(identifier) @variable)
|
||||||
|
|
||||||
|
(for_statement
|
||||||
|
"for"
|
||||||
|
(for_loop_parameters
|
||||||
|
(loop_variable) @variable
|
||||||
|
(loop_enumerator) @variable))
|
||||||
|
|
||||||
|
; Conditionals
|
||||||
|
"if" @keyword.conditional
|
||||||
|
|
||||||
|
(ternary_expression
|
||||||
|
"?" @keyword.conditional.ternary
|
||||||
|
":" @keyword.conditional.ternary)
|
||||||
|
|
||||||
|
; Loops
|
||||||
|
(for_statement
|
||||||
|
"for" @keyword.repeat
|
||||||
|
"in"
|
||||||
|
":" @punctuation.delimiter)
|
||||||
|
|
||||||
|
; Keywords
|
||||||
|
[
|
||||||
|
"module"
|
||||||
|
"metadata"
|
||||||
|
"output"
|
||||||
|
"param"
|
||||||
|
"resource"
|
||||||
|
"existing"
|
||||||
|
"targetScope"
|
||||||
|
"type"
|
||||||
|
"var"
|
||||||
|
"using"
|
||||||
|
"test"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
"func" @keyword.function
|
||||||
|
|
||||||
|
"assert" @keyword.exception
|
||||||
|
|
||||||
|
; Operators
|
||||||
|
[
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"||"
|
||||||
|
"&&"
|
||||||
|
"|"
|
||||||
|
"=="
|
||||||
|
"!="
|
||||||
|
"=~"
|
||||||
|
"!~"
|
||||||
|
">"
|
||||||
|
">="
|
||||||
|
"<="
|
||||||
|
"<"
|
||||||
|
"??"
|
||||||
|
"="
|
||||||
|
"!"
|
||||||
|
".?"
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
(subscript_expression
|
||||||
|
"?" @operator)
|
||||||
|
|
||||||
|
(nullable_type
|
||||||
|
"?" @operator)
|
||||||
|
|
||||||
|
"in" @keyword.operator
|
||||||
|
|
||||||
|
; Literals
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(boolean) @boolean
|
||||||
|
|
||||||
|
(null) @constant.builtin
|
||||||
|
|
||||||
|
; Misc
|
||||||
|
(compatible_identifier
|
||||||
|
"?" @punctuation.special)
|
||||||
|
|
||||||
|
(nullable_return_type) @punctuation.special
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
[
|
||||||
|
"."
|
||||||
|
":"
|
||||||
|
"::"
|
||||||
|
"=>"
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
; Interpolation
|
||||||
|
(interpolation) @none
|
||||||
|
|
||||||
|
(interpolation
|
||||||
|
"${" @punctuation.special
|
||||||
|
"}" @punctuation.special)
|
||||||
|
|
||||||
|
(interpolation
|
||||||
|
(identifier) @variable)
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
[
|
||||||
|
(comment)
|
||||||
|
(diagnostic_comment)
|
||||||
|
] @comment @spell
|
27
pack/ant/start/nvim-treesitter/queries/bicep/indents.scm
Normal file
27
pack/ant/start/nvim-treesitter/queries/bicep/indents.scm
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
[
|
||||||
|
(array)
|
||||||
|
(object)
|
||||||
|
] @indent.begin
|
||||||
|
|
||||||
|
"}" @indent.end
|
||||||
|
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
[
|
||||||
|
(ERROR)
|
||||||
|
(comment)
|
||||||
|
(diagnostic_comment)
|
||||||
|
] @indent.auto
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue