diff --git a/autoload/SpaceVim/layers/treesitter.vim b/autoload/SpaceVim/layers/treesitter.vim index affa14242..a9cb8ec8a 100644 --- a/autoload/SpaceVim/layers/treesitter.vim +++ b/autoload/SpaceVim/layers/treesitter.vim @@ -13,7 +13,13 @@ function! SpaceVim#layers#treesitter#plugins() abort let plugins = [] - call add(plugins, ['nvim-treesitter/nvim-treesitter', {'do' : ':TSUpdate'}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-treesitter', + \ { + \ 'merged' : 0, + \ 'loadconf' : 1 , + \ 'do' : 'TSUpdate', + \ 'loadconf_before' : 1 + \ }]) return plugins endfunction diff --git a/bundle/nvim-treesitter/.editorconfig b/bundle/nvim-treesitter/.editorconfig new file mode 100644 index 000000000..00ea231bb --- /dev/null +++ b/bundle/nvim-treesitter/.editorconfig @@ -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 diff --git a/bundle/nvim-treesitter/.github/CODEOWNERS b/bundle/nvim-treesitter/.github/CODEOWNERS new file mode 100644 index 000000000..8fcb7cd9e --- /dev/null +++ b/bundle/nvim-treesitter/.github/CODEOWNERS @@ -0,0 +1,7 @@ +/lua/nvim-treesitter/textobjects/ @theHamsta +/lua/nvim-treesitter/incremental_selection.lua @theHamsta + +/lua/nvim-treesitter/fold.lua @vigoux +/lua/nvim-treesitter/highlight.lua @vigoux + +/lua/nvim-treesitter/refactor/ @steelsojka diff --git a/bundle/nvim-treesitter/.github/FUNDING.yml b/bundle/nvim-treesitter/.github/FUNDING.yml new file mode 100644 index 000000000..d463c475f --- /dev/null +++ b/bundle/nvim-treesitter/.github/FUNDING.yml @@ -0,0 +1 @@ +open_collective: "nvim-treesitter" diff --git a/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/bug_report.yml b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..0b6c990a9 --- /dev/null +++ b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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. diff --git a/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/feature_request.md b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..11fc491ef --- /dev/null +++ b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +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. diff --git a/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/highlighting_issue.yml b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/highlighting_issue.yml new file mode 100644 index 000000000..6667bd33f --- /dev/null +++ b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/highlighting_issue.yml @@ -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 https://github.com/nvim-treesitter/playground 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 `:TSHighlightCapturesUnderCursor` from https://github.com/nvim-treesitter/playground 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 `:TSPlaygroundToggle` from https://github.com/nvim-treesitter/playground + (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 + `:TSHighlightCapturesUnderCursor'. + 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. diff --git a/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/language-request.md b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/language-request.md new file mode 100644 index 000000000..6182af225 --- /dev/null +++ b/bundle/nvim-treesitter/.github/ISSUE_TEMPLATE/language-request.md @@ -0,0 +1,12 @@ +--- +name: Language request +about: Request for a new language to be supported +title: '' +labels: enhancement, good first issue, help wanted +assignees: '' + +--- + +**Language information** + +Please paste any useful information here ! diff --git a/bundle/nvim-treesitter/.github/mergify.yml b/bundle/nvim-treesitter/.github/mergify.yml new file mode 100644 index 000000000..b95a074a5 --- /dev/null +++ b/bundle/nvim-treesitter/.github/mergify.yml @@ -0,0 +1,37 @@ +pull_request_rules: + - name: Merge lockfile updates + conditions: + - "title=Update lockfile.json" + actions: + review: + type: APPROVE + message: Automatically approving lockfile updates + merge: + method: merge + + - name: Prepare for merge + conditions: + - and: + - "-draft" + - "#approved-reviews-by=1" + - "#review-requested=0" + actions: + comment: + message: | + This PR is ready to be merged, and will be in 1 day if nothing happens before. + If you want other people to review your PR, request their reviews. + If you don't want this PR to be merged now, mark it as a Draft. + + - name: Merge on approval + conditions: + - and: + - or: + - "#approved-reviews-by>=2" + - and: + - "#approved-reviews-by=1" + - "updated-at>=1 day ago" + - "-draft" + - "#review-requested=0" + actions: + merge: + method: rebase diff --git a/bundle/nvim-treesitter/.github/workflows/lint.yml b/bundle/nvim-treesitter/.github/workflows/lint.yml new file mode 100644 index 000000000..9b75ab6b0 --- /dev/null +++ b/bundle/nvim-treesitter/.github/workflows/lint.yml @@ -0,0 +1,33 @@ +name: Linting and style checking + +on: + push: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + luacheck: + name: Luacheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - 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@v2 + - name: Lint with stylua + uses: JohnnyMorganz/stylua-action@1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --check . diff --git a/bundle/nvim-treesitter/.github/workflows/test-queries.yml b/bundle/nvim-treesitter/.github/workflows/test-queries.yml new file mode 100644 index 000000000..d4ec33052 --- /dev/null +++ b/bundle/nvim-treesitter/.github/workflows/test-queries.yml @@ -0,0 +1,92 @@ +name: Test queries + +on: + push: + branches: + - 'master' + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + 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-2022, macos-latest] + cc: [ gcc, clang ] + nvim_tag: [ stable ] + exclude: + - os: ubuntu-latest + cc: clang + nvim_tag: stable + + - os: macos-latest + cc: gcc + nvim_tag: stable + + - os: windows-2022 + cc: clang + nvim_tag: stable + + include: + - os: windows-2022 + cc: cl + nvim_tag: stable + + - os: ubuntu-latest + cc: gcc + nvim_tag: nightly + + name: Parser compilation + runs-on: ${{ matrix.os }} + env: + CC: ${{ matrix.cc }} + NVIM: ${{ matrix.os == 'windows-2022' && 'Neovim\\bin\\nvim.exe' || 'nvim' }} + steps: + - uses: actions/checkout@v2 + - uses: ilammy/msvc-dev-cmd@v1 + - uses: actions/setup-node@v2 + + - name: Install and prepare Neovim + env: + NVIM_TAG: ${{ matrix.nvim_tag }} + TREE_SITTER_CLI_TAG: v0.20.4 + run: | + bash ./scripts/ci-install-${{ matrix.os }}.sh + + - name: Setup Parsers Cache + id: parsers-cache + uses: actions/cache@v2 + with: + path: | + ./parser/ + ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/ + key: ${{ matrix.os }}-${{ matrix.cc }}-${{ matrix.nvim_tag }}-parsers-v1-${{ hashFiles('./lockfile.json', './lua/nvim-treesitter/parsers.lua', './lua/nvim-treesitter/install.lua', './lua/nvim-treesitter/shell_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: matrix.os == 'windows-2022' + run: cp -r ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/* parser + + # NOTE: this is a temporary workaround to skip swift tests on ubuntu + # stable and should be removed once neovim 0.7 is released. + - if: matrix.os == 'ubuntu-latest' && matrix.nvim_tag == 'stable' + run: echo "SKIP_SWIFT_CHECK=TRUE" >> $GITHUB_ENV + + - name: Check query files + env: + SKIP_SWIFT_CHECK: ${{ env.SKIP_SWIFT_CHECK }} + run: $NVIM --headless -c "luafile ./scripts/check-queries.lua" -c "q" diff --git a/bundle/nvim-treesitter/.github/workflows/tests.yml b/bundle/nvim-treesitter/.github/workflows/tests.yml new file mode 100644 index 000000000..1b445573e --- /dev/null +++ b/bundle/nvim-treesitter/.github/workflows/tests.yml @@ -0,0 +1,63 @@ +name: Tests + +on: + push: + branches: + - 'master' + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + 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@v2 + - uses: actions/setup-node@v2 + + - 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.5/highlight-assertions_v0.1.5_x86_64-unknown-linux-gnu.tar.gz | tar -xz + cp highlight-assertions /usr/local/bin + + - name: Install and prepare Neovim + env: + NVIM_TAG: stable + TREE_SITTER_CLI_TAG: v0.20.4 + run: | + bash ./scripts/ci-install-${{ matrix.os }}.sh + + - name: Setup Parsers Cache + id: parsers-cache + uses: actions/cache@v2 + with: + path: | + ./parser/ + ~/AppData/Local/nvim/pack/nvim-treesitter/start/nvim-treesitter/parser/ + key: ${{ matrix.os }}-${{ matrix.cc }}-parsers-v1-${{ hashFiles('./lockfile.json', './lua/nvim-treesitter/parsers.lua', './lua/nvim-treesitter/install.lua', './lua/nvim-treesitter/shell_selectors.lua') }} + + - name: Compile parsers Unix like + if: ${{ matrix.os != 'windows-latest' && steps.parsers-cache.outputs.cache-hit != 'true' }} + run: | + nvim --headless -c "TSInstallSync all" -c "q" + + - name: Tests + run: PATH=/usr/local/bin:$PATH ./scripts/run_tests.sh diff --git a/bundle/nvim-treesitter/.github/workflows/update-lockfile.yml b/bundle/nvim-treesitter/.github/workflows/update-lockfile.yml new file mode 100644 index 000000000..47e55ba42 --- /dev/null +++ b/bundle/nvim-treesitter/.github/workflows/update-lockfile.yml @@ -0,0 +1,55 @@ +name: Update lockfile + +on: + schedule: + - cron: '30 6 * * *' + push: + branches: + - master + +jobs: + update-lockfile: + name: Update lockfile + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: master + + - name: Prepare + env: + NVIM_TAG: stable + run: | + wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 + mv ./jq-linux64 /tmp/jq + chmod +x /tmp/jq + wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim.appimage + chmod u+x nvim.appimage + mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start + ln -s $(pwd) ~/.local/share/nvim/site/pack/nvim-treesitter/start + + - name: Update parsers + env: + SKIP_LOCKFILE_UPDATE_FOR_LANGS: verilog,gleam,nix + run: | + ./nvim.appimage --headless -c "luafile ./scripts/write-lockfile.lua" -c "q" + # Pretty print + cp lockfile.json /tmp/lockfile.json + cat /tmp/lockfile.json | /tmp/jq --sort-keys > lockfile.json + + - name: Commit changes + run: | + git config user.name "GitHub" + git config user.email "noreply@github.com" + git add lockfile.json + git commit -m "Update lockfile.json" || echo 'No commit necessary!' + git clean -xf + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: Update lockfile.json + title: Update lockfile.json + branch: update-lockfile-pr + base: ${{ github.head_ref }} + draft: true diff --git a/bundle/nvim-treesitter/.github/workflows/update-readme.yml b/bundle/nvim-treesitter/.github/workflows/update-readme.yml new file mode 100644 index 000000000..dba7ba260 --- /dev/null +++ b/bundle/nvim-treesitter/.github/workflows/update-readme.yml @@ -0,0 +1,40 @@ +name: Update README + +on: + push: + branches: + - master + +jobs: + update-readme: + name: Update README + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Prepare + env: + NVIM_TAG: stable + run: | + wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim.appimage + chmod u+x nvim.appimage + mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start + ln -s $(pwd) ~/.local/share/nvim/site/pack/nvim-treesitter/start + + - name: Check README + run: | + git config user.email "actions@github" + git config user.name "Github Actions" + ./nvim.appimage --headless -c "luafile ./scripts/update-readme.lua" -c "q" || echo "Needs update" + git add README.md + git commit -m "Update README" || echo 'No commit necessary!' + git clean -xf + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: Update README + title: Update README + branch: update-readme-pr + base: ${{ github.head_ref }} + draft: true diff --git a/bundle/nvim-treesitter/.gitignore b/bundle/nvim-treesitter/.gitignore new file mode 100644 index 000000000..6e01dc63c --- /dev/null +++ b/bundle/nvim-treesitter/.gitignore @@ -0,0 +1,4 @@ +doc/tags +.luacheckcache +/tags +nvim.appimage diff --git a/bundle/nvim-treesitter/.luacheckrc b/bundle/nvim-treesitter/.luacheckrc new file mode 100644 index 000000000..b0ee19d8a --- /dev/null +++ b/bundle/nvim-treesitter/.luacheckrc @@ -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", +} diff --git a/bundle/nvim-treesitter/.stylua.toml b/bundle/nvim-treesitter/.stylua.toml new file mode 100644 index 000000000..ecb6dca5a --- /dev/null +++ b/bundle/nvim-treesitter/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "None" diff --git a/bundle/nvim-treesitter/.styluaignore b/bundle/nvim-treesitter/.styluaignore new file mode 100644 index 000000000..2b6c4c6ab --- /dev/null +++ b/bundle/nvim-treesitter/.styluaignore @@ -0,0 +1 @@ +tests/indent/lua/ diff --git a/bundle/nvim-treesitter/CONTRIBUTING.md b/bundle/nvim-treesitter/CONTRIBUTING.md new file mode 100644 index 000000000..b3c51cee5 --- /dev/null +++ b/bundle/nvim-treesitter/CONTRIBUTING.md @@ -0,0 +1,299 @@ +# 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 [Zulip] +server, so we can help you with any question you might have! +There is also a [Matrix channel] for tree-sitter support in Neovim. + +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 +[Zulip] or 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://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries), + 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. + +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). + +### Highlights + +As languages differ quite a lot, here is a set of captures available to you when building a `highlights.scm` query. +One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any +effect on highlighting. We will work on improving highlighting in the near future though. + +#### Misc + +``` +@comment +@debug +@error for error `ERROR` nodes. +@none to disable completely the highlight +@preproc +@punctuation.delimiter for `;` `.` `,` +@punctuation.bracket for `()` or `{}` +@punctuation.special for symbols with special meaning like `{}` in string interpolation. +``` + +#### Constants + +``` +@constant +@constant.builtin +@constant.macro +@string +@string.regex +@string.escape +@string.special +@character +@character.special +@number +@boolean +@float +``` + +#### Functions + +``` +@function +@function.builtin +@function.macro +@parameter + +@method +@field +@property + +@constructor +``` + +#### Keywords + +``` +@conditional (e.g. `if`, `else`) +@repeat (e.g. `for`, `while`) +@label for C/Lua-like labels +@keyword +@keyword.function (keyword to define a function, e.g. `func` in Go, `def` in Python) +@keyword.operator (for operators that are English words, e.g. `and`, `or`) +@keyword.return +@operator (for symbolic operators, e.g. `+`, `*`) +@exception (e.g. `throw`, `catch`) +@include keywords for including modules (e.g. import/from in Python) +@storageclass + +@type +@type.builtin +@type.definition +@type.qualifier +@namespace for identifiers referring to namespaces +@symbol for identifiers referring to symbols +@attribute for e.g. Python decorators +``` + +@conceal followed by `(#set! conceal "")` for captures that are not used for highlights but only for concealing. + +#### Variables + +``` +@variable +@variable.builtin +``` + +#### Text + +Mainly for markup languages. + +``` +@text +@text.strong +@text.emphasis +@text.underline +@text.strike +@text.title +@text.literal +@text.uri +@text.math (e.g. for LaTeX math environments) +@text.environment (e.g. for text environments of markup languages) +@text.environment.name (e.g. for the name/the string indicating the type of text environment) +@text.reference (for footnotes, text references, citations) + +@text.note +@text.warning +@text.danger + +@todo +``` + +#### Tags + +Used for xml-like tags + +``` +@tag +@tag.attribute +@tag.delimiter +``` + +#### Conceal + +@conceal followed by `(#set! conceal "")` for captures that are not used for highlights but only for concealing. + +### Locals + +``` +@definition for various definitions +@definition.constant +@definition.function +@definition.method +@definition.var +@definition.parameter +@definition.macro +@definition.type +@definition.field +@definition.enum +@definition.namespace for modules or C++ namespaces +@definition.import for imported names + +@definition.associated to determine the type of a variable +@definition.doc for documentation adjacent to a definition. E.g. + +@scope +@reference +@constructor +``` + + +#### 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) @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 : + +``` +@fold +``` + +If the `fold.scm` query is not present, this will fallback to the `@scope` captures in the `locals` +query. + +### Injections + +Some captures are related to language injection (like markdown code blocks). They are used in `injections.scm`. +You can directly use the name of the language that you want to inject (e.g. `@html` to inject html). + +If you want to dynamically detect the language (e.g. for Markdown blocks) use the `@language` to capture +the node describing the language and `@content` to describe the injection region. + +``` +@{language} ; e.g. @html to describe a html region + +@language ; dynamic detection of the injection language (i.e. the text of the captured node describes the language). +@content ; region for the dynamically detected language. +@combined ; This will combine all matches of a pattern as one single block of content. +``` + +### Indents + +``` +@indent ; Indent children when matching this node +@indent_end ; Marks the end of indented block +@aligned_indent ; Behaves like python aligned/hanging indent +@dedent ; Dedent children when matching this node +@branch ; Dedent itself when matching this node +@ignore ; Do not indent in this node +@auto ; Behaves like 'autoindent' buffer option +@zero_indent ; Sets this node at position 0 (no indent) +``` + +[Zulip]: https://nvim-treesitter.zulipchat.com +[Matrix channel]: https://matrix.to/#/#nvim-treesitter:matrix.org diff --git a/bundle/nvim-treesitter/LICENSE b/bundle/nvim-treesitter/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/bundle/nvim-treesitter/LICENSE @@ -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. diff --git a/bundle/nvim-treesitter/README.md b/bundle/nvim-treesitter/README.md new file mode 100644 index 000000000..df159b796 --- /dev/null +++ b/bundle/nvim-treesitter/README.md @@ -0,0 +1,569 @@ +
+

nvim-treesitter

+

+ + Zulip Chat + + + Linting and Style + + + Syntax files + +

+
+ +
+

+ Logo +

+

+ Treesitter + configurations and abstraction layer for + Neovim. +

+

+ + Logo by @steelsojka + +

+
+ +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: + +![cpp example](assets/example-cpp.png) + +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/projects/1). +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 latest stable version or [nightly](https://github.com/neovim/neovim#install-from-source) +- `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 +``` +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 `:help 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" + ensure_installed = { "c", "lua", "rust" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- List of parsers to ignore installing (for "all") + ignore_install = { "javascript" }, + + highlight = { + -- `false` will disable the whole extension + 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" }, + + -- 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. + + + +- [x] [astro](https://github.com/virchau13/tree-sitter-astro) (maintained by @virchau13) +- [x] [bash](https://github.com/tree-sitter/tree-sitter-bash) (maintained by @TravonteD) +- [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] [c](https://github.com/tree-sitter/tree-sitter-c) (maintained by @vigoux) +- [x] [c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) (maintained by @Luxed) +- [x] [clojure](https://github.com/sogaiu/tree-sitter-clojure) (maintained by @sogaiu) +- [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] [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] [cuda](https://github.com/theHamsta/tree-sitter-cuda) (maintained by @theHamsta) +- [x] [d](https://github.com/CyberShadow/tree-sitter-d) (experimental, maintained by @nawordar) +- [x] [dart](https://github.com/UserNobody14/tree-sitter-dart) (maintained by @Akin909) +- [x] [devicetree](https://github.com/joelspadin/tree-sitter-devicetree) (maintained by @jedrzejboczar) +- [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] [eex](https://github.com/connorlay/tree-sitter-eex) (maintained by @connorlay) +- [x] [elixir](https://github.com/elixir-lang/tree-sitter-elixir) (maintained by @jonatanklosko, @connorlay) +- [ ] [elm](https://github.com/elm-tooling/tree-sitter-elm) +- [x] [elvish](https://github.com/ckafi/tree-sitter-elvish) (maintained by @ckafi) +- [x] [erlang](https://github.com/AbstractMachinesLab/tree-sitter-erlang) (maintained by @ostera) +- [x] [fennel](https://github.com/travonted/tree-sitter-fennel) (maintained by @TravonteD) +- [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) +- [ ] [fortran](https://github.com/stadelmanma/tree-sitter-fortran) +- [x] [fusion](https://gitlab.com/jirgn/tree-sitter-fusion.git) (maintained by @jirgn) +- [x] [Godot (gdscript)](https://github.com/PrestonKnopp/tree-sitter-gdscript) (maintained by @Shatur95) +- [x] [gleam](https://github.com/J3RN/tree-sitter-gleam) (maintained by @connorlay) +- [x] [Glimmer and Ember](https://github.com/alexlafroscia/tree-sitter-glimmer) (maintained by @alexlafroscia) +- [x] [glsl](https://github.com/theHamsta/tree-sitter-glsl) (maintained by @theHamsta) +- [x] [go](https://github.com/tree-sitter/tree-sitter-go) (maintained by @theHamsta, @WinWisely268) +- [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] [gowork](https://github.com/omertuc/tree-sitter-go-work) (maintained by @omertuc) +- [x] [graphql](https://github.com/bkegley/tree-sitter-graphql) (maintained by @bkegley) +- [ ] [hack](https://github.com/slackhq/tree-sitter-hack) +- [ ] [haskell](https://github.com/tree-sitter/tree-sitter-haskell) +- [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] [help](https://github.com/vigoux/tree-sitter-vimdoc) (experimental, maintained by @vigoux) +- [x] [hjson](https://github.com/winston0410/tree-sitter-hjson) (maintained by @winston0410) +- [x] [hocon](https://github.com/antosha417/tree-sitter-hocon) (maintained by @antosha417) +- [x] [html](https://github.com/tree-sitter/tree-sitter-html) (maintained by @TravonteD) +- [x] [http](https://github.com/NTBBloodbath/tree-sitter-http) (maintained by @NTBBloodbath) +- [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] [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] [julia](https://github.com/tree-sitter/tree-sitter-julia) (maintained by @mroavi, @theHamsta) +- [x] [kotlin](https://github.com/fwcd/tree-sitter-kotlin) (maintained by @SalBakraa) +- [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] [llvm](https://github.com/benwilliamgraham/tree-sitter-llvm) (maintained by @benwilliamgraham) +- [x] [lua](https://github.com/MunifTanjim/tree-sitter-lua) (maintained by @muniftanjim) +- [x] [make](https://github.com/alemuller/tree-sitter-make) (maintained by @lewis6991) +- [ ] [markdown](https://github.com/MDeiml/tree-sitter-markdown) +- [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, @mrossinek) +- [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] [pascal](https://github.com/Isopod/tree-sitter-pascal.git) (maintained by @isopod) +- [x] [perl](https://github.com/ganezdragon/tree-sitter-perl) (maintained by @ganezdragon) +- [x] [php](https://github.com/tree-sitter/tree-sitter-php) (maintained by @tk-shirasaka) +- [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] [prisma](https://github.com/victorhqc/tree-sitter-prisma) (maintained by @elianiva) +- [x] [pug](https://github.com/zealot128/tree-sitter-pug) (maintained by @zealot128) +- [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] [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 @jimhester) +- [x] [rasi](https://github.com/Fymyte/tree-sitter-rasi) (maintained by @Fymyte) +- [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] [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 @vigoux) +- [x] [scala](https://github.com/tree-sitter/tree-sitter-scala) (maintained by @stevanmilic) +- [x] [scheme](https://github.com/6cdh/tree-sitter-scheme) (maintained by @6cdh) +- [x] [scss](https://github.com/serenadeai/tree-sitter-scss) (maintained by @elianiva) +- [x] [slint](https://github.com/jrmoulton/tree-sitter-slint) (experimental, maintained by @jrmoulton) +- [x] [solidity](https://github.com/YongJieYongJie/tree-sitter-solidity) (maintained by @YongJieYongJie) +- [x] [sparql](https://github.com/BonaBeavis/tree-sitter-sparql) (maintained by @bonabeavis) +- [x] [supercollider](https://github.com/madskjeldgaard/tree-sitter-supercollider) (maintained by @madskjeldgaard) +- [x] [surface](https://github.com/connorlay/tree-sitter-surface) (maintained by @connorlay) +- [x] [svelte](https://github.com/Himujjal/tree-sitter-svelte) (maintained by @elianiva) +- [ ] [swift](https://github.com/alex-pinkus/tree-sitter-swift) +- [x] [teal](https://github.com/euclidianAce/tree-sitter-teal) (maintained by @euclidianAce) +- [x] [tlaplus](https://github.com/tlaplus-community/tree-sitter-tlaplus) (maintained by @ahelwer, @susliko) +- [x] [todotxt](https://github.com/arnarg/tree-sitter-todotxt.git) (experimental, maintained by @arnarg) +- [x] [toml](https://github.com/ikatyang/tree-sitter-toml) (maintained by @tk-shirasaka) +- [x] [tsx](https://github.com/tree-sitter/tree-sitter-typescript) (maintained by @steelsojka) +- [x] [turtle](https://github.com/BonaBeavis/tree-sitter-turtle) (maintained by @bonabeavis) +- [x] [typescript](https://github.com/tree-sitter/tree-sitter-typescript) (maintained by @steelsojka) +- [x] [vala](https://github.com/matbme/tree-sitter-vala) (maintained by @matbme) +- [x] [verilog](https://github.com/tree-sitter/tree-sitter-verilog) (experimental, maintained by @zegervdv) +- [x] [vim](https://github.com/vigoux/tree-sitter-viml) (maintained by @vigoux) +- [x] [vue](https://github.com/ikatyang/tree-sitter-vue) (maintained by @WhyNotHugo) +- [x] [wgsl](https://github.com/szebniok/tree-sitter-wgsl) (maintained by @szebniok) +- [x] [yaml](https://github.com/ikatyang/tree-sitter-yaml) (maintained by @stsewd) +- [x] [yang](https://github.com/Hubro/tree-sitter-yang) (maintained by @Hubro) +- [x] [zig](https://github.com/maxxnino/tree-sitter-zig) (maintained by @maxxnino) + + + +# 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, + }, +} +``` + +You can add custom highlight captures with: + +```vim +lua < 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"}, + -- 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 extend the `filetype_to_parsername` table: + +```lua +local ft_to_parser = require"nvim-treesitter.parsers".filetype_to_parsername +ft_to_parser.someft = "python" -- the someft filetype will use the python parser and queries. +``` + +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()) (0.7.0 and above) 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). + +All queries found in the runtime directories will be combined. +By convention, if you want to write a query, use the `queries/` directory, +but if you want to extend a query use the `after/queries/` directory. + +If you want to completely override a query, you can use `:h set_query()`. +For example, to override the `injections` queries from `c` with your own: + +```lua +require("vim.treesitter.query").set_query("c", "injections", "(comment) @comment") +``` + +Note: when using `set_query`, 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", "" }, +} +``` +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 { + -- + -- +} +``` diff --git a/bundle/nvim-treesitter/after/ftplugin/elixir.vim b/bundle/nvim-treesitter/after/ftplugin/elixir.vim new file mode 100644 index 000000000..463eea989 --- /dev/null +++ b/bundle/nvim-treesitter/after/ftplugin/elixir.vim @@ -0,0 +1 @@ +setlocal commentstring=#\ %s diff --git a/bundle/nvim-treesitter/after/ftplugin/graphql.vim b/bundle/nvim-treesitter/after/ftplugin/graphql.vim new file mode 100644 index 000000000..463eea989 --- /dev/null +++ b/bundle/nvim-treesitter/after/ftplugin/graphql.vim @@ -0,0 +1 @@ +setlocal commentstring=#\ %s diff --git a/bundle/nvim-treesitter/after/ftplugin/heex.vim b/bundle/nvim-treesitter/after/ftplugin/heex.vim new file mode 100644 index 000000000..1ec0d53e9 --- /dev/null +++ b/bundle/nvim-treesitter/after/ftplugin/heex.vim @@ -0,0 +1 @@ +setlocal commentstring=<%#\ %s\ %> diff --git a/bundle/nvim-treesitter/after/ftplugin/query.vim b/bundle/nvim-treesitter/after/ftplugin/query.vim new file mode 100644 index 000000000..a13b72624 --- /dev/null +++ b/bundle/nvim-treesitter/after/ftplugin/query.vim @@ -0,0 +1 @@ +setlocal commentstring=;\ %s diff --git a/bundle/nvim-treesitter/after/ftplugin/surface.vim b/bundle/nvim-treesitter/after/ftplugin/surface.vim new file mode 100644 index 000000000..7bbb073f5 --- /dev/null +++ b/bundle/nvim-treesitter/after/ftplugin/surface.vim @@ -0,0 +1 @@ +setlocal commentstring={!--\ %s\ --} diff --git a/bundle/nvim-treesitter/assets/example-cpp.png b/bundle/nvim-treesitter/assets/example-cpp.png new file mode 100644 index 000000000..a35d1d3d5 Binary files /dev/null and b/bundle/nvim-treesitter/assets/example-cpp.png differ diff --git a/bundle/nvim-treesitter/assets/logo.png b/bundle/nvim-treesitter/assets/logo.png new file mode 100644 index 000000000..a60e536bc Binary files /dev/null and b/bundle/nvim-treesitter/assets/logo.png differ diff --git a/bundle/nvim-treesitter/autoload/health/nvim_treesitter.vim b/bundle/nvim-treesitter/autoload/health/nvim_treesitter.vim new file mode 100644 index 000000000..53e187cda --- /dev/null +++ b/bundle/nvim-treesitter/autoload/health/nvim_treesitter.vim @@ -0,0 +1,3 @@ +function! health#nvim_treesitter#check() + lua require 'nvim-treesitter.health'.check() +endfunction diff --git a/bundle/nvim-treesitter/autoload/nvim_treesitter.vim b/bundle/nvim-treesitter/autoload/nvim_treesitter.vim new file mode 100644 index 000000000..1216e9967 --- /dev/null +++ b/bundle/nvim-treesitter/autoload/nvim_treesitter.vim @@ -0,0 +1,27 @@ +function! nvim_treesitter#statusline(...) abort + return luaeval("require'nvim-treesitter'.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', 'maintained'], "\n") +endfunction + +function! nvim_treesitter#installed_parsers(arglead, cmdline, cursorpos) abort + return join(luaeval("require'nvim-treesitter.info'.installed_parsers()") + ['all', 'maintained'], "\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 diff --git a/bundle/nvim-treesitter/doc/nvim-treesitter.txt b/bundle/nvim-treesitter/doc/nvim-treesitter.txt new file mode 100644 index 000000000..edb8579e8 --- /dev/null +++ b/bundle/nvim-treesitter/doc/nvim-treesitter.txt @@ -0,0 +1,775 @@ +*nvim-treesitter* Treesitter configurations and abstraction layer for Neovim. + +Minimum version of neovim: nightly + +Authors: + Kiyan Yazdani + Thomas Vigouroux + Stephan Seitz + Steven Sojka + Santos Gallegos + 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 list of parser names, or "all" + ensure_installed = { "c", "lua", "rust" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_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, + }, + } +< + +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`, `a`, `a` +`` (control + a), `` (alt + n), `` (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 < + 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 + }, + } +< +============================================================================== +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 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.get_node_text* +get_node_text(node, bufnr)~ + +Returns the text content of a `node`. + + *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?`: + - `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.get_node_range* +get_node_range(node_or_range)~ + +Get the range from either a node or a 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) return line:gsub('%s*[%[%(%{]*%s*$', '') end, + separator = ' -> ' + } +< +- `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 removes opening brackets and spaces from end. +- `separator` - Separator between nodes. + + *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, hiting `zx` should fix folding. + In any case, feel free to open an issue with the reproducing steps. + +============================================================================== +HIGHLIGHTS *nvim-treesitter-highlights* + +The following is a list of highlights groups, the syntactic elements they +apply to, and some examples. + + *hl-TSAttribute* +`TSAttribute` +Annotations that can be attached to the code to denote some kind of meta +information. e.g. C++/Dart attributes. + + *hl-TSBoolean* +`TSBoolean` +Boolean literals: `True` and `False` in Python. + + *hl-TSCharacter* +`TSCharacter` +Character literals: `'a'` in C. + + *hl-TSCharacterSpecial* +`TSCharacterSpecial` +Special characters. + + *hl-TSComment* +`TSComment` +Line comments and block comments. + + *hl-TSConditional* +`TSConditional` +Keywords related to conditionals: `if`, `when`, `cond`, etc. + + *hl-TSConstant* +`TSConstant` +Constants identifiers. These might not be semantically constant. +E.g. uppercase variables in Python. + + *hl-TSConstBuiltin* +`TSConstBuiltin` +Built-in constant values: `nil` in Lua. + + *hl-TSConstMacro* +`TSConstMacro` +Constants defined by macros: `NULL` in C. + + *hl-TSConstructor* +`TSConstructor` +Constructor calls and definitions: `{}` in Lua, and Java constructors. + + *hl-TSDebug* +`TSDebug` +Debugging statements. + + *hl-TSDefine* +`TSDefine` +Preprocessor #define statements. + + *hl-TSError* +`TSError` +Syntax/parser errors. This might highlight large sections of code while the +user is typing still incomplete code, use a sensible highlight. + + *hl-TSException* +`TSException` +Exception related keywords: `try`, `except`, `finally` in Python. + + *hl-TSField* +`TSField` +Object and struct fields. + + *hl-TSFloat* +`TSFloat` +Floating-point number literals. + + *hl-TSFunction* +`TSFunction` +Function calls and definitions. + + *hl-TSFuncBuiltin* +`TSFuncBuiltin` +Built-in functions: `print` in Lua. + + *hl-TSFuncMacro* +`TSFuncMacro` +Macro defined functions (calls and definitions): each `macro_rules` in +Rust. + + *hl-TSInclude* +`TSInclude` +File or module inclusion keywords: `#include` in C, `use` or `extern crate` in +Rust. + + *hl-TSKeyword* +`TSKeyword` +Keywords that don't fit into other categories. + + *hl-TSKeywordFunction* +`TSKeywordFunction` +Keywords used to define a function: `function` in Lua, `def` and `lambda` in +Python. + + *hl-TSKeywordOperator* +`TSKeywordOperator` +Unary and binary operators that are English words: `and`, `or` in Python; +`sizeof` in C. + + *hl-TSKeywordReturn* +`TSKeywordReturn` +Keywords like `return` and `yield`. + + *hl-TSLabel* +`TSLabel` +GOTO labels: `label:` in C, and `::label::` in Lua. + + *hl-TSMethod* +`TSMethod` +Method calls and definitions. + + *hl-TSNamespace* +`TSNamespace` +Identifiers referring to modules and namespaces. + + *hl-None* +`TSNone` +No highlighting (sets all highlight arguments to `NONE`). this group is used +to clear certain ranges, for example, string interpolations. Don't change the +values of this highlight group. + + *hl-TSNumber* +`TSNumber` +Numeric literals that don't fit into other categories. + + *hl-TSOperator* +`TSOperator` +Binary or unary operators: `+`, and also `->` and `*` in C. + + *hl-TSParameter* +`TSParameter` +Parameters of a function. + + *hl-TSParameterReference* +`TSParameterReference` +References to parameters of a function. + + *hl-TSPreProc* +`TSPreProc` +Preprocessor #if, #else, #endif, etc. + + *hl-TSProperty* +`TSProperty` +Same as `TSField`. + + *hl-TSPunctDelimiter* +`TSPunctDelimiter` +Punctuation delimiters: Periods, commas, semicolons, etc. + + *hl-TSPunctBracket* +`TSPunctBracket` +Brackets, braces, parentheses, etc. + + *hl-TSPunctSpecial* +`TSPunctSpecial` +Special punctuation that doesn't fit into the previous categories. + + *hl-TSRepeat* +`TSRepeat` +Keywords related to loops: `for`, `while`, etc. + + *hl-StorageClass* +`TSStorageClass` +Keywords that affect how a variable is stored: `static`, `comptime`, `extern`, +etc. + + *hl-TSString* +`TSString` +String literals. + + *hl-TSStringRegex* +`TSStringRegex` +Regular expression literals. + + *hl-TSStringEscape* +`TSStringEscape` +Escape characters within a string: `\n`, `\t`, etc. + + *hl-TSStringSpecial* +`TSStringSpecial` +Strings with special meaning that don't fit into the previous categories. + + *hl-TSSymbol* +`TSSymbol` +Identifiers referring to symbols or atoms. + + *hl-TSTag* +`TSTag` +Tags like HTML tag names. + + *hl-TSTagAttribute* +`TSTagAttribute` +HTML tag attributes. + + *hl-TSTagDelimiter* +`TSTagDelimiter` +Tag delimiters like `<` `>` `/`. + + *hl-TSText* +`TSText` +Non-structured text. Like text in a markup language. + + *hl-TSSTrong* +`TSStrong` +Text to be represented in bold. + + *hl-TSEmphasis* +`TSEmphasis` +Text to be represented with emphasis. + + *hl-TSUnderline* +`TSUnderline` +Text to be represented with an underline. + + *hl-TSStrike* +`TSStrike` +Strikethrough text. + + *hl-TSTitle* +`TSTitle` +Text that is part of a title. + + *hl-TSLiteral* +`TSLiteral` +Literal or verbatim text. + + *hl-TSURI* +`TSURI` +URIs like hyperlinks or email addresses. + + *hl-TSMath* +`TSMath` +Math environments like LaTeX's `$ ... $` + + *hl-TSTextReference* +`TSTextReference` +Footnotes, text references, citations, etc. + + *hl-TSEnvironment* +`TSEnvironment` +Text environments of markup languages. + + *hl-TSEnvironmentName* +`TSEnvironmentName` +Text/string indicating the type of text environment. Like the name of a +`\begin` block in LaTeX. + + *hl-TSNote* +`TSNote` +Text representation of an informational note. + + *TSWarning* +`TSWarning` +Text representation of a warning note. + + *TSDanger* +`TSDanger` +Text representation of a danger note. + + *hl-TSTodo* +`TSTodo` +Anything that needs extra attention, such as keywords like TODO or FIXME. + + *hl-TSType* +`TSType` +Type (and class) definitions and annotations. + + *hl-TSTypeBuiltin* +`TSTypeBuiltin` +Built-in types: `i32` in Rust. + + *hl-TSTypeQualifier* +`TSTypeQualifier` +Qualifiers on types, e.g. `const` or `volatile` in C or `mut` in Rust. + + *hl-TSTypeDefinition* +`TSTypeDefinition` +Type definitions, e.g. `typedef` in C. + + *hl-TSVariable* +`TSVariable` +Variable names that don't fit into other categories. + + *hl-TSVariableBuiltin* +`TSVariableBuiltin` +Variable names defined by the language: `this` or `self` in Javascript. + +============================================================================== +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: diff --git a/bundle/nvim-treesitter/ftdetect/cooklang.vim b/bundle/nvim-treesitter/ftdetect/cooklang.vim new file mode 100644 index 000000000..4f165b94f --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/cooklang.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.cook set filetype=cooklang diff --git a/bundle/nvim-treesitter/ftdetect/fusion.vim b/bundle/nvim-treesitter/ftdetect/fusion.vim new file mode 100644 index 000000000..7a7839b23 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/fusion.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.fusion setfiletype fusion diff --git a/bundle/nvim-treesitter/ftdetect/gdresource.vim b/bundle/nvim-treesitter/ftdetect/gdresource.vim new file mode 100644 index 000000000..df6b5b095 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/gdresource.vim @@ -0,0 +1,2 @@ +autocmd BufRead,BufNewFile *.tscn setlocal ft=gdresource +autocmd BufRead,BufNewFile *.tres setlocal ft=gdresource diff --git a/bundle/nvim-treesitter/ftdetect/gdscript.vim b/bundle/nvim-treesitter/ftdetect/gdscript.vim new file mode 100644 index 000000000..eaae36f38 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/gdscript.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.gd set ft=gdscript diff --git a/bundle/nvim-treesitter/ftdetect/glimmer.vim b/bundle/nvim-treesitter/ftdetect/glimmer.vim new file mode 100644 index 000000000..510b0c3d8 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/glimmer.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.hbs set ft=handlebars diff --git a/bundle/nvim-treesitter/ftdetect/glsl.vim b/bundle/nvim-treesitter/ftdetect/glsl.vim new file mode 100644 index 000000000..6d74fdd9b --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/glsl.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.glsl set filetype=glsl diff --git a/bundle/nvim-treesitter/ftdetect/gowork.vim b/bundle/nvim-treesitter/ftdetect/gowork.vim new file mode 100644 index 000000000..47edcb63c --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/gowork.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile go.work set filetype=gowork diff --git a/bundle/nvim-treesitter/ftdetect/graphql.vim b/bundle/nvim-treesitter/ftdetect/graphql.vim new file mode 100644 index 000000000..c4f3b7540 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/graphql.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.graphql,*.graphqls,*.gql setfiletype graphql diff --git a/bundle/nvim-treesitter/ftdetect/hack.vim b/bundle/nvim-treesitter/ftdetect/hack.vim new file mode 100644 index 000000000..e835a27a3 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/hack.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.hack,*.hackpartial setfiletype hack diff --git a/bundle/nvim-treesitter/ftdetect/hcl.vim b/bundle/nvim-treesitter/ftdetect/hcl.vim new file mode 100644 index 000000000..9d0c7fadf --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/hcl.vim @@ -0,0 +1,2 @@ +autocmd BufRead,BufNewFile *.hcl set filetype=hcl +autocmd BufRead,BufNewFile *.tf,*.tfvars set filetype=terraform diff --git a/bundle/nvim-treesitter/ftdetect/heex.vim b/bundle/nvim-treesitter/ftdetect/heex.vim new file mode 100644 index 000000000..6c7658877 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/heex.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.heex set filetype=heex diff --git a/bundle/nvim-treesitter/ftdetect/hjson.vim b/bundle/nvim-treesitter/ftdetect/hjson.vim new file mode 100644 index 000000000..65ed94625 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/hjson.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.hjson set filetype=hjson diff --git a/bundle/nvim-treesitter/ftdetect/json5.vim b/bundle/nvim-treesitter/ftdetect/json5.vim new file mode 100644 index 000000000..ba74f217a --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/json5.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.json5 set ft=json5 diff --git a/bundle/nvim-treesitter/ftdetect/ledger.vim b/bundle/nvim-treesitter/ftdetect/ledger.vim new file mode 100644 index 000000000..808e77e9e --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/ledger.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.ldg,*.ledger,*.journal setfiletype ledger diff --git a/bundle/nvim-treesitter/ftdetect/nix.vim b/bundle/nvim-treesitter/ftdetect/nix.vim new file mode 100644 index 000000000..96bff17d6 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/nix.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.nix setfiletype nix diff --git a/bundle/nvim-treesitter/ftdetect/prisma.vim b/bundle/nvim-treesitter/ftdetect/prisma.vim new file mode 100644 index 000000000..704717ef3 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/prisma.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.prisma set filetype=prisma diff --git a/bundle/nvim-treesitter/ftdetect/pug.vim b/bundle/nvim-treesitter/ftdetect/pug.vim new file mode 100644 index 000000000..3ca05c4a2 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/pug.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.pug setlocal filetype=pug diff --git a/bundle/nvim-treesitter/ftdetect/ql.vim b/bundle/nvim-treesitter/ftdetect/ql.vim new file mode 100644 index 000000000..b3dd5757f --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/ql.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.ql,*.qll setfiletype ql diff --git a/bundle/nvim-treesitter/ftdetect/query.vim b/bundle/nvim-treesitter/ftdetect/query.vim new file mode 100644 index 000000000..8339b6ba9 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/query.vim @@ -0,0 +1,11 @@ +" Last Change: 2020 Sep 01 + +function! s:shouldFt(path) + let l:q_dir = fnamemodify(a:path, ":p:h:h:t") + + if l:q_dir =~? "queries" + setlocal ft=query + endif +endfunction + +autocmd BufNewFile,BufRead *.scm call s:shouldFt(expand("%")) diff --git a/bundle/nvim-treesitter/ftdetect/surface.vim b/bundle/nvim-treesitter/ftdetect/surface.vim new file mode 100644 index 000000000..6fb2a69be --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/surface.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.sface set filetype=surface diff --git a/bundle/nvim-treesitter/ftdetect/teal.vim b/bundle/nvim-treesitter/ftdetect/teal.vim new file mode 100644 index 000000000..ffc63f143 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/teal.vim @@ -0,0 +1 @@ +autocmd BufRead,BufNewFile *.tl setfiletype teal diff --git a/bundle/nvim-treesitter/ftdetect/tlaplus.vim b/bundle/nvim-treesitter/ftdetect/tlaplus.vim new file mode 100644 index 000000000..a60919b21 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/tlaplus.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.tla set filetype=tla diff --git a/bundle/nvim-treesitter/ftdetect/yang.vim b/bundle/nvim-treesitter/ftdetect/yang.vim new file mode 100644 index 000000000..295e7c3d3 --- /dev/null +++ b/bundle/nvim-treesitter/ftdetect/yang.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.yang set filetype=yang diff --git a/bundle/nvim-treesitter/lockfile.json b/bundle/nvim-treesitter/lockfile.json new file mode 100644 index 000000000..cc26503f2 --- /dev/null +++ b/bundle/nvim-treesitter/lockfile.json @@ -0,0 +1,332 @@ +{ + "astro": { + "revision": "6602ccbf9a5f79845dad62f1e118e07f97e3533c" + }, + "bash": { + "revision": "275effdfc0edce774acf7d481f9ea195c6c403cd" + }, + "beancount": { + "revision": "78b8ddca3ab774573a4e3bf64eabd79e9452cea9" + }, + "bibtex": { + "revision": "ccfd77db0ed799b6c22c214fe9d2937f47bc8b34" + }, + "c": { + "revision": "e348e8ec5efd3aac020020e4af53d2ff18f393a9" + }, + "c_sharp": { + "revision": "5b6ae1f88e741b9ed738891ad1362fb9f2041671" + }, + "clojure": { + "revision": "879f0e726295807d917d576fcf9e1e432c4c20fc" + }, + "cmake": { + "revision": "5020572408a386d5d2dfac3516584f5edda7a49b" + }, + "comment": { + "revision": "a37ca370310ac6f89b6e0ebf2b86b2219780494e" + }, + "commonlisp": { + "revision": "c7e814975ab0d0d04333d1f32391c41180c58919" + }, + "cooklang": { + "revision": "5e113412aadb78955c27010daa4dbe1d202013cf" + }, + "cpp": { + "revision": "a832195eb3685a279856bb480ce19cff19554b6d" + }, + "css": { + "revision": "a03f1d2d1dfbf6f8e0fdca5f9ff030228241eb57" + }, + "cuda": { + "revision": "5178a7a5b25dc7ee4a69bf72f31bd6d3ff0a0795" + }, + "d": { + "revision": "c2fbf21bd3aa45495fe13247e040ad5815250032" + }, + "dart": { + "revision": "6a25376685d1d47968c2cef06d4db8d84a70025e" + }, + "devicetree": { + "revision": "877adbfa0174d25894c40fa75ad52d4515a36368" + }, + "dockerfile": { + "revision": "25c71d6a24cdba8f0c74ef40d4d2d93defd7e196" + }, + "dot": { + "revision": "917230743aa10f45a408fea2ddb54bbbf5fbe7b7" + }, + "eex": { + "revision": "f742f2fe327463335e8671a87c0b9b396905d1d1" + }, + "elixir": { + "revision": "1dabc1c790e07115175057863808085ea60dd08a" + }, + "elm": { + "revision": "9835f900e4df40277f0701d1bc0b6cee0853f81b" + }, + "elvish": { + "revision": "e50787cadd3bc54f6d9c0704493a79078bb8a4e5" + }, + "erlang": { + "revision": "fab680273af1a8f5cc0c3a0c62cbf5b1bea71f39" + }, + "fennel": { + "revision": "d37fd84a702b78ff0282f223ece83c61ab062a6e" + }, + "fish": { + "revision": "d482d70ea8e191c05b2c1b613ed6fdff30a14da0" + }, + "foam": { + "revision": "fdb7f14b885abfc4df57728c9b2a2f2ad24d3cb7" + }, + "fortran": { + "revision": "f0f2f100952a353e64e26b0fa710b4c296d7af13" + }, + "fusion": { + "revision": "19db2f47ba4c3a0f6238d4ae0e2abfca16e61dd6" + }, + "gdscript": { + "revision": "2a6abdaa47fcb91397e09a97c7433fd995ea46c6" + }, + "gleam": { + "revision": "cfcbca3f8f734773878e00d7bfcedea98eb10be2" + }, + "glimmer": { + "revision": "5caf63ac0e3c549b90c9aeb042871206b4b7bc16" + }, + "glsl": { + "revision": "ffb93961426926554a0ba4a389ea6e9d6fafdea9" + }, + "go": { + "revision": "c8fed1f0847a65a04a4b8cb7655f5f416e0742ca" + }, + "godot_resource": { + "revision": "b6ef0768711086a86b3297056f9ffb5cc1d77b4a" + }, + "gomod": { + "revision": "e8f51f8e4363a3d9a427e8f63f4c1bbc5ef5d8d0" + }, + "gowork": { + "revision": "6dd9dd79fb51e9f2abc829d5e97b15015b6a8ae2" + }, + "graphql": { + "revision": "5e66e961eee421786bdda8495ed1db045e06b5fe" + }, + "hack": { + "revision": "d434b4e6c9af0524b163d7a912c8ce79d2b1f778" + }, + "haskell": { + "revision": "ed976b81b00ce7b72b99bca75e7a616cc526220c" + }, + "hcl": { + "revision": "d559c46ba170808b23a73da0cf49f315d221d095" + }, + "heex": { + "revision": "592e22292a367312c35e13de7fdb888f029981d6" + }, + "help": { + "revision": "41ac50500e68fadc139737bbee2a0618628b822b" + }, + "hjson": { + "revision": "02fa3b79b3ff9a296066da6277adfc3f26cbc9e0" + }, + "hocon": { + "revision": "bb412e2633f4a3611a4e16efe58d917093bb4782" + }, + "html": { + "revision": "161a92474a7bb2e9e830e48e76426f38299d99d1" + }, + "http": { + "revision": "bfddd16b1cf78e0042fd1f6846a179f76a254e20" + }, + "java": { + "revision": "881b84fe7078651af5077cc4cea4c85f9fddde3b" + }, + "javascript": { + "revision": "fdeb68ac8d2bd5a78b943528bb68ceda3aade2eb" + }, + "jsdoc": { + "revision": "189a6a4829beb9cdbe837260653b4a3dfb0cc3db" + }, + "json": { + "revision": "203e239408d642be83edde8988d6e7b20a19f0e8" + }, + "json5": { + "revision": "5dd5cdc418d9659682556b6adca2dd9ace0ac6d2" + }, + "jsonc": { + "revision": "02b01653c8a1c198ae7287d566efa86a135b30d5" + }, + "julia": { + "revision": "12ea597262125fc22fd2e91aa953ac69b19c26ca" + }, + "kotlin": { + "revision": "a4f71eb9b8c9b19ded3e0e9470be4b1b77c2b569" + }, + "lalrpop": { + "revision": "7744b56f03ac1e5643fad23c9dd90837fe97291e" + }, + "latex": { + "revision": "ab9c1c59de5da1a8d8c629c81d856a6378b6f116" + }, + "ledger": { + "revision": "1050a25df55a62878102d10e524b5184b316b7ad" + }, + "llvm": { + "revision": "e9948edc41e9e5869af99dddb2b5ff5cc5581af6" + }, + "lua": { + "revision": "2b4ffd5a5ffd0c6b4c84f0d9e003050a70db2a37" + }, + "make": { + "revision": "a4b9187417d6be349ee5fd4b6e77b4172c6827dd" + }, + "markdown": { + "revision": "d24196f9b3e5af6fcb2ec2a0b6cbc5c06f58b85e" + }, + "ninja": { + "revision": "0a95cfdc0745b6ae82f60d3a339b37f19b7b9267" + }, + "nix": { + "revision": "6d6aaa50793b8265b6a8b6628577a0083d3b923d" + }, + "norg": { + "revision": "17d61df817c1e0a9cdef8d915d4e4c556b7cf68c" + }, + "ocaml": { + "revision": "23d419ba45789c5a47d31448061557716b02750a" + }, + "ocaml_interface": { + "revision": "23d419ba45789c5a47d31448061557716b02750a" + }, + "ocamllex": { + "revision": "ac1d5957e719d49bd6acd27439b79843e4daf8ed" + }, + "pascal": { + "revision": "2fd40f477d3e2794af152618ccfac8d92eb72a66" + }, + "perl": { + "revision": "bbf86084d9b7eb4768f3fb9fe094b3e0600057b1" + }, + "php": { + "revision": "3c17a28da38afac41332d3ce79bbd8951867f346" + }, + "phpdoc": { + "revision": "d9150d4cb5941f6ff10adba89bfa1f11f4b05b37" + }, + "pioasm": { + "revision": "924aadaf5dea2a6074d72027b064f939acf32e20" + }, + "prisma": { + "revision": "bf0833cbedb2c5b39250f5ba900f1239a16c6749" + }, + "pug": { + "revision": "5875f9a7d94836708119b0a1102bb5792e8bf673" + }, + "python": { + "revision": "78c4e9b6b2f08e1be23b541ffced47b15e2972ad" + }, + "ql": { + "revision": "8e7fd7e638d4a0ec7a792ee16b19dbc6407aa810" + }, + "query": { + "revision": "5217c6805c09f8fc00ed13d17d5fcb791437aee6" + }, + "r": { + "revision": "cc04302e1bff76fa02e129f332f44636813b0c3c" + }, + "rasi": { + "revision": "e2961f02244c068a67549adf896b0779e4a29516" + }, + "regex": { + "revision": "e1cfca3c79896ff79842f057ea13e529b66af636" + }, + "rego": { + "revision": "858ca3013da4d50ea1bdb32162a2bfb43641b422" + }, + "rst": { + "revision": "b74770c0166f28c1a0ab293513a78712ca1c338b" + }, + "ruby": { + "revision": "0b107de5415e7470a30ef1a390d9db3306432bdb" + }, + "rust": { + "revision": "0509e440ae042db6483984b3a56b3c5f24b5d9b9" + }, + "scala": { + "revision": "ec6047f531e7d4c13787d4ff208b94a84de34165" + }, + "scheme": { + "revision": "a1d2233f4e5498bb305858323c93525e1dd165c0" + }, + "scss": { + "revision": "c478c6868648eff49eb04a4df90d703dc45b312a" + }, + "slint": { + "revision": "0d4dda94f96623302dfc234e06be62a5717f47da" + }, + "solidity": { + "revision": "52ed0880c0126df2f2c7693f215fe6f38e4a2e0a" + }, + "sparql": { + "revision": "05f949d3c1c15e3261473a244d3ce87777374dec" + }, + "supercollider": { + "revision": "0f0e5b5a96dd3e048a9c3db648ed969c44068bff" + }, + "surface": { + "revision": "f4586b35ac8548667a9aaa4eae44456c1f43d032" + }, + "svelte": { + "revision": "84c90ee15f851e1541c25c86e8a4338f5b4d5af2" + }, + "swift": { + "revision": "897df54ad1b2d103dcab3df94f335fceefa230dc" + }, + "teal": { + "revision": "fcc5f6f4d194dede4e676834ff28a506e39e17b4" + }, + "tlaplus": { + "revision": "dde405e5128c3c47ab8aa014d21b6e5296ca450f" + }, + "todotxt": { + "revision": "0207f6a4ab6aeafc4b091914d31d8235049a2578" + }, + "toml": { + "revision": "8bd2056818b21860e3d756b5a58c4f6e05fb744e" + }, + "tsx": { + "revision": "8e9dba7bd7cf089838a036a98be94db53ba2d0a9" + }, + "turtle": { + "revision": "085437f5cb117703b7f520dd92161140a684f092" + }, + "typescript": { + "revision": "8e9dba7bd7cf089838a036a98be94db53ba2d0a9" + }, + "vala": { + "revision": "31a08784cc74b61cb10c5d8314cf8a8aa98aa9a8" + }, + "verilog": { + "revision": "8f6b1f357d1231c420404b5f7a368a73c25adfa2" + }, + "vim": { + "revision": "68f7cacfd9ae4698181511c9fdd6641bc25a260b" + }, + "vue": { + "revision": "91fe2754796cd8fba5f229505a23fa08f3546c06" + }, + "wgsl": { + "revision": "5ca98b174f7dddf69fb7a80c54d49badd1f1f8c4" + }, + "yaml": { + "revision": "0e36bed171768908f331ff7dff9d956bae016efb" + }, + "yang": { + "revision": "8e9d175982afcefa3dac8ca20d40d1643accd2bd" + }, + "zig": { + "revision": "4cff36421dae9c05388b86cd64d2bab4b9ed6676" + } +} diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter.lua b/bundle/nvim-treesitter/lua/nvim-treesitter.lua new file mode 100644 index 000000000..af46bd017 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter.lua @@ -0,0 +1,88 @@ +if not pcall(require, "vim.treesitter.languagetree") then + error "nvim-treesitter requires a more recent Neovim nightly version!" +end + +local install = require "nvim-treesitter.install" +local utils = require "nvim-treesitter.utils" +local ts_utils = require "nvim-treesitter.ts_utils" +local info = require "nvim-treesitter.info" +local configs = require "nvim-treesitter.configs" +local parsers = require "nvim-treesitter.parsers" + +-- 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 + +function M.define_modules(...) + configs.define_modules(...) +end + +local get_line_for_node = function(node, type_patterns, transform_fn) + 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(ts_utils.get_node_text(node)[1] or "")) + -- Escape % to avoid statusline to evaluate content as expression + return line:gsub("%%", "%%%%") +end + +-- 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 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 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 = get_line_for_node(expr, type_patterns, transform_fn) + if line ~= "" and not vim.tbl_contains(lines, line) then + table.insert(lines, 1, line) + 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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/caching.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/caching.lua new file mode 100644 index 000000000..cff0b5a1f --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/caching.lua @@ -0,0 +1,48 @@ +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 = {} + + local items = setmetatable({}, { + __index = function(tbl, key) + rawset(tbl, key, {}) + return rawget(tbl, key) + end, + }) + + function cache.set(type_name, bufnr, value) + if not cache.has(type_name, bufnr) then + -- Clean up the cache if the buffer is detached + -- to avoid memory leaks + api.nvim_buf_attach(bufnr, false, { + on_detach = function() + cache.remove(type_name, bufnr) + return true + end, + }) + end + + items[type_name][bufnr] = value + end + + function cache.get(type_name, bufnr) + return items[type_name][bufnr] + end + + function cache.has(type_name, bufnr) + return cache.get(type_name, bufnr) ~= nil + end + + function cache.remove(type_name, bufnr) + items[type_name][bufnr] = nil + end + + return cache +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/configs.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/configs.lua new file mode 100644 index 000000000..d4aa98e89 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/configs.lua @@ -0,0 +1,559 @@ +local api = vim.api + +local queries = require "nvim-treesitter.query" +local ts_query = require "vim.treesitter.query" +local parsers = require "nvim-treesitter.parsers" +local utils = require "nvim-treesitter.utils" +local caching = require "nvim-treesitter.caching" + +local M = {} + +local config = { + modules = {}, + sync_install = false, + ensure_installed = {}, + ignore_install = {}, + update_strategy = "lockfile", +} +-- List of modules that need to be setup on initialization. +local queued_modules_defs = {} +-- Whether we've initialized the plugin yet. +local is_initialized = false +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", + 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. +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 path to module +-- @param bufnr buffer number, defaults to current buffer +-- @param lang 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 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 + + local cmd = string.format("lua require'nvim-treesitter.configs'.reattach_module('%s')", mod) + api.nvim_command(string.format("autocmd NvimTreesitter FileType * %s", cmd)) + + 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 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 path to module +-- @param bufnr 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 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 + -- TODO(kyazdani): detach the correct autocmd... doesn't work when using %s, cmd. + -- This will remove all autocomands! + api.nvim_command "autocmd! NvimTreesitter FileType *" + 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 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 path to module +-- @param bufnr buffer number, defaults to current buffer +-- @param lang 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 root configuration table to start at +-- @param path 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 + +if not vim.ui then + vim.ui = { + select = function(items, opts, on_choice) + vim.validate { + items = { items, "table", false }, + on_choice = { on_choice, "function", false }, + } + opts = opts or {} + local choices = { opts.prompt or "Select one of:" } + local format_item = opts.format_item or tostring + for i, item in pairs(items) do + table.insert(choices, string.format("%d: %s", i, format_item(item))) + end + local choice = vim.fn.inputlist(choices) + if choice < 1 or choice > #items then + on_choice(nil, nil) + else + on_choice(items[choice], choice) + end + end, + } +end + +function M.edit_query_file(query_group, lang) + lang = lang or parsers.get_buf_lang() + local files = ts_query.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 + +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: module (string) +-- @param lang: the language of the buffer (string) +-- @param bufnr: the bufnr (number) +function M.is_enabled(mod, lang, bufnr) + if not parsers.list[lang] or 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 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 {} + + 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 + + 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 +-- } +-- } +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 the module name +-- @param bufnr the bufnr +-- @param lang 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 the module name +-- @param bufnr the bufnr +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 the module name +-- @param bufnr the bufnr +-- @param lang 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 root table to find modules +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 path to the module +-- @returns 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 the module table +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 + +function M.get_update_strategy() + return config.update_strategy +end + +function M.get_ignored_parser_installs() + return config.ignore_install or {} +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/fold.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/fold.lua new file mode 100644 index 000000000..01a7c08e9 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/fold.lua @@ -0,0 +1,112 @@ +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 + local start_counts = {} + local stop_counts = {} + + local prev_start = -1 + local prev_stop = -1 + + local min_fold_lines = api.nvim_win_get_option(0, "foldminlines") + + for _, node in ipairs(matches) do + local start, _, stop, stop_col = node.node:range() + + 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 + + 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) + +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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/health.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/health.lua new file mode 100644 index 000000000..8cbe0db1c --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/health.lua @@ -0,0 +1,168 @@ +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 health_start = vim.fn["health#report_start"] +local health_ok = vim.fn["health#report_ok"] +local health_error = vim.fn["health#report_error"] +local health_warn = vim.fn["health#report_warn"] + +local M = {} + +local NVIM_TREESITTER_MINIMUM_ABI = 13 + +local function install_health() + health_start "Installation" + + if fn.executable "tree-sitter" == 0 then + health_warn( + "`tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar," + .. " not required for :TSInstall)" + ) + else + health_ok( + "`tree-sitter` found " + .. (utils.ts_cli_version() or "(unknown version)") + .. " (parser generator, only needed for :TSInstallFromGrammar)" + ) + end + + if fn.executable "node" == 0 then + health_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] + health_ok("`node` found " .. version .. " (only needed for :TSInstallFromGrammar)") + end + + if fn.executable "git" == 0 then + health_error("`git` executable not found.", { + "Install it with your package manager.", + "Check that your `$PATH` is set correctly.", + }) + else + health_ok "`git` executable found." + end + + local cc = shell.select_executable(install.compilers) + if not cc then + health_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] + health_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 + health_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 + health_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 +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 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(" ", 15 - (#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, out) + 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 + health_start(table.concat(parser_installation, "\n")) + if #error_collection > 0 then + health_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 = vim.treesitter.query.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(vim.treesitter.query.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 + health_error(table.concat(lines, "\n")) + end + end +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/highlight.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/highlight.lua new file mode 100644 index 000000000..caca7ee00 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/highlight.lua @@ -0,0 +1,159 @@ +local api = vim.api +local ts = vim.treesitter + +local parsers = require "nvim-treesitter.parsers" +local configs = require "nvim-treesitter.configs" + +local M = {} + +local hlmap = vim.treesitter.highlighter.hl_map + +-- nvim-treesitter Highlight Group Mappings +-- Note: Some highlight groups may not be applied upstream, some may be experimental + +hlmap["annotation"] = "TSAnnotation" + +hlmap["attribute"] = "TSAttribute" + +hlmap["boolean"] = "TSBoolean" + +hlmap["character"] = "TSCharacter" +hlmap["character.special"] = "TSCharacterSpecial" + +hlmap["comment"] = "TSComment" + +hlmap["conditional"] = "TSConditional" + +hlmap["constant"] = "TSConstant" +hlmap["constant.builtin"] = "TSConstBuiltin" +hlmap["constant.macro"] = "TSConstMacro" + +hlmap["constructor"] = "TSConstructor" + +hlmap["debug"] = "TSDebug" +hlmap["define"] = "TSDefine" + +hlmap["error"] = "TSError" +hlmap["exception"] = "TSException" + +hlmap["field"] = "TSField" + +hlmap["float"] = "TSFloat" + +hlmap["function"] = "TSFunction" +hlmap["function.builtin"] = "TSFuncBuiltin" +hlmap["function.macro"] = "TSFuncMacro" + +hlmap["include"] = "TSInclude" + +hlmap["keyword"] = "TSKeyword" +hlmap["keyword.function"] = "TSKeywordFunction" +hlmap["keyword.operator"] = "TSKeywordOperator" +hlmap["keyword.return"] = "TSKeywordReturn" + +hlmap["label"] = "TSLabel" + +hlmap["method"] = "TSMethod" + +hlmap["namespace"] = "TSNamespace" + +hlmap["none"] = "TSNone" +hlmap["number"] = "TSNumber" + +hlmap["operator"] = "TSOperator" + +hlmap["parameter"] = "TSParameter" +hlmap["parameter.reference"] = "TSParameterReference" + +hlmap["preproc"] = "TSPreProc" + +hlmap["property"] = "TSProperty" + +hlmap["punctuation.delimiter"] = "TSPunctDelimiter" +hlmap["punctuation.bracket"] = "TSPunctBracket" +hlmap["punctuation.special"] = "TSPunctSpecial" + +hlmap["repeat"] = "TSRepeat" + +hlmap["storageclass"] = "TSStorageClass" + +hlmap["string"] = "TSString" +hlmap["string.regex"] = "TSStringRegex" +hlmap["string.escape"] = "TSStringEscape" +hlmap["string.special"] = "TSStringSpecial" + +hlmap["symbol"] = "TSSymbol" + +hlmap["tag"] = "TSTag" +hlmap["tag.attribute"] = "TSTagAttribute" +hlmap["tag.delimiter"] = "TSTagDelimiter" + +hlmap["text"] = "TSText" +hlmap["text.strong"] = "TSStrong" +hlmap["text.emphasis"] = "TSEmphasis" +hlmap["text.underline"] = "TSUnderline" +hlmap["text.strike"] = "TSStrike" +hlmap["text.title"] = "TSTitle" +hlmap["text.literal"] = "TSLiteral" +hlmap["text.uri"] = "TSURI" +hlmap["text.math"] = "TSMath" +hlmap["text.reference"] = "TSTextReference" +hlmap["text.environment"] = "TSEnvironment" +hlmap["text.environment.name"] = "TSEnvironmentName" + +hlmap["text.note"] = "TSNote" +hlmap["text.warning"] = "TSWarning" +hlmap["text.danger"] = "TSDanger" + +hlmap["todo"] = "TSTodo" + +hlmap["type"] = "TSType" +hlmap["type.builtin"] = "TSTypeBuiltin" +hlmap["type.qualifier"] = "TSTypeQualifier" +hlmap["type.definition"] = "TSTypeDefinition" + +hlmap["variable"] = "TSVariable" +hlmap["variable.builtin"] = "TSVariableBuiltin" + +local function should_enable_vim_regex(config, lang) + local additional_hl = config.additional_vim_regex_highlighting + local is_table = type(additional_hl) == "table" + + return additional_hl and (not is_table or vim.tbl_contains(additional_hl, lang)) +end + +local function enable_syntax(bufnr) + api.nvim_buf_set_option(bufnr, "syntax", "ON") +end + +function M.stop(bufnr) + if ts.highlighter.active[bufnr] then + ts.highlighter.active[bufnr]:destroy() + end +end + +function M.start(bufnr, lang) + local parser = parsers.get_parser(bufnr, lang) + ts.highlighter.new(parser, {}) +end + +function M.attach(bufnr, lang) + local config = configs.get_module "highlight" + M.start(bufnr, lang) + if should_enable_vim_regex(config, lang) then + enable_syntax(bufnr) + end +end + +function M.detach(bufnr) + M.stop(bufnr) + enable_syntax(bufnr) +end + +function M.set_custom_captures(captures) + for k, v in pairs(captures) do + hlmap[k] = v + end +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/incremental_selection.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/incremental_selection.lua new file mode 100644 index 000000000..857f4a482 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/incremental_selection.lua @@ -0,0 +1,148 @@ +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 M = {} + +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 start with 1 and the ending is inclusive. +local function visual_selection_range() + local _, csrow, cscol, _ = unpack(vim.fn.getpos "'<") + local _, cerow, cecol, _ = unpack(vim.fn.getpos "'>") + + local start_row, start_col, end_row, end_col + + 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 + +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 + +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] + 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] + ts_utils.update_selection(buf, node) +end + +function M.attach(bufnr) + local config = configs.get_module "incremental_selection" + for funcname, mapping in pairs(config.keymaps) do + local mode + if funcname == "init_selection" then + mode = "n" + else + mode = "x" + end + local cmd = string.format(":lua require'nvim-treesitter.incremental_selection'.%s()", funcname) + api.nvim_buf_set_keymap(bufnr, mode, mapping, cmd, { silent = true, noremap = true }) + end +end + +function M.detach(bufnr) + local config = configs.get_module "incremental_selection" + for f, mapping in pairs(config.keymaps) do + if f == "init_selection" then + api.nvim_buf_del_keymap(bufnr, "n", mapping) + else + api.nvim_buf_del_keymap(bufnr, "x", mapping) + end + end +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/indent.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/indent.lua new file mode 100644 index 000000000..de165904e --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/indent.lua @@ -0,0 +1,205 @@ +local parsers = require "nvim-treesitter.parsers" +local queries = require "nvim-treesitter.query" +local tsutils = require "nvim-treesitter.ts_utils" + +local M = {} + +M.avoid_force_reparsing = { + yaml = true, +} + +M.comment_parsers = { + comment = true, + jsdoc = true, + phpdoc = true, +} + +local function get_first_node_at_line(root, lnum) + local col = vim.fn.indent(lnum) + return root:descendant_for_range(lnum - 1, col, lnum - 1, col) +end + +local function get_last_node_at_line(root, lnum) + local col = #vim.fn.getline(lnum) - 1 + return root:descendant_for_range(lnum - 1, col, lnum - 1, col) +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_() } + return child, #line == end_char[2] + end + end +end + +local get_indents = tsutils.memoize_by_buf_tick(function(bufnr, root, lang) + local map = { + auto = {}, + indent = {}, + indent_end = {}, + dedent = {}, + branch = {}, + ignore = {}, + aligned_indent = {}, + zero_indent = {}, + } + + for name, node, metadata in queries.iter_captures(bufnr, "indents", root, lang) do + map[name][node:id()] = metadata or {} + end + + return map +end, { + -- Memoize by bufnr and lang together. + key = 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 + + 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() + end + + -- Get language tree with smallest range around node that's not a comment parser + local root, lang_tree + 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 tsutils.is_in_node_range(local_root, lnum - 1, 0) then + if not root or tsutils.node_length(root) >= tsutils.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(vim.fn.getline(lnum), "^%s*$") ~= nil + local node + if is_empty_line then + local prevlnum = vim.fn.prevnonblank(lnum) + node = get_last_node_at_line(root, prevlnum) + 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.zero_indent[node:id()] then + return 0 + end + + while node do + -- do 'autoindent' if not marked as @indent + if not q.indent[node:id()] and q.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[node:id()] and q.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.branch[node:id()] and srow == lnum - 1) or (q.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) + if + not is_processed_by_row[srow] + -- Dear stylua, please don't change the semantics of this statement! + -- stylua: ignore start + and (q.indent[node:id()] and srow ~= erow and ((srow ~= lnum - 1) or q.indent[node:id()].start_at_same_line)) + -- stylua: ignore end + 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) + if q.aligned_indent[node:id()] and srow ~= erow and (srow ~= lnum - 1) then + local metadata = q.aligned_indent[node:id()] + local o_delim_node, is_last_in_line + if metadata.delimiter then + local opening_delimiter = metadata.delimiter and metadata.delimiter:sub(1, 1) + o_delim_node, is_last_in_line = find_delimiter(bufnr, node, opening_delimiter) + else + o_delim_node = node + end + + if o_delim_node then + if is_last_in_line then + -- hanging indent (previous line ended with starting delimiter) + indent = indent + indent_size * 1 + else + local _, o_scol = o_delim_node:start() + return math.max(indent, 0) + o_scol + (metadata.increment or 1) + end + end + end + + is_processed_by_row[srow] = is_processed_by_row[srow] or is_processed + + node = node:parent() + end + + return indent +end + +local indent_funcs = {} + +function M.attach(bufnr) + indent_funcs[bufnr] = vim.bo.indentexpr + vim.bo.indentexpr = "nvim_treesitter#indent()" + vim.api.nvim_command("au Filetype " .. vim.bo.filetype .. " setlocal indentexpr=nvim_treesitter#indent()") +end + +function M.detach(bufnr) + vim.bo.indentexpr = indent_funcs[bufnr] +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/info.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/info.lua new file mode 100644 index 000000000..ed5a90b8d --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/info.lua @@ -0,0 +1,174 @@ +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 _, ft in pairs(parser_list) do + local is_installed = #api.nvim_get_runtime_file("parser/" .. ft .. ".so", false) > 0 + api.nvim_out_write(ft .. string.rep(" ", max_len - #ft + 1)) + if is_installed then + api.nvim_out_write "[✓] installed\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'}} +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 + +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 + +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 + + 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") + api.nvim_exec( + [[ + syntax match TSModuleInfoGood /✓/ + syntax match TSModuleInfoBad /✗/ + syntax match TSModuleInfoHeader /^>>.*$/ contains=TSModuleInfoNamespace + syntax match TSModuleInfoNamespace /^>> \w*/ contained + syntax match TSModuleInfoParser /^[^> ]*\ze / + 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 + ]], + false + ) +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 + +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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/install.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/install.lua new file mode 100644 index 000000000..b65c4b3f0 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/install.lua @@ -0,0 +1,600 @@ +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 M = {} +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 + +local function get_parser_install_info(lang, validate) + local parser_config = parsers.get_parser_configs()[lang] + + if not parser_config then + return 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 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 + + return (lockfile[lang] and lockfile[lang].revision) +end + +local function get_installed_revision(lang) + local lang_file = utils.join_path(utils.get_parser_info_dir(), lang .. ".revision") + if vim.fn.filereadable(lang_file) == 1 then + return vim.fn.readfile(lang_file)[1] + end +end + +local function is_installed(lang) + return #api.nvim_get_runtime_file("parser/" .. lang .. ".so", false) > 0 +end + +local function needs_update(lang) + local revision = get_revision(lang) + return not revision or revision ~= get_installed_revision(lang) +end + +local function outdated_parsers() + return vim.tbl_filter(function(lang) + return needs_update(lang) + end, info.installed_parsers()) +end + +local function onread(handle, is_stderr) + return function(err, 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 } + 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 + +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 final = string.format("%s %s", cmd.cmd, options) + if cmd.opts and cmd.opts.cwd then + final = shell.make_directory_change_for_command(cmd.opts.cwd, final) + end + return final +end + +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 + +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 + + -- compile_location only needed for typescript installs. + local compile_location + if from_local_path then + compile_location = repo.url + else + local repo_location = string.gsub(repo.location or project_name, "/", path_sep) + compile_location = cache_folder .. path_sep .. repo_location + end + local parser_lib_name = install_folder .. path_sep .. 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", "--abi", vim.treesitter.language_version } + else + M.ts_generate_args = { "generate" } + 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) + return type(c) == "string" + end, M.compilers), + '", "' + ) .. '" are not executable.') + return + end + local revision = configs.get_update_strategy() == "lockfile" and get_revision(lang) + + 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(utils.get_parser_info_dir(), lang .. ".revision")) + end, + }, + { -- auto-attach modules after installation + cmd = function() + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if parsers.get_buf_lang(buf) == lang then + for _, mod in ipairs(require("nvim-treesitter.configs").available_modules()) do + require("nvim-treesitter.configs").reattach_module(mod, buf) + end + end + end + end, + }, + }) + 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 + +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 install_info = get_parser_install_info(lang, true) + + run_install(cache_folder, install_folder, lang, install_info, with_sync, generate_from_grammar) +end + +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 + + local install_folder, err = utils.get_parser_install_dir() + if err then + return api.nvim_err_writeln(err) + end + + local languages + local ask + if ... == "all" then + languages = parsers.available_parsers() + ask = false + elseif ... == "maintained" then + languages = parsers.maintained_parsers() + ask = false + else + languages = vim.tbl_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.update(options) + options = options or {} + return function(...) + M.lockfile = {} + reset_progress_counter() + if ... and ... ~= "all" then + local languages = vim.tbl_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 = configs.get_update_strategy() == "lockfile" and 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(...) + local path_sep = "/" + if fn.has "win32" == 1 then + path_sep = "\\" + end + + if vim.tbl_contains({ "all", "maintained" }, ...) then + reset_progress_counter() + local installed = info.installed_parsers() + if ... == "maintained" then + local maintained = parsers.maintained_parsers() + installed = vim.tbl_filter(function(l) + return vim.tbl_contains(maintained, l) + end, installed) + end + for _, langitem in pairs(installed) do + M.uninstall(langitem) + end + elseif ... then + local languages = vim.tbl_flatten { ... } + for _, lang in ipairs(languages) do + local install_dir, err = utils.get_parser_install_dir() + if err then + return api.nvim_err_writeln(err) + end + + local parser_lib = install_dir .. path_sep .. lang .. ".so" + + local command_list = { + shell.select_rm_file_cmd(parser_lib, "Uninstalling parser for " .. lang), + } + M.iter_cmd(command_list, 1, lang, "Treesitter parser for " .. lang .. " has been uninstalled") + end + end +end + +function M.write_lockfile(verbose, skip_langs) + local sorted_parsers = {} + -- 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 + + 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 + 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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/locals.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/locals.lua new file mode 100644 index 000000000..e0da2d02e --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/locals.lua @@ -0,0 +1,349 @@ +-- 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 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 + +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: the scope node of the definition +-- @param bufnr: the buffer +-- @param node_text: the node text to use +-- @returns 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.definition then + table.insert(defs, loc.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.scope and loc.scope.node then + table.insert(scopes, loc.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.reference and loc.reference.node then + table.insert(refs, loc.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) +function M.get_scope_tree(node, bufnr) + local scopes = {} + + 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 +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 the local list result +-- @returns 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 The locals result +-- @param The accumulator function +-- @param The full match path to append to +-- @param 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: the buffer +-- @returns 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_utils.get_node_text(node_entry.node, bufnr)[1] + 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: the definition node +-- @param bufnr: the buffer +-- @param scope_type: the scope type +function M.get_definition_scopes(node, bufnr, scope_type) + local scopes = {} + local scope_count = 1 + + -- 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 + +function M.find_definition(node, bufnr) + local def_lookup = M.get_definitions_lookup_table(bufnr) + local node_text = ts_utils.get_node_text(node, bufnr)[1] + + 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 the node to find usages for +-- @param scope_node the node to look within +-- @returns a list of nodes +function M.find_usages(node, scope_node, bufnr) + local bufnr = bufnr or api.nvim_get_current_buf() + local node_text = ts_utils.get_node_text(node, bufnr)[1] + + 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 + if + match.reference + and match.reference.node + and ts_utils.get_node_text(match.reference.node, bufnr)[1] == 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 + +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 + local col = cursor_pos.col + 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 + +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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/parsers.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/parsers.lua new file mode 100644 index 000000000..07332d7c0 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/parsers.lua @@ -0,0 +1,1129 @@ +local api = vim.api +local ts = vim.treesitter + +local filetype_to_parsername = { + arduino = "cpp", + javascriptreact = "javascript", + ecma = "javascript", + jsx = "javascript", + PKGBUILD = "bash", + html_tags = "html", + ["typescript.tsx"] = "tsx", + terraform = "hcl", + ["html.handlebars"] = "glimmer", + systemverilog = "verilog", + cls = "latex", + sty = "latex", + OpenFOAM = "foam", + pandoc = "markdown", + rmd = "markdown", +} + +local list = setmetatable({}, { + __newindex = function(table, parsername, parserconfig) + rawset( + table, + parsername, + setmetatable(parserconfig, { + __newindex = function(parserconfigtable, key, value) + if key == "used_by" then + require("nvim-treesitter.utils").notify( + "used_by is deprecated, please use 'filetype_to_parsername'", + vim.log.levels.WARN + ) + filetype_to_parsername[value] = parsername + else + rawset(parserconfigtable, key, value) + end + end, + }) + ) + + filetype_to_parsername[parserconfig.filetype or parsername] = parsername + end, +}) + +list.scheme = { + install_info = { + url = "https://github.com/6cdh/tree-sitter-scheme", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@6cdh" }, +} + +list.javascript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-javascript", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@steelsojka" }, +} + +list.rego = { + install_info = { + url = "https://github.com/FallenAngel97/tree-sitter-rego", + files = { "src/parser.c" }, + }, + maintainers = { "@FallenAngel97" }, + filetype = "rego", +} + +list.c = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c", + files = { "src/parser.c" }, + }, + maintainers = { "@vigoux" }, +} + +list.clojure = { + install_info = { + url = "https://github.com/sogaiu/tree-sitter-clojure", + files = { "src/parser.c" }, + }, + maintainers = { "@sogaiu" }, +} + +list.commonlisp = { + install_info = { + url = "https://github.com/theHamsta/tree-sitter-commonlisp", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + filetype = "lisp", + maintainers = { "@theHamsta" }, +} + +list.cpp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-cpp", + files = { "src/parser.c", "src/scanner.cc" }, + generate_requires_npm = true, + }, + maintainers = { "@theHamsta" }, +} + +list.cuda = { + install_info = { + url = "https://github.com/theHamsta/tree-sitter-cuda", + files = { "src/parser.c", "src/scanner.cc" }, + generate_requires_npm = true, + }, + maintainers = { "@theHamsta" }, +} + +list.d = { + install_info = { + url = "https://github.com/CyberShadow/tree-sitter-d", + files = { "src/parser.c", "src/scanner.cc" }, + requires_generate_from_grammar = true, + }, + maintainers = { "@nawordar" }, + -- Generating grammar takes ~60s + experimental = true, +} + +list.glsl = { + install_info = { + url = "https://github.com/theHamsta/tree-sitter-glsl", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + maintainers = { "@theHamsta" }, +} + +list.dockerfile = { + install_info = { + url = "https://github.com/camdencheek/tree-sitter-dockerfile", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@camdencheek" }, +} + +list.dot = { + install_info = { + url = "https://github.com/rydesun/tree-sitter-dot", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@rydesun" }, +} + +list.rust = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-rust", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@vigoux" }, +} + +list.fusion = { + install_info = { + url = "https://gitlab.com/jirgn/tree-sitter-fusion.git", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + }, + maintainers = { "@jirgn" }, +} + +list.ledger = { + install_info = { + url = "https://github.com/cbarrete/tree-sitter-ledger", + files = { "src/parser.c" }, + }, + maintainers = { "@cbarrete" }, +} + +list.lua = { + install_info = { + url = "https://github.com/MunifTanjim/tree-sitter-lua", + branch = "main", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@muniftanjim" }, +} + +list.python = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-python", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@stsewd", "@theHamsta" }, +} + +list.go = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-go", + files = { "src/parser.c" }, + }, + maintainers = { "@theHamsta", "@WinWisely268" }, +} + +list.gomod = { + install_info = { + url = "https://github.com/camdencheek/tree-sitter-go-mod", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@camdencheek" }, + filetype = "gomod", +} + +list.gowork = { + install_info = { + url = "https://github.com/omertuc/tree-sitter-go-work", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@omertuc" }, + filetype = "gowork", +} + +list.graphql = { + install_info = { + url = "https://github.com/bkegley/tree-sitter-graphql", + files = { "src/parser.c" }, + }, + maintainers = { "@bkegley" }, +} + +list.ruby = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ruby", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@TravonteD" }, +} + +list.perl = { + install_info = { + url = "https://github.com/ganezdragon/tree-sitter-perl", + files = { "src/parser.c", "src/scanner.cc" }, + generate_requires_npm = true, + }, + maintainers = { "@ganezdragon" }, +} + +list.bash = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-bash", + files = { "src/parser.c", "src/scanner.cc" }, + }, + filetype = "sh", + maintainers = { "@TravonteD" }, +} + +list.fish = { + install_info = { + url = "https://github.com/ram02z/tree-sitter-fish", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@ram02z" }, +} + +list.php = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-php", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@tk-shirasaka" }, +} + +list.java = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-java", + files = { "src/parser.c" }, + }, + maintainers = { "@p00f" }, +} + +list.kotlin = { + install_info = { + url = "https://github.com/fwcd/tree-sitter-kotlin", + branch = "main", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@SalBakraa" }, +} + +list.html = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-html", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@TravonteD" }, +} + +list.julia = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-julia", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@mroavi", "@theHamsta" }, +} + +list.json = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-json", + files = { "src/parser.c" }, + }, + maintainers = { "@steelsojka" }, +} + +list.css = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-css", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@TravonteD" }, +} + +list.scss = { + install_info = { + url = "https://github.com/serenadeai/tree-sitter-scss", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@elianiva" }, +} + +list.erlang = { + install_info = { + url = "https://github.com/AbstractMachinesLab/tree-sitter-erlang", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@ostera" }, +} + +list.elixir = { + install_info = { + url = "https://github.com/elixir-lang/tree-sitter-elixir", + files = { "src/parser.c", "src/scanner.cc" }, + branch = "main", + }, + maintainers = { "@jonatanklosko", "@connorlay" }, +} + +list.gleam = { + install_info = { + url = "https://github.com/J3RN/tree-sitter-gleam", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@connorlay" }, +} + +list.surface = { + install_info = { + url = "https://github.com/connorlay/tree-sitter-surface", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "sface", + maintainers = { "@connorlay" }, +} + +list.eex = { + install_info = { + url = "https://github.com/connorlay/tree-sitter-eex", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "eex", + maintainers = { "@connorlay" }, +} + +list.heex = { + install_info = { + url = "https://github.com/connorlay/tree-sitter-heex", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "heex", + maintainers = { "@connorlay" }, +} + +list.ocaml = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ocaml", + files = { "src/parser.c", "src/scanner.cc" }, + location = "tree-sitter-ocaml/ocaml", + }, + maintainers = { "@undu" }, +} + +list.ocaml_interface = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ocaml", + files = { "src/parser.c", "src/scanner.cc" }, + location = "tree-sitter-ocaml_interface/interface", + }, + maintainers = { "@undu" }, + filetype = "ocamlinterface", +} + +list.ocamllex = { + install_info = { + url = "https://github.com/atom-ocaml/tree-sitter-ocamllex", + files = { "src/parser.c", "src/scanner.cc" }, + requires_generate_from_grammar = true, + }, + maintainers = { "@undu" }, +} + +list.swift = { + install_info = { + url = "https://github.com/alex-pinkus/tree-sitter-swift", + files = { "src/parser.c", "src/scanner.c" }, + requires_generate_from_grammar = true, + generate_requires_npm = true, + }, +} + +list.c_sharp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c-sharp", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = "cs", + maintainers = { "@Luxed" }, +} + +list.todotxt = { + install_info = { + url = "https://github.com/arnarg/tree-sitter-todotxt.git", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "todotxt", + maintainers = { "@arnarg" }, + experimental = true, +} + +list.typescript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-typescript/typescript", + generate_requires_npm = true, + }, + maintainers = { "@steelsojka" }, +} + +list.tsx = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-tsx/tsx", + generate_requires_npm = true, + }, + filetype = "typescriptreact", + maintainers = { "@steelsojka" }, +} + +list.scala = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-scala", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@stevanmilic" }, +} + +list.supercollider = { + install_info = { + url = "https://github.com/madskjeldgaard/tree-sitter-supercollider", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + }, + maintainers = { "@madskjeldgaard" }, + filetype = "supercollider", +} + +list.slint = { + install_info = { + url = "https://github.com/jrmoulton/tree-sitter-slint", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@jrmoulton" }, + experimental = true, +} + +list.haskell = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-haskell", + files = { "src/parser.c", "src/scanner.c" }, + }, +} + +list.hcl = { + install_info = { + url = "https://github.com/MichaHoffmann/tree-sitter-hcl", + files = { "src/parser.c", "src/scanner.cc" }, + branch = "main", + }, + maintainers = { "@MichaHoffmann" }, + filetype = "hcl", +} + +list.markdown = { + install_info = { + url = "https://github.com/MDeiml/tree-sitter-markdown", + files = { "src/parser.c", "src/scanner.cc" }, + branch = "main", + }, + experimental = true, +} + +list.tlaplus = { + install_info = { + url = "https://github.com/tlaplus-community/tree-sitter-tlaplus", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@ahelwer", "@susliko" }, + filetype = "tla", +} + +list.toml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-toml", + files = { "src/parser.c", "src/scanner.c" }, + generate_requires_npm = true, + }, + maintainers = { "@tk-shirasaka" }, +} + +list.glimmer = { + install_info = { + url = "https://github.com/alexlafroscia/tree-sitter-glimmer", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + }, + readme_name = "Glimmer and Ember", + maintainers = { "@alexlafroscia" }, + filetype = "handlebars", +} + +list.pug = { + install_info = { + url = "https://github.com/zealot128/tree-sitter-pug", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@zealot128" }, + filetype = "pug", +} + +list.vue = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@WhyNotHugo" }, +} + +list.jsonc = { + install_info = { + url = "https://gitlab.com/WhyNotHugo/tree-sitter-jsonc.git", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + readme_name = "JSON with comments", + maintainers = { "@WhyNotHugo" }, +} + +list.elm = { + install_info = { + url = "https://github.com/elm-tooling/tree-sitter-elm", + files = { "src/parser.c", "src/scanner.cc" }, + }, +} + +list.yaml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-yaml", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@stsewd" }, +} + +list.yang = { + install_info = { + url = "https://github.com/Hubro/tree-sitter-yang", + files = { "src/parser.c" }, + }, + maintainers = { "@Hubro" }, + filetype = "yang", +} + +list.ninja = { + install_info = { + url = "https://github.com/alemuller/tree-sitter-ninja", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@alemuller" }, +} + +list.nix = { + install_info = { + url = "https://github.com/cstrahan/tree-sitter-nix", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@leo60228" }, +} + +list.dart = { + install_info = { + url = "https://github.com/UserNobody14/tree-sitter-dart", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@Akin909" }, +} + +list.rst = { + install_info = { + url = "https://github.com/stsewd/tree-sitter-rst", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@stsewd" }, +} + +list.fennel = { + install_info = { + url = "https://github.com/travonted/tree-sitter-fennel", + files = { "src/parser.c" }, + }, + maintainers = { "@TravonteD" }, +} + +list.teal = { + install_info = { + url = "https://github.com/euclidianAce/tree-sitter-teal", + files = { "src/parser.c", "src/scanner.c" }, + requires_generate_from_grammar = true, + }, + maintainers = { "@euclidianAce" }, +} + +list.ql = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ql", + files = { "src/parser.c" }, + }, + maintainers = { "@pwntester" }, +} + +list.verilog = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-verilog", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + maintainers = { "@zegervdv" }, + -- The parser still uses API version 12, because it does not compile with 13 + experimental = true, +} + +list.pascal = { + install_info = { + url = "https://github.com/Isopod/tree-sitter-pascal.git", + files = { "src/parser.c" }, + }, + maintainers = { "@isopod" }, +} + +-- Parsers for injections +list.phpdoc = { + install_info = { + url = "https://github.com/claytonrcarter/tree-sitter-phpdoc", + files = { "src/parser.c", "src/scanner.c" }, + -- parser.c in the repo still based on TS 0.17 due to other dependencies + requires_generate_from_grammar = true, + generate_requires_npm = true, + }, + maintainers = { "@mikehaertl" }, + experimental = true, +} + +list.regex = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-regex", + files = { "src/parser.c" }, + }, + maintainers = { "@theHamsta" }, +} + +list.comment = { + install_info = { + url = "https://github.com/stsewd/tree-sitter-comment", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@stsewd" }, +} + +list.jsdoc = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-jsdoc", + files = { "src/parser.c" }, + }, + maintainers = { "@steelsojka" }, +} + +list.query = { + install_info = { + url = "https://github.com/nvim-treesitter/tree-sitter-query", + files = { "src/parser.c" }, + }, + readme_name = "Tree-sitter query language", + maintainers = { "@steelsojka" }, +} + +list.sparql = { + install_info = { + url = "https://github.com/BonaBeavis/tree-sitter-sparql", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@bonabeavis" }, +} + +list.gdscript = { + install_info = { + url = "https://github.com/PrestonKnopp/tree-sitter-gdscript", + files = { "src/parser.c", "src/scanner.cc" }, + }, + readme_name = "Godot (gdscript)", + maintainers = { "@Shatur95" }, +} + +list.godot_resource = { + install_info = { + url = "https://github.com/PrestonKnopp/tree-sitter-godot-resource", + files = { "src/parser.c", "src/scanner.c" }, + requires_generate_from_grammar = true, + }, + filetype = "gdresource", + readme_name = "Godot Resources (gdresource)", + maintainers = { "@pierpo" }, +} + +list.turtle = { + install_info = { + url = "https://github.com/BonaBeavis/tree-sitter-turtle", + files = { "src/parser.c" }, + branch = "main", + }, + maintainers = { "@bonabeavis" }, +} + +list.devicetree = { + install_info = { + url = "https://github.com/joelspadin/tree-sitter-devicetree", + files = { "src/parser.c" }, + branch = "main", + requires_generate_from_grammar = true, + }, + filetype = "dts", + maintainers = { "@jedrzejboczar" }, +} + +list.svelte = { + install_info = { + url = "https://github.com/Himujjal/tree-sitter-svelte", + files = { "src/parser.c", "src/scanner.c" }, + branch = "master", + }, + maintainers = { "@elianiva" }, +} + +list.r = { + install_info = { + url = "https://github.com/r-lib/tree-sitter-r", + files = { "src/parser.c" }, + }, + maintainers = { "@jimhester" }, +} + +list.beancount = { + install_info = { + url = "https://github.com/polarmutex/tree-sitter-beancount", + files = { "src/parser.c" }, + branch = "master", + }, + maintainers = { "@polarmutex" }, +} + +list.latex = { + install_info = { + url = "https://github.com/latex-lsp/tree-sitter-latex", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = "tex", + maintainers = { "@theHamsta, @clason" }, +} + +list.bibtex = { + install_info = { + url = "https://github.com/latex-lsp/tree-sitter-bibtex", + files = { "src/parser.c" }, + }, + filetype = "bib", + maintainers = { "@theHamsta, @clason" }, +} + +list.zig = { + install_info = { + url = "https://github.com/maxxnino/tree-sitter-zig", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "zig", + maintainers = { "@maxxnino" }, +} + +list.fortran = { + install_info = { + url = "https://github.com/stadelmanma/tree-sitter-fortran", + files = { "src/parser.c", "src/scanner.cc" }, + }, +} + +list.cmake = { + install_info = { + url = "https://github.com/uyha/tree-sitter-cmake", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@uyha" }, +} + +list.vim = { + install_info = { + url = "https://github.com/vigoux/tree-sitter-viml", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = "vim", + maintainers = { "@vigoux" }, +} + +list.help = { + install_info = { + url = "https://github.com/vigoux/tree-sitter-vimdoc", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = "help", + maintainers = { "@vigoux" }, + experimental = true, +} + +list.json5 = { + install_info = { + url = "https://github.com/Joakker/tree-sitter-json5", + files = { "src/parser.c" }, + }, + filetype = "json5", + maintainers = { "@Joakker" }, +} + +list.pioasm = { + install_info = { + url = "https://github.com/leo60228/tree-sitter-pioasm", + branch = "main", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@leo60228" }, +} + +list.hjson = { + install_info = { + url = "https://github.com/winston0410/tree-sitter-hjson", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + maintainers = { "@winston0410" }, +} + +list.hocon = { + install_info = { + url = "https://github.com/antosha417/tree-sitter-hocon", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + maintainers = { "@antosha417" }, +} + +list.llvm = { + install_info = { + url = "https://github.com/benwilliamgraham/tree-sitter-llvm", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@benwilliamgraham" }, +} + +list.http = { + install_info = { + url = "https://github.com/NTBBloodbath/tree-sitter-http", + branch = "main", + files = { "src/parser.c" }, + generate_requires_npm = true, + }, + maintainers = { "@NTBBloodbath" }, +} + +list.prisma = { + install_info = { + url = "https://github.com/victorhqc/tree-sitter-prisma", + branch = "master", + files = { "src/parser.c" }, + }, + maintainers = { "@elianiva" }, +} + +list.make = { + install_info = { + url = "https://github.com/alemuller/tree-sitter-make", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@lewis6991" }, +} + +list.rasi = { + install_info = { + url = "https://github.com/Fymyte/tree-sitter-rasi", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@Fymyte" }, +} + +list.foam = { + install_info = { + url = "https://github.com/FoamScience/tree-sitter-foam", + branch = "master", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@FoamScience" }, + filetype = "foam", + -- Queries might change over time on the grammar's side + -- Otherwise everything runs fine + experimental = true, +} + +list.hack = { + install_info = { + url = "https://github.com/slackhq/tree-sitter-hack", + branch = "main", + files = { "src/parser.c", "src/scanner.cc" }, + }, +} + +list.norg = { + install_info = { + url = "https://github.com/nvim-neorg/tree-sitter-norg", + branch = "main", + files = { "src/parser.c", "src/scanner.cc" }, + use_makefile = true, + cxx_standard = "c++14", + }, + maintainers = { "@JoeyGrajciar", "@vhyrro", "@mrossinek" }, +} + +list.vala = { + install_info = { + url = "https://github.com/matbme/tree-sitter-vala", + branch = "main", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@matbme" }, +} + +list.lalrpop = { + install_info = { + url = "https://github.com/traxys/tree-sitter-lalrpop", + branch = "master", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@traxys" }, +} + +list.solidity = { + install_info = { + url = "https://github.com/YongJieYongJie/tree-sitter-solidity", + branch = "with-generated-c-code", + files = { "src/parser.c" }, + }, + maintainers = { "@YongJieYongJie" }, +} + +list.cooklang = { + install_info = { + url = "https://github.com/addcninblue/tree-sitter-cooklang", + branch = "master", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@addcninblue" }, +} + +list.elvish = { + install_info = { + url = "https://github.com/ckafi/tree-sitter-elvish", + branch = "main", + files = { "src/parser.c" }, + }, + maintainers = { "@ckafi" }, +} + +list.astro = { + install_info = { + url = "https://github.com/virchau13/tree-sitter-astro", + branch = "master", + files = { "src/parser.c", "src/scanner.cc" }, + }, + maintainers = { "@virchau13" }, +} + +list.wgsl = { + install_info = { + url = "https://github.com/szebniok/tree-sitter-wgsl", + files = { "src/parser.c" }, + }, + maintainers = { "@szebniok" }, + filetype = "wgsl", +} + +local M = { + list = list, + filetype_to_parsername = filetype_to_parsername, +} + +function M.ft_to_lang(ft) + local result = filetype_to_parsername[ft] + if result then + return result + else + ft = vim.split(ft, ".", true)[1] + return filetype_to_parsername[ft] or ft + end +end + +function M.available_parsers() + if vim.fn.executable "tree-sitter" == 1 and vim.fn.executable "node" == 1 then + return vim.tbl_keys(M.list) + else + return vim.tbl_filter(function(p) + return not M.list[p].install_info.requires_generate_from_grammar + end, vim.tbl_keys(M.list)) + end +end + +function M.maintained_parsers() + require("nvim-treesitter.utils").notify( + "ensure_installed='maintained' will be removed April 30, 2022. Specify parsers explicitly or use 'all'.", + vim.log.levels.WARN + ) + local has_tree_sitter_cli = vim.fn.executable "tree-sitter" == 1 and vim.fn.executable "node" == 1 + return vim.tbl_filter(function(lang) + return M.list[lang].maintainers + and not M.list[lang].experimental + and (has_tree_sitter_cli or not M.list[lang].install_info.requires_generate_from_grammar) + end, M.available_parsers()) +end + +function M.get_parser_configs() + return M.list +end + +local parser_files + +function M.reset_cache() + parser_files = setmetatable({}, { + __index = function(tbl, key) + rawset(tbl, key, api.nvim_get_runtime_file("parser/" .. key .. ".*", false)) + return rawget(tbl, key) + end, + }) +end + +M.reset_cache() + +function M.has_parser(lang) + lang = lang or M.get_buf_lang(api.nvim_get_current_buf()) + + if not lang or #lang == 0 then + return false + end + -- HACK: nvim internal API + if vim._ts_has_language(lang) then + return true + end + return #parser_files[lang] > 0 +end + +function M.get_parser(bufnr, lang) + bufnr = bufnr or api.nvim_get_current_buf() + lang = lang or M.get_buf_lang(bufnr) + + if M.has_parser(lang) then + return ts.get_parser(bufnr, lang) + end +end + +-- @deprecated This is only kept for legacy purposes. +-- All root nodes should be accounted for. +function M.get_tree_root(bufnr) + bufnr = bufnr or api.nvim_get_current_buf() + return M.get_parser(bufnr):parse()[1]:root() +end + +-- get language of given buffer +-- @param optional buffer number or current buffer +-- @returns language string of buffer +function M.get_buf_lang(bufnr) + bufnr = bufnr or api.nvim_get_current_buf() + return M.ft_to_lang(api.nvim_buf_get_option(bufnr, "ft")) +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/query.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/query.lua new file mode 100644 index 000000000..bad1c27e6 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/query.lua @@ -0,0 +1,390 @@ +local api = vim.api +local tsq = require "vim.treesitter.query" +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. +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 + +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 + + 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 + +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 + +local query_files_cache = {} +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 + local cache = setmetatable({}, mt) + + --- Same as `vim.treesitter.query` except will return cached values + function M.get_query(lang, query_name) + if cache[lang][query_name] == nil then + cache[lang][query_name] = tsq.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 + 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_name, _ in pairs(cache[lang]) do + M.invalidate_query_cache(lang, query_name) + end + elseif not lang and not query_name then + query_files_cache = {} + for lang, _ in pairs(cache) do + for query_name, _ in pairs(cache[lang]) do + M.invalidate_query_cache(lang, query_name) + 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. +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 + +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 + +function M.iter_prepared_matches(query, qnode, bufnr, start_row, end_row) + -- A function that splits a string on '.' + local function split(string) + local t = {} + for str in string.gmatch(string, "([^.]+)") do + table.insert(t, str) + end + + return t + end + -- Given a path (i.e. a List(String)) this functions inserts value at path + local function 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 + + local matches = query:iter_matches(qnode, bufnr, start_row, end_row) + + local function iterator() + local pattern, match = 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") + insert_to_path(prepared_match, path, node) + end + end + + -- Add some predicates for testing + 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 + 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 + 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 the buffer +-- @param captures a single string or a list of strings +-- @param query_group the name of query group (highlights or injections for example) +-- @param root (optional) node from where to start the search +-- @param lang (optional) the language from where to get the captures. +-- Root nodes can have several languages. +function M.get_capture_matches(bufnr, captures, query_group, root, lang) + if type(captures) == "string" then + captures = { captures } + end + local strip_captures = {} + 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 + + 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 + +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 + local best_score + + 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 the buffer +-- @param query_group the query file to use +-- @param root the root node +-- @param root 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 + + 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 + +--- Same as get_capture_matches except this will recursively get matches for every language in the tree. +-- @param bufnr The bufnr +-- @param capture_or_fn 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 The query to get the capture from. This is ignore if a function is provided +-- for the captuer argument. +function M.get_capture_matches_recursively(bufnr, capture_or_fn, query_type) + local type_fn = type(capture_or_fn) == "function" and capture_or_fn + or function() + return capture_or_fn, query_type + 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)) + end + end) + end + + return matches +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/query_predicates.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/query_predicates.lua new file mode 100644 index 000000000..be713304c --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/query_predicates.lua @@ -0,0 +1,130 @@ +local query = require "vim.treesitter.query" + +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 + +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]] + 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) + +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) + +query.add_predicate("has-parent?", has_ancestor) + +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) + +query.add_predicate("has-type?", 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) + +-- Just avoid some annoying warnings for this directive +query.add_directive("make-range!", function() end) + +query.add_directive("downcase!", function(match, _, bufnr, pred, metadata) + local text, key, value + + if #pred == 3 then + -- (#downcase! @capture "key") + key = pred[3] + value = metadata[pred[2]][key] + else + -- (#downcase! "key") + key = pred[2] + value = metadata[key] + end + + if type(value) == "string" then + text = value + else + local node = match[value] + text = query.get_node_text(node, bufnr) or "" + end + + if #pred == 3 then + metadata[pred[2]][key] = string.lower(text) + else + metadata[key] = string.lower(text) + end +end) diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/shell_command_selectors.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/shell_command_selectors.lua new file mode 100644 index 000000000..e7de09552 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/shell_command_selectors.lua @@ -0,0 +1,264 @@ +local fn = vim.fn +local utils = require "nvim-treesitter.utils" + +local M = {} + +function M.select_mkdir_cmd(directory, cwd, info_msg) + if fn.has "win32" == 1 then + return { + cmd = "cmd", + opts = { + args = { "/C", "mkdir", 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 + +function M.select_rm_file_cmd(file, info_msg) + if fn.has "win32" == 1 then + return { + cmd = "cmd", + opts = { + args = { "/C", "if", "exist", file, "del", 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 + +function M.select_executable(executables) + return vim.tbl_filter(function(c) + return c ~= vim.NIL and fn.executable(c) == 1 + end, executables)[1] +end + +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", + "/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, + "-shared", + "-Os", + "-lstdc++", + } + if fn.has "win32" == 0 then + table.insert(args, "-fPIC") + end + return args + end +end + +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 = vim.tbl_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 + +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", dir, "rmdir", "/s", "/q", dir }, + }, + } + else + return { + cmd = "rm", + opts = { + args = { "-rf", cache_folder .. "/" .. project_name }, + }, + } + end +end + +function M.select_mv_cmd(from, to, cwd) + if fn.has "win32" == 1 then + return { + cmd = "cmd", + opts = { + args = { "/C", "move", "/Y", from, to }, + cwd = cwd, + }, + } + else + return { + cmd = "mv", + opts = { + args = { from, to }, + cwd = cwd, + }, + } + end +end + +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$", "") + + return { + M.select_install_rm_cmd(cache_folder, project_name .. "-tmp"), + { + cmd = "curl", + info = "Downloading...", + err = "Error during download, please verify your internet connection", + opts = { + args = { + "--silent", + "-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...", + 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 "[^/]-$" .. "-" .. revision), + 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" + + return { + { + cmd = "git", + info = "Downloading...", + err = clone_error, + opts = { + args = { + "clone", + repo.url, + project_name, + }, + 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 + +function M.make_directory_change_for_command(dir, command) + if fn.has "win32" == 1 then + return string.format("pushd %s & %s & popd", dir, command) + else + return string.format("cd %s;\n %s", dir, command) + end +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua new file mode 100644 index 000000000..5b7023c57 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua @@ -0,0 +1,392 @@ +local api = vim.api + +local parsers = require "nvim-treesitter.parsers" +local utils = require "nvim-treesitter.utils" + +local M = {} + +--- Gets the actual text content of a node +-- @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) + local 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 = M.get_node_range(node) + + if start_row ~= end_row then + local lines = api.nvim_buf_get_lines(bufnr, start_row, end_row + 1, false) + 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 + +--- 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 node +-- @param allow_switch_parents allow switching parents if last node +-- @param allow_next_parent 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 + 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 node +-- @param allow_switch_parents allow switching parents if first node +-- @param allow_previous_parent 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 + 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 = {} + 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) + 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 = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree) + + 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 ipairs(lang_tree:trees()) do + local root = tree:root() + + if root and M.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 + +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. +function M.get_vim_range(range, buf) + 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 + end + return srow, scol, erow, ecol +end + +function M.highlight_range(range, buf, hl_namespace, hl_group) + local start_row, start_col, end_row, end_col = unpack(range) + 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 "" (as a string with 5 characters or a single character) +function M.update_selection(buf, node, selection_mode) + selection_mode = selection_mode or "charwise" + local start_row, start_col, end_row, end_col = M.get_vim_range({ M.get_node_range(node) }, buf) + + vim.fn.setpos(".", { buf, start_row, start_col, 0 }) + + -- Start visual selection in appropriate mode + local v_table = { charwise = "v", linewise = "V", blockwise = "" } + ---- Call to `nvim_replace_termcodes()` is needed for sending appropriate + ---- command to enter blockwise mode + local mode_string = vim.api.nvim_replace_termcodes(v_table[selection_mode] or selection_mode, true, true, true) + vim.cmd("normal! " .. mode_string) + vim.fn.setpos(".", { buf, end_row, end_col, 0 }) +end + +-- Byte length of node range +function M.node_length(node) + local _, _, start_byte = node:start() + local _, _, end_byte = node:end_() + return end_byte - start_byte +end + +--- Determines whether (line, col) position is in node range +-- @param node Node defining the range +-- @param line A line (0-based) +-- @param col A column (0-based) +function M.is_in_node_range(node, line, col) + local start_line, start_col, end_line, end_col = node:range() + if line >= start_line and line <= end_line then + if line == start_line and line == end_line then + return col >= start_col and col < end_col + elseif line == start_line then + return col >= start_col + elseif line == end_line then + return col < end_col + else + return true + end + else + return false + end +end + +function M.get_node_range(node_or_range) + if type(node_or_range) == "table" then + return unpack(node_or_range) + else + return node_or_range:range() + end +end + +function M.node_to_lsp_range(node) + local start_line, start_col, end_line, end_col = M.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. +-- @param fn: the fn to memoize, taking the bufnr as first argument +-- @param options: +-- - bufnr: extracts a bufnr from the given arguments. +-- - key: extracts the cache key from the given arguments. +-- @returns a memoized function +function M.memoize_by_buf_tick(fn, options) + options = options or {} + + local cache = {} + 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 = M.get_node_text(node_or_range1) + local text2 = M.get_node_text(node_or_range2) + + local edit1 = { range = range1, newText = table.concat(text2, "\n") } + local edit2 = { range = range2, newText = table.concat(text1, "\n") } + 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() } } + local position + if not goto_end then + position = { range[1], range[2] } + else + position = { range[3], range[4] } + end + -- Position is 1, 0 indexed. + api.nvim_win_set_cursor(0, { position[1], position[2] - 1 }) +end + +return M diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/tsrange.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/tsrange.lua new file mode 100644 index 000000000..d41585c60 --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/tsrange.lua @@ -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 diff --git a/bundle/nvim-treesitter/lua/nvim-treesitter/utils.lua b/bundle/nvim-treesitter/lua/nvim-treesitter/utils.lua new file mode 100644 index 000000000..06e0e03fb --- /dev/null +++ b/bundle/nvim-treesitter/lua/nvim-treesitter/utils.lua @@ -0,0 +1,236 @@ +local api = vim.api +local fn = vim.fn +local luv = vim.loop + +local M = {} + +-- Wrapper around vim.notify with common options set. +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 + +--- 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 heirarchy - nvim-treesitter.module +---@param commands table, 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 ) +--- - 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 +---
+---  M.commands = {
+---      custom_command = {
+---          run = M.module_function,
+---          f_args = "",
+---          args = {
+---              "-range"
+---          }
+---      }
+---  }
+---
+---  utils.setup_commands("custom_mod", require("nvim-treesitter.custom_mod").commands)
+---  
+--- +--- Will generate command : +---
+---  command! -range custom_command \
+---      lua require'nvim-treesitter.custom_mod'.commands.custom_command['run']()
+---  
+function M.setup_commands(mod, commands) + for command_name, def in pairs(commands) do + local f_args = def.f_args or "" + local call_fn = string.format( + "lua require'nvim-treesitter.%s'.commands.%s['run'](%s)", + mod, + command_name, + f_args + ) + local parts = vim.tbl_flatten { + "command!", + def.args, + command_name, + call_fn, + } + api.nvim_command(table.concat(parts, " ")) + end +end + +function M.get_path_sep() + return fn.has "win32" == 1 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" +function M.generate_join(separator) + return function(...) + return table.concat({ ... }, separator) + end +end + +M.join_path = M.generate_join(M.get_path_sep()) + +local join_space = M.generate_join " " + +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, 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() + local path_sep = M.get_path_sep() + return M.join_path(fn.stdpath "data", path_sep, "site") +end + +-- 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. +function M.get_parser_install_dir(folder_name) + folder_name = folder_name or "parser" + local package_path = M.get_package_path() + local package_path_parser_dir = M.join_path(package_path, folder_name) + + -- If package_path is read/write, use that + if luv.fs_access(package_path_parser_dir, "RW") then + return package_path_parser_dir + end + + local site_dir = M.get_site_dir() + local path_sep = M.get_path_sep() + local parser_dir = M.join_path(site_dir, path_sep, folder_name) + + -- Try creating and using parser_dir if it doesn't exist + if not luv.fs_stat(parser_dir) then + local ok, error = pcall(vim.fn.mkdir, parser_dir, "p", "0755") + if not ok then + return nil, join_space("Couldn't create parser dir", parser_dir, ":", error) + end + + return parser_dir + end + + -- parser_dir exists, use it if it's read/write + if luv.fs_access(parser_dir, "RW") then + return parser_dir + end + + -- package_path isn't read/write, parser_dir exists but isn't read/write + -- either, give up + return nil, join_space("Invalid cache rights,", package_path, "or", parser_dir, "should be read/write") +end + +function M.get_parser_info_dir() + return M.get_parser_install_dir "parser-info" +end + +-- Gets a property at path +-- @param tbl the table to access +-- @param path the '.' separated path +-- @returns 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) + local result = tbl + + for _, segment in ipairs(segments) do + if type(result) == "table" then + result = result[segment] + end + end + + return result +end + +function M.set_jump() + vim.cmd "normal! m'" +end + +function M.index_of(tbl, obj) + for i, o in ipairs(tbl) do + if o == obj then + return i + end + end +end + +-- Filters a list based on the given predicate +-- @param tbl The list to filter +-- @param predicate 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. +-- @params tbl1 The first table +-- @params tbl2 The second 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 + +function M.constant(a) + return function() + return a + end +end + +function M.to_func(a) + return type(a) == "function" and a or M.constant(a) +end + +function M.ts_cli_version() + if fn.executable "tree-sitter" == 1 then + local handle = io.popen "tree-sitter -V" + local result = handle:read "*a" + handle:close() + return vim.split(result, "\n")[1]:match "[^tree%psitter ].*" + end +end + +return M diff --git a/bundle/nvim-treesitter/parser-info/.gitignore b/bundle/nvim-treesitter/parser-info/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/bundle/nvim-treesitter/parser-info/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/bundle/nvim-treesitter/parser/.gitignore b/bundle/nvim-treesitter/parser/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/bundle/nvim-treesitter/parser/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/bundle/nvim-treesitter/plugin/nvim-treesitter.vim b/bundle/nvim-treesitter/plugin/nvim-treesitter.vim new file mode 100644 index 000000000..c30bcaca5 --- /dev/null +++ b/bundle/nvim-treesitter/plugin/nvim-treesitter.vim @@ -0,0 +1,106 @@ +" Last Change: 2020 Aug 13 + +if exists('g:loaded_nvim_treesitter') + finish +endif + +augroup NvimTreesitter + " on every query file write we want to set an autocommand that will reload the cache + autocmd FileType query + \ autocmd! NvimTreesitter BufWritePost call v:lua.require('nvim-treesitter.query').invalidate_query_file(expand('%:p')) +augroup END + +let g:loaded_nvim_treesitter = 1 + +lua require'nvim-treesitter'.setup() + +function s:has_attr(attr, mode) + let norm_color = synIDattr(hlID('Normal'), a:attr, a:mode) + return strlen(norm_color) > 0 +endfunction + +" if the ctermfg or guifg is not known by nvim then using the +" fg or foreground highlighting value will cause an E419 error +" so we check to see if either highlight has been set if not default to NONE +let cterm_normal = s:has_attr('fg', 'cterm') ? 'fg' : 'NONE' +let gui_normal = s:has_attr('fg', 'gui') ? 'foreground' : 'NONE' + +execute 'highlight default TSNone term=NONE cterm=NONE gui=NONE guifg='.gui_normal.' ctermfg='.cterm_normal + +highlight default link TSPunctDelimiter Delimiter +highlight default link TSPunctBracket Delimiter +highlight default link TSPunctSpecial Delimiter + +highlight default link TSConstant Constant +highlight default link TSConstBuiltin Special +highlight default link TSConstMacro Define +highlight default link TSString String +highlight default link TSStringRegex String +highlight default link TSStringEscape SpecialChar +highlight default link TSStringSpecial SpecialChar +highlight default link TSCharacter Character +highlight default link TSCharacterSpecial SpecialChar +highlight default link TSNumber Number +highlight default link TSBoolean Boolean +highlight default link TSFloat Float + +highlight default link TSFunction Function +highlight default link TSFuncBuiltin Special +highlight default link TSFuncMacro Macro +highlight default link TSParameter Identifier +highlight default link TSParameterReference TSParameter +highlight default link TSMethod Function +highlight default link TSField Identifier +highlight default link TSProperty Identifier +highlight default link TSConstructor Special +highlight default link TSAnnotation PreProc +highlight default link TSAttribute PreProc +highlight default link TSNamespace Include +highlight default link TSSymbol Identifier + +highlight default link TSConditional Conditional +highlight default link TSRepeat Repeat +highlight default link TSLabel Label +highlight default link TSOperator Operator +highlight default link TSKeyword Keyword +highlight default link TSKeywordFunction Keyword +highlight default link TSKeywordOperator TSOperator +highlight default link TSKeywordReturn TSKeyword +highlight default link TSException Exception +highlight default link TSDebug Debug +highlight default link TSDefine Define +highlight default link TSPreProc PreProc +highlight default link TSStorageClass StorageClass + +highlight default link TSTodo Todo + +highlight default link TSType Type +highlight default link TSTypeBuiltin Type +highlight default link TSTypeQualifier Type +highlight default link TSTypeDefinition Typedef + +highlight default link TSInclude Include + +highlight default link TSVariableBuiltin Special + +highlight default link TSText TSNone +highlight default TSStrong term=bold cterm=bold gui=bold +highlight default TSEmphasis term=italic cterm=italic gui=italic +highlight default TSUnderline term=underline cterm=underline gui=underline +highlight default TSStrike term=strikethrough cterm=strikethrough gui=strikethrough +highlight default link TSMath Special +highlight default link TSTextReference Constant +highlight default link TSEnvironment Macro +highlight default link TSEnvironmentName Type +highlight default link TSTitle Title +highlight default link TSLiteral String +highlight default link TSURI Underlined + +highlight default link TSComment Comment +highlight default link TSNote SpecialComment +highlight default link TSWarning Todo +highlight default link TSDanger WarningMsg + +highlight default link TSTag Label +highlight default link TSTagDelimiter Delimiter +highlight default link TSTagAttribute TSProperty diff --git a/bundle/nvim-treesitter/queries/astro/folds.scm b/bundle/nvim-treesitter/queries/astro/folds.scm new file mode 100644 index 000000000..1f2129cf9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/astro/folds.scm @@ -0,0 +1 @@ +; inherits: html diff --git a/bundle/nvim-treesitter/queries/astro/highlights.scm b/bundle/nvim-treesitter/queries/astro/highlights.scm new file mode 100644 index 000000000..62e8ed247 --- /dev/null +++ b/bundle/nvim-treesitter/queries/astro/highlights.scm @@ -0,0 +1,5 @@ +; inherits: html + +[ "---" ] @punctuation.delimiter + +[ "{" "}" ] @punctuation.special diff --git a/bundle/nvim-treesitter/queries/astro/indents.scm b/bundle/nvim-treesitter/queries/astro/indents.scm new file mode 100644 index 000000000..1f2129cf9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/astro/indents.scm @@ -0,0 +1 @@ +; inherits: html diff --git a/bundle/nvim-treesitter/queries/astro/injections.scm b/bundle/nvim-treesitter/queries/astro/injections.scm new file mode 100644 index 000000000..8b68bee23 --- /dev/null +++ b/bundle/nvim-treesitter/queries/astro/injections.scm @@ -0,0 +1,7 @@ +; inherits: html + +((frontmatter + (raw_text) @typescript)) + +((interpolation + (raw_text) @tsx)) diff --git a/bundle/nvim-treesitter/queries/astro/locals.scm b/bundle/nvim-treesitter/queries/astro/locals.scm new file mode 100644 index 000000000..1f2129cf9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/astro/locals.scm @@ -0,0 +1 @@ +; inherits: html diff --git a/bundle/nvim-treesitter/queries/bash/folds.scm b/bundle/nvim-treesitter/queries/bash/folds.scm new file mode 100644 index 000000000..851c67eed --- /dev/null +++ b/bundle/nvim-treesitter/queries/bash/folds.scm @@ -0,0 +1,8 @@ +[ + (function_definition) + (if_statement) + (case_statement) + (for_statement) + (while_statement) + (c_style_for_statement) +] @fold diff --git a/bundle/nvim-treesitter/queries/bash/highlights.scm b/bundle/nvim-treesitter/queries/bash/highlights.scm new file mode 100644 index 000000000..f80986f95 --- /dev/null +++ b/bundle/nvim-treesitter/queries/bash/highlights.scm @@ -0,0 +1,131 @@ +(simple_expansion) @none +(expansion + "${" @punctuation.special + "}" @punctuation.special) @none +[ + "(" + ")" + "((" + "))" + "{" + "}" + "[" + "]" + "[[" + "]]" + ] @punctuation.bracket + +[ + ";" + ";;" + (heredoc_start) + ] @punctuation.delimiter + +[ + "$" +] @punctuation.special + +[ + ">" + ">>" + "<" + "<<" + "&" + "&&" + "|" + "||" + "=" + "=~" + "==" + "!=" + ] @operator + +[ + (string) + (raw_string) + (heredoc_body) +] @string + +(variable_assignment (word) @string) + +[ + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" + ] @conditional + +[ + "for" + "do" + "done" + "while" + ] @repeat + +[ + "declare" + "export" + "local" + "readonly" + "unset" + ] @keyword + +"function" @keyword.function + +(special_variable_name) @constant + +((word) @constant.builtin + (#match? @constant.builtin "^SIG(INT|TERM|QUIT|TIN|TOU|STP|HUP)$")) + +((word) @boolean + (#match? @boolean "^(true|false)$")) + +(comment) @comment +(test_operator) @string + +(command_substitution + [ "$(" ")" ] @punctuation.bracket) + +(process_substitution + [ "<(" ")" ] @punctuation.bracket) + + +(function_definition + name: (word) @function) + +(command_name (word) @function) + +((command_name (word) @function.builtin) + (#any-of? @function.builtin + "alias" "cd" "clear" "echo" "eval" "exit" "getopts" "popd" + "pushd" "return" "set" "shift" "shopt" "source" "test")) + +(command + argument: [ + (word) @parameter + (concatenation (word) @parameter) + ]) + +((word) @number + (#lua-match? @number "^[0-9]+$")) + +(file_redirect + descriptor: (file_descriptor) @operator + destination: (word) @parameter) + +(expansion + [ "${" "}" ] @punctuation.bracket) + +(variable_name) @variable + +((variable_name) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +(case_item + value: (word) @parameter) + +(regex) @string.regex diff --git a/bundle/nvim-treesitter/queries/bash/injections.scm b/bundle/nvim-treesitter/queries/bash/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/bash/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/bash/locals.scm b/bundle/nvim-treesitter/queries/bash/locals.scm new file mode 100644 index 000000000..a03bc3a56 --- /dev/null +++ b/bundle/nvim-treesitter/queries/bash/locals.scm @@ -0,0 +1,13 @@ +; Scopes +(function_definition) @scope + +; Definitions +(variable_assignment + name: (variable_name) @definition.var) + +(function_definition + name: (word) @definition.function) + +; References +(variable_name) @reference +(word) @reference diff --git a/bundle/nvim-treesitter/queries/beancount/folds.scm b/bundle/nvim-treesitter/queries/beancount/folds.scm new file mode 100644 index 000000000..b65ae0115 --- /dev/null +++ b/bundle/nvim-treesitter/queries/beancount/folds.scm @@ -0,0 +1,4 @@ +[ + (transaction) + (heading) +] @fold diff --git a/bundle/nvim-treesitter/queries/beancount/highlights.scm b/bundle/nvim-treesitter/queries/beancount/highlights.scm new file mode 100644 index 000000000..7fa78d84e --- /dev/null +++ b/bundle/nvim-treesitter/queries/beancount/highlights.scm @@ -0,0 +1,26 @@ + +(date) @field +(txn) @attribute + +(account) @type + +(amount) @number +(incomplete_amount) @number +(amount_tolerance) @number + +(currency) @property + +(key) @label +(string) @string + +(tag) @constant +(link) @constant + +(comment) @comment + +[ + (balance) (open) (close) (commodity) (pad) + (event) (price) (note) (document) (query) + (custom) (pushtag) (poptag) (pushmeta) + (popmeta) (option) (include) (plugin) +] @keyword diff --git a/bundle/nvim-treesitter/queries/bibtex/folds.scm b/bundle/nvim-treesitter/queries/bibtex/folds.scm new file mode 100644 index 000000000..3b24d5fea --- /dev/null +++ b/bundle/nvim-treesitter/queries/bibtex/folds.scm @@ -0,0 +1,3 @@ +[ + (entry) +] @fold diff --git a/bundle/nvim-treesitter/queries/bibtex/highlights.scm b/bundle/nvim-treesitter/queries/bibtex/highlights.scm new file mode 100644 index 000000000..00cae314d --- /dev/null +++ b/bundle/nvim-treesitter/queries/bibtex/highlights.scm @@ -0,0 +1,49 @@ +; CREDITS @pfoerster (adapted from https://github.com/latex-lsp/tree-sitter-bibtex) + +[ + (string_type) + (preamble_type) + (entry_type) +] @keyword + +[ + (junk) + (comment) +] @comment + +[ + "=" + "#" +] @operator + +(command) @function.builtin + +(number) @number + +(field + name: (identifier) @field) + +(token + (identifier) @parameter) + +[ + (brace_word) + (quote_word) +] @string + +[ + (key_brace) + (key_paren) +] @symbol + +(string + name: (identifier) @constant) + +[ + "{" + "}" + "(" + ")" +] @punctuation.bracket + +"," @punctuation.delimiter diff --git a/bundle/nvim-treesitter/queries/bibtex/indents.scm b/bundle/nvim-treesitter/queries/bibtex/indents.scm new file mode 100644 index 000000000..af652160e --- /dev/null +++ b/bundle/nvim-treesitter/queries/bibtex/indents.scm @@ -0,0 +1,10 @@ +[ + (entry) +] @indent + +[ + "{" + "}" +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/c/folds.scm b/bundle/nvim-treesitter/queries/c/folds.scm new file mode 100644 index 000000000..80c3039b6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c/folds.scm @@ -0,0 +1,19 @@ +[ + (for_statement) + (if_statement) + (while_statement) + (switch_statement) + (case_statement) + (function_definition) + (struct_specifier) + (enum_specifier) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (initializer_list) +] @fold + + (compound_statement + (compound_statement) @fold) diff --git a/bundle/nvim-treesitter/queries/c/highlights.scm b/bundle/nvim-treesitter/queries/c/highlights.scm new file mode 100644 index 000000000..2ea07a74a --- /dev/null +++ b/bundle/nvim-treesitter/queries/c/highlights.scm @@ -0,0 +1,187 @@ +(identifier) @variable + +[ + "const" + "default" + "enum" + "extern" + "inline" + "static" + "struct" + "typedef" + "union" + "volatile" + "goto" + "register" +] @keyword + +"sizeof" @keyword.operator +"return" @keyword.return + +[ + "while" + "for" + "do" + "continue" + "break" +] @repeat + +[ + "if" + "else" + "case" + "switch" +] @conditional + +"#define" @constant.macro +[ + "#if" + "#ifdef" + "#ifndef" + "#else" + "#elif" + "#endif" + (preproc_directive) +] @keyword + +"#include" @include + +[ + "=" + + "-" + "*" + "/" + "+" + "%" + + "~" + "|" + "&" + "^" + "<<" + ">>" + + "->" + + "<" + "<=" + ">=" + ">" + "==" + "!=" + + "!" + "&&" + "||" + + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" + "--" + "++" +] @operator + +[ + (true) + (false) +] @boolean + +[ "." ";" ":" "," ] @punctuation.delimiter + +"..." @punctuation.special + +(conditional_expression [ "?" ":" ] @conditional) + + +[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket + +(string_literal) @string +(system_lib_string) @string +(escape_sequence) @string.escape + +(null) @constant.builtin +(number_literal) @number +(char_literal) @character + +[ + (preproc_arg) + (preproc_defined) +] @function.macro + +(((field_expression + (field_identifier) @property)) @_parent + (#not-has-parent? @_parent template_method function_declarator call_expression)) + +(((field_identifier) @property) + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) + +(statement_identifier) @label + +[ + (type_identifier) + (primitive_type) + (sized_type_specifier) + (type_descriptor) +] @type + +(sizeof_expression value: (parenthesized_expression (identifier) @type)) + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) +(enumerator + name: (identifier) @constant) +(case_statement + value: (identifier) @constant) + +;; Preproc def / undef +(preproc_def + name: (_) @constant) +(preproc_call + directive: (preproc_directive) @_u + argument: (_) @constant + (#eq? @_u "#undef")) + +(call_expression + function: (identifier) @function) +(call_expression + function: (field_expression + field: (field_identifier) @function)) +(function_declarator + declarator: (identifier) @function) +(preproc_function_def + name: (identifier) @function.macro) + +(comment) @comment + +;; Parameters +(parameter_declaration + declarator: (identifier) @parameter) + +(parameter_declaration + declarator: (pointer_declarator) @parameter) + +(preproc_params (identifier) @parameter) + +[ + "__attribute__" + "__cdecl" + "__clrcall" + "__stdcall" + "__fastcall" + "__thiscall" + "__vectorcall" + "_unaligned" + "__unaligned" + "__declspec" +] @attribute + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/c/indents.scm b/bundle/nvim-treesitter/queries/c/indents.scm new file mode 100644 index 000000000..1931471b9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c/indents.scm @@ -0,0 +1,49 @@ +[ + (compound_statement) + (preproc_arg) + (field_declaration_list) + (case_statement) + (enumerator_list) + (struct_specifier) + (compound_literal_expression) + (initializer_list) + (while_statement) + (for_statement) + (switch_statement) + (expression_statement) +] @indent +(if_statement condition: (_) @indent) +((if_statement + consequence: (_) @_consequence + (#not-has-type? @_consequence compound_statement) + ) @indent) +(init_declarator) @indent + +(compound_statement "}" @indent_end) + +[ + "else" + ")" + "}" + (statement_identifier) +] @branch + +[ + "#define" + "#ifdef" + "#if" + "#else" + "#endif" +] @zero_indent + +[ + (preproc_arg) + (string_literal) +] @ignore + +((ERROR (parameter_declaration)) @aligned_indent + (#set! "delimiter" "()")) +([(argument_list) (parameter_list)] @aligned_indent + (#set! "delimiter" "()")) + +(comment) @auto diff --git a/bundle/nvim-treesitter/queries/c/injections.scm b/bundle/nvim-treesitter/queries/c/injections.scm new file mode 100644 index 000000000..afeb068a2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c/injections.scm @@ -0,0 +1,3 @@ +(preproc_arg) @c + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/c/locals.scm b/bundle/nvim-treesitter/queries/c/locals.scm new file mode 100644 index 000000000..78a2180d3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c/locals.scm @@ -0,0 +1,53 @@ +;; Functions definitions +(function_declarator + declarator: (identifier) @definition.function) +(preproc_function_def + name: (identifier) @definition.macro) @scope + +(preproc_def + name: (identifier) @definition.macro) +(pointer_declarator + declarator: (identifier) @definition.var) +(parameter_declaration + declarator: (identifier) @definition.parameter) +(init_declarator + declarator: (identifier) @definition.var) +(array_declarator + declarator: (identifier) @definition.var) +(declaration + declarator: (identifier) @definition.var) +(enum_specifier + name: (_) @definition.type + (enumerator_list + (enumerator name: (identifier) @definition.var))) + +;; Type / Struct / Enum +(field_declaration + declarator: (field_identifier) @definition.field) +(type_definition + declarator: (type_identifier) @definition.type) +(struct_specifier + name: (type_identifier) @definition.type) + +;; goto +(labeled_statement (statement_identifier) @definition) + +;; References +(identifier) @reference +((field_identifier) @reference + (set! reference.kind "field")) +((type_identifier) @reference + (set! reference.kind "type")) + +(goto_statement (statement_identifier) @reference) + +;; Scope +[ + (for_statement) + (if_statement) + (while_statement) + (translation_unit) + (function_definition) + (compound_statement) ; a block in curly braces + (struct_specifier) +] @scope diff --git a/bundle/nvim-treesitter/queries/c_sharp/folds.scm b/bundle/nvim-treesitter/queries/c_sharp/folds.scm new file mode 100644 index 000000000..4b5d94270 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c_sharp/folds.scm @@ -0,0 +1,15 @@ +body: [ + (declaration_list) + (switch_body) + (enum_member_declaration_list) +] @fold + +accessors: [ + (accessor_list) +] @fold + +initializer: [ + (initializer_expression) +] @fold + +(block) @fold diff --git a/bundle/nvim-treesitter/queries/c_sharp/highlights.scm b/bundle/nvim-treesitter/queries/c_sharp/highlights.scm new file mode 100644 index 000000000..fc3600e0e --- /dev/null +++ b/bundle/nvim-treesitter/queries/c_sharp/highlights.scm @@ -0,0 +1,390 @@ +(identifier) @variable + +((identifier) @keyword + (#eq? @keyword "value") + (#has-ancestor? @keyword accessor_declaration)) + +(method_declaration + name: (identifier) @method) + +(local_function_statement + name: (identifier) @method) + +(method_declaration + type: (identifier) @type) + +(local_function_statement + type: (identifier) @type) + +(interpolation) @none + +(invocation_expression + (member_access_expression + name: (identifier) @method)) + +(invocation_expression + function: (conditional_access_expression + (member_binding_expression + name: (identifier) @method))) + +(namespace_declaration + name: [(qualified_name) (identifier)] @namespace) + +(qualified_name + (identifier) @type) + +(invocation_expression + (identifier) @method) + +(field_declaration + (variable_declaration + (variable_declarator + (identifier) @field))) + +(initializer_expression + (assignment_expression + left: (identifier) @field)) + +(parameter_list + (parameter + name: (identifier) @parameter)) + +(parameter_list + (parameter + type: (identifier) @type)) + +(integer_literal) @number +(real_literal) @float + +(null_literal) @constant.builtin +(character_literal) @character + +[ + (string_literal) + (verbatim_string_literal) + (interpolated_string_expression) +] @string + +(boolean_literal) @boolean + +[ + (predefined_type) + (void_keyword) +] @type.builtin + +(implicit_type) @keyword + +(comment) @comment + +(using_directive + (identifier) @type) + +(property_declaration + name: (identifier) @property) + +(property_declaration + type: (identifier) @type) + +(nullable_type + (identifier) @type) + +(catch_declaration + type: (identifier) @type) + +(interface_declaration + name: (identifier) @type) +(class_declaration + name: (identifier) @type) +(record_declaration + name: (identifier) @type) +(enum_declaration + name: (identifier) @type) +(constructor_declaration + name: (identifier) @constructor) +(constructor_initializer [ + "base" @constructor +]) + +(variable_declaration + (identifier) @type) +(object_creation_expression + (identifier) @type) + +; Generic Types. +(type_of_expression + (generic_name + (identifier) @type)) + +(type_argument_list + (generic_name + (identifier) @type)) + +(base_list + (generic_name + (identifier) @type)) + +(type_constraint + (generic_name + (identifier) @type)) + +(object_creation_expression + (generic_name + (identifier) @type)) + +(property_declaration + (generic_name + (identifier) @type)) + +(_ + type: (generic_name + (identifier) @type)) +; Generic Method invocation with generic type +(invocation_expression + function: (generic_name + . (identifier) @method)) + +(invocation_expression + (member_access_expression + (generic_name + (identifier) @method))) + +(base_list + (identifier) @type) + +(type_argument_list + (identifier) @type) + +(type_parameter_list + (type_parameter) @type) + +(type_parameter_constraints_clause + target: (identifier) @type) + +(attribute + name: (identifier) @attribute) + +(for_each_statement + type: (identifier) @type) + +(tuple_element + type: (identifier) @type) + +(tuple_expression + (argument + (declaration_expression + type: (identifier) @type))) + +(as_expression + right: (identifier) @type) + +(type_of_expression + (identifier) @type) + +(name_colon + (identifier) @parameter) + +(warning_directive) @text.warning +(error_directive) @exception + +(define_directive + (identifier) @constant) @constant.macro +(undef_directive + (identifier) @constant) @constant.macro + +(line_directive) @constant.macro +(line_directive + (preproc_integer_literal) @constant + (preproc_string_literal)? @string) + +(pragma_directive + (identifier) @constant) @constant.macro +(pragma_directive + (preproc_string_literal) @string) @constant.macro + +[ + (nullable_directive) + (region_directive) + (endregion_directive) +] @constant.macro + +[ + "if" + "else" + "switch" + "break" + "case" + (if_directive) + (elif_directive) + (else_directive) + (endif_directive) +] @conditional + +(if_directive + (identifier) @constant) +(elif_directive + (identifier) @constant) + +[ + "while" + "for" + "do" + "continue" + "goto" + "foreach" +] @repeat + +[ + "try" + "catch" + "throw" + "finally" +] @exception + +[ + "+" + "?" + ":" + "++" + "-" + "--" + "&" + "&&" + "|" + "||" + "!" + "!=" + "==" + "*" + "/" + "%" + "<" + "<=" + ">" + ">=" + "=" + "-=" + "+=" + "*=" + "/=" + "%=" + "^" + "^=" + "&=" + "|=" + "~" + ">>" + "<<" + "<<=" + ">>=" + "=>" +] @operator + +[ + ";" + "." + "," + ":" +] @punctuation.delimiter + +[ + "[" + "]" + "{" + "}" + "(" + ")" + "<" + ">" +] @punctuation.bracket + +[ + (this_expression) + (base_expression) +] @variable.builtin + +[ + "using" +] @include + +(alias_qualified_name + (identifier "global") @include) + +[ + "with" + "new" + "typeof" + "nameof" + "sizeof" + "is" + "as" + "and" + "or" + "not" + "stackalloc" + "in" + "out" + "ref" +] @keyword.operator + +[ + "lock" + "params" + "operator" + "default" + "abstract" + "const" + "extern" + "implicit" + "explicit" + "internal" + "override" + "private" + "protected" + "public" + "internal" + "partial" + "readonly" + "sealed" + "static" + "virtual" + "volatile" + "async" + "await" + "class" + "delegate" + "enum" + "interface" + "namespace" + "struct" + "get" + "set" + "init" + "where" + "record" + "event" + "add" + "remove" + "checked" + "unchecked" + "fixed" +] @keyword + +(parameter_modifier) @operator + +(query_expression + (_ [ + "from" + "orderby" + "select" + "group" + "by" + "ascending" + "descending" + "equals" + "let" + ] @keyword)) + +[ + "return" + "yield" +] @keyword.return diff --git a/bundle/nvim-treesitter/queries/c_sharp/injections.scm b/bundle/nvim-treesitter/queries/c_sharp/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/c_sharp/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/c_sharp/locals.scm b/bundle/nvim-treesitter/queries/c_sharp/locals.scm new file mode 100644 index 000000000..c53eb1a19 --- /dev/null +++ b/bundle/nvim-treesitter/queries/c_sharp/locals.scm @@ -0,0 +1,41 @@ +;; Definitions +(variable_declarator + . (identifier) @definition.var) + +(variable_declarator + (tuple_pattern + (identifier) @definition.var)) + +(declaration_expression + name: (identifier) @definition.var) + +(for_each_statement + left: (identifier) @definition.var) + +(for_each_statement + left: (tuple_pattern + (identifier) @definition.var)) + +(parameter + (identifier) @definition.parameter) + +(method_declaration + name: (identifier) @definition.method) + +(local_function_statement + name: (identifier) @definition.method) + +(property_declaration + name: (identifier) @definition) + +(type_parameter + (identifier) @definition.type) + +(class_declaration + name: (identifier) @definition) + +;; References +(identifier) @reference + +;; Scope +(block) @scope diff --git a/bundle/nvim-treesitter/queries/clojure/folds.scm b/bundle/nvim-treesitter/queries/clojure/folds.scm new file mode 100644 index 000000000..d54daade6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/clojure/folds.scm @@ -0,0 +1 @@ +(source (list_lit) @fold) diff --git a/bundle/nvim-treesitter/queries/clojure/highlights.scm b/bundle/nvim-treesitter/queries/clojure/highlights.scm new file mode 100644 index 000000000..d6371c522 --- /dev/null +++ b/bundle/nvim-treesitter/queries/clojure/highlights.scm @@ -0,0 +1,338 @@ +;; >> Explanation +;; Parsers for lisps are a bit weird in that they just return the raw forms. +;; This means we have to do a bit of extra work in the queries to get things +;; highlighted as they should be. +;; +;; For the most part this means that some things have to be assigned multiple +;; groups. +;; By doing this we can add a basic capture and then later refine it with more +;; specialied captures. +;; This can mean that sometimes things are highlighted weirdly because they +;; have multiple highlight groups applied to them. + + +;; >> Literals + +( + (dis_expr) @comment + (#set! "priority" 105) ; Higher priority to mark the whole sexpr as a comment +) +(kwd_lit) @symbol +(str_lit) @string +(num_lit) @number +(char_lit) @character +(bool_lit) @boolean +(nil_lit) @constant.builtin +(comment) @comment +(regex_lit) @string.regex + +["'" "`"] @string.escape + +["~" "~@" "#"] @punctuation.special + +["{" "}" "[" "]" "(" ")"] @punctuation.bracket + + + +;; >> Symbols + +; General symbol highlighting +(sym_lit) @variable + +; General function calls +(list_lit + . + (sym_lit) @function) +(anon_fn_lit + . + (sym_lit) @function) + +; Quoted symbols +(quoting_lit + (sym_lit) @symbol) +(syn_quoting_lit + (sym_lit) @symbol) + +; Used in destructure pattern +((sym_lit) @parameter + (#lua-match? @parameter "^[&]")) + +; Inline function variables +((sym_lit) @variable.builtin + (#match? @variable.builtin "^[%]")) + +; Constructor +((sym_lit) @constructor + (#match? @constructor "^-\\>[^\\>].*")) + +; Dynamic variables +((sym_lit) @variable.builtin + (#match? @variable.builtin "^[*].+[*]$")) + +; Gensym +;; Might not be needed +((sym_lit) @variable + (#match? @variable "^.*#$")) + +; Types +;; TODO: improve? +((sym_lit) @type + (#match? @type "^[A-Z][^/]*$")) +;; Symbols with `.` but not `/` +((sym_lit) @type + (#match? @type "^[^/]+[.][^/]*$")) + +; Interop +((sym_lit) @method + (#match? @method "^\\.[^-]")) +((sym_lit) @field + (#match? @field "^\\.-")) +((sym_lit) @field + (#match? @field "^[A-Z].*/.+")) +(list_lit + . + (sym_lit) @method + (#match? @method "^[A-Z].*/.+")) +;; TODO: Special casing for the `.` macro + +; Operators +((sym_lit) @operator + (#any-of? @operator + "*" "*'" "+" "+'" "-" "-'" "/" + "<" "<=" ">" ">=" "=" "==")) +((sym_lit) @keyword.operator + (#any-of? @keyword.operator + "not" "not=" "and" "or")) + +; Definition functions +((sym_lit) @keyword + (#lua-match? @keyword "^def.*$")) +((sym_lit) @keyword + (#eq? @keyword "declare")) +((sym_lit) @keyword.function + (#match? @keyword.function "^(defn|defn-|fn|fn[*])$")) + +; Comment +((sym_lit) @comment + (#any-of? @comment "comment")) + +; Conditionals +((sym_lit) @conditional + (#any-of? @conditional + "case" "cond" "cond->" "cond->>" "condp")) +((sym_lit) @conditional + (#match? @conditional "^if(\\-.*)?$")) +((sym_lit) @conditional + (#match? @conditional "^when(\\-.*)?$")) + +; Repeats +((sym_lit) @repeat + (#any-of? @repeat + "doseq" "dotimes" "for" "loop" "recur" "while")) + +; Exception +((sym_lit) @exception + (#any-of? @exception + "throw" "try" "catch" "finally" "ex-info")) + +; Includes +((sym_lit) @include + (#any-of? @include "ns" "import" "require" "use")) + +; Builtin macros +;; TODO: Do all these items belong here? +((sym_lit) @function.macro + (#any-of? @function.macro + "." ".." "->" "->>" "amap" "areduce" "as->" "assert" + "binding" "bound-fn" "delay" "do" "dosync" + "doto" "extend-protocol" "extend-type" "future" + "gen-class" "gen-interface" "io!" "lazy-cat" + "lazy-seq" "let" "letfn" "locking" "memfn" "monitor-enter" + "monitor-exit" "proxy" "proxy-super" "pvalues" + "refer-clojure" "reify" "set!" "some->" "some->>" "sync" + "time" "unquote" "unquote-splicing" "var" "vswap!" + "ex-cause" "ex-data" "ex-message")) +((sym_lit) @function.macro + (#match? @function.macro "^with\\-.*$")) + +; All builtin functions +; (->> (ns-publics *ns*) +; (keep (fn [[s v]] (when-not (:macro (meta v)) s))) +; sort +; cp/print)) +;; ...and then lots of manual filtering... +((sym_lit) @function.builtin + (#any-of? @function.builtin + "->ArrayChunk" "->Eduction" "->Vec" "->VecNode" "->VecSeq" + "-cache-protocol-fn" "-reset-methods" "PrintWriter-on" + "StackTraceElement->vec" "Throwable->map" "accessor" + "aclone" "add-classpath" "add-tap" "add-watch" "agent" + "agent-error" "agent-errors" "aget" "alength" "alias" + "all-ns" "alter" "alter-meta!" "alter-var-root" "ancestors" + "any?" "apply" "array-map" "aset" "aset-boolean" "aset-byte" + "aset-char" "aset-double" "aset-float" "aset-int" + "aset-long" "aset-short" "assoc" "assoc!" "assoc-in" + "associative?" "atom" "await" "await-for" "await1" + "bases" "bean" "bigdec" "bigint" "biginteger" "bit-and" + "bit-and-not" "bit-clear" "bit-flip" "bit-not" "bit-or" + "bit-set" "bit-shift-left" "bit-shift-right" "bit-test" + "bit-xor" "boolean" "boolean-array" "boolean?" + "booleans" "bound-fn*" "bound?" "bounded-count" + "butlast" "byte" "byte-array" "bytes" "bytes?" + "cast" "cat" "char" "char-array" "char-escape-string" + "char-name-string" "char?" "chars" "chunk" "chunk-append" + "chunk-buffer" "chunk-cons" "chunk-first" "chunk-next" + "chunk-rest" "chunked-seq?" "class" "class?" + "clear-agent-errors" "clojure-version" "coll?" + "commute" "comp" "comparator" "compare" "compare-and-set!" + "compile" "complement" "completing" "concat" "conj" + "conj!" "cons" "constantly" "construct-proxy" "contains?" + "count" "counted?" "create-ns" "create-struct" "cycle" + "dec" "dec'" "decimal?" "dedupe" "default-data-readers" + "delay?" "deliver" "denominator" "deref" "derive" + "descendants" "destructure" "disj" "disj!" "dissoc" + "dissoc!" "distinct" "distinct?" "doall" "dorun" "double" + "double-array" "eduction" "empty" "empty?" "ensure" "ensure-reduced" + "enumeration-seq" "error-handler" "error-mode" "eval" + "even?" "every-pred" "every?" "extend" "extenders" "extends?" + "false?" "ffirst" "file-seq" "filter" "filterv" "find" + "find-keyword" "find-ns" "find-protocol-impl" + "find-protocol-method" "find-var" "first" "flatten" + "float" "float-array" "float?" "floats" "flush" "fn?" + "fnext" "fnil" "force" "format" "frequencies" + "future-call" "future-cancel" "future-cancelled?" + "future-done?" "future?" "gensym" "get" "get-in" + "get-method" "get-proxy-class" "get-thread-bindings" + "get-validator" "group-by" "halt-when" "hash" + "hash-combine" "hash-map" "hash-ordered-coll" "hash-set" + "hash-unordered-coll" "ident?" "identical?" "identity" + "ifn?" "in-ns" "inc" "inc'" "indexed?" "init-proxy" + "inst-ms" "inst-ms*" "inst?" "instance?" "int" "int-array" + "int?" "integer?" "interleave" "intern" "interpose" "into" + "into-array" "ints" "isa?" "iterate" "iterator-seq" "juxt" + "keep" "keep-indexed" "key" "keys" "keyword" "keyword?" + "last" "line-seq" "list" "list*" "list?" "load" "load-file" + "load-reader" "load-string" "loaded-libs" "long" "long-array" + "longs" "macroexpand" "macroexpand-1" "make-array" "make-hierarchy" + "map" "map-entry?" "map-indexed" "map?" "mapcat" "mapv" + "max" "max-key" "memoize" "merge" "merge-with" "meta" + "method-sig" "methods" "min" "min-key" "mix-collection-hash" + "mod" "munge" "name" "namespace" "namespace-munge" "nat-int?" + "neg-int?" "neg?" "newline" "next" "nfirst" "nil?" "nnext" + "not-any?" "not-empty" "not-every?" "ns-aliases" + "ns-imports" "ns-interns" "ns-map" "ns-name" "ns-publics" + "ns-refers" "ns-resolve" "ns-unalias" "ns-unmap" "nth" + "nthnext" "nthrest" "num" "number?" "numerator" "object-array" + "odd?" "parents" "partial" "partition" "partition-all" + "partition-by" "pcalls" "peek" "persistent!" "pmap" "pop" + "pop!" "pop-thread-bindings" "pos-int?" "pos?" "pr" + "pr-str" "prefer-method" "prefers" "primitives-classnames" + "print" "print-ctor" "print-dup" "print-method" "print-simple" + "print-str" "printf" "println" "println-str" "prn" "prn-str" + "promise" "proxy-call-with-super" "proxy-mappings" "proxy-name" + "push-thread-bindings" "qualified-ident?" "qualified-keyword?" + "qualified-symbol?" "quot" "rand" "rand-int" "rand-nth" "random-sample" + "range" "ratio?" "rational?" "rationalize" "re-find" "re-groups" + "re-matcher" "re-matches" "re-pattern" "re-seq" "read" + "read+string" "read-line" "read-string" "reader-conditional" + "reader-conditional?" "realized?" "record?" "reduce" + "reduce-kv" "reduced" "reduced?" "reductions" "ref" "ref-history-count" + "ref-max-history" "ref-min-history" "ref-set" "refer" + "release-pending-sends" "rem" "remove" "remove-all-methods" + "remove-method" "remove-ns" "remove-tap" "remove-watch" + "repeat" "repeatedly" "replace" "replicate" + "requiring-resolve" "reset!" "reset-meta!" "reset-vals!" + "resolve" "rest" "restart-agent" "resultset-seq" "reverse" + "reversible?" "rseq" "rsubseq" "run!" "satisfies?" + "second" "select-keys" "send" "send-off" "send-via" + "seq" "seq?" "seqable?" "seque" "sequence" "sequential?" + "set" "set-agent-send-executor!" "set-agent-send-off-executor!" + "set-error-handler!" "set-error-mode!" "set-validator!" + "set?" "short" "short-array" "shorts" "shuffle" + "shutdown-agents" "simple-ident?" "simple-keyword?" + "simple-symbol?" "slurp" "some" "some-fn" "some?" + "sort" "sort-by" "sorted-map" "sorted-map-by" + "sorted-set" "sorted-set-by" "sorted?" "special-symbol?" + "spit" "split-at" "split-with" "str" "string?" + "struct" "struct-map" "subs" "subseq" "subvec" "supers" + "swap!" "swap-vals!" "symbol" "symbol?" "tagged-literal" + "tagged-literal?" "take" "take-last" "take-nth" "take-while" + "tap>" "test" "the-ns" "thread-bound?" "to-array" + "to-array-2d" "trampoline" "transduce" "transient" + "tree-seq" "true?" "type" "unchecked-add" "unchecked-add-int" + "unchecked-byte" "unchecked-char" "unchecked-dec" + "unchecked-dec-int" "unchecked-divide-int" "unchecked-double" + "unchecked-float" "unchecked-inc" "unchecked-inc-int" + "unchecked-int" "unchecked-long" "unchecked-multiply" + "unchecked-multiply-int" "unchecked-negate" "unchecked-negate-int" + "unchecked-remainder-int" "unchecked-short" "unchecked-subtract" + "unchecked-subtract-int" "underive" "unquote" + "unquote-splicing" "unreduced" "unsigned-bit-shift-right" + "update" "update-in" "update-proxy" "uri?" "uuid?" + "val" "vals" "var-get" "var-set" "var?" "vary-meta" "vec" + "vector" "vector-of" "vector?" "volatile!" "volatile?" + "vreset!" "with-bindings*" "with-meta" "with-redefs-fn" "xml-seq" + "zero?" "zipmap")) + + + +;; >> Context based highlighting + +; def-likes +; Correctly highlight docstrings +(list_lit + . + (sym_lit) @_keyword ; Don't really want to highlight twice + (#lua-match? @_keyword "^def.*") + . + (sym_lit) + . + ;; TODO: Add @comment highlight + (str_lit)? + . + (_)) + +; Function definitions +(list_lit + . + (sym_lit) @_keyword.function + (#any-of? @_keyword.function "fn" "fn*" "defn" "defn-") + . + (sym_lit)? @function + . + ;; TODO: Add @comment highlight + (str_lit)?) +;; TODO: Fix parameter highlighting +;; I think there's a bug here in nvim-treesitter +;; TODO: Reproduce bug and file ticket + ;. + ;[(vec_lit + ; (sym_lit)* @parameter) + ; (list_lit + ; (vec_lit + ; (sym_lit)* @parameter))]) + +;[((list_lit +; (vec_lit +; (sym_lit) @parameter) +; (_) +; + +; ((vec_lit +; (sym_lit) @parameter) +; (_))) + + +; Meta punctuation +;; NOTE: When the above `Function definitions` query captures the +;; the @function it also captures the child meta_lit +;; We capture the meta_lit symbol (^) after so that the later +;; highlighting overrides the former +"^" @punctuation.special + +;; namespaces +(list_lit + . + (sym_lit) @_include + (#eq? @_include "ns") + . + (sym_lit) @namespace) diff --git a/bundle/nvim-treesitter/queries/clojure/injections.scm b/bundle/nvim-treesitter/queries/clojure/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/clojure/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/clojure/locals.scm b/bundle/nvim-treesitter/queries/clojure/locals.scm new file mode 100644 index 000000000..e47adce45 --- /dev/null +++ b/bundle/nvim-treesitter/queries/clojure/locals.scm @@ -0,0 +1 @@ +; placeholder file to get incremental selection to work diff --git a/bundle/nvim-treesitter/queries/cmake/folds.scm b/bundle/nvim-treesitter/queries/cmake/folds.scm new file mode 100644 index 000000000..ed5cc8d6a --- /dev/null +++ b/bundle/nvim-treesitter/queries/cmake/folds.scm @@ -0,0 +1,7 @@ +[ + (if_condition) + (foreach_loop) + (while_loop) + (function_def) + (macro_def) +] @fold diff --git a/bundle/nvim-treesitter/queries/cmake/highlights.scm b/bundle/nvim-treesitter/queries/cmake/highlights.scm new file mode 100644 index 000000000..18a87c25e --- /dev/null +++ b/bundle/nvim-treesitter/queries/cmake/highlights.scm @@ -0,0 +1,125 @@ +[ + (quoted_argument) + (bracket_argument) +] @string + +(variable_ref) @none +(variable) @variable + +[ + (bracket_comment) + (line_comment) +] @comment + +(normal_command (identifier) @function) + +["ENV" "CACHE"] @symbol +["$" "{" "}" "<" ">"] @punctuation.special +["(" ")"] @punctuation.bracket + +[ + (function) + (endfunction) + (macro) + (endmacro) +] @keyword.function + +[ + (if) + (elseif) + (else) + (endif) +] @conditional + +[ + (foreach) + (endforeach) + (while) + (endwhile) +] @repeat + +(function_command + (function) + . (argument) @function + (argument)* @parameter +) + +(macro_command + (macro) + . (argument) @function.macro + (argument)* @parameter +) + +(normal_command + (identifier) @function.builtin + . (argument) @variable + (#match? @function.builtin "\\c^(set)$") +) + +(normal_command + (identifier) @function.builtin + (#match? @function.builtin "\\c^(set)$") + ( + (argument) @constant + (#any-of? @constant "PARENT_SCOPE") + ) . +) + +(normal_command + (identifier) @function.builtin + (#match? @function.builtin "\\c^(set)$") + . (argument) + ( + (argument) @_cache @constant + . + (argument) @_type @constant + (#any-of? @_cache "CACHE") + (#any-of? @_type "BOOL" "FILEPATH" "PATH" "STRING" "INTERNAL") + ) +) +(normal_command + (identifier) @function.builtin + (#match? @function.builtin "\\c^(set)$") + . (argument) + (argument) @_cache + (#any-of? @_cache "CACHE") + ( + (argument) @_force @constant + (#any-of? @_force "FORCE") + ) . +) + +((argument) @boolean + (#match? @boolean "\\c^(1|on|yes|true|y|0|off|no|false|n|ignore|notfound|.*-notfound)$") +) + +(if_command + (if) + (argument) @keyword.operator + (#any-of? @keyword.operator "NOT" "AND" "OR" + "COMMAND" "POLICY" "TARGET" "TEST" "DEFINED" "IN_LIST" + "EXISTS" "IS_NEWER_THAN" "IS_DIRECTORY" "IS_SYMLINK" "IS_ABSOLUTE" + "MATCHES" + "LESS" "GREATER" "EQUAL" "LESS_EQUAL" "GREATER_EQUAL" + "STRLESS" "STRGREATER" "STREQUAL" "STRLESS_EQUAL" "STRGREATER_EQUAL" + "VERSION_LESS" "VERSION_GREATER" "VERSION_EQUAL" "VERSION_LESS_EQUAL" "VERSION_GREATER_EQUAL" + ) +) + +(normal_command + (identifier) @function.builtin + . (argument) + (argument) @constant + (#any-of? @constant "ALL" "COMMAND" "DEPENDS" "BYPRODUCTS" "WORKING_DIRECTORY" "COMMENT" + "JOB_POOL" "VERBATIM" "USES_TERMINAL" "COMMAND_EXPAND_LISTS" "SOURCES") + (#match? @function.builtin "\\c^(add_custom_target)$") +) + +(normal_command + (identifier) @function.builtin + (argument) @constant + (#any-of? @constant "OUTPUT" "COMMAND" "MAIN_DEPENDENCY" "DEPENDS" "BYPRODUCTS" "IMPLICIT_DEPENDS" "WORKING_DIRECTORY" + "COMMENT" "DEPFILE" "JOB_POOL" "VERBATIM" "APPEND" "USES_TERMINAL" "COMMAND_EXPAND_LISTS") + (#match? @function.builtin "\\c^(add_custom_command)$") +) + diff --git a/bundle/nvim-treesitter/queries/comment/highlights.scm b/bundle/nvim-treesitter/queries/comment/highlights.scm new file mode 100644 index 000000000..6c3e043c8 --- /dev/null +++ b/bundle/nvim-treesitter/queries/comment/highlights.scm @@ -0,0 +1,25 @@ +[ + "(" + ")" +] @punctuation.bracket + +":" @punctuation.delimiter + +(tag (name) @text.note (user)? @constant) + +((tag ((name) @text.warning)) + (#any-of? @text.warning "TODO" "HACK" "WARNING")) + +("text" @text.warning + (#any-of? @text.warning "TODO" "HACK" "WARNING")) + +((tag ((name) @text.danger)) + (#any-of? @text.danger "FIXME" "XXX" "BUG")) + +("text" @text.danger + (#any-of? @text.danger "FIXME" "XXX" "BUG")) + +; Issue number (#123) +("text" @number (#lua-match? @number "^#[0-9]+$")) +; User mention (@user) +("text" @constant (#lua-match? @constant "^[@][a-zA-Z0-9_-]+$")) diff --git a/bundle/nvim-treesitter/queries/commonlisp/folds.scm b/bundle/nvim-treesitter/queries/commonlisp/folds.scm new file mode 100644 index 000000000..d54daade6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/commonlisp/folds.scm @@ -0,0 +1 @@ +(source (list_lit) @fold) diff --git a/bundle/nvim-treesitter/queries/commonlisp/highlights.scm b/bundle/nvim-treesitter/queries/commonlisp/highlights.scm new file mode 100644 index 000000000..5cf7c1eb0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/commonlisp/highlights.scm @@ -0,0 +1,187 @@ +(sym_lit) @variable + +;; A highlighting for functions/macros in th cl namespace is available in theHamsta/nvim-treesitter-commonlisp +;(list_lit . (sym_lit) @function.builtin (#cl-standard-function? @function.builtin)) +;(list_lit . (sym_lit) @function.builtin (#cl-standard-macro? @function.macro)) + +(dis_expr) @comment + +(defun_keyword) @function.macro +(defun_header + function_name: (_) @function) +(defun_header + lambda_list: (list_lit (sym_lit) @parameter)) +(defun_header + keyword: (defun_keyword "defmethod") + lambda_list: (list_lit (list_lit . (sym_lit) . (sym_lit) @symbol))) +(defun_header + lambda_list: (list_lit (list_lit . (sym_lit) @parameter . (_)))) +(defun_header + specifier: (sym_lit) @symbol) + +[":" "::" "."] @punctuation.special + +[ + (accumulation_verb) + (for_clause_word) + "for" + "and" + "finally" + "thereis" + "always" + "when" + "if" + "unless" + "else" + "do" + "loop" + "below" + "in" + "from" + "across" + "repeat" + "being" + "into" + "with" + "as" + "while" + "until" + "return" + "initially" +] @function.macro +"=" @operator + +(include_reader_macro) @symbol +["#C" "#c"] @number + +[(kwd_lit) (self_referential_reader_macro)] @symbol + +(package_lit + package: (_) @namespace) +"cl" @namespace + +(str_lit) @string + +(num_lit) @number + +((sym_lit) @boolean (#match? @boolean "^(t|T)$")) + +(nil_lit) @constant.builtin + +(comment) @comment + +;; dynamic variables +((sym_lit) @variable.builtin + (#match? @variable.builtin "^[*].+[*]$")) + +;; quote +"'" @string.escape +(format_specifier) @string.escape +(quoting_lit) @string.escape + +;; syntax quote +"`" @string.escape +"," @string.escape +",@" @string.escape +(syn_quoting_lit) @string.escape +(unquoting_lit) @none +(unquote_splicing_lit) @none + + +["(" ")"] @punctuation.bracket + +(block_comment) @comment + + +(with_clause + type: (_) @type) +(for_clause + type: (_) @type) + +;; defun-like things +(list_lit + . + (sym_lit) @function.macro + . + (sym_lit) @function + (#eq? @function.macro "deftest")) + +;;; Macros and Special Operators +(list_lit + . + (sym_lit) @function.macro + ;; For a complete and more efficient version install theHamsta/nvim-treesitter-commonlisp + (#any-of? @function.macro + "let" + "function" + "the" + "unwind-protect" + "labels" + "flet" + "tagbody" + "go" + "symbol-macrolet" + "symbol-macrolet" + "progn" + "prog1" + "error" + "or" + "and" + "defvar" + "defparameter" + "in-package" + "defpackage" + "case" + "ecase" + "typecase" + "etypecase" + "defstruct" + "defclass" + "if" + "when" + "unless" + "cond" + "switch" + "declaim" + "optimize")) + +;; constant +((sym_lit) @constant + (#match? @constant "^[+].+[+]$")) + +(var_quoting_lit + marker: "#'" @symbol + value: (_) @symbol) + +["#" "#p" "#P"] @symbol + +(list_lit + . + (sym_lit) @function.builtin + ;; For a complete and more efficient version install theHamsta/nvim-treesitter-commonlisp + (#any-of? @function.builtin + "mapcar" + "reduce" + "remove-if-not" + "cons" + "car" + "last" + "nth" + "equal" + "cdr" + "first" + "rest" + "format")) + +(list_lit + . + (sym_lit) @operator + (#match? @operator "^([+*-+=<>]|<=|>=|/=)$")) + + +((sym_lit) @symbol +(#match? @symbol "^[&]")) + +[(array_dimension) "#0A" "#0a"] @number + +(char_lit) @character diff --git a/bundle/nvim-treesitter/queries/commonlisp/locals.scm b/bundle/nvim-treesitter/queries/commonlisp/locals.scm new file mode 100644 index 000000000..acdf965b7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/commonlisp/locals.scm @@ -0,0 +1,72 @@ + +(defun_header + function_name: (sym_lit) @definition.function (#set! definition.function.scope "parent")) +(defun_header + lambda_list: (list_lit (sym_lit) @definition.parameter)) + +(defun_header + keyword: (defun_keyword "defmethod") + lambda_list: (list_lit (list_lit . (sym_lit) . (sym_lit) @definition.type))) +(defun_header + lambda_list: (list_lit (list_lit . (sym_lit) @definition.parameter . (_)))) + +(sym_lit) @reference + +(defun) @scope + +((list_lit . (sym_lit) @_defvar . (sym_lit) @definition.var) +(#match? @_defvar "^(cl:)?(defvar|defparameter)$")) + +(list_lit + . + (sym_lit) @_deftest + . + (sym_lit) @definition.function + (#match? @_deftest "^(deftest)$")) @scope + +(list_lit + . + (sym_lit) @_deftest + . + (sym_lit) @definition.function + (#match? @_deftest "^(deftest)$")) @scope + +(for_clause . (sym_lit) @definition.var) +(with_clause . (sym_lit) @definition.var) +(loop_macro) @scope + +(list_lit + . + (sym_lit) @_let (#match? @_let "(cl:|cffi:)?(with-accessors|with-foreign-objects|let[*]?)") + . + (list_lit (list_lit . (sym_lit) @definition.var))) @scope + +(list_lit + . + (sym_lit) @_let (#match? @_let "(cl:|alexandria:)?(with-gensyms|dotimes|with-foreign-object)") + . + (list_lit . (sym_lit) @definition.var)) @scope + +(list_lit + . + (kwd_lit) @_import_from (#eq? @_import_from ":import-from") + . + (_) + (kwd_lit (kwd_symbol) @definition.import)) + +(list_lit + . + (kwd_lit) @_import_from (#eq? @_import_from ":import-from") + . + (_) + (sym_lit) @definition.import) + +(list_lit + . + (kwd_lit) @_use (#eq? @_use ":use") + (kwd_lit (kwd_symbol) @definition.import)) + +(list_lit + . + (kwd_lit) @_use (#eq? @_use ":use") + (sym_lit) @definition.import) diff --git a/bundle/nvim-treesitter/queries/cooklang/highlights.scm b/bundle/nvim-treesitter/queries/cooklang/highlights.scm new file mode 100644 index 000000000..4ced465bd --- /dev/null +++ b/bundle/nvim-treesitter/queries/cooklang/highlights.scm @@ -0,0 +1,22 @@ +(metadata) @comment + +(ingredient + "@" @tag + (name)? @text.title + (amount + (quantity)? @number + (units)? @tag.attribute)?) + +(timer + "~" @tag + (name)? @text.title + (amount + (quantity)? @number + (units)? @tag.attribute)?) + +(cookware + "#" @tag + (name)? @text.title + (amount + (quantity)? @number + (units)? @tag.attribute)?) diff --git a/bundle/nvim-treesitter/queries/cpp/folds.scm b/bundle/nvim-treesitter/queries/cpp/folds.scm new file mode 100644 index 000000000..23d623b04 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cpp/folds.scm @@ -0,0 +1,14 @@ +; inherits: c + +[ + (for_range_loop) + (class_specifier) + (field_declaration + type: (enum_specifier) + default_value: (initializer_list)) + (template_declaration) + (namespace_definition) + (try_statement) + (catch_clause) + (lambda_expression) +] @fold diff --git a/bundle/nvim-treesitter/queries/cpp/highlights.scm b/bundle/nvim-treesitter/queries/cpp/highlights.scm new file mode 100644 index 000000000..8dcbaeff5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cpp/highlights.scm @@ -0,0 +1,184 @@ +; inherits: c + +((identifier) @field + (#match? @field "(^_|^m_|_$)")) + +(parameter_declaration + declarator: (reference_declarator) @parameter) +; function(Foo ...foo) +(variadic_parameter_declaration + declarator: (variadic_declarator + (_) @parameter)) +; int foo = 0 +(optional_parameter_declaration + declarator: (_) @parameter) + +;(field_expression) @parameter ;; How to highlight this? +(template_function + name: (identifier) @function) + +(template_method + name: (field_identifier) @method) + +(((field_expression + (field_identifier) @method)) @_parent + (#has-parent? @_parent template_method function_declarator call_expression)) + +(field_initializer + (field_identifier) @property) + +(function_declarator + declarator: (field_identifier) @method) + +(concept_definition + name: (identifier) @type) + +(namespace_identifier) @namespace +((namespace_identifier) @type + (#lua-match? @type "^[A-Z]")) +((namespace_identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) +(case_statement + value: (qualified_identifier (identifier) @constant)) +(namespace_definition + name: (identifier) @namespace) + +(using_declaration . "using" . "namespace" . [(qualified_identifier) (identifier)] @namespace) + +(destructor_name + (identifier) @method) + +(function_declarator + declarator: (qualified_identifier + name: (identifier) @function)) +(function_declarator + declarator: (qualified_identifier + name: (qualified_identifier + name: (identifier) @function))) +((function_declarator + declarator: (qualified_identifier + name: (identifier) @constructor)) + (#lua-match? @constructor "^[A-Z]")) + +(operator_name) @function +"operator" @function +"static_assert" @function.builtin + +(call_expression + function: (qualified_identifier + name: (identifier) @function)) +(call_expression + function: (qualified_identifier + name: (qualified_identifier + name: (identifier) @function))) +(call_expression + function: + (qualified_identifier + name: (qualified_identifier + name: (qualified_identifier + name: (identifier) @function)))) + +(call_expression + function: (field_expression + field: (field_identifier) @function)) + +((call_expression + function: (identifier) @constructor) +(#lua-match? @constructor "^[A-Z]")) +((call_expression + function: (qualified_identifier + name: (identifier) @constructor)) +(#lua-match? @constructor "^[A-Z]")) + +((call_expression + function: (field_expression + field: (field_identifier) @constructor)) +(#lua-match? @constructor "^[A-Z]")) + +;; constructing a type in an initializer list: Constructor (): **SuperType (1)** +((field_initializer + (field_identifier) @constructor + (argument_list)) + (#lua-match? @constructor "^[A-Z]")) + + +; Constants + +(this) @variable.builtin +(nullptr) @constant + +(true) @boolean +(false) @boolean + +; Literals + +(raw_string_literal) @string + +; Keywords + +[ + "try" + "catch" + "noexcept" + "throw" +] @exception + + +[ + "class" + "decltype" + "constexpr" + "explicit" + "final" + "friend" + "mutable" + "namespace" + "override" + "private" + "protected" + "public" + "template" + "typename" + "using" + "virtual" + "co_await" + "concept" + "requires" + "consteval" + "constinit" + (auto) +] @keyword + +[ + "co_yield" + "co_return" +] @keyword.return + +[ + "new" + "delete" + + ;; these keywords are not supported by the parser + ;"eq" + ;"not_eq" + ; + ;"compl" + ;"and" + ;"or" + ; + ;"bitand" + ;"bitand_eq" + ;"bitor" + ;"bitor_eq" + ;"xor" + ;"xor_eq" +] @keyword.operator + +[ + "<=>" + "::" +] @operator + +(attribute_declaration) @attribute + +(literal_suffix) @operator diff --git a/bundle/nvim-treesitter/queries/cpp/indents.scm b/bundle/nvim-treesitter/queries/cpp/indents.scm new file mode 100644 index 000000000..f1007dd28 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cpp/indents.scm @@ -0,0 +1,10 @@ +; inherits: c + +[ + (class_specifier) + (condition_clause) +] @indent + +((field_initializer_list) @indent + (#set! "start_at_same_line" 1)) +(access_specifier) @branch diff --git a/bundle/nvim-treesitter/queries/cpp/injections.scm b/bundle/nvim-treesitter/queries/cpp/injections.scm new file mode 100644 index 000000000..13842120d --- /dev/null +++ b/bundle/nvim-treesitter/queries/cpp/injections.scm @@ -0,0 +1,3 @@ +(preproc_arg) @cpp + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/cpp/locals.scm b/bundle/nvim-treesitter/queries/cpp/locals.scm new file mode 100644 index 000000000..c48a7cc39 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cpp/locals.scm @@ -0,0 +1,71 @@ +; inherits: c + +;; Parameters +(variadic_parameter_declaration + declarator: (variadic_declarator + (identifier) @definition.parameter)) +(optional_parameter_declaration + declarator: (identifier) @definition.parameter) +;; Class / struct definitions +(class_specifier) @scope + +(reference_declarator + (identifier) @definition.var) + +(variadic_declarator + (identifier) @definition.var) + +(struct_specifier + name: (qualified_identifier + name: (type_identifier) @definition.type)) + +(class_specifier + name: (type_identifier) @definition.type) + +(concept_definition + name: (identifier) @definition.type) + +(class_specifier + name: (qualified_identifier + name: (type_identifier) @definition.type)) + +(alias_declaration + name: (type_identifier) @definition.type) + +;template +(type_parameter_declaration + (type_identifier) @definition.type) +(template_declaration) @scope + +;; Namespaces +(namespace_definition + name: (identifier) @definition.namespace + body: (_) @scope) + +((namespace_identifier) @reference + (set! reference.kind "namespace")) + +;; Function definitions +(template_function + name: (identifier) @definition.function) @scope + +(template_method + name: (field_identifier) @definition.method) @scope + +(function_declarator + declarator: (qualified_identifier + name: (identifier) @definition.function)) @scope + +(field_declaration + declarator: (function_declarator + (field_identifier) @definition.method)) + +(lambda_expression) @scope + +;; Control structures +(try_statement + body: (_) @scope) + +(catch_clause) @scope + +(requires_expression) @scope diff --git a/bundle/nvim-treesitter/queries/css/folds.scm b/bundle/nvim-treesitter/queries/css/folds.scm new file mode 100644 index 000000000..9d2995c48 --- /dev/null +++ b/bundle/nvim-treesitter/queries/css/folds.scm @@ -0,0 +1,3 @@ +[ + (rule_set) +] @fold diff --git a/bundle/nvim-treesitter/queries/css/highlights.scm b/bundle/nvim-treesitter/queries/css/highlights.scm new file mode 100644 index 000000000..d8439d678 --- /dev/null +++ b/bundle/nvim-treesitter/queries/css/highlights.scm @@ -0,0 +1,90 @@ +[ + "@media" + "@import" + "@charset" + "@namespace" + "@supports" + "@keyframes" + (at_keyword) + (to) + (from) + (important) + ] @keyword + +(comment) @comment + +[ + (tag_name) + (nesting_selector) + (universal_selector) + ] @type + +(function_name) @function + +[ + "~" + ">" + "+" + "-" + "*" + "/" + "=" + "^=" + "|=" + "~=" + "$=" + "*=" + "and" + "or" + "not" + "only" + ] @operator + + +(attribute_selector (plain_value) @string) +(pseudo_element_selector (tag_name) @property) +(pseudo_class_selector (class_name) @property) + +[ + (class_name) + (id_name) + (namespace_name) + (property_name) + (feature_name) + (attribute_name) + ] @property + + +((property_name) @type + (#match? @type "^--")) +((plain_value) @type + (#match? @type "^--")) + +[ + (string_value) + (color_value) + (unit) + ] @string + +[ + (integer_value) + (float_value) + ] @number + +[ + "#" + "," + "." + ":" + "::" + ";" + ] @punctuation.delimiter + +[ + "{" + ")" + "(" + "}" + ] @punctuation.bracket + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/css/indents.scm b/bundle/nvim-treesitter/queries/css/indents.scm new file mode 100644 index 000000000..1ea8a336f --- /dev/null +++ b/bundle/nvim-treesitter/queries/css/indents.scm @@ -0,0 +1,9 @@ +[ + (block) + (declaration) +] @indent + +(block ("}") @branch) +("}") @dedent + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/css/injections.scm b/bundle/nvim-treesitter/queries/css/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/css/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/cuda/folds.scm b/bundle/nvim-treesitter/queries/cuda/folds.scm new file mode 100644 index 000000000..b617fdc56 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cuda/folds.scm @@ -0,0 +1 @@ +; inherits: cpp diff --git a/bundle/nvim-treesitter/queries/cuda/highlights.scm b/bundle/nvim-treesitter/queries/cuda/highlights.scm new file mode 100644 index 000000000..404c72afb --- /dev/null +++ b/bundle/nvim-treesitter/queries/cuda/highlights.scm @@ -0,0 +1,14 @@ +; inherits: cpp + +[ "<<<" ">>>" ] @punctuation.bracket + +[ + "__local__" + "__shared__" + "__global__" + "__host__" + "__device__" + "__forceinline__" + "__restrict__" + "__launch_bounds__" +] @keyword diff --git a/bundle/nvim-treesitter/queries/cuda/indents.scm b/bundle/nvim-treesitter/queries/cuda/indents.scm new file mode 100644 index 000000000..b617fdc56 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cuda/indents.scm @@ -0,0 +1 @@ +; inherits: cpp diff --git a/bundle/nvim-treesitter/queries/cuda/injections.scm b/bundle/nvim-treesitter/queries/cuda/injections.scm new file mode 100644 index 000000000..49fe7c532 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cuda/injections.scm @@ -0,0 +1,3 @@ +(preproc_arg) @cuda + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/cuda/locals.scm b/bundle/nvim-treesitter/queries/cuda/locals.scm new file mode 100644 index 000000000..b617fdc56 --- /dev/null +++ b/bundle/nvim-treesitter/queries/cuda/locals.scm @@ -0,0 +1 @@ +; inherits: cpp diff --git a/bundle/nvim-treesitter/queries/d/folds.scm b/bundle/nvim-treesitter/queries/d/folds.scm new file mode 100644 index 000000000..be4dee45e --- /dev/null +++ b/bundle/nvim-treesitter/queries/d/folds.scm @@ -0,0 +1 @@ +(block_statement) @fold diff --git a/bundle/nvim-treesitter/queries/d/highlights.scm b/bundle/nvim-treesitter/queries/d/highlights.scm new file mode 100644 index 000000000..9a0887f3a --- /dev/null +++ b/bundle/nvim-treesitter/queries/d/highlights.scm @@ -0,0 +1,267 @@ +;; Misc + +[ + (line_comment) + (block_comment) + (nesting_block_comment) +] @comment + +[ + "(" ")" + "[" "]" + "{" "}" +] @punctuation.bracket + +[ + "," + ";" + "." + ":" +] @punctuation.delimiter + +[ + ".." + "$" +] @punctuation.special + +;; Constants + +[ + "__FILE_FULL_PATH__" + "__FILE__" + "__FUNCTION__" + "__LINE__" + "__MODULE__" + "__PRETTY_FUNCTION__" +] @constant.macro + +[ + (wysiwyg_string) + (alternate_wysiwyg_string) + (double_quoted_string) + (hex_string) + (delimited_string) + (token_string) +] @string + +(character_literal) @character + +(integer_literal) @number + +(float_literal) @float + +[ + "true" + "false" +] @boolean + +;; Functions + +(func_declarator + (identifier) @function +) + +[ + "__traits" + "__vector" + "assert" + "is" + "mixin" + "pragma" + "typeid" +] @function.builtin + +(import_expression + "import" @function.builtin +) + +(parameter + (var_declarator + (identifier) @parameter + ) +) + +(function_literal + (identifier) @parameter +) + +(constructor + "this" @constructor +) + +(destructor + "this" @constructor +) + +;; Keywords + +[ + "case" + "default" + "else" + "if" + "switch" +] @conditional + +[ + "break" + "continue" + "do" + "for" + "foreach" + "foreach_reverse" + "while" +] @repeat + +[ + "__gshared" + "__parameters" + "abstract" + "alias" + "align" + "asm" + "auto" + "body" + "class" + "const" + "debug" + "deprecated" + "enum" + "export" + "extern" + "final" + "goto" + "immutable" + "inout" + "interface" + "invariant" + "lazy" + "macro" + "nothrow" + "null" + "out" + "override" + "package" + "private" + "protected" + "public" + "pure" + "ref" + "scope" + "shared" + "static" + "struct" + "synchronized" + "template" + "union" + "unittest" + "version" + "with" +] @keyword + +[ + "delegate" + "function" +] @keyword.function + +"return" @keyword.return + +[ + "cast" + "new" +] @keyword.operator + +[ + "+" + "++" + "+=" + "-" + "--" + "-=" + "*" + "*=" + "%" + "%=" + "^" + "^=" + "^^" + "^^=" + "/" + "/=" + "|" + "|=" + "||" + "~" + "~=" + "=" + "==" + "=>" + "<" + "<=" + "<<" + "<<=" + ">" + ">=" + ">>" + ">>=" + ">>>" + ">>>=" + "!" + "!=" + "&" + "&&" +] @operator + +[ + "catch" + "finally" + "throw" + "try" +] @exception + +(module_declaration + "module" @include +) + +(import_declaration + "import" @include +) + +(type) @type + +(catch_parameter + (qualified_identifier) @type +) + +(var_declarations + (qualified_identifier) @type +) + +(func_declaration + (qualified_identifier) @type +) + +(parameter + (qualified_identifier) @type +) + +(class_declaration + (identifier) @type +) + +(fundamental_type) @type.builtin + +(module_fully_qualified_name (packages (package_name) @namespace)) +(module_name) @namespace + +(at_attribute) @attribute + +(user_defined_attribute + "@" @attribute +) + +;; Variables + +(primary_expression + "this" @variable.builtin +) diff --git a/bundle/nvim-treesitter/queries/d/indents.scm b/bundle/nvim-treesitter/queries/d/indents.scm new file mode 100644 index 000000000..7a6df759c --- /dev/null +++ b/bundle/nvim-treesitter/queries/d/indents.scm @@ -0,0 +1,17 @@ +[ + (block_statement) + (case_statement) + (token_string) +] @indent + +[ + "(" ")" + "{" "}" + "[" "]" +] @branch + +[ + (line_comment) + (block_comment) + (nesting_block_comment) +] @ignore diff --git a/bundle/nvim-treesitter/queries/d/injections.scm b/bundle/nvim-treesitter/queries/d/injections.scm new file mode 100644 index 000000000..d95514370 --- /dev/null +++ b/bundle/nvim-treesitter/queries/d/injections.scm @@ -0,0 +1,7 @@ +[ + (line_comment) + (block_comment) + (nesting_block_comment) +] @comment + +(token_string_tokens) @d diff --git a/bundle/nvim-treesitter/queries/dart/highlights.scm b/bundle/nvim-treesitter/queries/dart/highlights.scm new file mode 100644 index 000000000..9974d4095 --- /dev/null +++ b/bundle/nvim-treesitter/queries/dart/highlights.scm @@ -0,0 +1,259 @@ +(dotted_identifier_list) @string + +; Methods +; -------------------- +(super) @function + +; TODO: add method/call_expression to grammar and +; distinguish method call from variable access +(function_expression_body (identifier) @function) +; ((identifier)(selector (argument_part)) @function) + +; NOTE: This query is a bit of a work around for the fact that the dart grammar doesn't +; specifically identify a node as a function call +(((identifier) @function (#match? @function "^_?[a-z]")) + . (selector . (argument_part))) @function + +; Annotations +; -------------------- +(annotation + name: (identifier) @attribute) +(marker_annotation + name: (identifier) @attribute) + +; Operators and Tokens +; -------------------- +(template_substitution + "$" @punctuation.special + "{" @punctuation.special + "}" @punctuation.special +) @none + +(template_substitution + "$" @punctuation.special + (identifier_dollar_escaped) @variable +) @none + +(escape_sequence) @string.escape + +[ + "@" + "=>" + ".." + "??" + "==" + "?" + ":" + "&&" + "%" + "<" + ">" + "=" + ">=" + "<=" + "||" + (multiplicative_operator) + (increment_operator) + (is_operator) + (prefix_operator) + (equality_operator) + (additive_operator) +] @operator + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; Delimiters +; -------------------- +[ + ";" + "." + "," +] @punctuation.delimiter + +; Types +; -------------------- +(class_definition + name: (identifier) @type) +(constructor_signature + name: (identifier) @type) +(scoped_identifier + scope: (identifier) @type) +(function_signature + name: (identifier) @method) +(getter_signature + (identifier) @method) +(setter_signature + name: (identifier) @method) +(enum_declaration + name: (identifier) @type) +(enum_constant + name: (identifier) @type) +(void_type) @type + +((scoped_identifier + scope: (identifier) @type + name: (identifier) @type) + (#match? @type "^[a-zA-Z]")) + +(type_identifier) @type + +; Variables +; -------------------- +; var keyword +(inferred_type) @keyword + +(const_builtin) @constant.builtin +(final_builtin) @constant.builtin + +((identifier) @type + (#match? @type "^_?[A-Z].*[a-z]")) ; catch Classes or IClasses not CLASSES + +("Function" @type) + +; properties +(unconditional_assignable_selector + (identifier) @property) + +(conditional_assignable_selector + (identifier) @property) + +; assignments +(assignment_expression + left: (assignable_expression) @variable) + +(this) @variable.builtin + +; Parameters +; -------------------- +(formal_parameter + name: (identifier) @parameter) + +(named_argument + (label (identifier) @parameter)) + +; Literals +; -------------------- +[ + (hex_integer_literal) + (decimal_integer_literal) + (decimal_floating_point_literal) + ; TODO: inaccessbile nodes + ; (octal_integer_literal) + ; (hex_floating_point_literal) +] @number + +(symbol_literal) @symbol +(string_literal) @string +(true) @boolean +(false) @boolean +(null_literal) @constant.builtin + +(documentation_comment) @comment +(comment) @comment + +; Keywords +; -------------------- +["import" "library" "export"] @include + +; Reserved words (cannot be used as identifiers) +[ + ; TODO: + ; "rethrow" cannot be targeted at all and seems to be an invisible node + ; TODO: + ; the assert keyword cannot be specifically targeted + ; because the grammar selects the whole node or the content + ; of the assertion not just the keyword + ; assert + (case_builtin) + "late" + "required" + "extension" + "on" + "class" + "enum" + "extends" + "in" + "is" + "new" + "super" + "with" +] @keyword + +[ + "return" + "yield" +] @keyword.return + + +; Built in identifiers: +; alone these are marked as keywords +[ + "abstract" + "as" + "async" + "async*" + "sync*" + "await" + "covariant" + "deferred" + "dynamic" + "external" + "factory" + "get" + "implements" + "interface" + "library" + "operator" + "mixin" + "part" + "set" + "show" + "static" + "typedef" +] @keyword + +; when used as an identifier: +((identifier) @variable.builtin + (#any-of? @variable.builtin + "abstract" + "as" + "covariant" + "deferred" + "dynamic" + "export" + "external" + "factory" + "Function" + "get" + "implements" + "import" + "interface" + "library" + "operator" + "mixin" + "part" + "set" + "static" + "typedef")) + +["if" "else" "switch" "default"] @conditional + +[ + "try" + "throw" + "catch" + "finally" + (break_statement) +] @exception + +["do" "while" "continue" "for"] @repeat + +; Error +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/dart/indents.scm b/bundle/nvim-treesitter/queries/dart/indents.scm new file mode 100644 index 000000000..e01cc238d --- /dev/null +++ b/bundle/nvim-treesitter/queries/dart/indents.scm @@ -0,0 +1,27 @@ +[ + (class_body) + (function_body) + (function_expression_body) + (declaration (initializers)) + (switch_block) + (if_statement) + (formal_parameter_list) + (formal_parameter) + (list_literal) + (return_statement) + (arguments) +] @indent + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @branch + +; this one is for dedenting the else block +(if_statement (block) @branch) + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/dart/injections.scm b/bundle/nvim-treesitter/queries/dart/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/dart/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/dart/locals.scm b/bundle/nvim-treesitter/queries/dart/locals.scm new file mode 100644 index 000000000..1013d4a92 --- /dev/null +++ b/bundle/nvim-treesitter/queries/dart/locals.scm @@ -0,0 +1,8 @@ +(class_definition + body: (_) @scope) + + (block) @scope + + (try_statement) @scope + (catch_clause) @scope + (finally_clause) @scope diff --git a/bundle/nvim-treesitter/queries/devicetree/folds.scm b/bundle/nvim-treesitter/queries/devicetree/folds.scm new file mode 100644 index 000000000..206c4bed8 --- /dev/null +++ b/bundle/nvim-treesitter/queries/devicetree/folds.scm @@ -0,0 +1 @@ +(node) @fold diff --git a/bundle/nvim-treesitter/queries/devicetree/highlights.scm b/bundle/nvim-treesitter/queries/devicetree/highlights.scm new file mode 100644 index 000000000..e3140a5da --- /dev/null +++ b/bundle/nvim-treesitter/queries/devicetree/highlights.scm @@ -0,0 +1,35 @@ +(comment) @comment + +[ + (preproc_include) + (dtsi_include) +] @include + +(preproc_def) @constant.macro +(preproc_function_def) @function.macro + +[ + (memory_reservation) + (file_version) +] @attribute + +[ + (string_literal) + (byte_string_literal) + (system_lib_string) +] @string + +(integer_literal) @number + +(identifier) @variable +(node (identifier) @namespace) +(property (identifier) @property) +(labeled_item (identifier) @label) +(call_expression (identifier) @function.macro) + +(reference) @label ; referencing labeled_item.identifier +(unit_address) @constant + +[ "=" ] @operator +[ "(" ")" "[" "]" "{" "}" "<" ">" ] @punctuation.bracket +[ ";" ":" "," "@" ] @punctuation.delimiter diff --git a/bundle/nvim-treesitter/queries/devicetree/indents.scm b/bundle/nvim-treesitter/queries/devicetree/indents.scm new file mode 100644 index 000000000..cd7c8fcd6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/devicetree/indents.scm @@ -0,0 +1,14 @@ +[ + (node) + (property) + (integer_cells) +] @indent + +[ + "}" + ">" +] @branch + +[ + (comment) +] @ignore diff --git a/bundle/nvim-treesitter/queries/devicetree/injections.scm b/bundle/nvim-treesitter/queries/devicetree/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/devicetree/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/devicetree/locals.scm b/bundle/nvim-treesitter/queries/devicetree/locals.scm new file mode 100644 index 000000000..95b124bd1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/devicetree/locals.scm @@ -0,0 +1,4 @@ +[ + (node) + (integer_cells) +]@scope diff --git a/bundle/nvim-treesitter/queries/dockerfile/highlights.scm b/bundle/nvim-treesitter/queries/dockerfile/highlights.scm new file mode 100644 index 000000000..af1c088c5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/dockerfile/highlights.scm @@ -0,0 +1,50 @@ +[ + "FROM" + "AS" + "RUN" + "CMD" + "LABEL" + "EXPOSE" + "ENV" + "ADD" + "COPY" + "ENTRYPOINT" + "VOLUME" + "USER" + "WORKDIR" + "ARG" + "ONBUILD" + "STOPSIGNAL" + "HEALTHCHECK" + "SHELL" + "MAINTAINER" + "CROSS_BUILD" +] @keyword + +[ + ":" + "@" +] @operator + +(comment) @comment + +(image_spec + (image_tag + ":" @punctuation.special) + (image_digest + "@" @punctuation.special)) + +(double_quoted_string) @string + +(expansion + [ + "$" + "{" + "}" + ] @punctuation.special +) + +((variable) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + + diff --git a/bundle/nvim-treesitter/queries/dockerfile/injections.scm b/bundle/nvim-treesitter/queries/dockerfile/injections.scm new file mode 100644 index 000000000..c1fdd3f99 --- /dev/null +++ b/bundle/nvim-treesitter/queries/dockerfile/injections.scm @@ -0,0 +1,3 @@ +(comment) @comment + +(shell_command) @bash diff --git a/bundle/nvim-treesitter/queries/dot/highlights.scm b/bundle/nvim-treesitter/queries/dot/highlights.scm new file mode 100644 index 000000000..86bb9b303 --- /dev/null +++ b/bundle/nvim-treesitter/queries/dot/highlights.scm @@ -0,0 +1,45 @@ +(identifier) @type +(keyword) @keyword +(string_literal) @string +(number_literal) @number + +[ + (edgeop) + (operator) +] @operator + +[ + "," + ";" +] @punctuation.delimiter + +[ + "{" + "}" + "[" + "]" + "<" + ">" +] @punctuation.bracket + +(subgraph + id: (id + (identifier) @namespace) +) + +(attribute + name: (id + (identifier) @field) +) + +(attribute + value: (id + (identifier) @constant) +) + +[ +(comment) +(preproc) +] @comment + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/dot/injections.scm b/bundle/nvim-treesitter/queries/dot/injections.scm new file mode 100644 index 000000000..529d04d4a --- /dev/null +++ b/bundle/nvim-treesitter/queries/dot/injections.scm @@ -0,0 +1,2 @@ +(html_internal) @html +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/ecma/folds.scm b/bundle/nvim-treesitter/queries/ecma/folds.scm new file mode 100644 index 000000000..960b247d3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ecma/folds.scm @@ -0,0 +1,21 @@ +[ + (for_in_statement) + (for_statement) + (while_statement) + (arrow_function) + (function) + (function_declaration) + (class_declaration) + (method_definition) + (do_statement) + (with_statement) + (switch_statement) + (switch_case) + (import_statement) + (if_statement) + (try_statement) + (catch_clause) + (object) + (generator_function) + (generator_function_declaration) +] @fold diff --git a/bundle/nvim-treesitter/queries/ecma/highlights.scm b/bundle/nvim-treesitter/queries/ecma/highlights.scm new file mode 100644 index 000000000..7334bd1e6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ecma/highlights.scm @@ -0,0 +1,255 @@ +; Types + +; Javascript + +; Variables +;----------- +(identifier) @variable + +; Properties +;----------- + +(property_identifier) @property +(shorthand_property_identifier) @property +(private_property_identifier) @property + +(variable_declarator + name: (object_pattern + (shorthand_property_identifier_pattern))) @variable + +; Special identifiers +;-------------------- + +((identifier) @constructor + (#lua-match? @constructor "^[A-Z]")) + +((identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z%d_]+$")) + +((shorthand_property_identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z%d_]+$")) + +((identifier) @variable.builtin + (#vim-match? @variable.builtin "^(arguments|module|console|window|document)$")) + +((identifier) @function.builtin + (#eq? @function.builtin "require")) + +; Function and method definitions +;-------------------------------- + +(function + name: (identifier) @function) +(function_declaration + name: (identifier) @function) +(generator_function + name: (identifier) @function) +(generator_function_declaration + name: (identifier) @function) +(method_definition + name: [(property_identifier) (private_property_identifier)] @method) + +(pair + key: (property_identifier) @method + value: (function)) +(pair + key: (property_identifier) @method + value: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @method) + right: (arrow_function)) +(assignment_expression + left: (member_expression + property: (property_identifier) @method) + right: (function)) + +(variable_declarator + name: (identifier) @function + value: (arrow_function)) +(variable_declarator + name: (identifier) @function + value: (function)) + +(assignment_expression + left: (identifier) @function + right: (arrow_function)) +(assignment_expression + left: (identifier) @function + right: (function)) + +; Function and method calls +;-------------------------- + +(call_expression + function: (identifier) @function) + +(call_expression + function: (member_expression + property: [(property_identifier) (private_property_identifier)] @method)) + +; Variables +;---------- +(namespace_import + (identifier) @namespace) + +; Literals +;--------- + +(this) @variable.builtin +(super) @variable.builtin + +(true) @boolean +(false) @boolean +(null) @constant.builtin +[ +(comment) +(hash_bang_line) +] @comment +(string) @string +(regex) @punctuation.delimiter +(regex_pattern) @string.regex +(template_string) @string +(escape_sequence) @string.escape +(number) @number + +; Punctuation +;------------ + +"..." @punctuation.special + +";" @punctuation.delimiter +"." @punctuation.delimiter +"," @punctuation.delimiter +"?." @punctuation.delimiter + +(pair ":" @punctuation.delimiter) + +[ + "--" + "-" + "-=" + "&&" + "+" + "++" + "+=" + "&=" + "/=" + "**=" + "<<=" + "<" + "<=" + "<<" + "=" + "==" + "===" + "!=" + "!==" + "=>" + ">" + ">=" + ">>" + "||" + "%" + "%=" + "*" + "**" + ">>>" + "&" + "|" + "^" + "??" + "*=" + ">>=" + ">>>=" + "^=" + "|=" + "&&=" + "||=" + "??=" +] @operator + +(binary_expression "/" @operator) +(ternary_expression ["?" ":"] @conditional) +(unary_expression ["!" "~" "-" "+" "delete" "void" "typeof"] @operator) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +((template_substitution ["${" "}"] @punctuation.special) @none) + +; Keywords +;---------- + +[ +"if" +"else" +"switch" +"case" +"default" +] @conditional + +[ +"import" +"from" +"as" +] @include + +[ +"for" +"of" +"do" +"while" +"continue" +] @repeat + +[ +"async" +"await" +"break" +"class" +"const" +"debugger" +"export" +"extends" +"get" +"in" +"instanceof" +"let" +"set" +"static" +"switch" +"target" +"typeof" +"var" +"void" +"with" +] @keyword + +[ +"return" +"yield" +] @keyword.return + +[ + "function" +] @keyword.function + +[ + "new" + "delete" +] @keyword.operator + +[ + "throw" + "try" + "catch" + "finally" +] @exception diff --git a/bundle/nvim-treesitter/queries/ecma/indents.scm b/bundle/nvim-treesitter/queries/ecma/indents.scm new file mode 100644 index 000000000..55cae9b19 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ecma/indents.scm @@ -0,0 +1,53 @@ +[ + (arguments) + (array) + (binary_expression) + (class_body) + (export_clause) + (formal_parameters) + (named_imports) + (object) + (object_pattern) + (parenthesized_expression) + (return_statement) + (statement_block) + (switch_case) + (switch_statement) + (template_substitution) + (ternary_expression) +] @indent + +(arguments (call_expression) @indent) +(binary_expression (call_expression) @indent) +(expression_statement (call_expression) @indent) +(arrow_function + body: (_) @_body + (#not-has-type? @_body statement_block) +) @indent +(assignment_expression + right: (_) @_right + (#not-has-type? @_right arrow_function function) +) @indent +(variable_declarator + value: (_) @_value + (#not-has-type? @_value arrow_function call_expression function) +) @indent + +(arguments ")" @indent_end) +(object "}" @indent_end) +(statement_block "}" @indent_end) + +[ + (arguments (object)) + ")" + "}" + "]" +] @branch +(statement_block "{" @branch) + +[ + (comment) + (template_string) +] @ignore + +(ERROR) @auto diff --git a/bundle/nvim-treesitter/queries/ecma/injections.scm b/bundle/nvim-treesitter/queries/ecma/injections.scm new file mode 100644 index 000000000..f97f9cd2c --- /dev/null +++ b/bundle/nvim-treesitter/queries/ecma/injections.scm @@ -0,0 +1,58 @@ +(comment) @jsdoc +(comment) @comment + +(call_expression + function: ((identifier) @language) + arguments: ((template_string) @content + (#offset! @content 0 1 0 -1))) + +(call_expression + function: ((identifier) @_name + (#eq? @_name "gql")) + arguments: ((template_string) @graphql + (#offset! @graphql 0 1 0 -1))) + +(call_expression + function: ((identifier) @_name + (#eq? @_name "hbs")) + arguments: ((template_string) @glimmer + (#offset! @glimmer 0 1 0 -1))) + +; styled.div`` +(call_expression + function: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @css + (#offset! @css 0 1 0 -1))) + +; styled(Component)`` +(call_expression + function: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @css + (#offset! @css 0 1 0 -1))) + +; styled.div.attrs({ prop: "foo" })`` +(call_expression + function: (call_expression + function: (member_expression + object: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @css + (#offset! @css 0 1 0 -1))) + + +; styled(Component).attrs({ prop: "foo" })`` +(call_expression + function: (call_expression + function: (member_expression + object: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @css + (#offset! @css 0 1 0 -1))) + +(regex_pattern) @regex diff --git a/bundle/nvim-treesitter/queries/ecma/locals.scm b/bundle/nvim-treesitter/queries/ecma/locals.scm new file mode 100644 index 000000000..08c9b8e7d --- /dev/null +++ b/bundle/nvim-treesitter/queries/ecma/locals.scm @@ -0,0 +1,33 @@ +; Scopes +;------- + +(statement_block) @scope +(function) @scope +(arrow_function) @scope +(function_declaration) @scope +(method_definition) @scope +(for_statement) @scope +(for_in_statement) @scope +(catch_clause) @scope + +; Definitions +;------------ + +(variable_declarator + name: (identifier) @definition.var) + +(import_specifier + (identifier) @definition.import) + +(namespace_import + (identifier) @definition.import) + +(function_declaration + ((identifier) @definition.var) + (#set! definition.var.scope parent)) + +; References +;------------ + +(identifier) @reference +(shorthand_property_identifier) @reference diff --git a/bundle/nvim-treesitter/queries/eex/highlights.scm b/bundle/nvim-treesitter/queries/eex/highlights.scm new file mode 100644 index 000000000..781b39466 --- /dev/null +++ b/bundle/nvim-treesitter/queries/eex/highlights.scm @@ -0,0 +1,15 @@ +[ + "%>" + "--%>" + "<%!--" + "<%" + "<%#" + "<%%=" + "<%=" +] @tag.delimiter + +; EEx comments are highlighted as such +(comment) @comment + +; Tree-sitter parser errors +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/eex/injections.scm b/bundle/nvim-treesitter/queries/eex/injections.scm new file mode 100644 index 000000000..f43206f55 --- /dev/null +++ b/bundle/nvim-treesitter/queries/eex/injections.scm @@ -0,0 +1,5 @@ +; EEx expressions are Elixir +(expression) @elixir + +; EEx expressions can span multiple interpolated lines +(partial_expression) @elixir @combined diff --git a/bundle/nvim-treesitter/queries/elixir/folds.scm b/bundle/nvim-treesitter/queries/elixir/folds.scm new file mode 100644 index 000000000..b99a6d9e0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/elixir/folds.scm @@ -0,0 +1,9 @@ +[ + (anonymous_function) + (arguments) + (block) + (do_block) + (list) + (map) + (tuple) +] @fold diff --git a/bundle/nvim-treesitter/queries/elixir/highlights.scm b/bundle/nvim-treesitter/queries/elixir/highlights.scm new file mode 100644 index 000000000..db9bfbb2d --- /dev/null +++ b/bundle/nvim-treesitter/queries/elixir/highlights.scm @@ -0,0 +1,225 @@ +; Punctuation +[ + "," + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "<<" + ">>" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "%" +] @punctuation.special + +; Parser Errors +(ERROR) @error + +; Identifiers +(identifier) @variable + +; Unused Identifiers +((identifier) @comment (#match? @comment "^_")) + +; Comments +(comment) @comment + +; Strings +(string) @string + +; Modules +(alias) @type + +; Atoms & Keywords +[ + (atom) + (quoted_atom) + (keyword) + (quoted_keyword) +] @symbol + +; Interpolation +(interpolation "#{" @string.escape "}" @string.escape) + +; Escape sequences +(escape_sequence) @string.escape + +; Integers +(integer) @number + +; Floats +(float) @float + +; Characters +[ + (char) + (charlist) +] @character + +; Booleans +(boolean) @boolean + +; Nil +(nil) @constant.builtin + +; Operators +(operator_identifier) @operator + +(unary_operator operator: _ @operator) + +(binary_operator operator: _ @operator) + +; Pipe Operator +(binary_operator operator: "|>" right: (identifier) @function) + +(dot operator: _ @operator) + +(stab_clause operator: _ @operator) + +; Local Function Calls +(call target: (identifier) @function) + +; Remote Function Calls +(call target: (dot left: [ + (atom) @type + (_) +] right: (identifier) @function) (arguments)) + +; Definition Function Calls +(call target: ((identifier) @keyword.function (#any-of? @keyword.function + "def" + "defdelegate" + "defexception" + "defguard" + "defguardp" + "defimpl" + "defmacro" + "defmacrop" + "defmodule" + "defn" + "defnp" + "defoverridable" + "defp" + "defprotocol" + "defstruct" +)) (arguments [ + (identifier) @function + (binary_operator left: (identifier) @function operator: "when")])?) + +; Kernel Keywords & Special Forms +(call target: ((identifier) @keyword (#any-of? @keyword + "alias" + "case" + "catch" + "cond" + "else" + "for" + "if" + "import" + "quote" + "raise" + "receive" + "require" + "reraise" + "super" + "throw" + "try" + "unless" + "unquote" + "unquote_splicing" + "use" + "with" +))) + +; Special Constants +((identifier) @constant.builtin (#any-of? @constant.builtin + "__CALLER__" + "__DIR__" + "__ENV__" + "__MODULE__" + "__STACKTRACE__" +)) + +; Reserved Keywords +[ + "after" + "catch" + "do" + "end" + "fn" + "rescue" + "when" + "else" +] @keyword + +; Operator Keywords +[ + "and" + "in" + "not in" + "not" + "or" +] @keyword.operator + +; Capture Operator +(unary_operator + operator: "&" + operand: [ + (integer) @operator + (binary_operator + left: [ + (call target: (dot left: (_) right: (identifier) @function)) + (identifier) @function + ] operator: "/" right: (integer) @operator) + ]) + +; Non-String Sigils +(sigil + "~" @string.special + ((sigil_name) @string.special) @_sigil_name + quoted_start: _ @string.special + quoted_end: _ @string.special + ((sigil_modifiers) @string.special)? + (#not-any-of? @_sigil_name "s" "S")) + +; String Sigils +(sigil + "~" @string + ((sigil_name) @string) @_sigil_name + quoted_start: _ @string + (quoted_content) @string + quoted_end: _ @string + ((sigil_modifiers) @string)? + (#any-of? @_sigil_name "s" "S")) + +; Module attributes +(unary_operator + operator: "@" + operand: [ + (identifier) + (call target: (identifier)) + ] @constant) @constant + +; Documentation +(unary_operator + operator: "@" + operand: (call + target: ((identifier) @_identifier (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc")) @comment + (arguments [ + (string) + (boolean) + (charlist) + (sigil + "~" @comment + ((sigil_name) @comment) + quoted_start: _ @comment + (quoted_content) @comment + quoted_end: _ @comment) + ] @comment))) @comment diff --git a/bundle/nvim-treesitter/queries/elixir/indents.scm b/bundle/nvim-treesitter/queries/elixir/indents.scm new file mode 100644 index 000000000..517f66940 --- /dev/null +++ b/bundle/nvim-treesitter/queries/elixir/indents.scm @@ -0,0 +1,23 @@ +[ + (block) + (do_block) + (list) + (map) + (stab_clause) + (tuple) + (arguments) +] @indent + +[ + ")" + "]" + "after" + "catch" + "else" + "rescue" + "}" + "end" +] @indent_end @branch + +; Elixir pipelines are not indented, but other binary operator chains are +((binary_operator operator: _ @_operator) @indent (#not-eq? @_operator "|>")) diff --git a/bundle/nvim-treesitter/queries/elixir/injections.scm b/bundle/nvim-treesitter/queries/elixir/injections.scm new file mode 100644 index 000000000..423fddea7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/elixir/injections.scm @@ -0,0 +1,48 @@ +; Comments +(comment) @comment + +; Documentation +(unary_operator + operator: "@" + operand: (call + target: ((identifier) @_identifier (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc")) + (arguments [ + (string (quoted_content) @markdown) + (sigil (quoted_content) @markdown) + ]))) + +; HEEx +(sigil + (sigil_name) @_sigil_name + (quoted_content) @heex +(#eq? @_sigil_name "H")) + +; Surface +(sigil + (sigil_name) @_sigil_name + (quoted_content) @surface +(#eq? @_sigil_name "F")) + +; Zigler +(sigil + (sigil_name) @_sigil_name + (quoted_content) @eex +(#any-of? @_sigil_name "E" "L")) + +(sigil + (sigil_name) @_sigil_name + (quoted_content) @zig +(#any-of? @_sigil_name "z" "Z")) + +; Regex +(sigil + (sigil_name) @_sigil_name + (quoted_content) @regex +(#any-of? @_sigil_name "r" "R")) + +; Jason +(sigil + (sigil_name) @_sigil_name + (quoted_content) @json +(#any-of? @_sigil_name "j" "J")) + diff --git a/bundle/nvim-treesitter/queries/elixir/locals.scm b/bundle/nvim-treesitter/queries/elixir/locals.scm new file mode 100644 index 000000000..79a9676df --- /dev/null +++ b/bundle/nvim-treesitter/queries/elixir/locals.scm @@ -0,0 +1,164 @@ +; References +(identifier) @reference +(alias) @reference + +; Module Definitions +(call + target: ((identifier) @_identifier (#eq? @_identifier "defmodule")) + (arguments (alias) @definition.type)) + +; Pattern Match Definitions +(binary_operator left: [ + (identifier) @definition.var + (_ (identifier) @definition.var) + (_ (_ (identifier) @definition.var)) + (_ (_ (_ (identifier) @definition.var))) + (_ (_ (_ (_ (identifier) @definition.var)))) + (_ (_ (_ (_ (_ (identifier) @definition.var))))) + (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))) + (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))))) +] operator: "=") + +; Stab Clause Definitions +(stab_clause + left: [ + (arguments [ + (identifier) @definition.var + (_ (identifier) @definition.var) + (_ (_ (identifier) @definition.var)) + (_ (_ (_ (identifier) @definition.var))) + (_ (_ (_ (_ (identifier) @definition.var)))) + (_ (_ (_ (_ (_ (identifier) @definition.var))))) + (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))) + (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))))) + ]) + (binary_operator + left: (arguments [ + (identifier) @definition.var + (_ (identifier) @definition.var) + (_ (_ (identifier) @definition.var)) + (_ (_ (_ (identifier) @definition.var))) + (_ (_ (_ (_ (identifier) @definition.var)))) + (_ (_ (_ (_ (_ (identifier) @definition.var))))) + (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))) + (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var))))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.var)))))))))))))))))))) + ]) operator: "when") +]) + +; Aliases +(call + target: ((identifier) @_identifier (#any-of? @_identifier "require" "alias" "use" "import")) + (arguments [ + (alias) @definition.import + (_ (alias) @definition.import) + (_ (_ (alias) @definition.import)) + (_ (_ (_ (alias) @definition.import))) + (_ (_ (_ (_ (alias) @definition.import)))) + ] +)) + +; Local Function Definitions & Scopes +(call + target: ((identifier) @_identifier (#any-of? @_identifier "def" "defp" "defmacro" "defmacrop" "defguard" "defguardp" "defn" "defnp" "for")) + (arguments [ + (identifier) @definition.function + (binary_operator left: (identifier) @definition.function operator: "when") + (binary_operator (identifier) @definition.parameter) + (call target: (identifier) @definition.function (arguments [ + (identifier) @definition.parameter + (_ (identifier) @definition.parameter) + (_ (_ (identifier) @definition.parameter)) + (_ (_ (_ (identifier) @definition.parameter))) + (_ (_ (_ (_ (identifier) @definition.parameter)))) + (_ (_ (_ (_ (_ (identifier) @definition.parameter))))) + (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))) + (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))))))) + ])) + ]?) (#set! definition.function.scope parent) + (do_block)? +) @scope + +; ExUnit Test Definitions & Scopes +(call + target: ((identifier) @_identifier (#eq? @_identifier "test")) + (arguments [ + (string) + ((string) . "," . [ + (identifier) @definition.parameter + (_ (identifier) @definition.parameter) + (_ (_ (identifier) @definition.parameter)) + (_ (_ (_ (identifier) @definition.parameter))) + (_ (_ (_ (_ (identifier) @definition.parameter)))) + (_ (_ (_ (_ (_ (identifier) @definition.parameter))))) + (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))) + (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter))))))))))))))))))) + (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (_ (identifier) @definition.parameter)))))))))))))))))))) + ]) +]) (do_block)?) @scope + +; Stab Clause Scopes +(stab_clause) @scope diff --git a/bundle/nvim-treesitter/queries/elm/highlights.scm b/bundle/nvim-treesitter/queries/elm/highlights.scm new file mode 100644 index 000000000..4d644ac63 --- /dev/null +++ b/bundle/nvim-treesitter/queries/elm/highlights.scm @@ -0,0 +1,90 @@ +[(line_comment) (block_comment)] @comment + +; Keywords +[ + "if" + "then" + "else" + (case) + (of) +] @conditional + +[ + "let" + "in" + (as) + (port) + (exposing) + (alias) + (infix) + (module) +] @keyword + +[ + (double_dot) + "|" +] @punctuation.special +[ + "," + (dot) +] @punctuation.delimiter + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket + +(type_annotation(lower_case_identifier) @function) +(port_annotation(lower_case_identifier) @function) +(function_declaration_left(lower_case_identifier) @function) +(function_call_expr target: + (value_expr) @function) + +(value_qid (upper_case_identifier) @constructor) +(value_qid ((dot) (lower_case_identifier) @field)) +(field_access_expr ((dot) (lower_case_identifier) @field)) + +(lower_pattern) @parameter +(record_base_identifier) @method + +[ + (backslash) + (underscore) +] @function + +[ + (operator_identifier) + (eq) + (colon) + (arrow) +] @operator + +(import) @include + +(number_constant_expr) @number + +(type) @keyword + +(module_declaration(upper_case_qid(upper_case_identifier)) @constructor) +(type_declaration(upper_case_identifier) @constructor) +(type_ref) @type +(type_alias_declaration name: (upper_case_identifier) @type) +(field_type name: + (lower_case_identifier) @property) + +(union_variant(upper_case_identifier) @symbol) +(union_pattern) @symbol +(value_expr(upper_case_qid(upper_case_identifier)) @symbol) + +; strings +(string_escape) @string +(open_quote) @string +(close_quote) @string +(regular_string_part) @string + +[ + (open_char) + (close_char) +] @character diff --git a/bundle/nvim-treesitter/queries/elm/injections.scm b/bundle/nvim-treesitter/queries/elm/injections.scm new file mode 100644 index 000000000..6395776e1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/elm/injections.scm @@ -0,0 +1,3 @@ +[(line_comment) (block_comment)] @comment + +(glsl_content) @glsl diff --git a/bundle/nvim-treesitter/queries/elvish/highlights.scm b/bundle/nvim-treesitter/queries/elvish/highlights.scm new file mode 100644 index 000000000..4dba8eecb --- /dev/null +++ b/bundle/nvim-treesitter/queries/elvish/highlights.scm @@ -0,0 +1,70 @@ +(comment) @comment + +["if" "elif"] @conditional +(if (else "else" @conditional)) + +["while" "for"] @repeat +(while (else "else" @repeat)) +(for (else "else" @repeat)) + +["try" "catch" "finally"] @exception +(try (else "else" @exception)) + +"use" @include +(import (bareword) @string.special) + +["*" "**" "?"] @string.special + +(command argument: (bareword) @parameter) +(command head: (identifier) @function) +((command head: (identifier) @keyword.return) + (#eq? @keyword.return "return")) +((command (identifier) @keyword.operator) + (#any-of? @keyword.operator "and" "or" "coalesce")) +[ + "+" "-" "*" "/" "%" "<" "<=""==" "!=" ">" + ">=" "s" ">=s" +] @function + +[">" "<" ">>" "<>" "|"] @operator + +(io_port) @number + +(function_definition + "fn" @keyword.function + (identifier) @function) + +(parameter_list) @parameter +(parameter_list "|" @punctuation.bracket) + +["var" "set" "tmp" "del"] @keyword +(variable_declaration + (lhs (identifier) @variable)) + +(variable_assignment + (lhs (identifier) @variable)) + +(temporary_assignment + (lhs (identifier) @variable)) + +(variable_deletion + (identifier) @variable) + + +(number) @number +(string) @string + +(variable (identifier) @variable) +((variable (identifier) @function) + (#match? @function ".+\\~$")) +((variable (identifier) @boolean) + (#any-of? @boolean "true" "false")) +((variable (identifier) @constant.builtin) + (#any-of? @constant.builtin + "_" "after-chdir" "args" "before-chdir" "buildinfo" "nil" + "notify-bg-job-success" "num-bg-jobs" "ok" "paths" "pid" + "pwd" "value-out-indicator" "version")) + +["$" "@"] @punctuation.special +["(" ")" "[" "]" "{" "}"] @punctuation.bracket +";" @punctuation.delimiter diff --git a/bundle/nvim-treesitter/queries/elvish/injections.scm b/bundle/nvim-treesitter/queries/elvish/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/elvish/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/fennel/highlights.scm b/bundle/nvim-treesitter/queries/fennel/highlights.scm new file mode 100644 index 000000000..7322e55c3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fennel/highlights.scm @@ -0,0 +1,121 @@ +(comment) @comment + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + ":" + ":until" + "&" + "&as" + "?" +] @punctuation.special + +(nil) @constant.builtin +(vararg) @punctuation.special + +(boolean) @boolean +(number) @number + +(string) @string +(escape_sequence) @string.escape + +(symbol) @variable + +(multi_symbol + "." @punctuation.delimiter + (symbol) @field) + +(multi_symbol_method + ":" @punctuation.delimiter + (symbol) @method .) + +(list . (symbol) @function) +(list . (multi_symbol (symbol) @function .)) + +((symbol) @variable.builtin + (#match? @variable.builtin "^[$]")) + +(binding) @symbol + +[ + "fn" + "lambda" + "hashfn" + "#" +] @keyword.function + +(fn name: [ + (symbol) @function + (multi_symbol (symbol) @function .) +]) + +(lambda name: [ + (symbol) @function + (multi_symbol (symbol) @function .) +]) + +[ + "for" + "each" +] @repeat +((symbol) @repeat + (#any-of? @repeat + "while")) + +[ + "match" +] @conditional +((symbol) @conditional + (#any-of? @conditional + "if" "when")) + +[ + "global" + "local" + "let" + "set" + "var" + "where" + "or" +] @keyword +((symbol) @keyword + (#any-of? @keyword + "comment" "do" "doc" "eval-compiler" "lua" "macros" "quote" "tset" "values")) + +((symbol) @include + (#any-of? @include + "require" "require-macros" "import-macros" "include")) + +[ + "collect" + "icollect" + "accumulate" +] @function.macro + +((symbol) @function.macro + (#any-of? @function.macro + "->" "->>" "-?>" "-?>>" "?." "doto" "macro" "macrodebug" "partial" "pick-args" + "pick-values" "with-open")) + +; Lua builtins +((symbol) @constant.builtin + (#any-of? @constant.builtin + "arg" "_ENV" "_G" "_VERSION")) + +((symbol) @function.builtin + (#any-of? @function.builtin + "assert" "collectgarbage" "dofile" "error" "getmetatable" "ipairs" + "load" "loadfile" "next" "pairs" "pcall" "print" "rawequal" "rawget" + "rawlen" "rawset" "require" "select" "setmetatable" "tonumber" "tostring" + "type" "warn" "xpcall")) + +((symbol) @function.builtin + (#any-of? @function.builtin + "loadstring" "module" "setfenv" "unpack")) diff --git a/bundle/nvim-treesitter/queries/fennel/injections.scm b/bundle/nvim-treesitter/queries/fennel/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/fennel/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/fennel/locals.scm b/bundle/nvim-treesitter/queries/fennel/locals.scm new file mode 100644 index 000000000..3018732f9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fennel/locals.scm @@ -0,0 +1,26 @@ +[ + (program) + (fn) + (lambda) + (let) + (each) + (for) + (match) +] @scope + +( + (list . (symbol) @_special) @scope + (#any-of? @_special + "while" "if" "when" "do" "collect" "icollect" "accumulate") +) + +(fn name: (symbol) @definition.function + (#set! definition.function.scope "parent")) +(lambda name: (symbol) @definition.function + (#set! definition.function.scope "parent")) + +; TODO: use @definition.parameter for parameters +(binding (symbol) @definition.var) +(for_clause . (symbol) @definition.var) + +(symbol) @reference diff --git a/bundle/nvim-treesitter/queries/fish/folds.scm b/bundle/nvim-treesitter/queries/fish/folds.scm new file mode 100644 index 000000000..6075e2e04 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fish/folds.scm @@ -0,0 +1,8 @@ +[ + (function_definition) + (if_statement) + (switch_statement) + (for_statement) + (while_statement) + (begin_statement) +] @fold diff --git a/bundle/nvim-treesitter/queries/fish/highlights.scm b/bundle/nvim-treesitter/queries/fish/highlights.scm new file mode 100644 index 000000000..71c074630 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fish/highlights.scm @@ -0,0 +1,160 @@ +;; Fish highlighting + +;; Operators + +[ + "&&" + "||" + "|" + "&" + "=" + "!=" + ".." + "!" + (direction) + (stream_redirect) + (test_option) +] @operator + +[ + "not" + "and" + "or" +] @keyword.operator + +;; Conditionals + +(if_statement +[ + "if" + "end" +] @conditional) + +(switch_statement +[ + "switch" + "end" +] @conditional) + +(case_clause +[ + "case" +] @conditional) + +(else_clause +[ + "else" +] @conditional) + +(else_if_clause +[ + "else" + "if" +] @conditional) + +;; Loops/Blocks + +(while_statement +[ + "while" + "end" +] @repeat) + +(for_statement +[ + "for" + "end" +] @repeat) + +(begin_statement +[ + "begin" + "end" +] @repeat) + +;; Keywords + +[ + "in" + (break) + (continue) +] @keyword + +"return" @keyword.return + +;; Punctuation + +[ + "[" + "]" + "{" + "}" + "(" + ")" +] @punctuation.bracket + +"," @punctuation.delimiter + +;; Commands + +(command + argument: [ + (word) @parameter (#match? @parameter "^-") + ] +) + +(command_substitution_dollar "$" @punctuation.bracket) + +; non-bultin command names +(command name: (word) @function) + +; derived from builtin -n (fish 3.2.2) +(command + name: [ + (word) @function.builtin + (#any-of? @function.builtin "." ":" "_" "alias" "argparse" "bg" "bind" "block" "breakpoint" "builtin" "cd" "command" "commandline" "complete" "contains" "count" "disown" "echo" "emit" "eval" "exec" "exit" "fg" "functions" "history" "isatty" "jobs" "math" "printf" "pwd" "random" "read" "realpath" "set" "set_color" "source" "status" "string" "test" "time" "type" "ulimit" "wait") + ] +) + +(test_command "test" @function.builtin) + +;; Functions + +(function_definition ["function" "end"] @keyword.function) + +(function_definition + name: [ + (word) (concatenation) + ] +@function) + +(function_definition + option: [ + (word) + (concatenation (word)) + ] @parameter (#match? @parameter "^-") +) + +;; Strings + +[(double_quote_string) (single_quote_string)] @string +(escape_sequence) @string.escape + +;; Variables + +(variable_name) @variable +(variable_expansion) @constant + +;; Nodes + +[(integer) (float)] @number +(comment) @comment +(test_option) @string + +((word) @boolean +(#any-of? @boolean "true" "false")) + +;; Error + +(ERROR) @error + diff --git a/bundle/nvim-treesitter/queries/fish/indents.scm b/bundle/nvim-treesitter/queries/fish/indents.scm new file mode 100644 index 000000000..cf8d62658 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fish/indents.scm @@ -0,0 +1,16 @@ +[ + (function_definition) + (while_statement) + (for_statement) + (if_statement) + (begin_statement) + (switch_statement) +] @indent + +[ + (else_if_clause) + (else_clause) + "end" +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/fish/injections.scm b/bundle/nvim-treesitter/queries/fish/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/fish/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/fish/locals.scm b/bundle/nvim-treesitter/queries/fish/locals.scm new file mode 100644 index 000000000..a522c78dc --- /dev/null +++ b/bundle/nvim-treesitter/queries/fish/locals.scm @@ -0,0 +1,18 @@ +;; Scopes +[ + (command) + (function_definition) + (if_statement) + (for_statement) + (begin_statement) + (while_statement) + (switch_statement) +] @scope + +;; Definitions +(function_definition + name: (word) @definition.function) + +;; References +(variable_name) @reference +(word) @reference diff --git a/bundle/nvim-treesitter/queries/foam/folds.scm b/bundle/nvim-treesitter/queries/foam/folds.scm new file mode 100644 index 000000000..2e499c2e2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/foam/folds.scm @@ -0,0 +1,7 @@ +[ + (comment) + (list) + (dict_core) +] @fold + +(code (code_body)* @fold) diff --git a/bundle/nvim-treesitter/queries/foam/highlights.scm b/bundle/nvim-treesitter/queries/foam/highlights.scm new file mode 100644 index 000000000..86a3bf324 --- /dev/null +++ b/bundle/nvim-treesitter/queries/foam/highlights.scm @@ -0,0 +1,69 @@ +;; Comments +(comment) @comment + +;; Generic Key-value pairs and dictionary keywords +(key_value + keyword: (identifier) @function +) +(dict + key: (identifier) @type +) + +;; Macros +(macro + "$" @conditional + (prev_scope)* @conditional + (identifier)* @namespace +) + + +;; Directives +"#" @conditional +(preproc_call + directive: (identifier)* @conditional + argument: (identifier)* @namespace +) +( + (preproc_call + argument: (identifier)* @namespace + ) @conditional + (#match? @conditional "ifeq") +) +( + (preproc_call) @conditional + (#match? @conditional "(else|endif)") +) + +;; Literal numbers and strings +(number_literal) @float +(string_literal) @string +(escape_sequence) @string.escape + +;; Treat [m^2 s^-2] the same as if it was put in numbers format +(dimensions dimension: (identifier) @float) + +;; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" + "#{" + "#}" + "|-" + "-|" + "" + "$$" +] @punctuation.bracket + +[ + ";" +] @punctuation.delimiter + +;; Special identifiers +([(identifier) "on" "off" "true" "false" "yes" "no"] @constant.builtin +(#match? @constant.builtin "^(uniform|non-uniform|and|or|on|off|true|false|yes|no)$") +) diff --git a/bundle/nvim-treesitter/queries/foam/indents.scm b/bundle/nvim-treesitter/queries/foam/indents.scm new file mode 100644 index 000000000..033700c17 --- /dev/null +++ b/bundle/nvim-treesitter/queries/foam/indents.scm @@ -0,0 +1,11 @@ +[ + "{" + "}" +] @branch + +[(dict) (key_value)] @indent + + +[ + (comment) +] @ignore diff --git a/bundle/nvim-treesitter/queries/foam/injections.scm b/bundle/nvim-treesitter/queries/foam/injections.scm new file mode 100644 index 000000000..4afdb63b0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/foam/injections.scm @@ -0,0 +1,12 @@ +;; Pass code blocks to Cpp highlighter +(code (code_body) @cpp) + +;; Pass identifiers to Go highlighter (Cheating I know) +;;((identifier) @lua) + +;; Highlight regex syntax inside literal strings +((string_literal) @regex) + +;; Highlight PyFoam syntax as Python statements +(pyfoam_variable code_body: (_) @python) +(pyfoam_expression code_body: (_) @python) diff --git a/bundle/nvim-treesitter/queries/foam/locals.scm b/bundle/nvim-treesitter/queries/foam/locals.scm new file mode 100644 index 000000000..2abe743dd --- /dev/null +++ b/bundle/nvim-treesitter/queries/foam/locals.scm @@ -0,0 +1,6 @@ +(dict) @scope + +(dict key: (_) @definition.type) + +(key_value keyword: (_) @definition.parameter) +(key_value value: (macro (identifier)*)* @reference) diff --git a/bundle/nvim-treesitter/queries/fortran/folds.scm b/bundle/nvim-treesitter/queries/fortran/folds.scm new file mode 100644 index 000000000..a2edc64d3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fortran/folds.scm @@ -0,0 +1,11 @@ +;; by @oponkork +[ + (if_statement) + (where_statement) + (enum_statement) + (do_loop_statement) + (derived_type_definition) + (function) + (subroutine) + (interface) +] @fold diff --git a/bundle/nvim-treesitter/queries/fortran/highlights.scm b/bundle/nvim-treesitter/queries/fortran/highlights.scm new file mode 100644 index 000000000..6ef4867e7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fortran/highlights.scm @@ -0,0 +1,176 @@ +(identifier) @variable +(string_literal) @string +(number_literal) @number +(boolean_literal) @boolean +(comment) @comment + +[ + (intrinsic_type) + "allocatable" + "attributes" + "device" + "dimension" + "endtype" + "global" + "grid_global" + "host" + "import" + "in" + "inout" + "intent" + "optional" + "out" + "pointer" + "type" + "value" +] @type + +[ + "contains" + "private" + "public" +] @include + +[ + (none) + "implicit" +] @attribute + +[ + "endfunction" + "endprogram" + "endsubroutine" + "function" + "procedure" + "subroutine" +] @keyword.function + +[ + "bind" + "call" + "class" + "continue" + "cycle" + "endenum" + "endinterface" + "endmodule" + "endprogram" + "enum" + "enumerator" + "equivalence" + "exit" + "format" + "goto" + "include" + "interface" + "module" + "namelist" + "only" + "parameter" + "print" + "program" + "read" + "stop" + "use" + "write" + (default) + (procedure_qualifier) +] @keyword + +"return" @keyword.return + +[ + "else" + "elseif" + "endif" + "endwhere" + "if" + "then" + "where" +] @conditional + +[ + "do" + "enddo" + "forall" + "while" +] @repeat + +[ + "*" + "+" + "-" + "/" + "=" + "<" + ">" + "<=" + ">=" + "==" + "/=" +] @operator + +[ + "\\.and\\." + "\\.or\\." + "\\.lt\\." + "\\.gt\\." + "\\.ge\\." + "\\.le\\." + "\\.eq\\." + "\\.eqv\\." + "\\.neqv\\." +] @keyword.operator + + ;; Brackets + [ + "(" + ")" + "[" + "]" + "<<<" + ">>>" + ] @punctuation.bracket + + ;; Delimiter + [ + "::" + "," + "%" + ] @punctuation.delimiter + +(parameters + (identifier) @parameter) + +(program_statement + (name) @namespace) + +(module_statement + (name) @namespace) + +(function_statement + (name) @function) + +(subroutine_statement + (name) @function) + +(end_program_statement + (name) @namespace) + +(end_module_statement + (name) @namespace) + +(end_function_statement + (name) @function) + +(end_subroutine_statement + (name) @function) + +(subroutine_call + (name) @function) + +(keyword_argument + name: (identifier) @keyword) + +(derived_type_member_expression + (type_member) @property) diff --git a/bundle/nvim-treesitter/queries/fortran/indents.scm b/bundle/nvim-treesitter/queries/fortran/indents.scm new file mode 100644 index 000000000..67fa046de --- /dev/null +++ b/bundle/nvim-treesitter/queries/fortran/indents.scm @@ -0,0 +1,27 @@ +[ + (module) + (program) + (subroutine) + (function) + ; (interface) + (if_statement) + (do_loop_statement) + (where_statement) + (derived_type_definition) + (enum) +] @indent + +[ + (end_module_statement) + (end_program_statement) + (end_subroutine_statement) + (end_function_statement) + ; (end_interface_statement) + (end_if_statement) + (end_do_loop_statement) + (else_clause) + (elseif_clause) + (end_type_statement) + (end_enum_statement) + (end_where_statement) +] @branch diff --git a/bundle/nvim-treesitter/queries/fusion/folds.scm b/bundle/nvim-treesitter/queries/fusion/folds.scm new file mode 100644 index 000000000..179fc160b --- /dev/null +++ b/bundle/nvim-treesitter/queries/fusion/folds.scm @@ -0,0 +1,6 @@ +[ + (comment) + (block) + (afx_comment) + (afx_element) +] @fold diff --git a/bundle/nvim-treesitter/queries/fusion/highlights.scm b/bundle/nvim-treesitter/queries/fusion/highlights.scm new file mode 100644 index 000000000..7109ee651 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fusion/highlights.scm @@ -0,0 +1,117 @@ +(comment) @comment +(afx_comment) @comment + +; identifiers afx +(afx_opening_element + (afx_identifier) @tag) +(afx_closing_element + (afx_identifier) @tag) +(afx_element_self_closing + (afx_identifier) @tag) + +(afx_attribute + (afx_property_identifier) @tag.attribute) + +(afx_text) @text + +; identifiers eel + +(eel_object_path + (eel_path_identifier) @variable.builtin + (#match? @variable.builtin "^(this|props)$") +) + +(eel_object_path + (eel_path_identifier) @variable) + +(eel_object_pair + key: (eel_property_name) @property) + +(eel_method_name) @function + +(eel_parameter) @variable + +; identifiers fusion +; ----------- + +(path_part) @property +(meta_property) @attribute +(prototype_signature + "prototype" @keyword + +) +(include_statement + [ + "include" + ] @include + (source_file) @text.uri +) + +(namespace_declaration + "namespace" @keyword + (alias_namespace) @namespace) + +(type + name: (type_name) @type) + +; tokens +; ------ +(afx_opening_element + [ + "<" + ">" + ] @punctuation.bracket) + + (afx_closing_element + [ + "<" + ">" + "/" + ] @punctuation.bracket) + +(afx_element_self_closing + [ + "<" + "/>" + ] @punctuation.bracket) + +[ + (package_name) + (alias_namespace) +] @namespace + +(namespace_declaration "=" @operator) +(assignment "=" @operator) +(copy "<" @operator) +(deletion) @operator +(eel_binary_expression + operator: _ @operator) +(eel_not_expression + [ + "!" + "not" + ] @operator) + +(string) @string +(number) @number +(boolean) @boolean +(null) @constant.builtin + +(value_expression + start: _ @punctuation.special + end: _ @punctuation.special +) +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + ":" + "." + "?" +] @punctuation.delimiter diff --git a/bundle/nvim-treesitter/queries/fusion/indents.scm b/bundle/nvim-treesitter/queries/fusion/indents.scm new file mode 100644 index 000000000..68c57d528 --- /dev/null +++ b/bundle/nvim-treesitter/queries/fusion/indents.scm @@ -0,0 +1,19 @@ +[ + (block) + (value_dsl) + (afx_element) + (afx_element_self_closing) + (eel_array) + (eel_object) +] @indent + + +(block end: _ @branch) +(value_dsl end: _ @branch) +(eel_array end: _ @branch) +(eel_object end: _ @branch) +[ + (afx_closing_element) +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/fusion/locals.scm b/bundle/nvim-treesitter/queries/fusion/locals.scm new file mode 100644 index 000000000..24dc57bbe --- /dev/null +++ b/bundle/nvim-treesitter/queries/fusion/locals.scm @@ -0,0 +1,21 @@ +;; Fusion base +(block) @scope + +(namespace_declaration + (alias_namespace) @definition.namespace) + +(property + (path (path_part) @definition.field)) + +(type + namespace: (package_name)? @definition.namespace + name: (type_name) @definition.type +) + +;; Eel Expressions +(eel_arrow_function) @scope +(eel_object) @scope + +(eel_parameter) @definition.parameter +(eel_object_pair + key: (eel_property_name) @definition.field) diff --git a/bundle/nvim-treesitter/queries/gdscript/highlights.scm b/bundle/nvim-treesitter/queries/gdscript/highlights.scm new file mode 100644 index 000000000..d86e4c1de --- /dev/null +++ b/bundle/nvim-treesitter/queries/gdscript/highlights.scm @@ -0,0 +1,125 @@ +;; Basic +(identifier) @variable +(name) @variable +(type) @type +(comment) @comment +(get_node) @string +(string) @string +(float) @float +(integer) @number +(null) @constant +(setter) @function +(getter) @function +(static_keyword) @keyword +(tool_statement) @keyword +(breakpoint_statement) @keyword +(inferred_type) @operator +[(true) (false)] @boolean + +(class_name_statement + (name) @type) @keyword + +(const_statement + (name) @constant) @keyword + +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +;; Identifier naming conventions +((identifier) @type + (#lua-match? @type "^[A-Z]")) +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) +((identifier) @type + (#lua-match? @type "^[A-Z][A-Z_0-9]*$") . (_)) + +;; Functions +(constructor_definition) @constructor + +(function_definition + (name) @function (parameters + (identifier) @parameter)*) + +(typed_parameter + (identifier) @parameter) + +(default_parameter + (identifier) @parameter) + +(call + (identifier) @function) +(attribute_call + (identifier) @function) + +;; Alternations +["(" ")" "[" "]" "{" "}"] @punctuation.bracket + +["," "." ":"] @punctuation.delimiter + +["if" "elif" "else" "match"] @conditional + +["for" "while" "break" "continue"] @repeat + +[ + "~" + "-" + "*" + "/" + "%" + "+" + "-" + "<<" + ">>" + "&" + "^" + "|" + "<" + ">" + "==" + "!=" + ">=" + "<=" + "!" + "&&" + "||" + "=" + "+=" + "-=" + "*=" + "/=" + "%=" + "&=" + "|=" + "->" +] @operator + +[ + "and" + "as" + "in" + "is" + "not" + "or" +] @keyword.operator + +[ + "pass" + "class" + "class_name" + "extends" + "signal" + "func" + "enum" + "var" + "onready" + "export" + "setget" + "remote" + "master" + "puppet" + "remotesync" + "mastersync" + "puppetsync" +] @keyword + +"return" @keyword.return diff --git a/bundle/nvim-treesitter/queries/gdscript/indents.scm b/bundle/nvim-treesitter/queries/gdscript/indents.scm new file mode 100644 index 000000000..80b78234d --- /dev/null +++ b/bundle/nvim-treesitter/queries/gdscript/indents.scm @@ -0,0 +1,24 @@ +[ + (if_statement) + + (for_statement) + (while_statement) + + (parenthesized_expression) + + (function_definition) + (class_definition) +] @indent + +((argument_list) @aligned_indent + (#set! "delimiter" "()")) +((parameters) @aligned_indent + (#set! "delimiter" "()")) + +[ + ")" + "]" + "}" + (elif_clause) + (else_clause) +] @branch diff --git a/bundle/nvim-treesitter/queries/gdscript/injections.scm b/bundle/nvim-treesitter/queries/gdscript/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/gdscript/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/gdscript/locals.scm b/bundle/nvim-treesitter/queries/gdscript/locals.scm new file mode 100644 index 000000000..313af2aef --- /dev/null +++ b/bundle/nvim-treesitter/queries/gdscript/locals.scm @@ -0,0 +1,10 @@ +(function_definition) @definition.function + +[ + (extends_statement) + (variable_statement) + (expression_statement) + (if_statement) + (function_definition) + (body) +] @scope diff --git a/bundle/nvim-treesitter/queries/gleam/folds.scm b/bundle/nvim-treesitter/queries/gleam/folds.scm new file mode 100644 index 000000000..ff05eeb05 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gleam/folds.scm @@ -0,0 +1,11 @@ +; Folds +[ + (case) + (expression_group) + (function) + (public_function) + (anonymous_function) + (type_definition) + (public_type_definition) + (public_opaque_type_definition) +] @fold diff --git a/bundle/nvim-treesitter/queries/gleam/highlights.scm b/bundle/nvim-treesitter/queries/gleam/highlights.scm new file mode 100644 index 000000000..e1dc969ab --- /dev/null +++ b/bundle/nvim-treesitter/queries/gleam/highlights.scm @@ -0,0 +1,163 @@ +; Keywords +[ + "as" + "const" + "external" + "let" + "opaque" + "pub" + "todo" + "try" +] @keyword + +; Function Keywords +[ + "fn" + "type" +] @keyword.function + +; Imports +[ + "import" +] @include + +; Conditionals +[ + "case" + "if" +] @conditional + +; Exceptions +[ + "assert" +] @exception + +; Punctuation +[ + "(" + ")" + "<<" + ">>" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "," + "." +] @punctuation.delimiter + +[ + "#" +] @punctuation.special + +; Operators +[ + "%" + "&&" + "*" + "*." + "+" + "+." + "-" + "-." + "->" + ".." + "/" + "/." + ":" + "<" + "<." + "<=" + "<=." + "=" + "==" + ">" + ">." + ">=" + ">=." + "|>" + "||" +] @operator + +; Identifiers +(identifier) @variable + +; Comments +[ + (module_comment) + (statement_comment) + (comment) +] @comment + +; Unused Identifiers +[ + (discard) + (hole) +] @comment + +; Modules & Imports +(module ("/" @namespace)?) @namespace +(import alias: ((identifier) @namespace)?) +(remote_type_identifier module: (identifier) @namespace) +(unqualified_import name: (identifier) @function) + +; Strings +(string) @string + +; Bit Strings +(bit_string_segment) @string.special + +; Numbers +[ + (integer) + (float) + (bit_string_segment_option_unit) +] @number + +; Function Parameter Labels +(function_call arguments: (arguments (argument label: (label) @symbol ":" @symbol))) +(function_parameter label: (label)? @symbol name: (identifier) @parameter (":" @parameter)?) + +; Records +(record arguments: (arguments (argument label: (label) @property ":" @property)?)) +(record_pattern_argument label: (label) @property ":" @property) +(record_update_argument label: (label) @property ":" @property) +(field_access record: (identifier) @variable field: (label) @property) + +; Type Constructors +(data_constructor_argument label: (label) @property ":" @property) + +; Type Parameters +(type_parameter) @parameter + +; Types +((type_identifier) @type (#not-any-of? @type "True" "False")) + +; Booleans +((type_identifier) @boolean (#any-of? @boolean "True" "False")) + +; Type Variables +(type_var) @type + +; Tuples +(tuple_access index: (integer) @operator) + +; Functions +(function name: (identifier) @function) +(public_function name: (identifier) @function) +(function_call function: (identifier) @function) +(function_call function: (field_access field: (label) @function)) + +; External Functions +(public_external_function name: (identifier) @function) +(external_function name: (identifier) @function) +(external_function_body (string) @namespace . (string) @function) + +; Pipe Operator +(binary_expression operator: "|>" right: (identifier) @function) + +; Parser Errors +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/gleam/indents.scm b/bundle/nvim-treesitter/queries/gleam/indents.scm new file mode 100644 index 000000000..e2259b688 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gleam/indents.scm @@ -0,0 +1,33 @@ +; Gleam indents similar to Rust and JavaScript +[ + (assert) + (case) + (case_clause) + (constant) + (expression_group) + (external_function) + (function) + (import) + (let) + (list) + (public_constant) + (public_external_function) + (public_function) + (public_opaque_type_definition) + (public_type_alias) + (public_type_definition) + (todo) + (try) + (tuple) + (type_alias) + (type_definition) +] @indent + +[ + ")" + "]" + "}" +] @indent_end @branch + +; Gleam pipelines are not indented, but other binary expression chains are +((binary_expression operator: _ @_operator) @indent (#not-eq? @_operator "|>")) diff --git a/bundle/nvim-treesitter/queries/gleam/injections.scm b/bundle/nvim-treesitter/queries/gleam/injections.scm new file mode 100644 index 000000000..ed4c2de91 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gleam/injections.scm @@ -0,0 +1,6 @@ +; Comments +[ + (module_comment) + (statement_comment) + (comment) +] @comment diff --git a/bundle/nvim-treesitter/queries/gleam/locals.scm b/bundle/nvim-treesitter/queries/gleam/locals.scm new file mode 100644 index 000000000..8872e51f0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gleam/locals.scm @@ -0,0 +1,24 @@ +; Let Binding Definition +(let pattern: (identifier) @definition) + +; List Pattern Definitions +(list_pattern (identifier) @definition) +(list_pattern assign: (identifier) @definition) + +; Tuple Pattern Definition +(tuple_pattern (identifier) @definition) + +; Record Pattern Definition +(record_pattern_argument pattern: (identifier) @definition) + +; Function Parameter Definition +(function_parameter name: (identifier) @definition) + +; References +(identifier) @reference + +; Function Body Scope +(function_body) @scope + +; Case Scope +(case_clause) @scope diff --git a/bundle/nvim-treesitter/queries/glimmer/highlights.scm b/bundle/nvim-treesitter/queries/glimmer/highlights.scm new file mode 100644 index 000000000..b1b3f9141 --- /dev/null +++ b/bundle/nvim-treesitter/queries/glimmer/highlights.scm @@ -0,0 +1,88 @@ +; === Tag Names === + +; Tags that start with a lower case letter are HTML tags +; We'll also use this highlighting for named blocks (which start with `:`) +((tag_name) @tag + (#match? @tag "^(:)?[a-z]")) +; Tags that start with a capital letter are Glimmer components +((tag_name) @constructor + (#lua-match? @constructor "^[A-Z]")) + +(attribute_name) @property + +(string_literal) @string +(number_literal) @number +(boolean_literal) @boolean + +(concat_statement) @string + +; === Block Statements === + +; Highlight the brackets +(block_statement_start) @tag.delimiter +(block_statement_end) @tag.delimiter + +; Highlight `if`/`each`/`let` +(block_statement_start path: (identifier) @conditional) +(block_statement_end path: (identifier) @conditional) +((mustache_statement (identifier) @conditional) + (#lua-match? @conditional "else")) + +; == Mustache Statements === + +; Highlight the whole statement, to color brackets and separators +(mustache_statement) @tag.delimiter + +; An identifier in a mustache expression is a variable +((mustache_statement [ + (path_expression (identifier) @variable) + (identifier) @variable + ]) + (#not-match? @variable "yield|outlet|this|else")) +; As are arguments in a block statement +(block_statement_start argument: [ + (path_expression (identifier) @variable) + (identifier) @variable + ]) +; As is an identifier in a block param +(block_params (identifier) @variable) +; As are helper arguments +((helper_invocation argument: [ + (path_expression (identifier) @variable) + (identifier) @variable + ]) + (#not-match? @variable "this")) +; `this` should be highlighted as a built-in variable +((identifier) @variable.builtin + (#lua-match? @variable.builtin "this")) + +; If the identifier is just "yield" or "outlet", it's a keyword +((mustache_statement (identifier) @keyword) + (#any-of? @keyword "yield" "outlet")) + +; Helpers are functions +((helper_invocation helper: [ + (path_expression (identifier) @function) + (identifier) @function + ]) + (#not-match? @function "if|yield")) +((helper_invocation helper: (identifier) @conditional) + (#lua-match? @conditional "if")) +((helper_invocation helper: (identifier) @keyword) + (#lua-match? @keyword "yield")) + +(hash_pair key: (identifier) @property) + +(comment_statement) @comment + +(attribute_node "=" @operator) + +(block_params "as" @keyword) +(block_params "|" @operator) + +[ + "<" + ">" + "" +] @tag.delimiter diff --git a/bundle/nvim-treesitter/queries/glsl/folds.scm b/bundle/nvim-treesitter/queries/glsl/folds.scm new file mode 100644 index 000000000..a5a5208ca --- /dev/null +++ b/bundle/nvim-treesitter/queries/glsl/folds.scm @@ -0,0 +1 @@ +; inherits: c diff --git a/bundle/nvim-treesitter/queries/glsl/highlights.scm b/bundle/nvim-treesitter/queries/glsl/highlights.scm new file mode 100644 index 000000000..af2a049fb --- /dev/null +++ b/bundle/nvim-treesitter/queries/glsl/highlights.scm @@ -0,0 +1,37 @@ +; inherits: c + +[ + "in" + "out" + "inout" + "uniform" + "shared" + "layout" + "attribute" + "varying" + "buffer" + "coherent" + "readonly" + "writeonly" + "precision" + "highp" + "mediump" + "lowp" + "centroid" + "sample" + "patch" + "smooth" + "flat" + "noperspective" + "invariant" + "precise" +] @keyword + +"subroutine" @keyword.function + +(extension_storage_class) @attribute + +( + (identifier) @variable.builtin + (#match? @variable.builtin "^gl_") +) diff --git a/bundle/nvim-treesitter/queries/glsl/indents.scm b/bundle/nvim-treesitter/queries/glsl/indents.scm new file mode 100644 index 000000000..a5a5208ca --- /dev/null +++ b/bundle/nvim-treesitter/queries/glsl/indents.scm @@ -0,0 +1 @@ +; inherits: c diff --git a/bundle/nvim-treesitter/queries/glsl/injections.scm b/bundle/nvim-treesitter/queries/glsl/injections.scm new file mode 100644 index 000000000..7d3323b16 --- /dev/null +++ b/bundle/nvim-treesitter/queries/glsl/injections.scm @@ -0,0 +1,3 @@ +(preproc_arg) @glsl + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/glsl/locals.scm b/bundle/nvim-treesitter/queries/glsl/locals.scm new file mode 100644 index 000000000..a5a5208ca --- /dev/null +++ b/bundle/nvim-treesitter/queries/glsl/locals.scm @@ -0,0 +1 @@ +; inherits: c diff --git a/bundle/nvim-treesitter/queries/go/folds.scm b/bundle/nvim-treesitter/queries/go/folds.scm new file mode 100644 index 000000000..c79d45720 --- /dev/null +++ b/bundle/nvim-treesitter/queries/go/folds.scm @@ -0,0 +1,13 @@ +[ + (const_declaration) + (expression_switch_statement) + (for_statement) + (func_literal) + (function_declaration) + (if_statement) + (import_declaration) + (method_declaration) + (type_declaration) + (var_declaration) +] @fold + diff --git a/bundle/nvim-treesitter/queries/go/highlights.scm b/bundle/nvim-treesitter/queries/go/highlights.scm new file mode 100644 index 000000000..07c788ec7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/go/highlights.scm @@ -0,0 +1,201 @@ +;; Forked from tree-sitter-go +;; Copyright (c) 2014 Max Brunsfeld (The MIT License) + +;; +; Identifiers + +(type_identifier) @type +(field_identifier) @property +(identifier) @variable +(package_identifier) @namespace + +(parameter_declaration (identifier) @parameter) +(variadic_parameter_declaration (identifier) @parameter) + +((identifier) @constant + (#eq? @constant "_")) + +((identifier) @constant + (#vim-match? @constant "^[A-Z][A-Z\\d_]+$")) + +(const_spec + name: (identifier) @constant) + +; Function calls + +(call_expression + function: (identifier) @function) + +(call_expression + function: (selector_expression + field: (field_identifier) @method)) + +; Function definitions + +(function_declaration + name: (identifier) @function) + +(method_declaration + name: (field_identifier) @method) + +; Operators + +[ + "--" + "-" + "-=" + ":=" + "!" + "!=" + "..." + "*" + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "++" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" +] @operator + +; Keywords + +[ + "break" + "chan" + "const" + "continue" + "default" + "defer" + "go" + "goto" + "interface" + "map" + "range" + "select" + "struct" + "type" + "var" + "fallthrough" +] @keyword + +"func" @keyword.function +"return" @keyword.return + +"for" @repeat + +[ + "import" + "package" +] @include + +[ + "else" + "case" + "switch" + "if" + ] @conditional + + +;; Builtin types + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "bool" + "byte" + "complex128" + "complex64" + "error" + "float32" + "float64" + "int" + "int16" + "int32" + "int64" + "int8" + "rune" + "string" + "uint" + "uint16" + "uint32" + "uint64" + "uint8" + "uintptr")) + + +;; Builtin functions + +((identifier) @function.builtin + (#any-of? @function.builtin + "append" + "cap" + "close" + "complex" + "copy" + "delete" + "imag" + "len" + "make" + "new" + "panic" + "print" + "println" + "real" + "recover")) + + +; Delimiters + +"." @punctuation.delimiter +"," @punctuation.delimiter +":" @punctuation.delimiter +";" @punctuation.delimiter + +"(" @punctuation.bracket +")" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket + + +; Literals + +(interpreted_string_literal) @string +(raw_string_literal) @string +(rune_literal) @string +(escape_sequence) @string.escape + +(int_literal) @number +(float_literal) @float +(imaginary_literal) @number + +(true) @boolean +(false) @boolean +(nil) @constant.builtin + +(comment) @comment + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/go/indents.scm b/bundle/nvim-treesitter/queries/go/indents.scm new file mode 100644 index 000000000..f274ffb11 --- /dev/null +++ b/bundle/nvim-treesitter/queries/go/indents.scm @@ -0,0 +1,23 @@ +[ + (import_declaration) + (const_declaration) + (var_declaration) + (type_declaration) + (composite_literal) + (func_literal) + (literal_value) + (expression_case) + (default_case) + (block) + (call_expression) + (parameter_list) +] @indent + +[ + "case" + "}" +] @branch + +(parameter_list ")" @branch) + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/go/injections.scm b/bundle/nvim-treesitter/queries/go/injections.scm new file mode 100644 index 000000000..2391c1a7a --- /dev/null +++ b/bundle/nvim-treesitter/queries/go/injections.scm @@ -0,0 +1,6 @@ +((comment) @c (#offset! @c 1 0 0 -2) + (import_declaration + (import_spec path: (interpreted_string_literal) @_import_path)) + (#eq? @_import_path "\"C\"")) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/go/locals.scm b/bundle/nvim-treesitter/queries/go/locals.scm new file mode 100644 index 000000000..1de546c7c --- /dev/null +++ b/bundle/nvim-treesitter/queries/go/locals.scm @@ -0,0 +1,79 @@ +( + (function_declaration + name: (identifier) @definition.function) ;@function +) + +( + (method_declaration + name: (field_identifier) @definition.method); @method +) + +(short_var_declaration + left: (expression_list + (identifier) @definition.var)) + +(var_spec + name: (identifier) @definition.var) + +(parameter_declaration (identifier) @definition.var) +(variadic_parameter_declaration (identifier) @definition.var) + +(for_statement + (range_clause + left: (expression_list + (identifier) @definition.var))) + +(const_declaration + (const_spec + name: (identifier) @definition.var)) + +(type_declaration + (type_spec + name: (type_identifier) @definition.type)) + +;; reference +(identifier) @reference +(type_identifier) @reference +(field_identifier) @reference +((package_identifier) @reference + (set! reference.kind "namespace")) + +(package_clause + (package_identifier) @definition.namespace) + +(import_spec_list + (import_spec + name: (package_identifier) @definition.namespace)) + +;; Call references +((call_expression + function: (identifier) @reference) + (set! reference.kind "call" )) + +((call_expression + function: (selector_expression + field: (field_identifier) @reference)) + (set! reference.kind "call" )) + + +((call_expression + function: (parenthesized_expression + (identifier) @reference)) + (set! reference.kind "call" )) + +((call_expression + function: (parenthesized_expression + (selector_expression + field: (field_identifier) @reference))) + (set! reference.kind "call" )) + +;; Scopes + +(func_literal) @scope +(source_file) @scope +(function_declaration) @scope +(if_statement) @scope +(block) @scope +(expression_switch_statement) @scope +(for_statement) @scope +(method_declaration) @scope diff --git a/bundle/nvim-treesitter/queries/godot_resource/folds.scm b/bundle/nvim-treesitter/queries/godot_resource/folds.scm new file mode 100644 index 000000000..943e0628f --- /dev/null +++ b/bundle/nvim-treesitter/queries/godot_resource/folds.scm @@ -0,0 +1,3 @@ +[ + (section) +] @fold diff --git a/bundle/nvim-treesitter/queries/godot_resource/highlights.scm b/bundle/nvim-treesitter/queries/godot_resource/highlights.scm new file mode 100644 index 000000000..005ddaacb --- /dev/null +++ b/bundle/nvim-treesitter/queries/godot_resource/highlights.scm @@ -0,0 +1,28 @@ +(identifier) @type.builtin + +(attribute (identifier) @property) +(property (path) @property) +(constructor (identifier) @constructor) + +(string) @string +(integer) @number +(float) @float + +(true) @constant.builtin +(false) @constant.builtin + +[ + "[" + "]" +] @tag.delimiter + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket + +"=" @operator + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/godot_resource/locals.scm b/bundle/nvim-treesitter/queries/godot_resource/locals.scm new file mode 100644 index 000000000..1dce04f0c --- /dev/null +++ b/bundle/nvim-treesitter/queries/godot_resource/locals.scm @@ -0,0 +1,3 @@ +[ + (section) +] @scope diff --git a/bundle/nvim-treesitter/queries/gomod/highlights.scm b/bundle/nvim-treesitter/queries/gomod/highlights.scm new file mode 100644 index 000000000..63e1f0128 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gomod/highlights.scm @@ -0,0 +1,17 @@ +[ + "require" + "replace" + "go" + "exclude" + "retract" + "module" +] @keyword + +"=>" @operator + +(comment) @comment + +[ +(version) +(go_version) +] @string diff --git a/bundle/nvim-treesitter/queries/gomod/injections.scm b/bundle/nvim-treesitter/queries/gomod/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/gomod/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/gowork/highlights.scm b/bundle/nvim-treesitter/queries/gowork/highlights.scm new file mode 100644 index 000000000..9c84bcc44 --- /dev/null +++ b/bundle/nvim-treesitter/queries/gowork/highlights.scm @@ -0,0 +1,14 @@ +[ + "replace" + "go" + "use" +] @keyword + +"=>" @operator + +(comment) @comment + +[ +(version) +(go_version) +] @string diff --git a/bundle/nvim-treesitter/queries/gowork/injections.scm b/bundle/nvim-treesitter/queries/gowork/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/gowork/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/graphql/highlights.scm b/bundle/nvim-treesitter/queries/graphql/highlights.scm new file mode 100644 index 000000000..cedf8e113 --- /dev/null +++ b/bundle/nvim-treesitter/queries/graphql/highlights.scm @@ -0,0 +1,164 @@ +; Types +;------ + +(scalar_type_definition + (name) @type) + +(object_type_definition + (name) @type) + +(interface_type_definition + (name) @type) + +(union_type_definition + (name) @type) + +(enum_type_definition + (name) @type) + +(input_object_type_definition + (name) @type) + +(directive_definition + (name) @type) + +(directive_definition + "@" @type) + +(scalar_type_extension + (name) @type) + +(object_type_extension + (name) @type) + +(interface_type_extension + (name) @type) + +(union_type_extension + (name) @type) + +(enum_type_extension + (name) @type) + +(input_object_type_extension + (name) @type) + +(named_type + (name) @type) + +(directive) @type + +; Properties +;----------- + +(field + (name) @property) + +(field + (alias + (name) @property)) + +(field_definition + (name) @property) + +(object_value + (object_field + (name) @property)) + +(enum_value + (name) @property) + +; Variable Definitions and Arguments +;----------------------------------- + +(operation_definition + (name) @variable) + +(fragment_name + (name) @variable) + +(input_fields_definition + (input_value_definition + (name) @parameter)) + +(argument + (name) @parameter) + +(arguments_definition + (input_value_definition + (name) @parameter)) + +(variable_definition + (variable) @parameter) + +(argument + (value + (variable) @variable)) + +; Constants +;---------- + +(string_value) @string + +(int_value) @number + +(float_value) @float + +(boolean_value) @boolean + +; Literals +;--------- + +(description + (string_value) @comment) + +(comment) @comment + +(directive_location + (executable_directive_location) @type.builtin) + +(directive_location + (type_system_directive_location) @type.builtin) + +; Keywords +;---------- + +[ + "query" + "mutation" + "subscription" + "fragment" + "scalar" + "type" + "interface" + "union" + "enum" + "input" + "extend" + "directive" + "schema" + "on" + "repeatable" + "implements" +] @keyword + +; Punctuation +;------------ + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +"=" @operator + +"|" @punctuation.delimiter +"&" @punctuation.delimiter +":" @punctuation.delimiter + +"..." @punctuation.special +"!" @punctuation.special diff --git a/bundle/nvim-treesitter/queries/graphql/indents.scm b/bundle/nvim-treesitter/queries/graphql/indents.scm new file mode 100644 index 000000000..0f222b6d4 --- /dev/null +++ b/bundle/nvim-treesitter/queries/graphql/indents.scm @@ -0,0 +1,9 @@ +[ + (definition) + (selection) +] @indent + +[ + "{" + "}" +] @branch diff --git a/bundle/nvim-treesitter/queries/graphql/injections.scm b/bundle/nvim-treesitter/queries/graphql/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/graphql/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/hack/highlights.scm b/bundle/nvim-treesitter/queries/hack/highlights.scm new file mode 100644 index 000000000..9ec38266a --- /dev/null +++ b/bundle/nvim-treesitter/queries/hack/highlights.scm @@ -0,0 +1,302 @@ +(variable) @variable +(identifier) @variable +((variable) @variable.builtin + (#eq? @variable.builtin "$this")) + +(braced_expression) @none + +(scoped_identifier + (qualified_identifier + (identifier) @type)) + +(comment) @comment +(heredoc) @comment + +[ + "function" +] @keyword.function + +[ + "async" + "await" + "type" + "interface" + "implements" + "class" + "protected" + "private" + "public" + "using" + "namespace" + "attribute" + "const" + (xhp_modifier) + (final_modifier) + "extends" + "insteadof" +] @keyword + +"use" @include + +[ + "new" + "print" + "echo" + "newtype" + "clone" + "as" +] @keyword.operator + +[ + "return" +] @keyword.return + +[ + "shape" + "tuple" + (array_type) + "bool" + "float" + "int" + "string" + "arraykey" + "void" + "nonnull" + "mixed" + "dynamic" + "noreturn" +] @type.builtin + +[ + (null) +] @constant.builtin + +[ + (true) + (false) +] @boolean + +(type_specifier) @type +(new_expression + (_) @type) + +(alias_declaration "newtype" . (_) @type) +(alias_declaration "type" . (_) @type) + +(class_declaration + name: (identifier) @type) +(type_parameter + name: (identifier) @type) + +(collection + (qualified_identifier + (identifier) @type .)) + +(attribute_modifier) @attribute +[ + "@required" + "@lateinit" +] @attribute + +[ + "=" + "??=" + ".=" + "|=" + "^=" + "&=" + "<<=" + ">>=" + "+=" + "-=" + "*=" + "/=" + "%=" + "**=" + + "==>" + "|>" + "??" + "||" + "&&" + "|" + "^" + "&" + "==" + "!=" + "===" + "!==" + "<" + ">" + "<=" + ">=" + "<=>" + "<<" + ">>" + "->" + "+" + "-" + "." + "*" + "/" + "%" + "**" + + "++" + "--" + "!" + + "?:" + + "=" + "??=" + ".=" + "|=" + "^=" + "&=" + "<<=" + ">>=" + "+=" + "-=" + "*=" + "/=" + "%=" + "**=" + "=>" + + ;; type modifiers + "@" + "?" + "~" +] @operator + +(integer) @number +(float) @float + +(parameter + (variable) @parameter) + +(call_expression + function: (qualified_identifier (identifier) @function .)) + +(call_expression + function: (scoped_identifier (identifier) @function .)) + +(call_expression + function: (selection_expression + (qualified_identifier (identifier) @method .))) + +(qualified_identifier + (_) @namespace . + (_)) + +(use_statement + (qualified_identifier + (_) @namespace .) + (use_clause)) + +(use_statement + (use_type "namespace") + (use_clause + (qualified_identifier + (identifier) @namespace .) + alias: (identifier)? @namespace)) + +(use_statement + (use_type "const") + (use_clause + (qualified_identifier + (identifier) @constant .) + alias: (identifier)? @constant)) + +(use_statement + (use_type "function") + (use_clause + (qualified_identifier + (identifier) @function .) + alias: (identifier)? @function)) + +(use_statement + (use_type "type") + (use_clause + (qualified_identifier + (identifier) @type .) + alias: (identifier)? @type)) + +(use_clause + (use_type "namespace") + (qualified_identifier + (_) @namespace .) + alias: (identifier)? @namespace) + +(use_clause + (use_type "function") + (qualified_identifier + (_) @function .) + alias: (identifier)? @function) + +(use_clause + (use_type "const") + (qualified_identifier + (_) @constant .) + alias: (identifier)? @constant) + +(use_clause + (use_type "type") + (qualified_identifier + (_) @type .) + alias: (identifier)? @type) + +(function_declaration + name: (identifier) @function) +(method_declaration + name: (identifier) @method) + +(type_arguments + [ "<" ">" ] @punctuation.bracket) +[ "(" ")" "[" "]" "{" "}" "<<" ">>"] @punctuation.bracket + +(xhp_open + [ "<" ">" ] @tag.delimiter) +(xhp_close + [ "" ] @tag.delimiter) + +[ "." ";" "::" ":" "," ] @punctuation.delimiter + +(ternary_expression + ["?" ":"] @conditional) + +[ + "if" + "else" + "elseif" + "switch" + "case" +] @conditional + +[ + "try" + "catch" + "finally" +] @exception + +[ + "for" + "while" + "foreach" + "do" + "continue" + "break" +] @repeat + +[ + (string) + (xhp_string) +] @string + +[ + (xhp_open) + (xhp_close) +] @tag + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/haskell/highlights.scm b/bundle/nvim-treesitter/queries/haskell/highlights.scm new file mode 100644 index 000000000..03744f5d6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/haskell/highlights.scm @@ -0,0 +1,139 @@ +;; ---------------------------------------------------------------------------- +;; Literals and comments + +(integer) @number +(exp_negation) @number +(exp_literal (float)) @float +(char) @character +(string) @string + +(con_unit) @symbol ; unit, as in () + +(comment) @comment + + +;; ---------------------------------------------------------------------------- +;; Punctuation + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + (comma) + ";" +] @punctuation.delimiter + + +;; ---------------------------------------------------------------------------- +;; Keywords, operators, includes + +[ + "forall" + "∀" +] @repeat + +(pragma) @constant.macro + +[ + "if" + "then" + "else" + "case" + "of" +] @conditional + +[ + "import" + "qualified" + "module" +] @include + +[ + (operator) + (constructor_operator) + (type_operator) + (tycon_arrow) + (qualified_module) ; grabs the `.` (dot), ex: import System.IO + (all_names) + (wildcard) + "=" + "|" + "::" + "=>" + "->" + "<-" + "\\" + "`" + "@" +] @operator + +(module) @namespace + +[ + (where) + "let" + "in" + "class" + "instance" + "data" + "newtype" + "family" + "type" + "as" + "hiding" + "deriving" + "via" + "stock" + "anyclass" + "do" + "mdo" + "rec" + "infix" + "infixl" + "infixr" +] @keyword + + +;; ---------------------------------------------------------------------------- +;; Functions and variables + +(variable) @variable +(pat_wildcard) @variable + +(signature name: (variable) @type) +(function + name: (variable) @function + patterns: (patterns)) +((signature (fun)) . (function (variable) @function)) +((signature (context (fun))) . (function (variable) @function)) +((signature (forall (context (fun)))) . (function (variable) @function)) + +(exp_infix (variable) @operator) ; consider infix functions as operators + +(exp_apply . (exp_name (variable) @function)) +(exp_apply . (exp_name (qualified_variable (variable) @function))) + + +;; ---------------------------------------------------------------------------- +;; Types + +(type) @type +(type_variable) @type + +(constructor) @constructor + +; True or False +((constructor) @_bool (#match? @_bool "(True|False)")) @boolean + + +;; ---------------------------------------------------------------------------- +;; Quasi-quotes + +(quoter) @function +; Highlighting of quasiquote_body is handled by injections.scm diff --git a/bundle/nvim-treesitter/queries/haskell/injections.scm b/bundle/nvim-treesitter/queries/haskell/injections.scm new file mode 100644 index 000000000..0b231a7a1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/haskell/injections.scm @@ -0,0 +1,58 @@ +;; ----------------------------------------------------------------------------- +;; General language injection + +(quasiquote + ((quoter) @language) + ((quasiquote_body) @content) +) + +(comment) @comment + +;; ----------------------------------------------------------------------------- +;; shakespeare library +;; NOTE: doesn't support templating + +; TODO: add once CoffeeScript parser is added +; ; CoffeeScript: Text.Coffee +; (quasiquote +; (quoter) @_name +; (#eq? @_name "coffee") +; ((quasiquote_body) @coffeescript) + +; CSS: Text.Cassius, Text.Lucius +(quasiquote + (quoter) @_name + (#any-of? @_name "cassius" "lucius") + ((quasiquote_body) @css) +) + +; HTML: Text.Hamlet +(quasiquote + (quoter) @_name + (#any-of? @_name "shamlet" "xshamlet" "hamlet" "xhamlet" "ihamlet") + ((quasiquote_body) @html) +) + +; JS: Text.Julius +(quasiquote + (quoter) @_name + (#any-of? @_name "js" "julius") + ((quasiquote_body) @javascript) +) + +; TS: Text.TypeScript +(quasiquote + (quoter) @_name + (#any-of? @_name "tsc" "tscJSX") + ((quasiquote_body) @typescript) +) + + +;; ----------------------------------------------------------------------------- +;; HSX + +(quasiquote + (quoter) @_name + (#eq? @_name "hsx") + ((quasiquote_body) @html) +) diff --git a/bundle/nvim-treesitter/queries/hcl/folds.scm b/bundle/nvim-treesitter/queries/hcl/folds.scm new file mode 100644 index 000000000..cb20b2aa8 --- /dev/null +++ b/bundle/nvim-treesitter/queries/hcl/folds.scm @@ -0,0 +1,6 @@ +[ + (comment) + (block) + (heredoc_template) + (object) +] @fold diff --git a/bundle/nvim-treesitter/queries/hcl/highlights.scm b/bundle/nvim-treesitter/queries/hcl/highlights.scm new file mode 100644 index 000000000..67e85cb61 --- /dev/null +++ b/bundle/nvim-treesitter/queries/hcl/highlights.scm @@ -0,0 +1,102 @@ +; highlights.scm + +[ + "!" + "\*" + "/" + "%" + "\+" + "-" + ">" + ">=" + "<" + "<=" + "==" + "!=" + "&&" + "||" +] @operator + +[ + "{" + "}" + "[" + "]" + "(" + ")" +] @punctuation.bracket + +[ + "." + ".*" + "," + "[*]" +] @punctuation.delimiter + +[ + (ellipsis) + "\?" + "=>" +] @punctuation.special + +[ + ":" + "=" +] @none + +[ + "for" + "endfor" + "in" +] @repeat + +[ + "if" + "else" + "endif" +] @conditional + +[ + (quoted_template_start) ; " + (quoted_template_end); " + (template_literal) ; non-interpolation/directive content +] @string + +[ + (heredoc_identifier) ; <" + "--%>" + "-->" + "/>" + "" + "{" + "}" +] @tag.delimiter + +; HEEx operators are highlighted as such +"=" @operator + +; HEEx inherits the DOCTYPE tag from HTML +(doctype) @constant + +; HEEx comments are highlighted as such +(comment) @comment + +; HEEx text content is treated as markup +(text) @text + +; Tree-sitter parser errors +(ERROR) @error + +; HEEx tags and slots are highlighted as HTML +[ + (tag_name) + (slot_name) +] @tag + +; HEEx attributes are highlighted as HTML attributes +(attribute_name) @tag.attribute +[ + (attribute_value) + (quoted_attribute_value) +] @string + +; HEEx components are highlighted as modules and function calls +(component_name [ + (module) @type + (function) @function + "." @punctuation.delimiter +]) diff --git a/bundle/nvim-treesitter/queries/heex/indents.scm b/bundle/nvim-treesitter/queries/heex/indents.scm new file mode 100644 index 000000000..99fc693dc --- /dev/null +++ b/bundle/nvim-treesitter/queries/heex/indents.scm @@ -0,0 +1,20 @@ +; HEEx tags, components, and slots indent like HTML +[ + (component) + (slot) + (tag) +] @indent + +; Dedent at the end of each tag, component, and slot +[ + (end_component) + (end_slot) + (end_tag) +] @branch @dedent + +; Self-closing tags and components should not change +; indentation level of sibling nodes +[ + (self_closing_component) + (self_closing_tag) +] @auto diff --git a/bundle/nvim-treesitter/queries/heex/injections.scm b/bundle/nvim-treesitter/queries/heex/injections.scm new file mode 100644 index 000000000..fffd1dc53 --- /dev/null +++ b/bundle/nvim-treesitter/queries/heex/injections.scm @@ -0,0 +1,11 @@ +; HEEx directives can span multiple interpolated lines of Elixir +(directive [ + (expression_value) + (partial_expression_value) +] @elixir @combined) + +; HEEx Elixir expressions are always within a tag or component +(expression (expression_value) @elixir) + +; HEEx comments +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/heex/locals.scm b/bundle/nvim-treesitter/queries/heex/locals.scm new file mode 100644 index 000000000..4371bc979 --- /dev/null +++ b/bundle/nvim-treesitter/queries/heex/locals.scm @@ -0,0 +1,13 @@ +; HEEx tags, components, and slots are references +[ + (component_name) + (slot_name) + (tag_name) +] @reference + +; Create a new scope within each HEEx tag, component, and slot +[ + (component) + (slot) + (tag) +] @scope diff --git a/bundle/nvim-treesitter/queries/help/highlights.scm b/bundle/nvim-treesitter/queries/help/highlights.scm new file mode 100644 index 000000000..e2fb65533 --- /dev/null +++ b/bundle/nvim-treesitter/queries/help/highlights.scm @@ -0,0 +1,14 @@ +(headline) @text.title +(column_heading) @text.title +(tag + "*" @conceal (#set! conceal "") + name: (_) @label) +(option + "'" @conceal (#set! conceal "") + name: (_) @text.literal) +(hotlink + "|" @conceal (#set! conceal "") + destination: (_) @text.uri) +(backtick + "`" @conceal (#set! conceal "") + content: (_) @string) diff --git a/bundle/nvim-treesitter/queries/hjson/folds.scm b/bundle/nvim-treesitter/queries/hjson/folds.scm new file mode 100644 index 000000000..41269219e --- /dev/null +++ b/bundle/nvim-treesitter/queries/hjson/folds.scm @@ -0,0 +1 @@ +; inherits: json diff --git a/bundle/nvim-treesitter/queries/hjson/highlights.scm b/bundle/nvim-treesitter/queries/hjson/highlights.scm new file mode 100644 index 000000000..c8eed139f --- /dev/null +++ b/bundle/nvim-treesitter/queries/hjson/highlights.scm @@ -0,0 +1,16 @@ +(true) @boolean +(false) @boolean +(null) @constant.builtin +(number) @number +(pair key: (string) @label) +(pair value: (string) @string) +(array (string) @string) +; (string_content (escape_sequence) @string.escape) +(ERROR) @error +; "," @punctuation.delimiter +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/hjson/indents.scm b/bundle/nvim-treesitter/queries/hjson/indents.scm new file mode 100644 index 000000000..26a42eeda --- /dev/null +++ b/bundle/nvim-treesitter/queries/hjson/indents.scm @@ -0,0 +1,3 @@ +; inherits: json + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/hjson/injections.scm b/bundle/nvim-treesitter/queries/hjson/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/hjson/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/hjson/locals.scm b/bundle/nvim-treesitter/queries/hjson/locals.scm new file mode 100644 index 000000000..41269219e --- /dev/null +++ b/bundle/nvim-treesitter/queries/hjson/locals.scm @@ -0,0 +1 @@ +; inherits: json diff --git a/bundle/nvim-treesitter/queries/hocon/highlights.scm b/bundle/nvim-treesitter/queries/hocon/highlights.scm new file mode 100644 index 000000000..3fb8249a9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/hocon/highlights.scm @@ -0,0 +1,37 @@ +(comment) @comment + +(null) @constant.builtin +[ (true) (false) ] @boolean +(number) @number +(unit) @keyword +(string) @string +(multiline_string) @string +(string (escape_sequence) @string.escape) +(unquoted_string) @string + +[ "url" + "file" + "classpath" + "required" +] @keyword + +(include "include" @include) + +(substitution ["${" "${?" "}"] @punctuation.special) +(substitution (_) @field) + +(path (_) @field) +(value [":" "=" "+=" ] @operator) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ "," ] @punctuation.delimiter +(unquoted_path "." @punctuation.delimiter) + diff --git a/bundle/nvim-treesitter/queries/hocon/injections.scm b/bundle/nvim-treesitter/queries/hocon/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/hocon/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/html/folds.scm b/bundle/nvim-treesitter/queries/html/folds.scm new file mode 100644 index 000000000..69b57eac5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/html/folds.scm @@ -0,0 +1,5 @@ +[ + (element) + (style_element) + (script_element) +] @fold diff --git a/bundle/nvim-treesitter/queries/html/highlights.scm b/bundle/nvim-treesitter/queries/html/highlights.scm new file mode 100644 index 000000000..6da261c0a --- /dev/null +++ b/bundle/nvim-treesitter/queries/html/highlights.scm @@ -0,0 +1,5 @@ +; inherits: html_tags + +(doctype) @constant + +"" + "" +] @tag.delimiter + +"=" @operator diff --git a/bundle/nvim-treesitter/queries/html_tags/indents.scm b/bundle/nvim-treesitter/queries/html_tags/indents.scm new file mode 100644 index 000000000..7b9d6afe1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/html_tags/indents.scm @@ -0,0 +1,11 @@ +[ + (element) +] @indent + +[ + (end_tag) + ">" + "/>" +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/html_tags/injections.scm b/bundle/nvim-treesitter/queries/html_tags/injections.scm new file mode 100644 index 000000000..80c0d2a4a --- /dev/null +++ b/bundle/nvim-treesitter/queries/html_tags/injections.scm @@ -0,0 +1,7 @@ +((style_element + (raw_text) @css)) + +((script_element + (raw_text) @javascript)) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/http/highlights.scm b/bundle/nvim-treesitter/queries/http/highlights.scm new file mode 100644 index 000000000..f5a08813b --- /dev/null +++ b/bundle/nvim-treesitter/queries/http/highlights.scm @@ -0,0 +1,19 @@ +; inherits: json + +; Display errors +(ERROR) @error + +; Comments +(comment) @comment + +(request + method: (method) @keyword + url: (url) @text.uri) + +(header + name: (name) @constant + value: (value)) + +; rest.nvim Neovim plugin specific features +(external_body + json_file: (json_file) @text.uri) @keyword diff --git a/bundle/nvim-treesitter/queries/http/injections.scm b/bundle/nvim-treesitter/queries/http/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/http/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/java/highlights.scm b/bundle/nvim-treesitter/queries/java/highlights.scm new file mode 100644 index 000000000..dfac3aadf --- /dev/null +++ b/bundle/nvim-treesitter/queries/java/highlights.scm @@ -0,0 +1,260 @@ +; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com) + +; Variables + +(identifier) @variable + +; Methods + +(method_declaration + name: (identifier) @method) +(method_invocation + name: (identifier) @method) + +(super) @function.builtin + +; Parameters +(formal_parameter + name: (identifier) @parameter) +(catch_formal_parameter + name: (identifier) @parameter) + +(spread_parameter + (variable_declarator) @parameter) ; int... foo + +;; Lambda parameter +(inferred_parameters (identifier) @parameter) ; (x,y) -> ... +(lambda_expression + parameters: (identifier) @parameter) ; x -> ... + + +; Annotations + + +(annotation + name: (identifier) @attribute) +(marker_annotation + name: (identifier) @attribute) + + +; Operators + +[ +"@" +"+" +":" +"++" +"-" +"--" +"&" +"&&" +"|" +"||" +"!=" +"==" +"*" +"/" +"%" +"<" +"<=" +">" +">=" +"=" +"-=" +"+=" +"*=" +"/=" +"%=" +"->" +"^" +"^=" +"&=" +"|=" +"~" +">>" +">>>" +"<<" +"::" +] @operator + +; Types + +(interface_declaration + name: (identifier) @type) +(class_declaration + name: (identifier) @type) +(record_declaration + name: (identifier) @type) +(enum_declaration + name: (identifier) @type) +(constructor_declaration + name: (identifier) @type) +(type_identifier) @type +((method_invocation + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) +((method_reference + . (identifier) @type) + (#lua-match? @type "^[A-Z]")) + + + +((field_access + object: (identifier) @type) + (#lua-match? @type "^[A-Z]")) +((scoped_identifier + scope: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +; Fields + +(field_declaration + declarator: (variable_declarator) @field) + +(field_access + field: (identifier) @field) + +[ +(boolean_type) +(integral_type) +(floating_point_type) +(void_type) +] @type.builtin + +; Variables + +((identifier) @constant + (#lua-match? @constant "^[A-Z_][A-Z%d_]+$")) + +(this) @variable.builtin + +; Literals + +[ +(hex_integer_literal) +(decimal_integer_literal) +(octal_integer_literal) +(binary_integer_literal) +] @number + +[ +(decimal_floating_point_literal) +(hex_floating_point_literal) +] @float + +(character_literal) @character +(string_literal) @string +(null_literal) @constant.builtin + +[ + (line_comment) + (block_comment) +] @comment + +[ +(true) +(false) +] @boolean + +; Keywords + +[ +"abstract" +"assert" +"break" +"class" +"record" +"continue" +"default" +"enum" +"exports" +"extends" +"final" +"implements" +"instanceof" +"interface" +"module" +"native" +"open" +"opens" +"package" +"private" +"protected" +"provides" +"public" +"requires" +"static" +"strictfp" +"synchronized" +"to" +"transient" +"transitive" +"uses" +"volatile" +"with" +] @keyword + +[ +"return" +"yield" +] @keyword.return + +[ + "new" +] @keyword.operator + +; Conditionals + +[ +"if" +"else" +"switch" +"case" +] @conditional + +(ternary_expression ["?" ":"] @conditional) + +; + +[ +"for" +"while" +"do" +] @repeat + +; Includes + +"import" @include +"package" @include + +; Punctuation + +[ +";" +"." +"..." +"," +] @punctuation.delimiter + +[ +"[" +"]" +"{" +"}" +"(" +")" +] @punctuation.bracket + +; Exceptions + +[ +"throw" +"throws" +"finally" +"try" +"catch" +] @exception + +; Labels +(labeled_statement + (identifier) @label) diff --git a/bundle/nvim-treesitter/queries/java/indents.scm b/bundle/nvim-treesitter/queries/java/indents.scm new file mode 100644 index 000000000..8e5375486 --- /dev/null +++ b/bundle/nvim-treesitter/queries/java/indents.scm @@ -0,0 +1,34 @@ +[ + (class_body) + (enum_body) + (interface_body) + (constructor_declaration) + (constructor_body) + (block) + (switch_block) + (array_initializer) + (argument_list) + (formal_parameters) +] @indent + +(expression_statement (method_invocation) @indent) + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @branch + +[ + "}" +] @indent_end + +(line_comment) @ignore + +[ + (ERROR) + (block_comment) +] @auto diff --git a/bundle/nvim-treesitter/queries/java/injections.scm b/bundle/nvim-treesitter/queries/java/injections.scm new file mode 100644 index 000000000..e4fd85f1c --- /dev/null +++ b/bundle/nvim-treesitter/queries/java/injections.scm @@ -0,0 +1 @@ +[(block_comment) (line_comment)] @comment diff --git a/bundle/nvim-treesitter/queries/java/locals.scm b/bundle/nvim-treesitter/queries/java/locals.scm new file mode 100644 index 000000000..a7a624289 --- /dev/null +++ b/bundle/nvim-treesitter/queries/java/locals.scm @@ -0,0 +1,77 @@ +; SCOPES +; declarations +(program) @scope +(class_declaration + body: (_) @scope) +(record_declaration + body: (_) @scope) +(enum_declaration + body: (_) @scope) +(lambda_expression) @scope +(enhanced_for_statement) @scope + +; block +(block) @scope + +; if/else +(if_statement) @scope ; if+else +(if_statement + consequence: (_) @scope) ; if body in case there are no braces +(if_statement + alternative: (_) @scope) ; else body in case there are no braces + +; try/catch +(try_statement) @scope ; covers try+catch, individual try and catch are covered by (block) +(catch_clause) @scope ; needed because `Exception` variable + +; loops +(for_statement) @scope ; whole for_statement because loop iterator variable +(for_statement ; "for" body in case there are no braces + body: (_) @scope) +(do_statement + body: (_) @scope) +(while_statement + body: (_) @scope) + +; Functions + +(constructor_declaration) @scope +(method_declaration) @scope + + +; DEFINITIONS +(package_declaration + (identifier) @definition.namespace) +(class_declaration + name: (identifier) @definition.type) +(record_declaration + name: (identifier) @definition.type) +(enum_declaration + name: (identifier) @definition.enum) +(method_declaration + name: (identifier) @definition.method) + +(local_variable_declaration + declarator: (variable_declarator + name: (identifier) @definition.var)) +(formal_parameter + name: (identifier) @definition.var) +(catch_formal_parameter + name: (identifier) @definition.var) +(inferred_parameters (identifier) @definition.var) ; (x,y) -> ... +(lambda_expression + parameters: (identifier) @definition.var) ; x -> ... +(enhanced_for_statement ; for (var item : items) { + name: (identifier) @definition.var) + +((scoped_identifier + (identifier) @definition.import) + (#has-ancestor? @definition.import import_declaration)) + +(field_declaration + declarator: (variable_declarator + name: (identifier) @definition.field)) + +; REFERENCES +(identifier) @reference +(type_identifier) @reference diff --git a/bundle/nvim-treesitter/queries/javascript/folds.scm b/bundle/nvim-treesitter/queries/javascript/folds.scm new file mode 100644 index 000000000..b6d9b28bf --- /dev/null +++ b/bundle/nvim-treesitter/queries/javascript/folds.scm @@ -0,0 +1 @@ +; inherits: ecma,jsx diff --git a/bundle/nvim-treesitter/queries/javascript/highlights.scm b/bundle/nvim-treesitter/queries/javascript/highlights.scm new file mode 100644 index 000000000..57634434e --- /dev/null +++ b/bundle/nvim-treesitter/queries/javascript/highlights.scm @@ -0,0 +1,33 @@ +; inherits: ecma,jsx + +;;; Parameters +(formal_parameters (identifier) @parameter) + +(formal_parameters + (rest_pattern + (identifier) @parameter)) + +;; ({ a }) => null +(formal_parameters + (object_pattern + (shorthand_property_identifier_pattern) @parameter)) + +;; ({ a: b }) => null +(formal_parameters + (object_pattern + (pair_pattern + value: (identifier) @parameter))) + +;; ([ a ]) => null +(formal_parameters + (array_pattern + (identifier) @parameter)) + +;; a => null +(arrow_function + parameter: (identifier) @parameter) + +;; optional parameters +(formal_parameters + (assignment_pattern + left: (identifier) @parameter)) diff --git a/bundle/nvim-treesitter/queries/javascript/indents.scm b/bundle/nvim-treesitter/queries/javascript/indents.scm new file mode 100644 index 000000000..b6d9b28bf --- /dev/null +++ b/bundle/nvim-treesitter/queries/javascript/indents.scm @@ -0,0 +1 @@ +; inherits: ecma,jsx diff --git a/bundle/nvim-treesitter/queries/javascript/injections.scm b/bundle/nvim-treesitter/queries/javascript/injections.scm new file mode 100644 index 000000000..b6d9b28bf --- /dev/null +++ b/bundle/nvim-treesitter/queries/javascript/injections.scm @@ -0,0 +1 @@ +; inherits: ecma,jsx diff --git a/bundle/nvim-treesitter/queries/javascript/locals.scm b/bundle/nvim-treesitter/queries/javascript/locals.scm new file mode 100644 index 000000000..f4f0e92de --- /dev/null +++ b/bundle/nvim-treesitter/queries/javascript/locals.scm @@ -0,0 +1,33 @@ +; inherits: ecma,jsx + +(formal_parameters + (identifier) @definition.parameter) + +; function(arg = []) { +(formal_parameters + (assignment_pattern + left: (identifier) @definition.parameter)) + +; x => x +(arrow_function + parameter: (identifier) @definition.parameter) + +;; ({ a }) => null +(formal_parameters + (object_pattern + (shorthand_property_identifier_pattern) @definition.parameter)) + +;; ({ a: b }) => null +(formal_parameters + (object_pattern + (pair_pattern + value: (identifier) @definition.parameter))) + +;; ([ a ]) => null +(formal_parameters + (array_pattern + (identifier) @definition.parameter)) + +(formal_parameters + (rest_pattern + (identifier) @definition.parameter)) diff --git a/bundle/nvim-treesitter/queries/jsdoc/highlights.scm b/bundle/nvim-treesitter/queries/jsdoc/highlights.scm new file mode 100644 index 000000000..4b4266c9f --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsdoc/highlights.scm @@ -0,0 +1,2 @@ +(tag_name) @keyword +(type) @type diff --git a/bundle/nvim-treesitter/queries/json/folds.scm b/bundle/nvim-treesitter/queries/json/folds.scm new file mode 100644 index 000000000..4c2b9d32e --- /dev/null +++ b/bundle/nvim-treesitter/queries/json/folds.scm @@ -0,0 +1,5 @@ +[ + (pair) + (object) + (array) +] @fold diff --git a/bundle/nvim-treesitter/queries/json/highlights.scm b/bundle/nvim-treesitter/queries/json/highlights.scm new file mode 100644 index 000000000..1ac778982 --- /dev/null +++ b/bundle/nvim-treesitter/queries/json/highlights.scm @@ -0,0 +1,16 @@ +(true) @boolean +(false) @boolean +(null) @constant.builtin +(number) @number +(pair key: (string) @label) +(pair value: (string) @string) +(array (string) @string) +(string_content (escape_sequence) @string.escape) +(ERROR) @error +["," ":"] @punctuation.delimiter +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +(("\"" @conceal) (#set! conceal "")) diff --git a/bundle/nvim-treesitter/queries/json/indents.scm b/bundle/nvim-treesitter/queries/json/indents.scm new file mode 100644 index 000000000..0345b945b --- /dev/null +++ b/bundle/nvim-treesitter/queries/json/indents.scm @@ -0,0 +1,9 @@ +[ + (object) + (array) +] @indent + +[ + "}" + "]" +] @branch diff --git a/bundle/nvim-treesitter/queries/json/locals.scm b/bundle/nvim-treesitter/queries/json/locals.scm new file mode 100644 index 000000000..6609a2d22 --- /dev/null +++ b/bundle/nvim-treesitter/queries/json/locals.scm @@ -0,0 +1,4 @@ +[ + (object) + (array) +] @scope diff --git a/bundle/nvim-treesitter/queries/json5/highlights.scm b/bundle/nvim-treesitter/queries/json5/highlights.scm new file mode 100644 index 000000000..4e41971ba --- /dev/null +++ b/bundle/nvim-treesitter/queries/json5/highlights.scm @@ -0,0 +1,17 @@ +[ + "true" + "false" +] @boolean + +"null" @constant + +(string) @string + +(number) @number + +(comment) @comment + +(member + name: (_) @keyword) + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/json5/injections.scm b/bundle/nvim-treesitter/queries/json5/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/json5/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/jsonc/folds.scm b/bundle/nvim-treesitter/queries/jsonc/folds.scm new file mode 100644 index 000000000..41269219e --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsonc/folds.scm @@ -0,0 +1 @@ +; inherits: json diff --git a/bundle/nvim-treesitter/queries/jsonc/highlights.scm b/bundle/nvim-treesitter/queries/jsonc/highlights.scm new file mode 100644 index 000000000..a51c5c7e7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsonc/highlights.scm @@ -0,0 +1,3 @@ +; inherits: json + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/jsonc/indents.scm b/bundle/nvim-treesitter/queries/jsonc/indents.scm new file mode 100644 index 000000000..26a42eeda --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsonc/indents.scm @@ -0,0 +1,3 @@ +; inherits: json + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/jsonc/injections.scm b/bundle/nvim-treesitter/queries/jsonc/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsonc/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/jsonc/locals.scm b/bundle/nvim-treesitter/queries/jsonc/locals.scm new file mode 100644 index 000000000..41269219e --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsonc/locals.scm @@ -0,0 +1 @@ +; inherits: json diff --git a/bundle/nvim-treesitter/queries/jsx/folds.scm b/bundle/nvim-treesitter/queries/jsx/folds.scm new file mode 100644 index 000000000..93c3d9c8c --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsx/folds.scm @@ -0,0 +1 @@ +(jsx_element) @fold diff --git a/bundle/nvim-treesitter/queries/jsx/highlights.scm b/bundle/nvim-treesitter/queries/jsx/highlights.scm new file mode 100644 index 000000000..1f19c6b2a --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsx/highlights.scm @@ -0,0 +1,36 @@ +(jsx_element + open_tag: (jsx_opening_element ["<" ">"] @tag.delimiter)) +(jsx_element + close_tag: (jsx_closing_element ["<" "/" ">"] @tag.delimiter)) +(jsx_self_closing_element ["/" ">" "<"] @tag.delimiter) +(jsx_fragment [">" "<" "/"] @tag.delimiter) +(jsx_attribute (property_identifier) @tag.attribute) + +(jsx_opening_element + name: (identifier) @tag) + +(jsx_closing_element + name: (identifier) @tag) + +(jsx_self_closing_element + name: (identifier) @tag) + +(jsx_opening_element ((identifier) @constructor + (#lua-match? @constructor "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_opening_element ((nested_identifier (identifier) @tag (identifier) @constructor))) + +(jsx_closing_element ((identifier) @constructor + (#lua-match? @constructor "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor))) + +(jsx_self_closing_element ((identifier) @constructor + (#lua-match? @constructor "^[A-Z]"))) + +; Handle the dot operator effectively - +(jsx_self_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor))) + +(jsx_text) @none diff --git a/bundle/nvim-treesitter/queries/jsx/indents.scm b/bundle/nvim-treesitter/queries/jsx/indents.scm new file mode 100644 index 000000000..d1a12be9c --- /dev/null +++ b/bundle/nvim-treesitter/queries/jsx/indents.scm @@ -0,0 +1,12 @@ +[ + (jsx_fragment) + (jsx_element) + (jsx_self_closing_element) +] @indent + +(parenthesized_expression) @indent + +[ + (jsx_closing_element) + ">" +] @branch diff --git a/bundle/nvim-treesitter/queries/julia/folds.scm b/bundle/nvim-treesitter/queries/julia/folds.scm new file mode 100644 index 000000000..a8cfc9406 --- /dev/null +++ b/bundle/nvim-treesitter/queries/julia/folds.scm @@ -0,0 +1,17 @@ +[ + (module_definition) + (struct_definition) + (macro_definition) + (function_definition) + + (if_statement) + (try_statement) + (for_statement) + (while_statement) + (let_statement) + (quote_statement) + + (do_clause) + (compound_expression) +] @fold + diff --git a/bundle/nvim-treesitter/queries/julia/highlights.scm b/bundle/nvim-treesitter/queries/julia/highlights.scm new file mode 100644 index 000000000..a355367a5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/julia/highlights.scm @@ -0,0 +1,190 @@ +(identifier) @variable +;; In case you want type highlighting based on Julia naming conventions (this might collide with mathematical notation) +;((identifier) @type ; exception: mark `A_foo` sort of identifiers as variables + ;(match? @type "^[A-Z][^_]")) +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_]{2}[A-Z_]*$")) + +[ + (triple_string) + (string) +] @string +(command_string) @string.special + +(string + prefix: (identifier) @constant.builtin) + +(macro_identifier) @function.macro +(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight +(macro_definition + name: (identifier) @function.macro + ["macro" "end" @keyword]) + +(field_expression + (identifier) + (identifier) @field .) + +(function_definition + name: (identifier) @function) +(call_expression + (identifier) @function) +(call_expression + (field_expression (identifier) @method .)) +(broadcast_call_expression + (identifier) @function) +(broadcast_call_expression + (field_expression (identifier) @method .)) +(parameter_list + (identifier) @parameter) +(parameter_list + (optional_parameter . + (identifier) @parameter)) +(typed_parameter + (identifier) @parameter + (identifier) @type) +(type_parameter_list + (identifier) @type) +(typed_parameter + (identifier) @parameter + (parameterized_identifier) @type) +(function_expression + . (identifier) @parameter) +(spread_parameter) @parameter +(spread_parameter + (identifier) @parameter) +(named_argument + . (identifier) @parameter) +(argument_list + (typed_expression + (identifier) @parameter + (identifier) @type)) +(argument_list + (typed_expression + (identifier) @parameter + (parameterized_identifier) @type)) + +;; Symbol expressions (:my-wanna-be-lisp-keyword) +(quote_expression + (identifier)) @symbol + +;; Parsing error! foo (::Type) gets parsed as two quote expressions +(argument_list + (quote_expression + (quote_expression + (identifier) @type))) + +(type_argument_list + (identifier) @type) +(parameterized_identifier (_)) @type +(argument_list + (typed_expression . (identifier) @parameter)) + +(typed_expression + (identifier) @type .) +(typed_expression + (parameterized_identifier) @type .) + +(abstract_definition + name: (identifier) @type) +(struct_definition + name: (identifier) @type) + +(number) @number +(range_expression + (identifier) @number + (#eq? @number "end")) +(range_expression + (_ + (identifier) @number + (#eq? @number "end"))) +(coefficient_expression + (number) + (identifier) @constant.builtin) + +;; TODO: operators. +;; Those are a bit difficult to implement since the respective nodes are hidden right now (_power_operator) +;; and heavily use Unicode chars (support for those are bad in vim/lua regexes) +;[; + ;(power_operator); + ;(times_operator); + ;(plus_operator); + ;(arrow_operator); + ;(comparison_operator); + ;(assign_operator); +;] @operator ; + +"end" @keyword + +(if_statement + ["if" "end"] @conditional) +(elseif_clause + ["elseif"] @conditional) +(else_clause + ["else"] @conditional) +(ternary_expression + ["?" ":"] @conditional) + +(function_definition ["function" "end"] @keyword.function) + +[ + (comment) + (block_comment) +] @comment + +[ + "abstract" + "const" + "macro" + "primitive" + "struct" + "type" +] @keyword + +"return" @keyword.return + +((identifier) @keyword (#any-of? @keyword "global" "local")) + +(compound_expression + ["begin" "end"] @keyword) +(try_statement + ["try" "end" ] @exception) +(finally_clause + "finally" @exception) +(catch_clause + "catch" @exception) +(quote_statement + ["quote" "end"] @keyword) +(let_statement + ["let" "end"] @keyword) +(for_statement + ["for" "end"] @repeat) +(while_statement + ["while" "end"] @repeat) +(break_statement) @repeat +(continue_statement) @repeat +(for_binding + "in" @repeat) +(for_clause + "for" @repeat) +(do_clause + ["do" "end"] @keyword) + +(export_statement + ["export"] @include) + +(import_statement + ["import" "using"] @include) + +(module_definition + ["module" "end"] @include) + +((identifier) @include (#eq? @include "baremodule")) + +(((identifier) @constant.builtin) (#match? @constant.builtin "^(nothing|Inf|NaN)$")) +(((identifier) @boolean) (#eq? @boolean "true")) +(((identifier) @boolean) (#eq? @boolean "false")) + +(range_expression ":" @operator) +(quote_expression ":" @symbol) +["::" "." "," "..." "!"] @punctuation.delimiter +["[" "]" "(" ")" "{" "}"] @punctuation.bracket diff --git a/bundle/nvim-treesitter/queries/julia/indents.scm b/bundle/nvim-treesitter/queries/julia/indents.scm new file mode 100644 index 000000000..3c87a05fb --- /dev/null +++ b/bundle/nvim-treesitter/queries/julia/indents.scm @@ -0,0 +1,42 @@ +[ + (struct_definition) + (macro_definition) + (function_definition) + + (if_statement) + (try_statement) + (for_statement) + (while_statement) + (let_statement) + (quote_statement) + + (do_clause) + (compound_expression) + + (assignment_expression) + (binary_expression) + (call_expression) + + (array_expression) + (tuple_expression) + (matrix_expression) +] @indent + +[ + "end" + "(" + ")" + "[" + "]" + (else_clause) + (elseif_clause) + (catch_clause) + (finally_clause) +] @branch + +[ + (comment) + (block_comment) + (triple_string) +] @ignore + diff --git a/bundle/nvim-treesitter/queries/julia/injections.scm b/bundle/nvim-treesitter/queries/julia/injections.scm new file mode 100644 index 000000000..77c503455 --- /dev/null +++ b/bundle/nvim-treesitter/queries/julia/injections.scm @@ -0,0 +1,8 @@ +; TODO: re-add when markdown is added. +; ((triple_string) @markdown +; (#offset! @markdown 0 3 0 -3)) + +[ + (comment) + (block_comment) +] @comment diff --git a/bundle/nvim-treesitter/queries/julia/locals.scm b/bundle/nvim-treesitter/queries/julia/locals.scm new file mode 100644 index 000000000..f8b34f71d --- /dev/null +++ b/bundle/nvim-treesitter/queries/julia/locals.scm @@ -0,0 +1,59 @@ + +(import_statement + (identifier) @definition.import) +(variable_declaration + (identifier) @definition.var) +(variable_declaration + (tuple_expression + (identifier) @definition.var)) +(for_binding + (identifier) @definition.var) +(for_binding + (tuple_expression + (identifier) @definition.var)) + +(assignment_expression + (tuple_expression + (identifier) @definition.var)) +(assignment_expression + (bare_tuple_expression + (identifier) @definition.var)) +(assignment_expression + (identifier) @definition.var) + +(type_parameter_list + (identifier) @definition.type) +(type_argument_list + (identifier) @definition.type) +(struct_definition + name: (identifier) @definition.type) + +(parameter_list + (identifier) @definition.parameter) +(typed_parameter + (identifier) @definition.parameter + (identifier)) +(function_expression + . (identifier) @definition.parameter) +(argument_list + (typed_expression + (identifier) @definition.parameter + (identifier))) +(spread_parameter + (identifier) @definition.parameter) + +(function_definition + name: (identifier) @definition.function) @scope +(macro_definition + name: (identifier) @definition.macro) @scope + +(identifier) @reference + +[ + (try_statement) + (finally_clause) + (quote_statement) + (let_statement) + (compound_expression) + (for_statement) +] @scope diff --git a/bundle/nvim-treesitter/queries/kotlin/folds.scm b/bundle/nvim-treesitter/queries/kotlin/folds.scm new file mode 100644 index 000000000..768972b8b --- /dev/null +++ b/bundle/nvim-treesitter/queries/kotlin/folds.scm @@ -0,0 +1,17 @@ +[ + (import_list) + + (when_expression) + (control_structure_body) + + (lambda_literal) + (function_body) + (primary_constructor) + (secondary_constructor) + (anonymous_initializer) + + (class_body) + (enum_class_body) + + (interpolated_expression) +] @fold diff --git a/bundle/nvim-treesitter/queries/kotlin/highlights.scm b/bundle/nvim-treesitter/queries/kotlin/highlights.scm new file mode 100644 index 000000000..2567a74c1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/kotlin/highlights.scm @@ -0,0 +1,409 @@ +;;; Identifiers + +(simple_identifier) @variable + +; `it` keyword inside lambdas +; FIXME: This will highlight the keyword outside of lambdas since tree-sitter +; does not allow us to check for arbitrary nestation +((simple_identifier) @variable.builtin +(#eq? @variable.builtin "it")) + +; `field` keyword inside property getter/setter +; FIXME: This will highlight the keyword outside of getters and setters +; since tree-sitter does not allow us to check for arbitrary nestation +((simple_identifier) @variable.builtin +(#eq? @variable.builtin "field")) + +; `this` this keyword inside classes +(this_expression) @variable.builtin + +; `super` keyword inside classes +(super_expression) @variable.builtin + +(class_parameter + (simple_identifier) @property) + +(class_body + (property_declaration + (variable_declaration + (simple_identifier) @property))) + +; id_1.id_2.id_3: `id_2` and `id_3` are assumed as object properties +(_ + (navigation_suffix + (simple_identifier) @property)) + +; SCREAMING CASE identifiers are assumed to be constants +((simple_identifier) @constant +(#lua-match? @constant "^[A-Z][A-Z0-9_]*$")) + +(_ + (navigation_suffix + (simple_identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]*$"))) + +(enum_entry + (simple_identifier) @constant) + +(type_identifier) @type + +((type_identifier) @type.builtin + (#any-of? @type.builtin + "Byte" + "Short" + "Int" + "Long" + "UByte" + "UShort" + "UInt" + "ULong" + "Float" + "Double" + "Boolean" + "Char" + "String" + "Array" + "ByteArray" + "ShortArray" + "IntArray" + "LongArray" + "UByteArray" + "UShortArray" + "UIntArray" + "ULongArray" + "FloatArray" + "DoubleArray" + "BooleanArray" + "CharArray" + "Map" + "Set" + "List" + "EmptyMap" + "EmptySet" + "EmptyList" + "MutableMap" + "MutableSet" + "MutableList" +)) + +(package_header + . (identifier)) @namespace + +(import_header + "import" @include) + +; The last `simple_identifier` in a `import_header` will always either be a function +; or a type. Classes can appear anywhere in the import path, unlike functions +(import_header + (identifier + (simple_identifier) @type @_import) + (import_alias + (type_identifier) @type)? + (#lua-match? @_import "^[A-Z]")) + +(import_header + (identifier + (simple_identifier) @function @_import .) + (import_alias + (type_identifier) @function)? + (#lua-match? @_import "^[a-z]")) + +; TODO: Seperate labeled returns/breaks/continue/super/this +; Must be implemented in the parser first +(label) @label + +;;; Function definitions + +(function_declaration + . (simple_identifier) @function) + +(getter + ("get") @function.builtin) +(setter + ("set") @function.builtin) + +(primary_constructor) @constructor +(secondary_constructor + ("constructor") @constructor) + +(constructor_invocation + (user_type + (type_identifier) @constructor)) + +(anonymous_initializer + ("init") @constructor) + +(parameter + (simple_identifier) @parameter) + +(parameter_with_optional_type + (simple_identifier) @parameter) + +; lambda parameters +(lambda_literal + (lambda_parameters + (variable_declaration + (simple_identifier) @parameter))) + +;;; Function calls + +; function() +(call_expression + . (simple_identifier) @function) + +; object.function() or object.property.function() +(call_expression + (navigation_expression + (navigation_suffix + (simple_identifier) @function) . )) + +(call_expression + . (simple_identifier) @function.builtin + (#any-of? @function.builtin + "arrayOf" + "arrayOfNulls" + "byteArrayOf" + "shortArrayOf" + "intArrayOf" + "longArrayOf" + "ubyteArrayOf" + "ushortArrayOf" + "uintArrayOf" + "ulongArrayOf" + "floatArrayOf" + "doubleArrayOf" + "booleanArrayOf" + "charArrayOf" + "emptyArray" + "mapOf" + "setOf" + "listOf" + "emptyMap" + "emptySet" + "emptyList" + "mutableMapOf" + "mutableSetOf" + "mutableListOf" + "print" + "println" + "error" + "TODO" + "run" + "runCatching" + "repeat" + "lazy" + "lazyOf" + "enumValues" + "enumValueOf" + "assert" + "check" + "checkNotNull" + "require" + "requireNotNull" + "with" + "suspend" + "synchronized" +)) + +;;; Literals + +[ + (comment) + (shebang_line) +] @comment + +(real_literal) @float +[ + (integer_literal) + (long_literal) + (hex_literal) + (bin_literal) + (unsigned_literal) +] @number + +[ + "null" ; should be highlighted the same as booleans + (boolean_literal) +] @boolean + +(character_literal) @character + +[ + (line_string_literal) + (multi_line_string_literal) +] @string + +; NOTE: Escapes not allowed in multi-line strings +(line_string_literal (character_escape_seq) @string.escape) + +; There are 3 ways to define a regex +; - "[abc]?".toRegex() +(call_expression + (navigation_expression + ([(line_string_literal) (multi_line_string_literal)] @string.regex) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "toRegex"))))) + +; - Regex("[abc]?") +(call_expression + ((simple_identifier) @_function + (#eq? @_function "Regex")) + (call_suffix + (value_arguments + (value_argument + [ (line_string_literal) (multi_line_string_literal) ] @string.regex)))) + +; - Regex.fromLiteral("[abc]?") +(call_expression + (navigation_expression + ((simple_identifier) @_class + (#eq? @_class "Regex")) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "fromLiteral")))) + (call_suffix + (value_arguments + (value_argument + [ (line_string_literal) (multi_line_string_literal) ] @string.regex)))) + +;;; Keywords + +(type_alias "typealias" @keyword) +[ + (class_modifier) + (member_modifier) + (function_modifier) + (property_modifier) + (platform_modifier) + (variance_modifier) + (parameter_modifier) + (visibility_modifier) + (reification_modifier) + (inheritance_modifier) +]@keyword + +[ + "val" + "var" + "enum" + "class" + "object" + "interface" +; "typeof" ; NOTE: It is reserved for future use +] @keyword + +("fun") @keyword.function + +(jump_expression) @keyword.return + +[ + "if" + "else" + "when" +] @conditional + +[ + "for" + "do" + "while" +] @repeat + +[ + "try" + "catch" + "throw" + "finally" +] @exception + + +(annotation + "@" @attribute (use_site_target)? @attribute) +(annotation + (user_type + (type_identifier) @attribute)) +(annotation + (constructor_invocation + (user_type + (type_identifier) @attribute))) + +(file_annotation + "@" @attribute "file" @attribute ":" @attribute) +(file_annotation + (user_type + (type_identifier) @attribute)) +(file_annotation + (constructor_invocation + (user_type + (type_identifier) @attribute))) + +;;; Operators & Punctuation + +[ + "!" + "!=" + "!==" + "=" + "==" + "===" + ">" + ">=" + "<" + "<=" + "||" + "&&" + "+" + "++" + "+=" + "-" + "--" + "-=" + "*" + "*=" + "/" + "/=" + "%" + "%=" + "?." + "?:" + "!!" + "is" + "!is" + "in" + "!in" + "as" + "as?" + ".." + "->" +] @operator + +[ + "(" ")" + "[" "]" + "{" "}" +] @punctuation.bracket + +[ + "." + "," + ";" + ":" + "::" +] @punctuation.delimiter + +; NOTE: `interpolated_identifier`s can be highlighted in any way +(line_string_literal + "$" @punctuation.special + (interpolated_identifier) @none) +(line_string_literal + "${" @punctuation.special + (interpolated_expression) @none + "}" @punctuation.special) + +(multi_line_string_literal + "$" @punctuation.special + (interpolated_identifier) @none) +(multi_line_string_literal + "${" @punctuation.special + (interpolated_expression) @none + "}" @punctuation.special) diff --git a/bundle/nvim-treesitter/queries/kotlin/injections.scm b/bundle/nvim-treesitter/queries/kotlin/injections.scm new file mode 100644 index 000000000..371345cfd --- /dev/null +++ b/bundle/nvim-treesitter/queries/kotlin/injections.scm @@ -0,0 +1,32 @@ +(comment) @comment + +; There are 3 ways to define a regex +; - "[abc]?".toRegex() +(call_expression + (navigation_expression + ([(line_string_literal) (multi_line_string_literal)] @regex) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "toRegex"))))) + +; - Regex("[abc]?") +(call_expression + ((simple_identifier) @_function + (#eq? @_function "Regex")) + (call_suffix + (value_arguments + (value_argument + [ (line_string_literal) (multi_line_string_literal) ] @regex)))) + +; - Regex.fromLiteral("[abc]?") +(call_expression + (navigation_expression + ((simple_identifier) @_class + (#eq? @_class "Regex")) + (navigation_suffix + ((simple_identifier) @_function + (#eq? @_function "fromLiteral")))) + (call_suffix + (value_arguments + (value_argument + [ (line_string_literal) (multi_line_string_literal) ] @regex)))) diff --git a/bundle/nvim-treesitter/queries/kotlin/locals.scm b/bundle/nvim-treesitter/queries/kotlin/locals.scm new file mode 100644 index 000000000..d1b45f276 --- /dev/null +++ b/bundle/nvim-treesitter/queries/kotlin/locals.scm @@ -0,0 +1,83 @@ +;;; Imports + +(package_header + . (identifier) @definition.namespace) + +(import_header + (identifier + (simple_identifier) @definition.import .) + (import_alias + (type_identifier) @definition.import)?) + +;;; Functions + +(function_declaration + . (simple_identifier) @definition.function + (#set! "definition.function.scope" "parent")) + +(class_body + (function_declaration + . (simple_identifier) @definition.method) + (#set! "definition.method.scope" "parent")) + +;;; Variables + +(function_declaration + (parameter + (simple_identifier) @definition.parameter)) + +(lambda_literal + (lambda_parameters + (variable_declaration + (simple_identifier) @definition.parameter))) + +(class_body + (property_declaration + (variable_declaration + (simple_identifier) @definition.field))) + +(class_declaration + (primary_constructor + (class_parameter + (simple_identifier) @definition.field))) + +(enum_class_body + (enum_entry + (simple_identifier) @definition.field)) + +(variable_declaration + (simple_identifier) @definition.var) + +;;; Types + +(class_declaration + (type_identifier) @definition.type + (#set! "definition.type.scope" "parent")) + +(type_alias + (type_identifier) @definition.type + (#set! "definition.type.scope" "parent")) + +;;; Scopes + +[ + (if_expression) + (when_expression) + (when_entry) + + (for_statement) + (while_statement) + (do_while_statement) + + (lambda_literal) + (function_declaration) + (primary_constructor) + (secondary_constructor) + (anonymous_initializer) + + (class_declaration) + (enum_class_body) + (enum_entry) + + (interpolated_expression) +] @scope diff --git a/bundle/nvim-treesitter/queries/lalrpop/highlights.scm b/bundle/nvim-treesitter/queries/lalrpop/highlights.scm new file mode 100644 index 000000000..34040dd5f --- /dev/null +++ b/bundle/nvim-treesitter/queries/lalrpop/highlights.scm @@ -0,0 +1,57 @@ +[ + "pub" + "grammar" + "match" + "extern" + "type" + "enum" +] @keyword + +[ + "+" + "*" + "?" +] @operator + +(grammar_type_params + "<" @punctuation.bracket + ">" @punctuation.bracket) + +(symbol + "<" @punctuation.bracket + ">" @punctuation.bracket) + +(binding_symbol + "<" @punctuation.bracket + ">" @punctuation.bracket) + +(binding_symbol + name: (identifier) @parameter) + +(bare_symbol + (macro + ((macro_id) @function))) + +(bare_symbol + (identifier) @function) + +(nonterminal_name + (macro_id) @function) + +(nonterminal_name + (identifier) @function) + +(nonterminal + (type_ref) @type) + +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket + +";" @punctuation.delimiter + +(lifetime (identifier) @label) + +(string_literal) @string +(regex_literal) @string diff --git a/bundle/nvim-treesitter/queries/lalrpop/locals.scm b/bundle/nvim-treesitter/queries/lalrpop/locals.scm new file mode 100644 index 000000000..7a30cce9f --- /dev/null +++ b/bundle/nvim-treesitter/queries/lalrpop/locals.scm @@ -0,0 +1,5 @@ +(nonterminal_name + (macro_id) @definition.function) + +(nonterminal_name + (identifier) @definition.function) diff --git a/bundle/nvim-treesitter/queries/latex/folds.scm b/bundle/nvim-treesitter/queries/latex/folds.scm new file mode 100644 index 000000000..6769b2e6a --- /dev/null +++ b/bundle/nvim-treesitter/queries/latex/folds.scm @@ -0,0 +1,13 @@ +[ + (chapter) + (part) + (section) + (subsection) + (subsubsection) + (paragraph) + (subparagraph) + + (generic_environment) + (comment_environment) + (displayed_equation) +] @fold diff --git a/bundle/nvim-treesitter/queries/latex/highlights.scm b/bundle/nvim-treesitter/queries/latex/highlights.scm new file mode 100644 index 000000000..bfa3edbc6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/latex/highlights.scm @@ -0,0 +1,255 @@ +;; General syntax +(ERROR) @error + +(generic_command) @function +(caption + command: _ @function) + +(key_value_pair + key: (_) @parameter + value: (_)) + +[ + (line_comment) + (block_comment) + (comment_environment) +] @comment + +[ + (brack_group) + (brack_group_argc) +] @parameter + +[(operator) "="] @operator + +"\\item" @punctuation.special + +((word) @punctuation.delimiter +(#eq? @punctuation.delimiter "&")) + +["[" "]" "{" "}"] @punctuation.bracket ; "(" ")" has no syntactical meaning in LaTeX + +;; General environments +(begin + command: _ @text.environment + name: (curly_group_text + (text) @text.environment.name) + (#not-any-of? @text.environment.name + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) + +(end + command: _ @text.environment + name: (curly_group_text + (text) @text.environment.name) + (#not-any-of? @text.environment.name + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) + +;; Definitions and references +(new_command_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) +(old_command_definition + command: _ @function.macro + declaration: (_) @function) +(let_command_definition + command: _ @function.macro + declaration: (_) @function) + +(theorem_definition + command: _ @function.macro + name: (curly_group_text (_) @text.environment.name)) + +(label_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(label_reference_range + command: _ @function.macro + from: (curly_group_text (_) @text.reference) + to: (curly_group_text (_) @text.reference)) +(label_reference + command: _ @function.macro + names: (curly_group_text_list (_) @text.reference)) +(label_number + command: _ @function.macro + name: (curly_group_text (_) @text.reference) + number: (_) @text.reference) + +(citation + command: _ @function.macro + keys: (curly_group_text_list) @text.reference) + +(glossary_entry_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(glossary_entry_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(acronym_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(acronym_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(color_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(color_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +;; Math +[ + (displayed_equation) + (inline_formula) +] @text.math + +((generic_environment + (begin + command: _ @text.math + name: (curly_group_text + (text) @_env))) @text.math + (#any-of? @_env + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) +((generic_environment + (end + command: _ @text.math + name: (curly_group_text + (text) @_env))) @text.math + (#any-of? @_env + "displaymath" "displaymath*" + "equation" "equation*" + "multline" "multline*" + "eqnarray" "eqnarray*" + "align" "align*" + "array" "array*" + "split" "split*" + "alignat" "alignat*" + "gather" "gather*" + "flalign" "flalign*")) + +;; Sectioning +(chapter + command: _ @namespace + text: (curly_group) @text.title) + +(part + command: _ @namespace + text: (curly_group) @text.title) + +(section + command: _ @namespace + text: (curly_group) @text.title) + +(subsection + command: _ @namespace + text: (curly_group) @text.title) + +(subsubsection + command: _ @namespace + text: (curly_group) @text.title) + +(paragraph + command: _ @namespace + text: (curly_group) @text.title) + +(subparagraph + command: _ @namespace + text: (curly_group) @text.title) + +;; Beamer frames +(generic_environment + (begin + name: (curly_group_text + (text) @text.environment.name) + (#any-of? @text.environment.name "frame")) + . + (curly_group (_) @text.title)) + +((generic_command + command: (command_name) @_name + arg: (curly_group + (text) @text.title)) + (#eq? @_name "\\frametitle")) + +;; Formatting +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#eq? @_name "\\emph")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#match? @_name "^(\\\\textit|\\\\mathit)$")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.strong)) + (#match? @_name "^(\\\\textbf|\\\\mathbf)$")) + +((generic_command + command: (command_name) @_name + . + arg: (curly_group (_) @text.uri)) + (#match? @_name "^(\\\\url|\\\\href)$")) + +;; File inclusion commands +(class_include + command: _ @include + path: (curly_group_path) @string) + +(package_include + command: _ @include + paths: (curly_group_path_list) @string) + +(latex_include + command: _ @include + path: (curly_group_path) @string) +(import_include + command: _ @include + directory: (curly_group_path) @string + file: (curly_group_path) @string) + +(bibtex_include + command: _ @include + path: (curly_group_path) @string) +(biblatex_include + "\\addbibresource" @include + glob: (curly_group_glob_pattern) @string.regex) + +(graphics_include + command: _ @include + path: (curly_group_path) @string) +(tikz_library_import + command: _ @include + paths: (curly_group_path_list) @string) + diff --git a/bundle/nvim-treesitter/queries/latex/injections.scm b/bundle/nvim-treesitter/queries/latex/injections.scm new file mode 100644 index 000000000..e68c6d938 --- /dev/null +++ b/bundle/nvim-treesitter/queries/latex/injections.scm @@ -0,0 +1,22 @@ +[ + (line_comment) + (block_comment) + (comment_environment) +] @comment + +(pycode_environment + code: (source_code) @python +) + +(minted_environment + (begin + language: (curly_group_text + (text) @language)) + (source_code) @content) + +((generic_environment + (begin + name: (curly_group_text + (text) @_env))) @c + (#any-of? @_env "asy" "asydef")) + diff --git a/bundle/nvim-treesitter/queries/ledger/folds.scm b/bundle/nvim-treesitter/queries/ledger/folds.scm new file mode 100644 index 000000000..d807fc35e --- /dev/null +++ b/bundle/nvim-treesitter/queries/ledger/folds.scm @@ -0,0 +1,3 @@ +[ + (xact) +] @fold diff --git a/bundle/nvim-treesitter/queries/ledger/highlights.scm b/bundle/nvim-treesitter/queries/ledger/highlights.scm new file mode 100644 index 000000000..86c609c2a --- /dev/null +++ b/bundle/nvim-treesitter/queries/ledger/highlights.scm @@ -0,0 +1,38 @@ +[ + (comment) + (note) +] @comment + +[ + (date) + (interval) + (quantity) +] @number + +((account) @field) +((commodity) @text.literal) + +"include" @include + +[ + "account" + "alias" + "assert" + "check" + "commodity" + "def" + "default" + "end" + "eval" + "format" + "nomarket" + "note" + "payee" + "check" + "A" + "Y" + "N" + "D" + "C" + "P" +] @keyword diff --git a/bundle/nvim-treesitter/queries/ledger/indents.scm b/bundle/nvim-treesitter/queries/ledger/indents.scm new file mode 100644 index 000000000..af74b1d41 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ledger/indents.scm @@ -0,0 +1,3 @@ +[ + (journal_item) +] @indent diff --git a/bundle/nvim-treesitter/queries/ledger/injections.scm b/bundle/nvim-treesitter/queries/ledger/injections.scm new file mode 100644 index 000000000..2d9481414 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ledger/injections.scm @@ -0,0 +1,2 @@ +(comment) @comment +(note) @comment diff --git a/bundle/nvim-treesitter/queries/llvm/highlights.scm b/bundle/nvim-treesitter/queries/llvm/highlights.scm new file mode 100644 index 000000000..d61d52937 --- /dev/null +++ b/bundle/nvim-treesitter/queries/llvm/highlights.scm @@ -0,0 +1,156 @@ +(type) @type +(type_keyword) @type.builtin + +(type [ + (local_var) + (global_var) + ] @type) + +(argument) @parameter + +(_ inst_name: _ @keyword.operator) + +[ + "catch" + "filter" +] @keyword.operator + +[ + "to" + "nuw" + "nsw" + "exact" + "unwind" + "from" + "cleanup" + "swifterror" + "volatile" + "inbounds" + "inrange" +] @keyword +(icmp_cond) @keyword +(fcmp_cond) @keyword + +(fast_math) @keyword + +(_ callee: _ @function) +(function_header name: _ @function) + +[ + "declare" + "define" +] @keyword.function +(calling_conv) @keyword.function + +[ + "target" + "triple" + "datalayout" + "source_filename" + "addrspace" + "blockaddress" + "align" + "syncscope" + "within" + "uselistorder" + "uselistorder_bb" + "module" + "asm" + "sideeffect" + "alignstack" + "inteldialect" + "unwind" + "type" + "global" + "constant" + "externally_initialized" + "alias" + "ifunc" + "section" + "comdat" + "thread_local" + "localdynamic" + "initialexec" + "localexec" + "any" + "exactmatch" + "largest" + "nodeduplicate" + "samesize" + "distinct" + "attributes" + "vscale" + "no_cfi" +] @keyword + +(linkage_aux) @keyword +(dso_local) @keyword +(visibility) @keyword +(dll_storage_class) @keyword +(unnamed_addr) @keyword +(attribute_name) @keyword + +(function_header [ + (linkage) + (calling_conv) + (unnamed_addr) + ] @keyword.function) + +(number) @number +(comment) @comment +(string) @string +(cstring) @string +(label) @label +(_ inst_name: "ret" @keyword.return) +(float) @float + +[ + (local_var) + (global_var) +] @variable + +[ + (struct_value) + (array_value) + (vector_value) +] @constructor + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "<" + ">" + "<{" + "}>" +] @punctuation.bracket + +[ + "," + ":" +] @punctuation.delimiter + +[ + "=" + "|" + "x" + "..." +] @operator + +[ + "true" + "false" +] @boolean + +[ + "undef" + "poison" + "null" + "none" + "zeroinitializer" +] @constant.builtin + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/lua/folds.scm b/bundle/nvim-treesitter/queries/lua/folds.scm new file mode 100644 index 000000000..d8f0b42df --- /dev/null +++ b/bundle/nvim-treesitter/queries/lua/folds.scm @@ -0,0 +1,10 @@ +[ + (do_statement) + (while_statement) + (repeat_statement) + (if_statement) + (for_statement) + (function_declaration) + (function_definition) + (table_constructor) +] @fold diff --git a/bundle/nvim-treesitter/queries/lua/highlights.scm b/bundle/nvim-treesitter/queries/lua/highlights.scm new file mode 100644 index 000000000..1beddb5e3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/lua/highlights.scm @@ -0,0 +1,192 @@ +;; Keywords + +"return" @keyword.return + +[ + "goto" + "in" + "local" +] @keyword + +(label_statement) @label + +(break_statement) @keyword + +(do_statement +[ + "do" + "end" +] @keyword) + +(while_statement +[ + "while" + "do" + "end" +] @repeat) + +(repeat_statement +[ + "repeat" + "until" +] @repeat) + +(if_statement +[ + "if" + "elseif" + "else" + "then" + "end" +] @conditional) + +(elseif_statement +[ + "elseif" + "then" + "end" +] @conditional) + +(else_statement +[ + "else" + "end" +] @conditional) + +(for_statement +[ + "for" + "do" + "end" +] @repeat) + +(function_declaration +[ + "function" + "end" +] @keyword.function) + +(function_definition +[ + "function" + "end" +] @keyword.function) + +;; Operators + +[ + "and" + "not" + "or" +] @keyword.operator + +[ + "+" + "-" + "*" + "/" + "%" + "^" + "#" + "==" + "~=" + "<=" + ">=" + "<" + ">" + "=" + "&" + "~" + "|" + "<<" + ">>" + "//" + ".." +] @operator + +;; Punctuations + +[ + ";" + ":" + "," + "." +] @punctuation.delimiter + +;; Brackets + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +;; Variables + +(identifier) @variable + +((identifier) @variable.builtin + (#match? @variable.builtin "self")) + +;; Constants + +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +(vararg_expression) @constant + +(nil) @constant.builtin + +[ + (false) + (true) +] @boolean + +;; Tables + +(field name: (identifier) @field) + +(dot_index_expression field: (identifier) @field) + +(table_constructor +[ + "{" + "}" +] @constructor) + +;; Functions + +(parameters (identifier) @parameter) + +(function_call name: (identifier) @function) +(function_declaration name: (identifier) @function) + +(function_call name: (dot_index_expression field: (identifier) @function)) +(function_declaration name: (dot_index_expression field: (identifier) @function)) + +(method_index_expression method: (identifier) @method) + +(function_call + (identifier) @function.builtin + (#any-of? @function.builtin + ;; built-in functions in Lua 5.1 + "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" + "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" + "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable" + "tonumber" "tostring" "type" "unpack" "xpcall")) + +;; Others + +(comment) @comment + +(hash_bang_line) @comment + +(number) @number + +(string) @string + +;; Error +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/lua/indents.scm b/bundle/nvim-treesitter/queries/lua/indents.scm new file mode 100644 index 000000000..283808843 --- /dev/null +++ b/bundle/nvim-treesitter/queries/lua/indents.scm @@ -0,0 +1,40 @@ +[ + (function_definition) + (function_declaration) + (field) + (do_statement) + (while_statement) + (repeat_statement) + (if_statement) + (for_statement) + (return_statement) + (table_constructor) + (arguments) + (return_statement) +] @indent + +[ + "end" + ")" + "}" +] @indent_end + +(return_statement + (expression_list + (function_call))) @dedent + +[ + "end" + "then" + "until" + "}" + ")" + "elseif" + (elseif_statement) + "else" + (else_statement) +] @branch + +(comment) @auto + +(string) @auto diff --git a/bundle/nvim-treesitter/queries/lua/injections.scm b/bundle/nvim-treesitter/queries/lua/injections.scm new file mode 100644 index 000000000..18d20e616 --- /dev/null +++ b/bundle/nvim-treesitter/queries/lua/injections.scm @@ -0,0 +1,19 @@ +((function_call + name: [ + (identifier) @_cdef_identifier + (_ _ (identifier) @_cdef_identifier) + ] + arguments: (arguments (string content: _ @c))) + (#eq? @_cdef_identifier "cdef")) + +((function_call + name: (_) @_vimcmd_identifier + arguments: (arguments (string content: _ @vim))) + (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec")) + +((function_call + name: (_) @_vimcmd_identifier + arguments: (arguments (string content: _ @query) .)) + (#eq? @_vimcmd_identifier "vim.treesitter.query.set_query")) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/lua/locals.scm b/bundle/nvim-treesitter/queries/lua/locals.scm new file mode 100644 index 000000000..1fad4a1ed --- /dev/null +++ b/bundle/nvim-treesitter/queries/lua/locals.scm @@ -0,0 +1,51 @@ +; Scopes + +[ + (chunk) + (do_statement) + (while_statement) + (repeat_statement) + (if_statement) + (for_statement) + (function_declaration) + (function_definition) +] @scope + +; Definitions + +(assignment_statement + (variable_list + (identifier) @definition.var)) + +(assignment_statement + (variable_list + (dot_index_expression . (_) @definition.associated (identifier) @definition.var))) + +(function_declaration + name: (identifier) @definition.function) + (#set! definition.function.scope "parent") + +(function_declaration + name: (dot_index_expression + . (_) @definition.associated (identifier) @definition.function)) + (#set! definition.method.scope "parent") + +(function_declaration + name: (method_index_expression + . (_) @definition.associated (identifier) @definition.method)) + (#set! definition.method.scope "parent") + +(for_generic_clause + (variable_list + (identifier) @definition.var)) + +(for_numeric_clause + name: (identifier) @definition.var) + +(parameters (identifier) @definition.parameter) + +; References + +[ + (identifier) +] @reference diff --git a/bundle/nvim-treesitter/queries/make/highlights.scm b/bundle/nvim-treesitter/queries/make/highlights.scm new file mode 100644 index 000000000..adde2f9dc --- /dev/null +++ b/bundle/nvim-treesitter/queries/make/highlights.scm @@ -0,0 +1,120 @@ +(comment) @comment + +(conditional + (_ [ + "ifeq" + "else" + "ifneq" + "ifdef" + "ifndef" + ] @conditional) + "endif" @conditional) + +(rule (targets + (word) @function.builtin + (#any-of? @function.builtin + ".DEFAULT" + ".SUFFIXES" + ".DEFAULT" + ".DELETE_ON_ERROR" + ".EXPORT_ALL_VARIABLES" + ".IGNORE" + ".INTERMEDIATE" + ".LOW_RESOLUTION_TIME" + ".NOTPARALLEL" + ".ONESHELL" + ".PHONY" + ".POSIX" + ".PRECIOUS" + ".SECONDARY" + ".SECONDEXPANSION" + ".SILENT" + ".SUFFIXES"))) + +(rule ["&:" ":" "::"] @operator) + +(export_directive "export" @keyword) +(override_directive "override" @keyword) +(include_directive ["include" "-include"] @include) + +(variable_assignment + (word) @symbol) +(variable_assignment [ + "?=" + ":=" + "+=" + "=" + ] @operator) + + +(variable_assignment + (word) @variable.builtin + (#any-of? @variable.builtin + ".DEFAULT_GOAL" + ".EXTRA_PREREQS" + ".FEATURES" + ".INCLUDE_DIRS" + ".RECIPEPREFIX" + ".SHELLFLAGS" + ".VARIABLES" + "MAKEARGS" + "MAKEFILE_LIST" + "MAKEFLAGS" + "MAKE_RESTARTS" + "MAKE_TERMERR" + "MAKE_TERMOUT" + "SHELL" + ) + ) + + + +; Use string to match bash +(variable_reference (word) @string ) @operator + + +(shell_function + ["$" "(" ")"] @operator + "shell" @function.builtin + ) + +(function_call ["$" "(" ")"] @operator) + +(function_call [ + "subst" + "patsubst" + "strip" + "findstring" + "filter" + "filter-out" + "sort" + "word" + "words" + "wordlist" + "firstword" + "lastword" + "dir" + "notdir" + "suffix" + "basename" + "addsuffix" + "addprefix" + "join" + "wildcard" + "realpath" + "abspath" + "error" + "warning" + "info" + "origin" + "flavor" + "foreach" + "if" + "or" + "and" + "call" + "eval" + "file" + "value" + ] @function.builtin +) diff --git a/bundle/nvim-treesitter/queries/make/injections.scm b/bundle/nvim-treesitter/queries/make/injections.scm new file mode 100644 index 000000000..3add7f494 --- /dev/null +++ b/bundle/nvim-treesitter/queries/make/injections.scm @@ -0,0 +1,4 @@ +(comment) @comment + +(shell_text) @bash +(shell_command) @bash diff --git a/bundle/nvim-treesitter/queries/markdown/folds.scm b/bundle/nvim-treesitter/queries/markdown/folds.scm new file mode 100644 index 000000000..f6c34f74a --- /dev/null +++ b/bundle/nvim-treesitter/queries/markdown/folds.scm @@ -0,0 +1,5 @@ +[ + (fenced_code_block) + (indented_code_block) + (list) +] @fold diff --git a/bundle/nvim-treesitter/queries/markdown/highlights.scm b/bundle/nvim-treesitter/queries/markdown/highlights.scm new file mode 100644 index 000000000..3a88ecedd --- /dev/null +++ b/bundle/nvim-treesitter/queries/markdown/highlights.scm @@ -0,0 +1,74 @@ +;; From MDeiml/tree-sitter-markdown +(atx_heading (heading_content) @text.title) +(setext_heading (heading_content) @text.title) + +[ + (atx_h1_marker) + (atx_h2_marker) + (atx_h3_marker) + (atx_h4_marker) + (atx_h5_marker) + (atx_h6_marker) + (setext_h1_underline) + (setext_h2_underline) +] @punctuation.special + +[ + (code_span) + (link_title) + (indented_code_block) + (fenced_code_block) +] @text.literal + +[ + (emphasis_delimiter) + (code_span_delimiter) + (fenced_code_block_delimiter) +] @punctuation.delimiter + +(code_fence_content) @none + +(emphasis) @text.emphasis + +(strong_emphasis) @text.strong + +[ + (link_destination) + (uri_autolink) +] @text.uri + +[ + (link_label) + (link_text) + (image_description) +] @text.reference + +[ + (list_marker_plus) + (list_marker_minus) + (list_marker_star) + (list_marker_dot) + (list_marker_parenthesis) + (thematic_break) +] @punctuation.special + +(block_quote_marker) @punctuation.special + +[ + (backslash_escape) + (hard_line_break) +] @string.escape + +(image "!" @punctuation.delimiter) +(image "[" @punctuation.delimiter) +(image "]" @punctuation.delimiter) +(image "(" @punctuation.delimiter) +; (image ")" @punctuation.delimiter) + +(inline_link "[" @punctuation.delimiter) +(inline_link "]" @punctuation.delimiter) +(inline_link "(" @punctuation.delimiter) +; (inline_link ")" @punctuation.delimiter) + +(shortcut_link "[" @punctuation.delimiter) +(shortcut_link "]" @punctuation.delimiter) diff --git a/bundle/nvim-treesitter/queries/markdown/injections.scm b/bundle/nvim-treesitter/queries/markdown/injections.scm new file mode 100644 index 000000000..6fa047ac9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/markdown/injections.scm @@ -0,0 +1,9 @@ +(fenced_code_block + (info_string + (language) @language) + (code_fence_content) @content) + +((html_block) @html) +((html_tag) @html) + +(document . (thematic_break) (_) @yaml @combined (thematic_break)) diff --git a/bundle/nvim-treesitter/queries/ninja/folds.scm b/bundle/nvim-treesitter/queries/ninja/folds.scm new file mode 100644 index 000000000..341a8b8c1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ninja/folds.scm @@ -0,0 +1 @@ +(body) @fold diff --git a/bundle/nvim-treesitter/queries/ninja/highlights.scm b/bundle/nvim-treesitter/queries/ninja/highlights.scm new file mode 100644 index 000000000..1b31b560c --- /dev/null +++ b/bundle/nvim-treesitter/queries/ninja/highlights.scm @@ -0,0 +1,98 @@ +[ + "default" + "pool" + "rule" + "build" +] @keyword + +[ + "include" + "subninja" +] @include + +[ + ":" +] @punctuation.delimiter + +[ + "=" + "|" + "||" + "|@" +] @operator + +[ + "$" + "{" + "}" +] @punctuation.special + +;; +;; Names +;; ===== +(pool name: (identifier) @type) +(rule name: (identifier) @function) +(let name: (identifier) @constant) +(expansion (identifier) @constant) +(build rule: (identifier) @function) + +;; +;; Paths and Text +;; ============== +(path) @string.special +(text) @string + +;; +;; Builtins +;; ======== +(pool name: (identifier) @type.builtin + (#any-of? @type.builtin "console")) +(build rule: (identifier) @function.builtin + (#any-of? @function.builtin "phony" "dyndep")) + +;; Top level bindings +;; ------------------ +(manifest + (let name: ((identifier) @constant.builtin + (#any-of? @constant.builtin "builddir" + "ninja_required_version")))) + +;; Rules bindings +;; ----------------- +(rule + (body + (let name: (identifier) @constant.builtin + (#not-any-of? @constant.builtin "command" + "depfile" + "deps" + "msvc_deps_prefix" + "description" + "dyndep" + "generator" + "in" + "in_newline" + "out" + "restat" + "rspfile" + "rspfile_content" + "pool")))) + +;; +;; Expansion +;; --------- +(expansion + (identifier) @constant.macro + (#any-of? @constant.macro "in" "out")) + +;; +;; Escape sequences +;; ================ +(quote) @string.escape + +;; +;; Others +;; ====== +[ + (split) + (comment) +] @comment diff --git a/bundle/nvim-treesitter/queries/ninja/indents.scm b/bundle/nvim-treesitter/queries/ninja/indents.scm new file mode 100644 index 000000000..088dec2cd --- /dev/null +++ b/bundle/nvim-treesitter/queries/ninja/indents.scm @@ -0,0 +1,6 @@ +[ + (pool) + (rule) + (build) +] @indent + diff --git a/bundle/nvim-treesitter/queries/nix/folds.scm b/bundle/nvim-treesitter/queries/nix/folds.scm new file mode 100644 index 000000000..72050aa6f --- /dev/null +++ b/bundle/nvim-treesitter/queries/nix/folds.scm @@ -0,0 +1,11 @@ +; Nix doesn't really have blocks, so just guess what people might want folds for +[ + (if) + (with) + (let) + (function) + (attrset) + (rec_attrset) + (list) + (indented_string) +] @fold diff --git a/bundle/nvim-treesitter/queries/nix/highlights.scm b/bundle/nvim-treesitter/queries/nix/highlights.scm new file mode 100644 index 000000000..38b413fe4 --- /dev/null +++ b/bundle/nvim-treesitter/queries/nix/highlights.scm @@ -0,0 +1,120 @@ +; basic keywords +[ + ("assert") + ("with") + ("let") + ("in") + ("rec") + ("inherit") +] @keyword + +; if/then/else +[ + ("if") + ("then") + ("else") +] @conditional + +; field access default (`a.b or c`) +("or") @keyword.operator + +; comments +(comment) @comment + +; strings +[ (string) (indented_string) ] @string + +; paths and URLs +[ (path) (spath) (uri) ] @string.special + +; escape sequences +(escape_sequence) @string.escape + +; delimiters +[ + "." + ";" + "," +] @punctuation.delimiter + +; brackets +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; `?` in `{ x ? y }:`, used to set defaults for named function arguments +; I'm not really sure what group this should go in, but it should probably have highlighting, so I'm putting it in @punctuation.special +(formal "?" @punctuation.special) + +; `...` in `{ ... }`, used to ignore unknown named function arguments (see above) +(ellipses) @punctuation.special + +; `:` in `x: y`, used to separate function argument from body (see above) +(function ":" @punctuation.special) + +; basic identifiers +(identifier) @variable + +; builtin functions +((identifier) @_i (#match? @_i "^(builtins|baseNameOf|dirOf|fetchTarball|map|removeAttrs|toString)$")) @variable.builtin + +; display entire builtins path as builtin (ex. `builtins.filter` is highlighted as one long builtin) +(select ((identifier) @_i (#eq? @_i "builtins")) (attrpath (attr_identifier) @variable.builtin)) @variable.builtin + +; import +((identifier) @_i (#eq? @_i "import")) @include + +; null +((identifier) @_i (#eq? @_i "import")) @constant.builtin + +; these are technically functions but they act more like keywords (abort and throw are control flow, derivation is a core language construct) +((identifier) @_i (#match? @_i "^(abort|derivation|throw)$")) @keyword + +; booleans +((identifier) @_i (#match? @_i "^(true|false)$")) @boolean + +; string interpolation (this was very annoying to get working properly) +(interpolation "${" @punctuation.special (_) "}" @punctuation.special) @none + +; fields (the `.` in `a.b = c;` isn't included) +(attrset (bind . (attrpath (attr_identifier) @field))) +(rec_attrset (bind . (attrpath (attr_identifier) @field))) + +; unary operators +(unary "-" @operator) +(unary "!" @operator) + +; binary operators +(binary "?" @operator) +(binary "++" @operator) +(binary "*" @operator) +(binary "/" @operator) +(binary "+" @operator) +(binary "-" @operator) +(binary "//" @operator) +(binary "<" @operator) +(binary "<=" @operator) +(binary ">" @operator) +(binary ">=" @operator) +(binary "==" @operator) +(binary "!=" @operator) +(binary "&&" @operator) +(binary "||" @operator) +(binary "->" @operator) + +; integers, also highlight a unary - +[ + (unary "-" (integer)) + (integer) +] @number + +; floats, also highlight a unary - +[ + (unary "-" (float)) + (float) +] @float diff --git a/bundle/nvim-treesitter/queries/nix/injections.scm b/bundle/nvim-treesitter/queries/nix/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/nix/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/nix/locals.scm b/bundle/nvim-treesitter/queries/nix/locals.scm new file mode 100644 index 000000000..1720a848c --- /dev/null +++ b/bundle/nvim-treesitter/queries/nix/locals.scm @@ -0,0 +1,15 @@ +; let bindings +(let (bind . (attrpath) @definition.var)) @scope + +; rec attrsets +(rec_attrset (bind . (attrpath) @definition.field)) @scope + +; functions and parameters +(function . [ + (identifier) @definition.parameter + (formals (formal . (identifier) @definition.parameter)) +]) @scope +((formals) "@" (identifier) @definition.parameter) ; I couldn't get this to work properly inside the (function) + +; some identifiers can't be references, but @reference doesn't seem to have an inverse like @none +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/ocaml/folds.scm b/bundle/nvim-treesitter/queries/ocaml/folds.scm new file mode 100644 index 000000000..1d45dbbde --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml/folds.scm @@ -0,0 +1,30 @@ +[ + (let_binding) + (external) + (type_binding) + (exception_definition) + (module_binding) + (module_type_definition) + (open_module) + (include_module) + (include_module_type) + (class_binding) + (class_type_binding) + (value_specification) + (inheritance_specification) + (instance_variable_specification) + (method_specification) + (inheritance_definition) + (instance_variable_definition) + (method_definition) + (class_initializer) + (match_case) + (attribute) + (item_attribute) + (floating_attribute) + (extension) + (item_extension) + (quoted_extension) + (quoted_item_extension) + (comment) +] @fold diff --git a/bundle/nvim-treesitter/queries/ocaml/highlights.scm b/bundle/nvim-treesitter/queries/ocaml/highlights.scm new file mode 100644 index 000000000..eb41fbb26 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml/highlights.scm @@ -0,0 +1,173 @@ +; Modules +;-------- + +[(module_name) (module_type_name)] @namespace + +; Types +;------ + +( + (type_constructor) @type.builtin + (#any-of? @type.builtin + "int" "char" "bytes" "string" "float" + "bool" "unit" "exn" "array" "list" "option" + "int32" "int64" "nativeint" "format6" "lazy_t") +) + +[(class_name) (class_type_name) (type_constructor)] @type + +[(constructor_name) (tag)] @constructor + +; Functions +;---------- + +(let_binding + pattern: (value_name) @function + (parameter)) + +(let_binding + pattern: (value_name) @function + body: [(fun_expression) (function_expression)]) + +(value_specification (value_name) @function) + +(external (value_name) @function) + +(method_name) @method + +; Variables +;---------- + +[(value_name) (type_variable)] @variable + +(value_pattern) @parameter + +; Application +;------------ + +(infix_expression + left: (value_path (value_name) @function) + (infix_operator) @operator + (#eq? @operator "@@")) + +(infix_expression + (infix_operator) @operator + right: (value_path (value_name) @function) + (#eq? @operator "|>")) + +(application_expression + function: (value_path (value_name) @function)) + +( + (value_name) @function.builtin + (#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$") +) + +; Properties +;----------- + +[(label_name) (field_name) (instance_variable_name)] @property + +; Constants +;---------- + +(unit) @constant.builtin + +(boolean) @boolean + +[(number) (signed_number)] @number + +(character) @character + +(string) @string + +(quoted_string "{" @string "}" @string) @string + +(escape_sequence) @string.escape + +[ + (conversion_specification) + (pretty_printing_indication) +] @string.special + +; Keywords +;--------- + +[ + "and" "as" "assert" "begin" "class" "constraint" + "end" "external" "in" + "inherit" "initializer" "lazy" "let" "match" "method" "module" + "mutable" "new" "nonrec" "object" "of" "private" "rec" "sig" "struct" + "type" "val" "virtual" "when" "with" +] @keyword + +["fun" "function" "functor"] @keyword.function + +["if" "then" "else"] @conditional + +["exception" "try"] @exception + +["include" "open"] @include + +["for" "to" "downto" "while" "do" "done"] @repeat + +; Punctuation +;------------ + +(attribute ["[@" "]"] @punctuation.special) +(item_attribute ["[@@" "]"] @punctuation.special) +(floating_attribute ["[@@@" "]"] @punctuation.special) +(extension ["[%" "]"] @punctuation.special) +(item_extension ["[%%" "]"] @punctuation.special) +(quoted_extension ["{%" "}"] @punctuation.special) +(quoted_item_extension ["{%%" "}"] @punctuation.special) + +"%" @punctuation.special + +["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket + +(object_type ["<" ">"] @punctuation.bracket) + +[ + "," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&" + "->" ";;" ":>" "+=" ":=" ".." +] @punctuation.delimiter + +; Operators +;---------- + +[ + (prefix_operator) + (sign_operator) + (infix_operator) + (hash_operator) + (indexing_operator) + (let_operator) + (and_operator) + (match_operator) +] @operator + +(match_expression (match_operator) @keyword) + +(value_definition [(let_operator) (and_operator)] @keyword) + +;; TODO: this is an error now +;(prefix_operator "!" @operator) + +(infix_operator ["&" "+" "-" "=" ">" "|" "%"] @operator) + +(signed_number ["+" "-"] @operator) + +["*" "#" "::" "<-"] @operator + +; Attributes +;----------- + +(attribute_id) @property + +; Comments +;--------- + +[(comment) (line_number_directive) (directive) (shebang)] @comment + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/ocaml/injections.scm b/bundle/nvim-treesitter/queries/ocaml/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/ocaml/locals.scm b/bundle/nvim-treesitter/queries/ocaml/locals.scm new file mode 100644 index 000000000..9321ced2e --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml/locals.scm @@ -0,0 +1,77 @@ +; Scopes +;------- + +[ + (compilation_unit) + (structure) + (signature) + (module_binding) + (functor) + (let_binding) + (match_case) + (class_binding) + (class_function) + (method_definition) + (let_expression) + (fun_expression) + (for_expression) + (let_class_expression) + (object_expression) + (attribute_payload) +] @scope + +; Definitions +;------------ + +(value_pattern) @definition.var + +(let_binding + pattern: (value_name) @definition.var + (set! definition.var.scope "parent")) + +(let_binding + pattern: (tuple_pattern (value_name) @definition.var) + (set! definition.var.scope "parent")) + +(let_binding + pattern: (record_pattern (field_pattern (value_name) @definition.var)) + (set! definition.var.scope "parent")) + +(external (value_name) @definition.var) + +(type_binding (type_constructor) @definition.type) + +(abstract_type (type_constructor) @definition.type) + +(method_definition (method_name) @definition.method) + +(module_binding + (module_name) @definition.namespace + (set! definition.namespace.scope "parent")) + +(module_parameter (module_name) @definition.namespace) + +(module_type_definition (module_type_name) @definition.type) + +; References +;------------ + +(value_path . + (value_name) @reference + (set! reference.kind "var")) + +(type_constructor_path . + (type_constructor) @reference + (set! reference.kind "type")) + +(method_invocation + (method_name) @reference + (set! reference.kind "method")) + +(module_path . + (module_name) @reference + (set! reference.kind "type")) + +(module_type_path . + (module_type_name) @reference + (set! reference.kind "type")) diff --git a/bundle/nvim-treesitter/queries/ocaml_interface/folds.scm b/bundle/nvim-treesitter/queries/ocaml_interface/folds.scm new file mode 100644 index 000000000..6d3dfbcf2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml_interface/folds.scm @@ -0,0 +1 @@ +; inherits: ocaml diff --git a/bundle/nvim-treesitter/queries/ocaml_interface/highlights.scm b/bundle/nvim-treesitter/queries/ocaml_interface/highlights.scm new file mode 100644 index 000000000..6d3dfbcf2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml_interface/highlights.scm @@ -0,0 +1 @@ +; inherits: ocaml diff --git a/bundle/nvim-treesitter/queries/ocaml_interface/injections.scm b/bundle/nvim-treesitter/queries/ocaml_interface/injections.scm new file mode 100644 index 000000000..6d3dfbcf2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml_interface/injections.scm @@ -0,0 +1 @@ +; inherits: ocaml diff --git a/bundle/nvim-treesitter/queries/ocaml_interface/locals.scm b/bundle/nvim-treesitter/queries/ocaml_interface/locals.scm new file mode 100644 index 000000000..6d3dfbcf2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocaml_interface/locals.scm @@ -0,0 +1 @@ +; inherits: ocaml diff --git a/bundle/nvim-treesitter/queries/ocamllex/highlights.scm b/bundle/nvim-treesitter/queries/ocamllex/highlights.scm new file mode 100644 index 000000000..513316159 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocamllex/highlights.scm @@ -0,0 +1,29 @@ + +[(lexer_argument) (regexp_name) (any)] @type + +(lexer_entry_name) @function + +["as" "let" "and" "parse" "rule"] @keyword + +[(eof) (character)] @character +(string) @string + +(ocaml) @none + +(character_range "-" @operator) +(character_set "^" @operator) +(regexp_alternative ["|"] @operator) +(regexp_difference ["#"] @operator) +(regexp_option ["?"] @operator) +(regexp_repetition ["*"] @operator) +(regexp_strict_repetition ["+"] @operator) + +(action ["{" "}"] @punctuation.special) +(character_set ["[" "]"] @punctuation.bracket) +(parenthesized_regexp ["(" ")"] @punctuation.bracket) + +["="] @punctuation.delimiter +(lexer_entry "|" @punctuation.delimiter) + +(comment) @comment +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/ocamllex/injections.scm b/bundle/nvim-treesitter/queries/ocamllex/injections.scm new file mode 100644 index 000000000..337d8073e --- /dev/null +++ b/bundle/nvim-treesitter/queries/ocamllex/injections.scm @@ -0,0 +1,3 @@ +(ocaml) @ocaml + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/pascal/folds.scm b/bundle/nvim-treesitter/queries/pascal/folds.scm new file mode 100644 index 000000000..6db2857bf --- /dev/null +++ b/bundle/nvim-treesitter/queries/pascal/folds.scm @@ -0,0 +1,33 @@ +[ + (interface) + (implementation) + (initialization) + (finalization) + + (if) + (ifElse) + (while) + (repeat) + (for) + (foreach) + (try) + (case) + (caseCase) + (asm) + (with) + + (declVar) + (declConst) + (declEnum) + (declProcRef) + (declExports) + (declProcRef) + (declType) + (defProc) + (declField) + (declProp) + + (comment) +] @fold + +(interface (declProc) @fold) diff --git a/bundle/nvim-treesitter/queries/pascal/highlights.scm b/bundle/nvim-treesitter/queries/pascal/highlights.scm new file mode 100644 index 000000000..77c509cc1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/pascal/highlights.scm @@ -0,0 +1,389 @@ +; -- Keywords +[ + (kProgram) + (kLibrary) + (kUnit) + (kUses) + + (kBegin) + (kEnd) + (kAsm) + + (kVar) + (kThreadvar) + (kConst) + (kResourcestring) + (kConstref) + (kOut) + (kType) + (kLabel) + (kExports) + + (kAbsolute) + + (kProperty) + (kRead) + (kWrite) + (kImplements) + + (kClass) + (kInterface) + (kObject) + (kRecord) + (kObjcclass) + (kObjccategory) + (kObjcprotocol) + (kArray) + (kFile) + (kString) + (kSet) + (kOf) + (kHelper) + (kPacked) + + (kInherited) + + (kGeneric) + (kSpecialize) + + (kFunction) + (kProcedure) + (kConstructor) + (kDestructor) + (kOperator) + (kReference) + + (kInterface) + (kImplementation) + (kInitialization) + (kFinalization) + + (kPublished) + (kPublic) + (kProtected) + (kPrivate) + (kStrict) + (kRequired) + (kOptional) + + (kTry) + (kExcept) + (kFinally) + (kRaise) + (kOn) + (kCase) + (kWith) + (kGoto) +] @keyword + +[ + (kFor) + (kTo) + (kDownto) + (kDo) + (kWhile) + (kRepeat) + (kUntil) +] @repeat + +[ + (kIf) + (kThen) + (kElse) +] @conditional + + +; -- Attributes + +[ + (kDefault) + (kIndex) + (kNodefault) + (kStored) + + (kStatic) + (kVirtual) + (kAbstract) + (kSealed) + (kDynamic) + (kOverride) + (kOverload) + (kReintroduce) + (kInline) + + (kForward) + + (kStdcall) + (kCdecl) + (kCppdecl) + (kPascal) + (kRegister) + (kMwpascal) + (kExternal) + (kName) + (kMessage) + (kDeprecated) + (kExperimental) + (kPlatform) + (kUnimplemented) + (kCvar) + (kExport) + (kFar) + (kNear) + (kSafecall) + (kAssembler) + (kNostackframe) + (kInterrupt) + (kNoreturn) + (kIocheck) + (kLocal) + (kHardfloat) + (kSoftfloat) + (kMs_abi_default) + (kMs_abi_cdecl) + (kSaveregisters) + (kSysv_abi_default) + (kSysv_abi_cdecl) + (kVectorcall) + (kVarargs) + (kWinapi) + (kAlias) + (kDelayed) + + (rttiAttributes) + (procAttribute) + +] @attribute + +(procAttribute (kPublic) @attribute) + +; -- Punctuation & operators + +[ + "(" + ")" + "[" + "]" +] @punctuation.bracket + +[ + ";" + "," + ":" + (kEndDot) +] @punctuation.delimiter + +[ + ".." +] @punctuation.special + +[ + (kDot) + (kAdd) + (kSub) + (kMul) + (kFdiv) + (kAssign) + (kAssignAdd) + (kAssignSub) + (kAssignMul) + (kAssignDiv) + (kEq) + (kLt) + (kLte) + (kGt) + (kGte) + (kNeq) + (kAt) + (kHat) +] @operator + +[ + (kOr) + (kXor) + (kDiv) + (kMod) + (kAnd) + (kShl) + (kShr) + (kNot) + (kIs) + (kAs) + (kIn) +] @keyword.operator + +; -- Builtin constants + +[ + (kTrue) + (kFalse) +] @boolean + +[ + (kNil) +] @constant.builtin + +; -- Literals + +(literalNumber) @number +(literalString) @string + +; -- Variables + +(exprBinary (identifier) @variable) +(exprUnary (identifier) @variable) +(assignment (identifier) @variable) +(exprBrackets (identifier) @variable) +(exprParens (identifier) @variable) +(exprDot (identifier) @variable) +(exprTpl (identifier) @variable) +(exprArgs (identifier) @variable) +(defaultValue (identifier) @variable) + +; -- Comments + +(comment) @comment +(pp) @function.macro + +; -- Type declaration + +(declType name: (identifier) @type) +(declType name: (genericTpl entity: (identifier) @type)) + +; -- Procedure & function declarations + +; foobar +(declProc name: (identifier) @function) +; foobar +(declProc name: (genericTpl entity: (identifier) @function)) +; foo.bar +(declProc name: (genericDot rhs: (identifier) @function)) +; foo.bar +(declProc name: (genericDot rhs: (genericTpl entity: (identifier) @function))) + +; Treat property declarations like functions + +(declProp name: (identifier) @function) +(declProp getter: (identifier) @property) +(declProp setter: (identifier) @property) + +; -- Function parameters + +(declArg name: (identifier) @parameter) + +; -- Template parameters + +(genericArg name: (identifier) @parameter) +(genericArg type: (typeref) @type) + +(declProc name: (genericDot lhs: (identifier) @type)) +(declType (genericDot (identifier) @type)) + +(genericDot (genericTpl (identifier) @type)) +(genericDot (genericDot (identifier) @type)) + +(genericTpl entity: (identifier) @type) +(genericTpl entity: (genericDot (identifier) @type)) + +; -- Exception parameters + +(exceptionHandler variable: (identifier) @parameter) + +; -- Type usage + +(typeref) @type + +; -- Constant usage + +[ + (caseLabel) + (label) +] @constant + +(procAttribute (identifier) @constant) +(procExternal (identifier) @constant) + +; -- Variable & constant declarations +; (This is only questionable because we cannot detect types of identifiers +; declared in other units, so the results will be inconsistent) + +(declVar name: (identifier) @variable) +(declConst name: (identifier) @constant) +(declEnumValue name: (identifier) @constant) + +; -- Fields + +(exprDot rhs: (identifier) @property) +(exprDot rhs: (exprDot) @property) +(declClass (declField name:(identifier) @property)) +(declSection (declField name:(identifier) @property)) +(declSection (declVars (declVar name:(identifier) @property))) + +(recInitializerField name:(identifier) @property) + + +;;; ---------------------------------------------- ;;; +;;; EVERYTHING BELOW THIS IS OF QUESTIONABLE VALUE ;;; +;;; ---------------------------------------------- ;;; + + +; -- Procedure name in calls with parentheses +; (Pascal doesn't require parentheses for procedure calls, so this will not +; detect all calls) + +; foobar +(exprCall entity: (identifier) @function) +; foobar +(exprCall entity: (exprTpl entity: (identifier) @function)) +; foo.bar +(exprCall entity: (exprDot rhs: (identifier) @function)) +; foo.bar +(exprCall entity: (exprDot rhs: (exprTpl entity: (identifier) @function))) + +(inherited) @function + +; -- Heuristic for procedure/function calls without parentheses +; (If a statement consists only of an identifier, assume it's a procedure) +; (This will still not match all procedure calls, and also may produce false +; positives in rare cases, but only for nonsensical code) + +(statement (identifier) @function) +(statement (exprDot rhs: (identifier) @function)) +(statement (exprTpl entity: (identifier) @function)) +(statement (exprDot rhs: (exprTpl entity: (identifier) @function))) + +; -- Break, Continue & Exit +; (Not ideal: ideally, there would be a way to check if these special +; identifiers are shadowed by a local variable) +(statement ((identifier) @keyword.return + (#lua-match? @keyword.return "^[eE][xX][iI][tT]$"))) +(statement (exprCall entity: ((identifier) @keyword.return + (#lua-match? @keyword.return "^[eE][xX][iI][tT]$")))) +(statement ((identifier) @repeat + (#lua-match? @repeat "^[bB][rR][eE][aA][kK]$"))) +(statement ((identifier) @repeat + (#lua-match? @repeat "^[cC][oO][nN][tT][iI][nN][uU][eE]$"))) + +; -- Identifier type inferrence + +; VERY QUESTIONABLE: Highlighting of identifiers based on spelling +(exprBinary ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprUnary ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(assignment rhs: ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprBrackets ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprParens ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprDot rhs: ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprTpl args: ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(exprArgs ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(declEnumValue ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) +(defaultValue ((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$"))) diff --git a/bundle/nvim-treesitter/queries/pascal/indents.scm b/bundle/nvim-treesitter/queries/pascal/indents.scm new file mode 100644 index 000000000..829054ddb --- /dev/null +++ b/bundle/nvim-treesitter/queries/pascal/indents.scm @@ -0,0 +1,32 @@ +[ + (statement) + (declVars) + (declConsts) + (declTypes) + (declProc) + (declArgs) + (declUses) + (declClass) + (exprArgs) + (exprSubscript) + (exprBrackets) + (exprParens) + (recInitializer) + (arrInitializer) + (defaultValue) +] @indent + +(defProc (block) @indent) + +[ + (kEnd) + (kFinally) + (kDo) + (kUntil) + (kExcept) + (kElse) + (kThen) + (declSection) + "]" + ")" +] @branch diff --git a/bundle/nvim-treesitter/queries/pascal/injections.scm b/bundle/nvim-treesitter/queries/pascal/injections.scm new file mode 100644 index 000000000..c410fbb41 --- /dev/null +++ b/bundle/nvim-treesitter/queries/pascal/injections.scm @@ -0,0 +1,4 @@ +(comment) @comment +; There is no parser for assembly language yet. Add an injection here when we +; have a parser. +; (asmBody) @asm diff --git a/bundle/nvim-treesitter/queries/pascal/locals.scm b/bundle/nvim-treesitter/queries/pascal/locals.scm new file mode 100644 index 000000000..b97cb096f --- /dev/null +++ b/bundle/nvim-treesitter/queries/pascal/locals.scm @@ -0,0 +1,25 @@ + +(root) @scope + +(defProc) @scope +(lambda) @scope +(interface (declProc) @scope) +(declSection (declProc) @scope) +(declClass (declProc) @scope) +(declHelper (declProc) @scope) +(declProcRef) @scope + +(exceptionHandler) @scope +(exceptionHandler variable: (identifier) @definition) + +(declArg name: (identifier) @definition) +(declVar name: (identifier) @definition) +(declConst name: (identifier) @definition) +(declLabel name: (identifier) @definition) +(genericArg name: (identifier) @definition) +(declEnumValue name: (identifier) @definition) +(declType name: (identifier) @definition) +(declType name: (genericTpl entity: (identifier) @definition)) + +(declProc name: (identifier) @definition) +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/perl/folds.scm b/bundle/nvim-treesitter/queries/perl/folds.scm new file mode 100644 index 000000000..994d569bc --- /dev/null +++ b/bundle/nvim-treesitter/queries/perl/folds.scm @@ -0,0 +1,12 @@ +[ + (function_definition) + (if_statement) + (unless_statement) + (while_statement) + (until_statement) + (for_statement_1) + (for_statement_2) + (foreach_statement) + (standalone_block) + (pod_statement) +] @fold diff --git a/bundle/nvim-treesitter/queries/perl/highlights.scm b/bundle/nvim-treesitter/queries/perl/highlights.scm new file mode 100644 index 000000000..66403530d --- /dev/null +++ b/bundle/nvim-treesitter/queries/perl/highlights.scm @@ -0,0 +1,182 @@ +; Misc keywords +[ + "my" "our" "local" + "next" "last" "redo" + "goto" + "package" +; "do" +; "eval" +] @keyword + +; Keywords for including +[ "use" "no" "require" ] @include + +; Keywords that mark conditional statements +[ "if" "elsif" "unless" "else" ] @conditional + +; Keywords that mark repeating loops +[ "while" "until" "for" "foreach" ] @repeat + +; Keyword for return expressions +[ "return" ] @keyword.return + +; Keywords for phaser blocks +; TODO: Ideally these would be @keyword.phaser but vim-treesitter doesn't +; have such a thing yet +[ "BEGIN" "CHECK" "UNITCHECK" "INIT" "END" ] @keyword.function + +; Keywords to define a function +[ "sub" ] @keyword.function + +; Lots of builtin functions, except tree-sitter-perl doesn't emit most of +; these yet +;[ +; "print" "printf" "sprintf" "say" +; "push" "pop" "shift" "unshift" "splice" +; "exists" "delete" "keys" "values" +; "each" +;] @function.builtin + +; Keywords that are regular infix operators +[ + "and" "or" "not" "xor" + "eq" "ne" "lt" "le" "ge" "gt" "cmp" +] @keyword.operator + +; Variables +[ + (scalar_variable) + (array_variable) + (hash_variable) +] @variable + +; Special builtin variables +[ + (special_scalar_variable) + (special_array_variable) + (special_hash_variable) + (special_literal) + (super) +] @variable.builtin + +; Integer numbers +[ + (integer) + (hexadecimal) +] @number + +; Float numbers +[ + (floating_point) + (scientific_notation) +] @float + +; version sortof counts as a kind of multipart integer +(version) @constant + +; Package names are types +(package_name) @type + +; The special SUPER:: could be called a namespace. It isn't really but it +; should highlight differently and we might as well do it this way +(super) @namespace + +; Comments are comments +(comments) @comment + +; POD should be handled specially with its own embedded subtype but for now +; we'll just have to do this. +(pod_statement) @text + +(method_invocation + function_name: (identifier) @method) +(call_expression + function_name: (identifier) @function) + +;; ---------- + +(use_constant_statement + constant: (identifier) @constant) + +(named_block_statement + function_name: (identifier) @function) + +(function_definition + name: (identifier) @function) + +[ +(function) +(map) +(grep) +(bless) +] @function + +[ +"(" +")" +"[" +"]" +"{" +"}" +] @punctuation.bracket +(standard_input_to_variable) @punctuation.bracket + +[ +"=~" +"!~" +"=" +"==" +"+" +"-" +"." +"//" +"||" +(arrow_operator) +(hash_arrow_operator) +(array_dereference) +(hash_dereference) +(to_reference) +(type_glob) +(hash_access_variable) +(ternary_expression) +(ternary_expression_in_hash) +] @operator + +[ +(regex_option) +(regex_option_for_substitution) +(regex_option_for_transliteration) +] @parameter + +(type_glob + (identifier) @variable) + +[ +(word_list_qw) +(command_qx_quoted) +(string_single_quoted) +(string_double_quoted) +(string_qq_quoted) +(bareword) +(transliteration_tr_or_y) +] @string + +[ +(regex_pattern_qr) +(patter_matcher_m) +(substitution_pattern_s) +] @string.regex + +(escape_sequence) @string.escape + +[ +"," +(semi_colon) +(start_delimiter) +(end_delimiter) +(ellipsis_statement) +] @punctuation.delimiter + +(function_attribute) @field + +(function_signature) @type diff --git a/bundle/nvim-treesitter/queries/php/folds.scm b/bundle/nvim-treesitter/queries/php/folds.scm new file mode 100644 index 000000000..3d447829a --- /dev/null +++ b/bundle/nvim-treesitter/queries/php/folds.scm @@ -0,0 +1,6 @@ +[ + (class_declaration) + (compound_statement) + (switch_statement) + (case_statement) +] @fold diff --git a/bundle/nvim-treesitter/queries/php/highlights.scm b/bundle/nvim-treesitter/queries/php/highlights.scm new file mode 100644 index 000000000..16f478465 --- /dev/null +++ b/bundle/nvim-treesitter/queries/php/highlights.scm @@ -0,0 +1,284 @@ +; Variables + +(variable_name) @variable + +; Types + +[ + (primitive_type) + (cast_type) + ] @type.builtin +(named_type (name)) @type +(named_type (qualified_name)) @type +(class_declaration + name: (name) @type) +(base_clause + [(name) (qualified_name)] @type) +(enum_declaration + name: (name) @type) +(interface_declaration + name: (name) @type) +(namespace_use_clause + [(name) (qualified_name)] @type) +(namespace_aliasing_clause (name)) @type +(class_interface_clause + [(name) (qualified_name)] @type) +(scoped_call_expression + scope: [(name) (qualified_name)] @type) +(class_constant_access_expression + . [(name) (qualified_name)] @type + (name) @constant) +(trait_declaration + name: (name) @type) +(use_declaration + (name) @type) + +; Functions, methods, constructors + +(array_creation_expression "array" @function.builtin) +(list_literal "list" @function.builtin) + +(method_declaration + name: (name) @method) + +(function_call_expression + function: (qualified_name (name)) @function) + +(function_call_expression + (name) @function) + +(scoped_call_expression + name: (name) @function) + +(member_call_expression + name: (name) @method) + +(function_definition + name: (name) @function) + +(nullsafe_member_call_expression + name: (name) @method) + +(method_declaration + name: (name) @constructor + (#eq? @constructor "__construct")) +(object_creation_expression + [(name) (qualified_name)] @constructor) + +; Parameters +[ + (simple_parameter) + (variadic_parameter) +] @parameter + +(argument + (name) @parameter) + +; Member + +(property_element + (variable_name) @property) + +(member_access_expression + name: (variable_name (name)) @property) + +(member_access_expression + name: (name) @property) + +; Variables + +(relative_scope) @variable.builtin + +((name) @constant + (#vim-match? @constant "^_?[A-Z][A-Z\d_]*$")) +((name) @constant.builtin + (#vim-match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) + +(const_declaration (const_element (name) @constant)) + +((name) @variable.builtin + (#eq? @variable.builtin "this")) + +; Namespace +(namespace_definition + name: (namespace_name) @namespace) + +; Conditions ( ? : ) +(conditional_expression) @conditional +; Basic tokens + +[ + (string) + (heredoc) + (shell_command_expression) ; backtick operator: `ls -la` + ] @string +(encapsed_string (escape_sequence) @string.escape) + +(boolean) @boolean +(null) @constant.builtin +(integer) @number +(float) @float +(comment) @comment + +(named_label_statement) @label +; Keywords + +[ + "and" + "as" + "instanceof" + "or" + "xor" +] @keyword.operator + +[ + "fn" + "function" +] @keyword.function + +[ + "$" + "abstract" + "break" + "class" + "clone" + "const" + "declare" + "default" + "echo" + "enddeclare" + "enum" + "extends" + "final" + "global" + "goto" + "implements" + "insteadof" + "interface" + "namespace" + "new" + "private" + "protected" + "public" + "static" + "trait" + "unset" + ] @keyword + +[ + "return" + "yield" +] @keyword.return + +[ + "case" + "else" + "elseif" + "endif" + "endswitch" + "if" + "switch" + "match" + "??" + ] @conditional + +[ + "continue" + "do" + "endfor" + "endforeach" + "endwhile" + "for" + "foreach" + "while" + ] @repeat + +[ + "catch" + "finally" + "throw" + "try" + ] @exception + +[ + "include_once" + "include" + "require_once" + "require" + "use" + ] @include + +[ + "," + ";" + ] @punctuation.delimiter + +[ + (php_tag) + "?>" + "(" + ")" + "[" + "]" + "{" + "}" + ] @punctuation.bracket + +[ + "=" + + "." + "-" + "*" + "/" + "+" + "%" + "**" + + "~" + "|" + "^" + "&" + "<<" + ">>" + + "->" + "?->" + + "=>" + + "<" + "<=" + ">=" + ">" + "<>" + "==" + "!=" + "===" + "!==" + + "!" + "&&" + "||" + + ".=" + "-=" + "+=" + "*=" + "/=" + "%=" + "**=" + "&=" + "|=" + "^=" + "<<=" + ">>=" + "??=" + "--" + "++" + + "@" + "::" +] @operator + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/php/indents.scm b/bundle/nvim-treesitter/queries/php/indents.scm new file mode 100644 index 000000000..2247f17ac --- /dev/null +++ b/bundle/nvim-treesitter/queries/php/indents.scm @@ -0,0 +1,21 @@ +[ + (array_creation_expression) + (compound_statement) + (declaration_list) + (binary_expression) + (return_statement) + (arguments) + (formal_parameters) +] @indent + +[ + ")" + "}" + "]" +] @branch + +[ + (comment) +] @ignore + +(compound_statement "}" @indent_end) diff --git a/bundle/nvim-treesitter/queries/php/injections.scm b/bundle/nvim-treesitter/queries/php/injections.scm new file mode 100644 index 000000000..c90e2f937 --- /dev/null +++ b/bundle/nvim-treesitter/queries/php/injections.scm @@ -0,0 +1,3 @@ +(text) @html + +(comment) @phpdoc diff --git a/bundle/nvim-treesitter/queries/php/locals.scm b/bundle/nvim-treesitter/queries/php/locals.scm new file mode 100644 index 000000000..277888d5c --- /dev/null +++ b/bundle/nvim-treesitter/queries/php/locals.scm @@ -0,0 +1,87 @@ +; Scopes +;------- + +((class_declaration + name: (name) @definition.type) @scope + (set! definition.type.scope "parent")) + +((method_declaration + name: (name) @definition.method) @scope + (set! definition.method.scope "parent")) + +((function_definition + name: (name) @definition.function) @scope + (set! definition.function.scope "parent")) + +(anonymous_function_creation_expression + (anonymous_function_use_clause + (variable_name + (name) @definition.var))) @scope + +; Definitions +;------------ + +(simple_parameter + (variable_name + (name) @definition.var)) + +(foreach_statement + (pair + (variable_name + (name) @definition.var))) + +(foreach_statement + (variable_name + (name) @reference + (set! reference.kind "var")) + (variable_name + (name) @definition.var)) + +(property_declaration + (property_element + (variable_name + (name) @definition.field))) + +(namespace_use_clause + (qualified_name + (name) @definition.type)) + +; References +;------------ + +(named_type + (name) @reference + (set! reference.kind "type")) + +(named_type + (qualified_name) @reference + (set! reference.kind "type")) + +(variable_name + (name) @reference + (set! reference.kind "var")) + +(member_access_expression + name: (name) @reference + (set! reference.kind "field")) + +(member_call_expression + name: (name) @reference + (set! reference.kind "method")) + +(function_call_expression + function: (qualified_name + (name) @reference + (set! reference.kind "function"))) + +(object_creation_expression + (qualified_name + (name) @reference + (set! reference.kind "type"))) + +(scoped_call_expression + scope: (qualified_name + (name) @reference + (set! reference.kind "type")) + name: (name) @reference + (set! reference.kind "method")) diff --git a/bundle/nvim-treesitter/queries/phpdoc/highlights.scm b/bundle/nvim-treesitter/queries/phpdoc/highlights.scm new file mode 100644 index 000000000..b0433da9f --- /dev/null +++ b/bundle/nvim-treesitter/queries/phpdoc/highlights.scm @@ -0,0 +1,42 @@ +(tag_name) @attribute +(tag + (tag_name) @_tag (#eq? @_tag "@param") + (variable_name) @parameter +) +(tag + (tag_name) @_tag (#eq? @_tag "@property") + (variable_name) @property +) +(tag + (tag_name) @_tag (#eq? @_tag "@var") + (variable_name) @variable +) +(tag + (tag_name) @_tag (#eq? @_tag "@method") + (name) @method +) +(parameter + (variable_name) @parameter) +(type_list + [ + (array_type) + (primitive_type) + (named_type) + ] @type) +(tag + (description (text) @text)) +(tag + [ + (author_name) + (version) + ] @text) +(tag + (email_address) @text.uri +) + +(type_list "|" @keyword) +(variable_name "$" @keyword) +(tag + (tag_name) @_tag_name + ["<" ">"] @keyword + (#eq? @_tag_name "@author")) diff --git a/bundle/nvim-treesitter/queries/pioasm/highlights.scm b/bundle/nvim-treesitter/queries/pioasm/highlights.scm new file mode 100644 index 000000000..c455103f9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/pioasm/highlights.scm @@ -0,0 +1,30 @@ +[ (line_comment) (block_comment) ] @comment + +(label_decl) @label + +(string) @string + +(instruction + opcode: _ @keyword) + +[ "pins" "x" "y" "null" "isr" "osr" "status" "pc" "exec" ] @variable.builtin + +(out_target "pindirs" @variable.builtin) +(directive "pindirs" @keyword) + +(condition [ "--" "!=" ] @operator) +(expression [ "+" "-" "*" "/" "|" "&" "^" "::" ] @operator) +(not) @operator + +[ "optional" "opt" "side" "sideset" "side_set" "pin" "gpio" "osre" ] @keyword +[ "block" "noblock" "iffull" "ifempty" "rel" ] @keyword +(irq_modifiers) @keyword + +(integer) @number + +(directive (identifier) @variable) +(directive (symbol_def (identifier) @variable)) +(value (identifier) @variable) + +(directive + directive: _ @keyword) diff --git a/bundle/nvim-treesitter/queries/pioasm/injections.scm b/bundle/nvim-treesitter/queries/pioasm/injections.scm new file mode 100644 index 000000000..a8a0cf49e --- /dev/null +++ b/bundle/nvim-treesitter/queries/pioasm/injections.scm @@ -0,0 +1,10 @@ + [ (line_comment) (block_comment) ] @comment + +((code_block + (code_block_language) @_language + (code_block_body) @c) + (#eq? @_language "c-sdk")) + +(code_block + (code_block_language) @language + (code_block_body) @content) diff --git a/bundle/nvim-treesitter/queries/prisma/highlights.scm b/bundle/nvim-treesitter/queries/prisma/highlights.scm new file mode 100644 index 000000000..e3a025d98 --- /dev/null +++ b/bundle/nvim-treesitter/queries/prisma/highlights.scm @@ -0,0 +1,39 @@ +(variable) @variable + +[ + "datasource" + "enum" + "generator" + "model" + "type" +] @keyword + +[ + (comment) + (developer_comment) +] @comment + +[ + (attribute) + (call_expression) +] @function + +(arguments) @property +(column_type) @type +(enumeral) @constant +(column_declaration (identifier) @variable) +(string) @string + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "@" +] @operator diff --git a/bundle/nvim-treesitter/queries/pug/highlights.scm b/bundle/nvim-treesitter/queries/pug/highlights.scm new file mode 100644 index 000000000..af860be04 --- /dev/null +++ b/bundle/nvim-treesitter/queries/pug/highlights.scm @@ -0,0 +1,30 @@ +(comment) @comment +(tag_name) @tag +( + (tag_name) @constant.builtin + ; https://www.script-example.com/html-tag-liste + (#any-of? @constant.builtin + "head" "title" "base" "link" "meta" "style" + "body" "article" "section" "nav" "aside" "h1" "h2" "h3" "h4" "h5" "h6" "hgroup" "header" "footer" "address" + "p" "hr" "pre" "blockquote" "ol" "ul" "menu" "li" "dl" "dt" "dd" "figure" "figcaption" "main" "div" + "a" "em" "strong" "small" "s" "cite" "q" "dfn" "abbr" "ruby" "rt" "rp" "data" "time" "code" "var" "samp" "kbd" "sub" "sup" "i" "b" "u" "mark" "bdi" "bdo" "span" "br" "wbr" + "ins" "del" + "picture" "source" "img" "iframe" "embed" "object" "param" "video" "audio" "track" "map" "area" + "table" "caption" "colgroup" "col" "tbody" "thead" "tfoot" "tr" "td" "th " + "form" "label" "input" "button" "select" "datalist" "optgroup" "option" "textarea" "output" "progress" "meter" "fieldset" "legend" + "details" "summary" "dialog" + "script" "noscript" "template" "slot" "canvas") +) +(content) @none +(quoted_attribute_value) @string +(id) @constant +(class) @constant +(attribute_name) @symbol +( + (attribute_name ) @keyword + (#match? @keyword "^(:|v-bind|v-|\\@)") +) @keyword + +[ + ":" +] @punctuation.delimiter diff --git a/bundle/nvim-treesitter/queries/pug/injections.scm b/bundle/nvim-treesitter/queries/pug/injections.scm new file mode 100644 index 000000000..027744402 --- /dev/null +++ b/bundle/nvim-treesitter/queries/pug/injections.scm @@ -0,0 +1,7 @@ +(javascript) @javascript + +( + (attribute_name) @_attribute_name + (quoted_attribute_value (attribute_value ) @javascript) + (#match? @_attribute_name "^(:|v-bind|v-|\\@)") +) diff --git a/bundle/nvim-treesitter/queries/python/folds.scm b/bundle/nvim-treesitter/queries/python/folds.scm new file mode 100644 index 000000000..aacd0aaca --- /dev/null +++ b/bundle/nvim-treesitter/queries/python/folds.scm @@ -0,0 +1,27 @@ +(function_definition (block) @fold) +(class_definition (block) @fold) + +(while_statement (block) @fold) +(for_statement (block) @fold) +(if_statement (block) @fold) +(with_statement (block) @fold) +(try_statement (block) @fold) + +[ + (import_from_statement) + (parameters) + (argument_list) + + (parenthesized_expression) + (generator_expression) + (list_comprehension) + (set_comprehension) + (dictionary_comprehension) + + (tuple) + (list) + (set) + (dictionary) + + (string) +] @fold diff --git a/bundle/nvim-treesitter/queries/python/highlights.scm b/bundle/nvim-treesitter/queries/python/highlights.scm new file mode 100644 index 000000000..ec419375f --- /dev/null +++ b/bundle/nvim-treesitter/queries/python/highlights.scm @@ -0,0 +1,299 @@ +;; From tree-sitter-python licensed under MIT License +; Copyright (c) 2016 Max Brunsfeld + +; Variables +(identifier) @variable + +; Reset highlighting in f-string interpolations +(interpolation) @none + +;; Identifier naming conventions +((identifier) @type + (#lua-match? @type "^[A-Z].*[a-z]")) +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +((identifier) @constant.builtin + (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + ;; https://docs.python.org/3/library/constants.html + "NotImplemented" + "Ellipsis" + "quit" + "exit" + "copyright" + "credits" + "license")) + +((attribute + attribute: (identifier) @field) + (#match? @field "^([A-Z])@!.*$")) + +((identifier) @type.builtin + (#any-of? @type.builtin + ;; https://docs.python.org/3/library/exceptions.html + "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError" + "EOFError" "FloatingPointError" "GeneratorExit" "ImportError" "ModuleNotFoundError" "IndexError" "KeyError" + "KeyboardInterrupt" "MemoryError" "NameError" "NotImplementedError" "OSError" "OverflowError" "RecursionError" + "ReferenceError" "RuntimeError" "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" + "SystemError" "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" "UnicodeDecodeError" + "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" "IOError" "WindowsError" + "BlockingIOError" "ChildProcessError" "ConnectionError" "BrokenPipeError" "ConnectionAbortedError" + "ConnectionRefusedError" "ConnectionResetError" "FileExistsError" "FileNotFoundError" "InterruptedError" + "IsADirectoryError" "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning" + "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning" + "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning")) + +; Function calls + +(decorator) @function +((decorator (attribute (identifier) @function)) + (#match? @function "^([A-Z])@!.*$")) +(decorator) @function +((decorator (identifier) @function) + (#match? @function "^([A-Z])@!.*$")) + +(call + function: (identifier) @function) + +(call + function: (attribute + attribute: (identifier) @method)) + +((call + function: (identifier) @constructor) + (#lua-match? @constructor "^[A-Z]")) + +((call + function: (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^[A-Z]")) + +;; Builtin functions + +((call + function: (identifier) @function.builtin) + (#any-of? @function.builtin + "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr" "classmethod" + "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec" "filter" "float" "format" + "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance" "issubclass" + "iter" "len" "list" "locals" "map" "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" + "print" "property" "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" + "sum" "super" "tuple" "type" "vars" "zip" "__import__")) + +;; Function definitions + +(function_definition + name: (identifier) @function) + +(type (identifier) @type) +(type + (subscript + (identifier) @type)) ; type subscript: Tuple[int] + +((call + function: (identifier) @_isinstance + arguments: (argument_list + (_) + (identifier) @type)) + (#eq? @_isinstance "isinstance")) + +;; Normal parameters +(parameters + (identifier) @parameter) +;; Lambda parameters +(lambda_parameters + (identifier) @parameter) +(lambda_parameters + (tuple_pattern + (identifier) @parameter)) +; Default parameters +(keyword_argument + name: (identifier) @parameter) +; Naming parameters on call-site +(default_parameter + name: (identifier) @parameter) +(typed_parameter + (identifier) @parameter) +(typed_default_parameter + (identifier) @parameter) +; Variadic parameters *args, **kwargs +(parameters + (list_splat_pattern ; *args + (identifier) @parameter)) +(parameters + (dictionary_splat_pattern ; **kwargs + (identifier) @parameter)) + + +;; Literals + +(none) @constant.builtin +[(true) (false)] @boolean +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +(integer) @number +(float) @float + +(comment) @comment +(string) @string +[ + (escape_sequence) + "{{" + "}}" +] @string.escape + +; Tokens + +[ + "-" + "-=" + ":=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "@" + "@=" + "|" + "|=" + "~" + "->" +] @operator + +; Keywords +[ + "and" + "in" + "is" + "not" + "or" + + "del" +] @keyword.operator + +[ + "def" + "lambda" +] @keyword.function + +[ + "assert" + "async" + "await" + "class" + "exec" + "global" + "nonlocal" + "pass" + "print" + "with" + "as" +] @keyword + +[ + "return" + "yield" +] @keyword.return +(yield "from" @keyword.return) + +(import_from_statement "from" @include) +"import" @include + +(aliased_import "as" @include) + +["if" "elif" "else" "match" "case"] @conditional + +["for" "while" "break" "continue"] @repeat + +[ + "try" + "except" + "raise" + "finally" +] @exception + +(try_statement + (else_clause + "else" @exception)) + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) + +["," "." ":" ";" (ellipsis)] @punctuation.delimiter + +;; Class definitions + +(class_definition name: (identifier) @type) + +(class_definition + body: (block + (function_definition + name: (identifier) @method))) + +(class_definition + superclasses: (argument_list + (identifier) @type)) + +((class_definition + body: (block + (expression_statement + (assignment + left: (identifier) @field)))) + (#match? @field "^([A-Z])@!.*$")) +((class_definition + body: (block + (expression_statement + (assignment + left: (_ + (identifier) @field))))) + (#match? @field "^([A-Z])@!.*$")) + +((class_definition + (block + (function_definition + name: (identifier) @constructor))) + (#any-of? @constructor "__new__" "__init__")) + +; First parameter of a classmethod is cls. +((class_definition + body: (block + (decorated_definition + (decorator (identifier) @_decorator) + definition: (function_definition + parameters: (parameters . (identifier) @variable.builtin))))) + (#eq? @variable.builtin "cls") + (#eq? @_decorator "classmethod")) + +;; Error +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/python/indents.scm b/bundle/nvim-treesitter/queries/python/indents.scm new file mode 100644 index 000000000..3032cedfb --- /dev/null +++ b/bundle/nvim-treesitter/queries/python/indents.scm @@ -0,0 +1,55 @@ +[ + (list) + (dictionary) + (set) + + (if_statement) + (for_statement) + (while_statement) + (with_statement) + (try_statement) + (import_from_statement) + + (parenthesized_expression) + (generator_expression) + (list_comprehension) + (set_comprehension) + (dictionary_comprehension) + + (tuple_pattern) + (list_pattern) + (binary_operator) + + (lambda) + (function_definition) + (class_definition) + + (concatenated_string) +] @indent + +(if_statement + condition: (parenthesized_expression) @aligned_indent + (#set! "delimiter" "()") +) +((ERROR "(" . (_)) @aligned_indent + (#set! "delimiter" "()")) +((argument_list) @aligned_indent + (#set! "delimiter" "()")) +((argument_list) @aligned_indent + (#set! "delimiter" "()")) +((parameters) @aligned_indent + (#set! "delimiter" "()")) +((tuple) @aligned_indent + (#set! "delimiter" "()")) + +[ + ")" + "]" + "}" + (elif_clause) + (else_clause) + (except_clause) + (finally_clause) +] @branch + +(string) @auto diff --git a/bundle/nvim-treesitter/queries/python/injections.scm b/bundle/nvim-treesitter/queries/python/injections.scm new file mode 100644 index 000000000..04d0eed1f --- /dev/null +++ b/bundle/nvim-treesitter/queries/python/injections.scm @@ -0,0 +1,8 @@ +((call + function: (attribute + object: (identifier) @_re) + arguments: (argument_list (string) @regex)) + (#eq? @_re "re") + (#lua-match? @regex "^r.*")) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/python/locals.scm b/bundle/nvim-treesitter/queries/python/locals.scm new file mode 100644 index 000000000..76a14fef5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/python/locals.scm @@ -0,0 +1,115 @@ +;;; Program structure +(module) @scope + +(class_definition + body: (block + (expression_statement + (assignment + left: (identifier) @definition.field)))) @scope +(class_definition + body: (block + (expression_statement + (assignment + left: (_ + (identifier) @definition.field))))) @scope + +; Imports +(aliased_import + alias: (identifier) @definition.import) +(import_statement + name: (dotted_name ((identifier) @definition.import))) +(import_from_statement + name: (dotted_name ((identifier) @definition.import))) + +; Function with parameters, defines parameters +(parameters + (identifier) @definition.parameter) + +(default_parameter + (identifier) @definition.parameter) + +(typed_parameter + (identifier) @definition.parameter) + +(typed_default_parameter + (identifier) @definition.parameter) + +; *args parameter +(parameters + (list_splat_pattern + (identifier) @definition.parameter)) + +; **kwargs parameter +(parameters + (dictionary_splat_pattern + (identifier) @definition.parameter)) + +; Function defines function and scope +((function_definition + name: (identifier) @definition.function) @scope + (#set! definition.function.scope "parent")) + + +((class_definition + name: (identifier) @definition.type) @scope + (#set! definition.type.scope "parent")) + +(class_definition + body: (block + (function_definition + name: (identifier) @definition.method))) + +;;; Loops +; not a scope! +(for_statement + left: (pattern_list + (identifier) @definition.var)) +(for_statement + left: (tuple_pattern + (identifier) @definition.var)) +(for_statement + left: (identifier) @definition.var) + +; not a scope! +;(while_statement) @scope + +; for in list comprehension +(for_in_clause + left: (identifier) @definition.var) +(for_in_clause + left: (tuple_pattern + (identifier) @definition.var)) +(for_in_clause + left: (pattern_list + (identifier) @definition.var)) + +(dictionary_comprehension) @scope +(list_comprehension) @scope +(set_comprehension) @scope + +;;; Assignments + +(assignment + left: (identifier) @definition.var) + +(assignment + left: (pattern_list + (identifier) @definition.var)) +(assignment + left: (tuple_pattern + (identifier) @definition.var)) + +(assignment + left: (attribute + (identifier) + (identifier) @definition.field)) + +; Walrus operator x := 1 +(named_expression + (identifier) @definition.var) + +(as_pattern + alias: (as_pattern_target) @definition.var) + +;;; REFERENCES +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/ql/highlights.scm b/bundle/nvim-treesitter/queries/ql/highlights.scm new file mode 100644 index 000000000..7481f3c60 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ql/highlights.scm @@ -0,0 +1,130 @@ +[ + "as" + "asc" + "by" + "class" + "desc" + "extends" + "forall" + "forex" + "from" + "implies" + "in" + "module" + "newtype" + "order" + "select" + "where" + + (predicate) + (result) + (specialId) +] @keyword + +[ + "and" + "not" + "or" +] @keyword.operator + +[ + "avg" + "any" + "count" + "concat" + "exists" + "max" + "min" + "instanceof" + "rank" + "sum" + "strictconcat" + "strictcount" + "strictsum" +] @function.builtin + +[ + "import" +] @include + +[ + "if" + "then" + "else" +] @conditional + +[ + (true) + (false) +] @boolean + +[ + (this) + (super) +] @variable.builtin + +[ + "boolean" + "float" + "int" + "date" + "string" +] @type.builtin + +(annotName) @attribute + +[ + "<" + "<=" + "=" + ">" + ">=" + "-" + "!=" + "/" + "*" + "%" + "+" + "::" +] @operator + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + "," + "|" +] @punctuation.delimiter + +(moduleExpr (simpleId) @namespace) +(module name: (moduleName) @namespace) + +(dataclass name: (className) @type) +(datatype name: (className) @type) +(typeExpr name: (className) @type) + +(importModuleExpr name: (simpleId) @variable) +(qualModuleExpr name: (simpleId) @variable) +(varName) @variable + +(integer) @number +(float) @float + +(string) @string + +(aritylessPredicateExpr (literalId) @function) +(memberPredicate name: (predicateName) @function) +(classlessPredicate name: (predicateName) @function) +(charpred (className) @function) + +[ + (line_comment) + (block_comment) + (qldoc) +] @comment diff --git a/bundle/nvim-treesitter/queries/ql/indents.scm b/bundle/nvim-treesitter/queries/ql/indents.scm new file mode 100644 index 000000000..1641db671 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ql/indents.scm @@ -0,0 +1,22 @@ +[ + (dataclass) + (charpred) + (memberPredicate) + (quantified) +] @indent + +[ + (variable) + "(" + ")" + "{" + "}" + "[" + "]" +] @branch + +[ + (block_comment) + (line_comment) + (qldoc) +] @ignore diff --git a/bundle/nvim-treesitter/queries/ql/injections.scm b/bundle/nvim-treesitter/queries/ql/injections.scm new file mode 100644 index 000000000..88d49d424 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ql/injections.scm @@ -0,0 +1,5 @@ +[ + (line_comment) + (block_comment) + (qldoc) +] @comment diff --git a/bundle/nvim-treesitter/queries/ql/locals.scm b/bundle/nvim-treesitter/queries/ql/locals.scm new file mode 100644 index 000000000..e5fcb1698 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ql/locals.scm @@ -0,0 +1,30 @@ +; SCOPES +(module) @scope +(dataclass) @scope +(datatype) @scope +;; TODO does not work +;(classMember (body) @scope) +(memberPredicate (body) @scope) +(classlessPredicate (body) @scope) +(quantified (conjunction) @scope) +(select) @scope + +; DEFINITIONS + +; module +(module name: (moduleName) @definition.namespace) + +; classes +(dataclass name: (className) @definition.type) +(datatype name: (className) @definition.type) + +; predicates +(charpred (className) @definition.method) +(memberPredicate name: (predicateName) @definition.method) +(classlessPredicate name: (predicateName) @definition.function) + +; variables +(varDecl (varName (simpleId) @definition.var)) + +; REFERENCES +(simpleId) @reference diff --git a/bundle/nvim-treesitter/queries/query/folds.scm b/bundle/nvim-treesitter/queries/query/folds.scm new file mode 100644 index 000000000..47dd96512 --- /dev/null +++ b/bundle/nvim-treesitter/queries/query/folds.scm @@ -0,0 +1,6 @@ +[ + (named_node) + (predicate) + (grouping) + (list) +] @fold diff --git a/bundle/nvim-treesitter/queries/query/highlights.scm b/bundle/nvim-treesitter/queries/query/highlights.scm new file mode 100644 index 000000000..37435a871 --- /dev/null +++ b/bundle/nvim-treesitter/queries/query/highlights.scm @@ -0,0 +1,31 @@ +(string) @string +(escape_sequence) @string.escape +(capture (identifier) @type) +(anonymous_node (identifier) @string) +(predicate name: (identifier) @function) +(named_node name: (identifier) @variable) +(field_definition name: (identifier) @property) +(negated_field "!" @operator (identifier) @property) +(comment) @comment + +(quantifier) @operator +(predicate_type) @punctuation.special + +"." @operator + +[ + "[" + "]" + "(" + ")" +] @punctuation.bracket + +":" @punctuation.delimiter +["@" "#"] @punctuation.special +"_" @constant + +((parameters (identifier) @number) + (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) + +((program . (comment) @include) + (#match? @include "^;\ +inherits\ *:")) diff --git a/bundle/nvim-treesitter/queries/query/indents.scm b/bundle/nvim-treesitter/queries/query/indents.scm new file mode 100644 index 000000000..0df23706f --- /dev/null +++ b/bundle/nvim-treesitter/queries/query/indents.scm @@ -0,0 +1,8 @@ +[ + (list) +] @indent + +[ + "[" + "]" +] @branch diff --git a/bundle/nvim-treesitter/queries/query/injections.scm b/bundle/nvim-treesitter/queries/query/injections.scm new file mode 100644 index 000000000..95ce2978f --- /dev/null +++ b/bundle/nvim-treesitter/queries/query/injections.scm @@ -0,0 +1,6 @@ +((predicate + name: (identifier) @_name + parameters: (parameters (string) @regex)) + (#match? @_name "^#?(not-)?(match|vim-match|lua-match)$")) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/query/locals.scm b/bundle/nvim-treesitter/queries/query/locals.scm new file mode 100644 index 000000000..29ab9fe0d --- /dev/null +++ b/bundle/nvim-treesitter/queries/query/locals.scm @@ -0,0 +1,15 @@ +(program) @scope +(program (named_node) @scope) +(program (anonymous_node) @scope) +(program (grouping) @scope) + +(identifier) @reference + +(named_node + (capture) @definition.var) + +(anonymous_node + (capture) @definition.var) + +(grouping + (capture) @definition.var) diff --git a/bundle/nvim-treesitter/queries/r/highlights.scm b/bundle/nvim-treesitter/queries/r/highlights.scm new file mode 100644 index 000000000..287fb648f --- /dev/null +++ b/bundle/nvim-treesitter/queries/r/highlights.scm @@ -0,0 +1,124 @@ +; highlights.scm + +; Literals +(integer) @number + +(float) @float + +(complex) @number + +(string) @string +(string (escape_sequence) @string.escape) + +(comment) @comment + +(identifier) @variable + +(formal_parameters (identifier) @parameter) +(formal_parameters + (default_parameter name: (identifier) @parameter)) + +; Operators +[ + "=" + "<-" + "<<-" + "->" +] @operator + +(unary operator: [ + "-" + "+" + "!" + "~" +] @operator) + +(binary operator: [ + "-" + "+" + "*" + "/" + "^" + "<" + ">" + "<=" + ">=" + "==" + "!=" + "||" + "|" + "&&" + "&" + ":" + "~" +] @operator) + +[ + "|>" + (special) +] @operator + +(lambda_function "\\" @operator) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(dollar "$" @operator) + +(subset2 + "[[" @punctuation.bracket + "]]" @punctuation.bracket) + +[ + "in" + (dots) + (break) + (next) + (inf) +] @keyword + +[ + (nan) + (na) + (null) +] @type.builtin + +[ + "if" + "else" + "switch" +] @conditional + +[ + "while" + "repeat" + "for" +] @repeat + +[ + (true) + (false) +] @boolean + +"function" @keyword.function + +(call function: (identifier) @function) +(default_argument name: (identifier) @parameter) + +(namespace_get function: (identifier) @method) +(namespace_get_internal function: (identifier) @method) + +(namespace_get namespace: (identifier) @namespace + "::" @operator) + +(namespace_get_internal namespace: (identifier) @namespace + ":::" @operator) + +; Error +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/r/indents.scm b/bundle/nvim-treesitter/queries/r/indents.scm new file mode 100644 index 000000000..66e1e989b --- /dev/null +++ b/bundle/nvim-treesitter/queries/r/indents.scm @@ -0,0 +1,30 @@ +[ + (brace_list) + (paren_list) + (special) + (pipe) + (call) + "|>" + "if" + "else" + "while" + "repeat" + "for" +] @indent + +[ + "}" + ")" +] @branch + +((formal_parameters (identifier)) @aligned_indent + (#set! "delimiter" "()")) + +[ + ")" + "}" +] @indent_end + +[ + (comment) +] @ignore diff --git a/bundle/nvim-treesitter/queries/r/injections.scm b/bundle/nvim-treesitter/queries/r/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/r/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/r/locals.scm b/bundle/nvim-treesitter/queries/r/locals.scm new file mode 100644 index 000000000..394a23dfc --- /dev/null +++ b/bundle/nvim-treesitter/queries/r/locals.scm @@ -0,0 +1,11 @@ +; locals.scm + +(function_definition) @scope + +(formal_parameters (identifier) @definition.parameter) + +(left_assignment name: (identifier) @definition) +(equals_assignment name: (identifier) @definition) +(right_assignment name: (identifier) @definition) + +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/rasi/folds.scm b/bundle/nvim-treesitter/queries/rasi/folds.scm new file mode 100644 index 000000000..1557b831e --- /dev/null +++ b/bundle/nvim-treesitter/queries/rasi/folds.scm @@ -0,0 +1,5 @@ +[ + (rule_set) + (list_value) + (distance_calc) + ] @fold diff --git a/bundle/nvim-treesitter/queries/rasi/highlights.scm b/bundle/nvim-treesitter/queries/rasi/highlights.scm new file mode 100644 index 000000000..8d8876eb8 --- /dev/null +++ b/bundle/nvim-treesitter/queries/rasi/highlights.scm @@ -0,0 +1,82 @@ +(comment) @comment + +"@media" @keyword +"@import" @include +"@theme" @include + +(string_value) @string +[ + (integer_value) + (float_value) + "0" + ] @number +(boolean_value) @boolean + +[ + (feature_name) + (url_image_scale) + (direction) + (text_style_value) + (line_style_value) + (position_value) + (orientation_value) + (cursor_value) + "inherit" + ] @keyword + + +(url_image "url" @function.builtin) +(gradient_image "linear-gradient" @function.builtin) +(distance_calc "calc" @function.builtin) +(rgb_color ["rgb" "rgba"] @function.builtin) +(hsl_color ["hsl" "hsla"] @function.builtin) +(hwb_color ["hwb" "hwba"] @function.builtin) +(cmyk_color "cmyk" @function.builtin) + +[ + "(" + ")" + "{" + "}" + "[" + "]" + ] @punctuation.bracket + +(distance_op) @operator + +[ + ";" + "," + ":" + "." + ] @punctuation.delimiter + +[ + (angle_unit) + (integer_distance_unit) + (float_distance_unit) + ] @type +(percentage) @number +(percentage "%" @type) + +[ + (global_selector) + (id_selector) + ] @namespace + +(id_selector_view [ "normal" "selected" "alternate" ] @property) +(id_selector_state [ "normal" "urgent" "active" ] @tag) + +(hex_color) @number +(hex_color "#" @punctuation.special) +(named_color (identifier) @string.special) +(named_color "/" @operator) +(reference_value "@" @punctuation.special (identifier) @variable) +(reference_value "var" @function.builtin (identifier) @variable) +(list_value (identifier) @variable) +(environ_value "$" @punctuation.special (identifier) @variable) +(environ_value "env" @function.builtin (identifier) @variable) + +(property_name) @variable + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/rasi/indents.scm b/bundle/nvim-treesitter/queries/rasi/indents.scm new file mode 100644 index 000000000..ad8fe49bf --- /dev/null +++ b/bundle/nvim-treesitter/queries/rasi/indents.scm @@ -0,0 +1,5 @@ +(rule_set) @indent + +(block "}" @branch) + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/rasi/locals.scm b/bundle/nvim-treesitter/queries/rasi/locals.scm new file mode 100644 index 000000000..a658e2477 --- /dev/null +++ b/bundle/nvim-treesitter/queries/rasi/locals.scm @@ -0,0 +1,5 @@ +(rule_set (selectors (id_selector))) @scope + +(block (declaration (property_name) @definition.var)) + +(reference_value name:(identifier) @reference) diff --git a/bundle/nvim-treesitter/queries/regex/highlights.scm b/bundle/nvim-treesitter/queries/regex/highlights.scm new file mode 100644 index 000000000..3f5ee8515 --- /dev/null +++ b/bundle/nvim-treesitter/queries/regex/highlights.scm @@ -0,0 +1,34 @@ +;; Forked from tree-sitter-regex +;; The MIT License (MIT) Copyright (c) 2014 Max Brunsfeld +[ + "(" + ")" + "(?" + "(?:" + "(?<" + ">" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(group_name) @property + +;; These are escaped special characters that lost their special meaning +;; -> no special highlighting +(identity_escape) @string.regex + +(class_character) @constant + +[ + (control_letter_escape) + (character_class_escape) + (control_escape) + (start_assertion) + (end_assertion) + (boundary_assertion) + (non_boundary_assertion) +] @string.escape + +[ "*" "+" "?" "|" "=" "<=" "!" "" + "=>" + "->" + ">>" + "<<" + ">" + "<" + ">=" + "<=" + "**" + "*" + "/" + "%" + "+" + "-" + "&" + "|" + "^" + "&&" + "||" + "||=" + "&&=" + "!=" + "%=" + "+=" + "-=" + "*=" + "/=" + "=~" + "!~" + "?" + ":" + ".." + "..." + ] @operator + +[ + "," + ";" + "." + ] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" + "%w(" + "%i(" + ] @punctuation.bracket + +(interpolation + "#{" @punctuation.special + "}" @punctuation.special) @none + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/ruby/indents.scm b/bundle/nvim-treesitter/queries/ruby/indents.scm new file mode 100644 index 000000000..882a81574 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ruby/indents.scm @@ -0,0 +1,41 @@ +[ + (class) + (singleton_class) + (method) + (singleton_method) + (module) + (call) + (if) + (block) + (do_block) + (hash) + (array) + (argument_list) + (case) + (while) + (until) + (for) + (begin) +] @indent + +[ + "end" + ")" + "}" + "]" +] @indent_end + +[ + "(" + ")" + "{" + "}" + "[" + "]" + (when) + (elsif) + (else) + "end" +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/ruby/injections.scm b/bundle/nvim-treesitter/queries/ruby/injections.scm new file mode 100644 index 000000000..89bb058a6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ruby/injections.scm @@ -0,0 +1,7 @@ +(comment) @comment + +(heredoc_body + (heredoc_content) @content + (heredoc_end) @language + (#set! "language" @language) + (#downcase! "language")) diff --git a/bundle/nvim-treesitter/queries/ruby/locals.scm b/bundle/nvim-treesitter/queries/ruby/locals.scm new file mode 100644 index 000000000..dacc46994 --- /dev/null +++ b/bundle/nvim-treesitter/queries/ruby/locals.scm @@ -0,0 +1,55 @@ +; The MIT License (MIT) +; +; Copyright (c) 2016 Rob Rix +; +; Permission is hereby granted, free of charge, to any person obtaining a copy +; of this software and associated documentation files (the "Software"), to deal +; in the Software without restriction, including without limitation the rights +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +; copies of the Software, and to permit persons to whom the Software is +; furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included in all +; copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +; SOFTWARE. + +;;; DECLARATIONS AND SCOPES +(method) @scope +(class) @scope + +[ + (block) + (do_block) + ] @scope + +(identifier) @reference +(constant) @reference +(instance_variable) @reference + +(module name: (constant) @definition.namespace) +(class name: (constant) @definition.type) +(method name: [(identifier) (constant)] @definition.function) +(singleton_method name: [(identifier) (constant)] @definition.function) + +(method_parameters (identifier) @definition.var) +(lambda_parameters (identifier) @definition.var) +(block_parameters (identifier) @definition.var) +(splat_parameter (identifier) @definition.var) +(hash_splat_parameter (identifier) @definition.var) +(optional_parameter name: (identifier) @definition.var) +(destructured_parameter (identifier) @definition.var) +(block_parameter name: (identifier) @definition.var) +(keyword_parameter name: (identifier) @definition.var) + +(assignment left: (_) @definition.var) + +(left_assignment_list (identifier) @definition.var) +(rest_assignment (identifier) @definition.var) +(destructured_left_assignment (identifier) @definition.var) diff --git a/bundle/nvim-treesitter/queries/rust/folds.scm b/bundle/nvim-treesitter/queries/rust/folds.scm new file mode 100644 index 000000000..d83351cb4 --- /dev/null +++ b/bundle/nvim-treesitter/queries/rust/folds.scm @@ -0,0 +1,25 @@ +[(mod_item) + (function_item) + (struct_item) + (trait_item) + (enum_item) + (impl_item) + (type_item) + (union_item) + + (use_declaration) + (let_declaration) + + (loop_expression) + (for_expression) + (while_expression) + (if_expression) + (if_let_expression) + (match_expression) + (call_expression) + + (macro_definition) + (macro_invocation) + + (attribute_item) +] @fold diff --git a/bundle/nvim-treesitter/queries/rust/highlights.scm b/bundle/nvim-treesitter/queries/rust/highlights.scm new file mode 100644 index 000000000..554d64542 --- /dev/null +++ b/bundle/nvim-treesitter/queries/rust/highlights.scm @@ -0,0 +1,273 @@ +; Forked from https://github.com/tree-sitter/tree-sitter-rust +; Copyright (c) 2017 Maxim Sokolov +; Licensed under the MIT license. + +; Identifier conventions + +(identifier) @variable +((identifier) @type + (#lua-match? @type "^[A-Z]")) +(const_item + name: (identifier) @constant) +; Assume all-caps names are constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z%d_]*$")) + +; Other identifiers + +(type_identifier) @type +(primitive_type) @type.builtin +(field_identifier) @field +(shorthand_field_initializer + (identifier) @field) +(mod_item + name: (identifier) @namespace) + +(self) @variable.builtin + +(lifetime ["'" (identifier)] @label) +(loop_label ["'" (identifier)] @label) + + +; Function definitions + +(function_item (identifier) @function) +(function_signature_item (identifier) @function) + +(parameter (identifier) @parameter) +(closure_parameters (_) @parameter) + +; Function calls +(call_expression + function: (identifier) @function) +(call_expression + function: (scoped_identifier + (identifier) @function .)) +(call_expression + function: (field_expression + field: (field_identifier) @function)) + +(generic_function + function: (identifier) @function) +(generic_function + function: (scoped_identifier + name: (identifier) @function)) +(generic_function + function: (field_expression + field: (field_identifier) @function)) + +; Assume other uppercase names are enum constructors +((field_identifier) @constant + (#lua-match? @constant "^[A-Z]")) + +(enum_variant + name: (identifier) @constant) + +; Assume that uppercase names in paths are types +(scoped_identifier + path: (identifier) @namespace) +(scoped_identifier + (scoped_identifier + name: (identifier) @namespace)) +(scoped_type_identifier + path: (identifier) @namespace) +(scoped_type_identifier + (scoped_identifier + name: (identifier) @namespace)) +((scoped_identifier + path: (identifier) @type) + (#lua-match? @type "^[A-Z]")) +((scoped_identifier + name: (identifier) @type) + (#lua-match? @type "^[A-Z]")) + +[ + (crate) + (super) +] @namespace + +(scoped_use_list + path: (identifier) @namespace) +(scoped_use_list + path: (scoped_identifier + (identifier) @namespace)) +(use_list (scoped_identifier (identifier) @namespace . (_))) +(use_list (identifier) @type (#lua-match? @type "^[A-Z]")) +(use_as_clause alias: (identifier) @type (#lua-match? @type "^[A-Z]")) + +;; Correct enum constructors +(call_expression + function: (scoped_identifier + "::" + name: (identifier) @constant) + (#lua-match? @constant "^[A-Z]")) + +; Assume uppercase names in a match arm are constants. +((match_arm + pattern: (match_pattern (identifier) @constant)) + (#lua-match? @constant "^[A-Z]")) +((match_arm + pattern: (match_pattern + (scoped_identifier + name: (identifier) @constant))) + (#lua-match? @constant "^[A-Z]")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin "Some" "None" "Ok" "Err")) + +;; Macro definitions +"$" @function.macro +(metavariable) @function.macro +(macro_definition "macro_rules!" @function.macro) + +;; Attribute macros +(attribute_item (meta_item (identifier) @function.macro)) +(meta_item (scoped_identifier (identifier) @function.macro .)) + +;; Derive macros (assume all arguments are types) +(meta_item + (identifier) @_name + arguments: (meta_arguments (meta_item (identifier) @type)) + (#eq? @_name "derive")) + +;; Function-like macros +(macro_invocation + macro: (identifier) @function.macro) +(macro_invocation + macro: (scoped_identifier + (identifier) @function.macro .)) + + + +;;; Literals + +[ + (line_comment) + (block_comment) +] @comment + +(boolean_literal) @boolean +(integer_literal) @number +(float_literal) @float + +[ + (raw_string_literal) + (string_literal) +] @string +(escape_sequence) @string.escape +(char_literal) @character + + +;;; Keywords + +[ + "use" + "mod" +] @include +(use_as_clause "as" @include) + +[ + "async" + "await" + "const" + "default" + "dyn" + "enum" + "extern" + "impl" + "let" + "match" + "move" + "pub" + "ref" + "static" + "struct" + "trait" + "type" + "union" + "unsafe" + "where" + (mutable_specifier) +] @keyword + +"fn" @keyword.function +[ + "return" + "yield" +] @keyword.return + +(type_cast_expression "as" @keyword.operator) +(qualified_type "as" @keyword.operator) + +(use_list (self) @keyword) +(scoped_use_list (self) @keyword) +(scoped_identifier (self) @keyword) + +[ + "else" + "if" +] @conditional + +[ + "break" + "continue" + "for" + "in" + "loop" + "while" +] @repeat + + + +;;; Operators & Punctuation + +[ + "!" + "!=" + "%" + "%=" + "&" + "&&" + "&=" + "*" + "*=" + "+" + "+=" + "-" + "-=" + "->" + ".." + "..=" + "/" + "/=" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + "=>" + ">" + ">=" + ">>" + ">>=" + "?" + "@" + "^" + "^=" + "|" + "|=" + "||" +] @operator + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket +(closure_parameters "|" @punctuation.bracket) +(type_arguments ["<" ">"] @punctuation.bracket) +(type_parameters ["<" ">"] @punctuation.bracket) + +["," "." ":" "::" ";"] @punctuation.delimiter + +(attribute_item "#" @punctuation.special) +(inner_attribute_item ["!" "#"] @punctuation.special) +(macro_invocation "!" @function.macro) +(empty_type "!" @type.builtin) diff --git a/bundle/nvim-treesitter/queries/rust/indents.scm b/bundle/nvim-treesitter/queries/rust/indents.scm new file mode 100644 index 000000000..e6d16dadf --- /dev/null +++ b/bundle/nvim-treesitter/queries/rust/indents.scm @@ -0,0 +1,60 @@ +[ + (mod_item) + (struct_item) + (enum_item) + (impl_item) + (for_expression) + (struct_expression) + (match_expression) + (tuple_expression) + (match_arm) + (match_block) + (if_let_expression) + (call_expression) + (assignment_expression) + (arguments) + (block) + (where_clause) + (use_list) + (array_expression) + (ordered_field_declaration_list) + (field_declaration_list) + (enum_variant_list) + (parameters) + (token_tree) + (macro_definition) +] @indent +(trait_item body: (_) @indent) +(string_literal (escape_sequence)) @indent + +(block "}" @indent_end) +(enum_item + body: (enum_variant_list "}" @indent_end)) +(impl_item + body: (declaration_list "}" @indent_end)) +(match_expression + body: (match_block "}" @indent_end)) +(mod_item + body: (declaration_list "}" @indent_end)) +(struct_item + body: (field_declaration_list "}" @indent_end)) +(trait_item + body: (declaration_list "}" @indent_end)) + +(impl_item (where_clause) @dedent) + +[ + "where" + ")" + "]" + "}" +] @branch +(impl_item (declaration_list) @branch) + +[ + (line_comment) + (string_literal) +] @ignore + + +(raw_string_literal) @auto diff --git a/bundle/nvim-treesitter/queries/rust/injections.scm b/bundle/nvim-treesitter/queries/rust/injections.scm new file mode 100644 index 000000000..fd19fbec2 --- /dev/null +++ b/bundle/nvim-treesitter/queries/rust/injections.scm @@ -0,0 +1,34 @@ +(macro_invocation + (token_tree) @rust) + +(macro_definition + (macro_rule + left: (token_tree_pattern) @rust + right: (token_tree) @rust)) + +[ + (line_comment) + (block_comment) +] @comment + +( + (macro_invocation + macro: ((identifier) @_html_def) + (token_tree) @html) + + (#eq? @_html_def "html") +) + +(call_expression + function: (scoped_identifier + path: (identifier) @_regex (#eq? @_regex "Regex") + name: (identifier) @_new (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal) @regex)) + +(call_expression + function: (scoped_identifier + path: (scoped_identifier (identifier) @_regex (#eq? @_regex "Regex").) + name: (identifier) @_new (#eq? @_new "new")) + arguments: (arguments + (raw_string_literal) @regex)) diff --git a/bundle/nvim-treesitter/queries/rust/locals.scm b/bundle/nvim-treesitter/queries/rust/locals.scm new file mode 100644 index 000000000..010bf4afd --- /dev/null +++ b/bundle/nvim-treesitter/queries/rust/locals.scm @@ -0,0 +1,104 @@ +; Imports +(extern_crate_declaration + name: (identifier) @definition.import) + +(use_declaration + argument: (scoped_identifier + name: (identifier) @definition.import)) + +(use_as_clause + alias: (identifier) @definition.import) + +(use_list + (identifier) @definition.import) ; use std::process::{Child, Command, Stdio}; + +; Functions +(function_item + name: (identifier) @definition.function) + +(function_item + name: (identifier) @definition.method + parameters: (parameters + (self_parameter))) + +; Variables +(parameter + pattern: (identifier) @definition.var) + +(let_declaration + pattern: (identifier) @definition.var) + +(const_item + name: (identifier) @definition.var) + +(tuple_pattern + (identifier) @definition.var) + +(if_let_expression + pattern: (_ + (identifier) @definition.var)) + +(tuple_struct_pattern + (identifier) @definition.var) + +(closure_parameters + (identifier) @definition.var) + +(self_parameter + (self) @definition.var) + +(for_expression + pattern: (identifier) @definition.var) + +; Types +(struct_item + name: (type_identifier) @definition.type) + +(constrained_type_parameter + left: (type_identifier) @definition.type) ; the P in remove_file>(path: P) + +(enum_item + name: (type_identifier) @definition.type) + + +; Fields +(field_declaration + name: (field_identifier) @definition.field) + +(enum_variant + name: (identifier) @definition.field) + +; References +(identifier) @reference +((type_identifier) @reference + (set! reference.kind "type")) +((field_identifier) @reference + (set! reference.kind "field")) + + +; Macros +(macro_definition + name: (identifier) @definition.macro) + +; Module +(mod_item + name: (identifier) @definition.namespace) + +; Scopes +[ + (block) + (function_item) + (closure_expression) + (while_expression) + (for_expression) + (loop_expression) + (if_expression) + (if_let_expression) + (match_expression) + (match_arm) + + (struct_item) + (enum_item) + (impl_item) +] @scope + diff --git a/bundle/nvim-treesitter/queries/scala/folds.scm b/bundle/nvim-treesitter/queries/scala/folds.scm new file mode 100644 index 000000000..e748e86df --- /dev/null +++ b/bundle/nvim-treesitter/queries/scala/folds.scm @@ -0,0 +1,15 @@ +(call_expression (block) @fold) + +[(class_definition) + (trait_definition) + (object_definition) + (function_definition) + (val_definition) + (import_declaration) + + (while_expression) + (do_while_expression) + (for_expression) + (try_expression) + (match_expression) +] @fold diff --git a/bundle/nvim-treesitter/queries/scala/highlights.scm b/bundle/nvim-treesitter/queries/scala/highlights.scm new file mode 100644 index 000000000..7cf5906b0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/scala/highlights.scm @@ -0,0 +1,204 @@ +; CREDITS @stumash (stuart.mashaal@gmail.com) + +;; variables + +(identifier) @variable + +((identifier) @variable.builtin + (#lua-match? @variable.builtin "^this$")) + +(interpolation) @none + +; Assume other uppercase names constants. +; NOTE: In order to distinguish constants we highlight +; all the identifiers that are uppercased. But this solution +; is not suitable for all occurrences e.g. it will highlight +; an uppercased method as a constant if used with no params. +; Introducing highlighting for those specific cases, is probably +; best way to resolve the issue. +((identifier) @constant (#lua-match? @constant "^[A-Z]")) + +;; types + +(type_identifier) @type + +(class_definition + name: (identifier) @type) + +(object_definition + name: (identifier) @type) + +(trait_definition + name: (identifier) @type) + +(type_definition + name: (type_identifier) @type) + +; method definition + +(class_definition + body: (template_body + (function_definition + name: (identifier) @method))) +(object_definition + body: (template_body + (function_definition + name: (identifier) @method))) +(trait_definition + body: (template_body + (function_definition + name: (identifier) @method))) + +; imports + +(import_declaration + path: (identifier) @namespace) +((stable_identifier (identifier) @namespace)) + +((import_declaration + path: (identifier) @type) (#lua-match? @type "^[A-Z]")) +((stable_identifier (identifier) @type) (#lua-match? @type "^[A-Z]")) + +((import_selectors (identifier) @type) (#lua-match? @type "^[A-Z]")) + +; method invocation + + +(call_expression + function: (identifier) @function) + +(call_expression + function: (field_expression + field: (identifier) @method)) + +((call_expression + function: (identifier) @constructor) + (#lua-match? @constructor "^[A-Z]")) + +(generic_function + function: (identifier) @function) + +( + (identifier) @function.builtin + (#lua-match? @function.builtin "^super$") +) + +; function definitions + +(function_definition + name: (identifier) @function) + +(parameter + name: (identifier) @parameter) + +; expressions + + +(field_expression field: (identifier) @property) +(field_expression value: (identifier) @type + (#lua-match? @type "^[A-Z]")) + +(infix_expression operator: (identifier) @operator) +(infix_expression operator: (operator_identifier) @operator) +(infix_type operator: (operator_identifier) @operator) +(infix_type operator: (operator_identifier) @operator) + +; literals + +(boolean_literal) @boolean +(integer_literal) @number +(floating_point_literal) @float + +[ +(symbol_literal) +(string) +(character_literal) +(interpolated_string_expression) +] @string + +(interpolation "$" @punctuation.special) + +;; keywords + +[ + "abstract" + "case" + "class" + "extends" + "final" + "finally" +;; `forSome` existential types not implemented yet + "implicit" + "lazy" +;; `macro` not implemented yet + "object" + "override" + "package" + "private" + "protected" + "sealed" + "trait" + "type" + "val" + "var" + "with" +] @keyword + +(null_literal) @keyword +(wildcard) @keyword + +;; special keywords + +"new" @keyword.operator + +[ + "else" + "if" + "match" +] @conditional + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "." + "," +] @punctuation.delimiter + +[ + "do" + "for" + "while" + "yield" +] @repeat + +"def" @keyword.function + +[ + "=>" + "<-" + "@" +] @operator + +"import" @include + +[ + "try" + "catch" + "throw" +] @exception + +"return" @keyword.return + +(comment) @comment + +;; `case` is a conditional keyword in case_block + +(case_block + (case_clause ("case") @conditional)) diff --git a/bundle/nvim-treesitter/queries/scala/injections.scm b/bundle/nvim-treesitter/queries/scala/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/scala/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/scheme/folds.scm b/bundle/nvim-treesitter/queries/scheme/folds.scm new file mode 100644 index 000000000..64a9a08e6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/scheme/folds.scm @@ -0,0 +1 @@ +(program (list) @fold) diff --git a/bundle/nvim-treesitter/queries/scheme/highlights.scm b/bundle/nvim-treesitter/queries/scheme/highlights.scm new file mode 100644 index 000000000..7798eff7c --- /dev/null +++ b/bundle/nvim-treesitter/queries/scheme/highlights.scm @@ -0,0 +1,181 @@ +;; A highlight query can override the highlights queries before it. +;; So the order is important. +;; We should highlight general rules, then highlight special forms. + +(number) @number +(character) @character +(boolean) @boolean +(string) @string +(comment) @comment + +;; highlight for datum comment +;; copied from ../clojure/highlights.scm +([(comment) (directive)] @comment + (#set! "priority" 105)) + +(escape_sequence) @string.escape + +["(" ")" "[" "]" "{" "}"] @punctuation.bracket + +;; variables + +(symbol) @variable +((symbol) @variable.builtin + (#any-of? @variable.builtin "..." ".")) + +;; procedure + +(list + . + (symbol) @function) + +;; special forms + +(list + "[" + (symbol)+ @variable + "]") + +(list + . + (symbol) @_f + . + (list + (symbol) @variable) + (#eq? @_f "lambda")) + +(list + . + (symbol) @_f + . + (list + (list + (symbol) @variable)) + (#any-of? @_f + "let" "let*" "let-syntax" "let-values" "let*-values" "letrec" "letrec*" "letrec-syntax")) + +;; operators + +((symbol) @operator + (#any-of? @operator + "+" "-" "*" "/" "=" "<=" ">=" "<" ">")) + +;; keyword + +((symbol) @keyword + (#any-of? @keyword + "define" "lambda" "begin" "do" "define-syntax" + "and" "or" + "if" "cond" "case" "when" "unless" "else" "=>" + "let" "let*" "let-syntax" "let-values" "let*-values" "letrec" "letrec*" "letrec-syntax" + "set!" + "syntax-rules" "identifier-syntax" + "quote" "unquote" "quote-splicing" "quasiquote" "unquote-splicing" + "delay" + "assert" + "library" "export" "import" "rename" "only" "except" "prefix")) + +((symbol) @conditional + (#any-of? @conditional "if" "cond" "case" "when" "unless")) + +;; quote + +(abbreviation + "'" + (symbol)) @symbol + +(list + . + (symbol) @_f + (#eq? @_f "quote")) @symbol + +;; library + +(list + . + (symbol) @_lib + . + (symbol) @namespace + + (#eq? @_lib "library")) + +;; builtin procedures +;; procedures in R5RS and R6RS but not in R6RS-lib + +((symbol) @function.builtin + (#any-of? @function.builtin + ;; eq + "eqv?" "eq?" "equal?" + ;; number + "number?" "complex?" "real?" "rational?" "integer?" + "exact?" "inexact?" + "zero?" "positive?" "negative?" "odd?" "even?" "finite?" "infinite?" "nan?" + "max" "min" + "abs" "quotient" "remainder" "modulo" + "div" "div0" "mod" "mod0" "div-and-mod" "div0-and-mod0" + "gcd" "lcm" "numerator" "denominator" + "floor" "ceiling" "truncate" "round" + "rationalize" + "exp" "log" "sin" "cos" "tan" "asin" "acos" "atan" + "sqrt" "expt" + "exact-integer-sqrt" + "make-rectangular" "make-polar" "real-part" "imag-part" "magnitude" "angle" + "real-valued" "rational-valued?" "integer-valued?" + "exact" "inexact" "exact->inexact" "inexact->exact" + "number->string" "string->number" + ;; boolean + "boolean?" "not" "boolean=?" + ;; pair + "pair?" "cons" + "car" "cdr" + "caar" "cadr" "cdar" "cddr" + "caaar" "caadr" "cadar" "caddr" "cdaar" "cdadr" "cddar" "cdddr" + "caaaar" "caaadr" "caadar" "caaddr" "cadaar" "cadadr" "caddar" "cadddr" + "cdaaar" "cdaadr" "cdadar" "cdaddr" "cddaar" "cddadr" "cdddar" "cddddr" + "set-car!" "set-cdr!" + ;; list + "null?" "list?" + "list" "length" "append" "reverse" "list-tail" "list-ref" + "map" "for-each" + "memq" "memv" "member" "assq" "assv" "assoc" + ;; symbol + "symbol?" "symbol->string" "string->symbol" "symbol=?" + ;; char + "char?" "char=?" "char?" "char<=?" "char>=?" + "char-ci=?" "char-ci?" "char-ci<=?" "char-ci>=?" + "char-alphabetic?" "char-numeric?" "char-whitespace?" "char-upper-case?" "char-lower-case?" + "char->integer" "integer->char" + "char-upcase" "char-downcase" + ;; string + "string?" "make-string" "string" "string-length" "string-ref" "string-set!" + "string=?" "string-ci=?" "string?" "string<=?" "string>=?" + "string-ci?" "string-ci<=?" "string-ci>=?" + "substring" "string-append" "string->list" "list->string" + "string-for-each" + "string-copy" "string-fill!" + "string-upcase" "string-downcase" + ;; vector + "vector?" "make-vector" "vector" "vector-length" "vector-ref" "vector-set!" + "vector->list" "list->vector" "vector-fill!" "vector-map" "vector-for-each" + ;; bytevector + "bytevector?" "native-endianness" + "make-bytevector" "bytevector-length" "bytevector=?" "bytevector-fill!" + "bytevector-copy!" "bytevector-copy" + ;; error + "error" "assertion-violation" + ;; control + "procedure?" "apply" "force" + "call-with-current-continuation" "call/cc" + "values" "call-with-values" "dynamic-wind" + "eval" "scheme-report-environment" "null-environment" "interaction-environment" + ;; IO + "call-with-input-file" "call-with-output-file" "input-port?" "output-port?" + "current-input-port" "current-output-port" "with-input-from-file" "with-output-to-file" + "open-input-file" "open-output-file" "close-input-port" "close-output-port" + ;; input + "read" "read-char" "peek-char" "eof-object?" "char-ready?" + ;; output + "write" "display" "newline" "write-char" + ;; system + "load" "transcript-on" "transcript-off")) + diff --git a/bundle/nvim-treesitter/queries/scheme/injections.scm b/bundle/nvim-treesitter/queries/scheme/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/scheme/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/scss/highlights.scm b/bundle/nvim-treesitter/queries/scss/highlights.scm new file mode 100644 index 000000000..f60e78019 --- /dev/null +++ b/bundle/nvim-treesitter/queries/scss/highlights.scm @@ -0,0 +1,50 @@ +; inherits: css + +[ + "@mixin" + "@media" + "@include" +] @keyword + +[ + "@while" + "@each" + "@for" + "from" + "through" + "in" +] @repeat + +(single_line_comment) @comment +(function_name) @function + + +[ + ">=" + "<=" +] @operator + + +(mixin_statement (name) @function) +(mixin_statement (parameters (parameter) @parameter)) +(plain_value) @string +(keyword_query) @function +(identifier) @variable +(variable_name) @variable + +(each_statement (key) @parameter) +(each_statement (value) @parameter) +(each_statement (variable_value) @parameter) + +(for_statement (variable) @parameter) +(for_statement (_ (variable_value) @parameter)) + +(argument) @parameter +(arguments (variable_value) @parameter) + +[ + "[" + "]" +] @punctuation.bracket + +(include_statement (identifier) @function) diff --git a/bundle/nvim-treesitter/queries/scss/indents.scm b/bundle/nvim-treesitter/queries/scss/indents.scm new file mode 100644 index 000000000..2889ddca7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/scss/indents.scm @@ -0,0 +1,7 @@ +; inherits: css + +[ + (mixin_statement) + (while_statement) + (each_statement) +] @indent diff --git a/bundle/nvim-treesitter/queries/slint/highlights.scm b/bundle/nvim-treesitter/queries/slint/highlights.scm new file mode 100644 index 000000000..7372f331c --- /dev/null +++ b/bundle/nvim-treesitter/queries/slint/highlights.scm @@ -0,0 +1,115 @@ + +(user_type_identifier) @type + +(var_identifier) @variable + +(state_identifier) @field + +(var_identifier + (post_identifier) @variable) + +(function_identifier) @function + +(reference_identifier) @keyword +(visibility_modifier) @include + +(comment) @comment + +(value) @number +(string) @string + +[ +"in" +"for" +] @repeat + +"@" @keyword + +[ +"import" +"from" +] @include + +[ +"if" +"else" +] @conditional + +[ +"root" +"parent" +"this" +] @variable.builtin + +[ +"true" +"false" +] @boolean + + +[ +"struct" +"property" +"callback" +"in" +"animate" +"states" +"when" +"out" +"transitions" +"global" +] @keyword + +[ + "black" + "transparent" + "blue" + "ease" + "ease_in" + "ease-in" + "ease_in_out" + "ease-in-out" + "ease_out" + "ease-out" + "end" + "green" + "red" + "red" + "start" + "yellow" + ] @constant.builtin + + +; Punctuation +[ +"," +"." +] @punctuation.delimiter + +; Brackets +[ +"(" +")" +"[" +"]" +"{" +"}" +] @punctuation.bracket + +[ +"angle" +"bool" +"brush" +; "color" // This causes problems +"duration" +"easing" +"float" +"image" +"int" +"length" +"percent" +"physical-length" +"physical_length" +"string" +] @type.builtin + diff --git a/bundle/nvim-treesitter/queries/slint/indents.scm b/bundle/nvim-treesitter/queries/slint/indents.scm new file mode 100644 index 000000000..30761ef8f --- /dev/null +++ b/bundle/nvim-treesitter/queries/slint/indents.scm @@ -0,0 +1,13 @@ + +[ +(field_declaration_list_body) +(list_definition_body) +(struct_field_declaration_list_body) +] @indent + +"}" @indent_end + +(comment) @auto + +(string) @auto + diff --git a/bundle/nvim-treesitter/queries/solidity/highlights.scm b/bundle/nvim-treesitter/queries/solidity/highlights.scm new file mode 100644 index 000000000..abb3ec3d0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/solidity/highlights.scm @@ -0,0 +1,212 @@ +(comment) @comment +( + (comment) @attribute + (#match? @attribute "^/// .*") +) ;; Handles natspec comments + +; Pragma +(pragma_directive) @tag + + +; Literals +[ + (string) + (hex_string_literal) + (unicode_string_literal) + (yul_string_literal) +] @string +[ + (number_literal) + (yul_decimal_number) + (yul_hex_number) +] @number +[ + (true) + (false) +] @constant.builtin + + +; Type +(type_name (identifier) @type) +(type_name "mapping" @type) +(primitive_type) @type +(contract_declaration name: (identifier) @type) +(struct_declaration struct_name: (identifier) @type) +(struct_member name: (identifier) @field) +(enum_declaration enum_type_name: (identifier) @type) +; Color payable in payable address conversion as type and not as keyword +(payable_conversion_expression "payable" @type) +(emit_statement . (identifier) @type) +; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {} +(override_specifier (identifier) @type) +; Ensures that delimiters in mapping( ... => .. ) are not colored like types +(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket) + + +; Functions and parameters + +(function_definition + function_name: (identifier) @function) +(modifier_definition + name: (identifier) @function) +(yul_evm_builtin) @function.builtin + +; Use contructor coloring for special functions +(constructor_definition "constructor" @constructor) +(fallback_receive_definition "receive" @constructor) +(fallback_receive_definition "fallback" @constructor) + +(modifier_invocation (identifier) @function) + +; Handles expressions like structVariable.g(); +(call_expression . (member_expression (property_identifier) @method)) + +; Handles expressions like g(); +(call_expression . (identifier) @function) +(function_definition + function_name: (identifier) @function) + +; Handles the field in struct literals like MyStruct({MyField: MyVar * 2}) +(call_expression (identifier) @field . ":") + +; Function parameters +(event_paramater name: (identifier) @parameter) +(parameter name: (identifier) @parameter) + +; Yul functions +(yul_function_call function: (yul_identifier) @function) + +; Yul function parameters +(yul_function_definition . (yul_identifier) @function (yul_identifier) @parameter) + +(meta_type_expression "type" @keyword) + +(member_expression (property_identifier) @field) +(property_identifier) @field +(struct_expression ((identifier) @field . ":")) +(enum_value) @constant + + +; Keywords +[ + "pragma" + "contract" + "interface" + "library" + "is" + "struct" + "enum" + "event" + "using" + "assembly" + "emit" + "public" + "internal" + "private" + "external" + "pure" + "view" + "payable" + "modifier" + "memory" + "storage" + "calldata" + "var" + (constant) + (virtual) + (override_specifier) + (yul_leave) +] @keyword + +[ + "for" + "while" + "do" +] @repeat + +[ + "break" + "continue" + "if" + "else" + "switch" + "case" + "default" +] @conditional + +[ + "try" + "catch" +] @exception + +[ + "return" + "returns" +] @keyword.return + +"function" @keyword.function + +"import" @include +(import_directive "as" @include) +(import_directive "from" @include) + +(event_paramater "indexed" @keyword) + +; Punctuation + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + + +[ + "." + "," +] @punctuation.delimiter + + +; Operators + +[ + "&&" + "||" + ">>" + ">>>" + "<<" + "&" + "^" + "|" + "+" + "-" + "*" + "/" + "%" + "**" + "<" + "<=" + "==" + "!=" + "!==" + ">=" + ">" + "!" + "~" + "-" + "+" + "++" + "--" +] @operator + +[ + "delete" + "new" +] @keyword.operator + +(identifier) @variable +(yul_identifier) @variable + diff --git a/bundle/nvim-treesitter/queries/sparql/folds.scm b/bundle/nvim-treesitter/queries/sparql/folds.scm new file mode 100644 index 000000000..2b93a7bc7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/sparql/folds.scm @@ -0,0 +1,26 @@ +[ + (prologue) + (select_query) + (construct_query) + (describe_query) + (ask_query) + (values_clause) + (load) + (clear) + (drop) + (add) + (move) + (copy) + (create) + (insert_data) + (delete_data) + (delete_where) + (modify) + (group_graph_pattern) + (triples_same_subject) + (where_clause) + (delete_clause) + (insert_clause) + (data_block) + (blank_node_property_list) +] @fold diff --git a/bundle/nvim-treesitter/queries/sparql/highlights.scm b/bundle/nvim-treesitter/queries/sparql/highlights.scm new file mode 100644 index 000000000..8b09502bc --- /dev/null +++ b/bundle/nvim-treesitter/queries/sparql/highlights.scm @@ -0,0 +1,211 @@ +[ + (path_mod) + "||" + "&&" + "=" + "<" + ">" + "<=" + ">=" + "+" + "-" + "*" + "/" + "!" + "|" + "^" +] @operator + +[ + "_:" + (namespace) +] @namespace + +[ + "UNDEF" + "a" +] @variable.builtin + + +[ + "ADD" + "ALL" + "AS" + "ASC" + "ASK" + "BIND" + "BY" + "CLEAR" + "CONSTRUCT" + "COPY" + "CREATE" + "DEFAULT" + "DELETE" + "DELETE DATA" + "DELETE WHERE" + "DESC" + "DESCRIBE" + "DISTINCT" + "DROP" + "EXISTS" + "FILTER" + "FROM" + "GRAPH" + "GROUP" + "HAVING" + "INSERT" + "INSERT DATA" + "INTO" + "LIMIT" + "LOAD" + "MINUS" + "MOVE" + "NAMED" + "NOT" + "OFFSET" + "OPTIONAL" + "ORDER" + "PREFIX" + "REDUCED" + "SELECT" + "SERVICE" + "SILENT" + "UNION" + "USING" + "VALUES" + "WHERE" + "WITH" +] @keyword + +(string) @string +(echar) @string.escape + +(integer) @number +[ + (decimal) + (double) +] @float +(boolean_literal) @boolean + +[ + "BASE" + "PREFIX" +] @keyword + +[ + "ABS" + "AVG" + "BNODE" + "BOUND" + "CEIL" + "CONCAT" + "COALESCE" + "CONTAINS" + "DATATYPE" + "DAY" + "ENCODE_FOR_URI" + "FLOOR" + "HOURS" + "IF" + "IRI" + "LANG" + "LANGMATCHES" + "LCASE" + "MD5" + "MINUTES" + "MONTH" + "NOW" + "RAND" + "REGEX" + "ROUND" + "SECONDS" + "SHA1" + "SHA256" + "SHA384" + "SHA512" + "STR" + "SUM" + "MAX" + "MIN" + "SAMPLE" + "GROUP_CONCAT" + "SEPARATOR" + "COUNT" + "STRAFTER" + "STRBEFORE" + "STRDT" + "STRENDS" + "STRLANG" + "STRLEN" + "STRSTARTS" + "STRUUID" + "TIMEZONE" + "TZ" + "UCASE" + "URI" + "UUID" + "YEAR" + "isBLANK" + "isIRI" + "isLITERAL" + "isNUMERIC" + "isURI" + "sameTerm" +] @function.builtin + +[ + "." + "," + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" + (nil) + (anon) +] @punctuation.bracket + +[ + "IN" + ("NOT" "IN") +] @keyword.operator + + +(comment) @comment + + +; Could this be summarized? +(select_clause + [ + bound_variable: (var) + "*" + ] @parameter) +(bind bound_variable: (var) @parameter) +(data_block bound_variable: (var) @parameter) +(group_condition bound_variable: (var) @parameter) + +(iri_reference ["<" ">"] @namespace) + +(lang_tag) @type +(rdf_literal + "^^" @type + datatype: (_ ["<" ">" (namespace)] @type) @type) + +(function_call identifier: (_) @function) + +(function_call identifier: (iri_reference ["<" ">"] @function)) +(function_call identifier: (prefixed_name (namespace) @function)) +(base_declaration (iri_reference ["<" ">"] @variable)) +(prefix_declaration (iri_reference ["<" ">"] @variable)) + +[ + (var) + (blank_node_label) + (iri_reference) + (prefixed_name) +] @variable diff --git a/bundle/nvim-treesitter/queries/sparql/indents.scm b/bundle/nvim-treesitter/queries/sparql/indents.scm new file mode 100644 index 000000000..a154522a5 --- /dev/null +++ b/bundle/nvim-treesitter/queries/sparql/indents.scm @@ -0,0 +1,17 @@ +[ + (group_graph_pattern) + (triples_block) + (triples_template) + (construct_template) + (construct_triples) + (quads) + (data_block) + (blank_node_property_list) + (collection) +] @indent +[ + "}" + "]" + ")" + (triples_same_subject) +] @branch diff --git a/bundle/nvim-treesitter/queries/sparql/injections.scm b/bundle/nvim-treesitter/queries/sparql/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/sparql/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/sparql/locals.scm b/bundle/nvim-treesitter/queries/sparql/locals.scm new file mode 100644 index 000000000..107aaeb75 --- /dev/null +++ b/bundle/nvim-treesitter/queries/sparql/locals.scm @@ -0,0 +1,8 @@ +(group_graph_pattern (triples_block) @scope) + +((sub_select (select_clause (var) @definition.var)) + (#set! "definition.var.scope" "parent")) +((select_query (select_clause (var) @definition.var)) + (#set! "definition.var.scope" "parent")) + +(var) @reference diff --git a/bundle/nvim-treesitter/queries/supercollider/folds.scm b/bundle/nvim-treesitter/queries/supercollider/folds.scm new file mode 100644 index 000000000..214247bc0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/supercollider/folds.scm @@ -0,0 +1,7 @@ +[ +(function_call) +(code_block) +(function_block) +(control_structure) +] @fold + diff --git a/bundle/nvim-treesitter/queries/supercollider/highlights.scm b/bundle/nvim-treesitter/queries/supercollider/highlights.scm new file mode 100644 index 000000000..f9b6d6f1f --- /dev/null +++ b/bundle/nvim-treesitter/queries/supercollider/highlights.scm @@ -0,0 +1,97 @@ +; highlights.scm +; See this for full list: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md + +; comments +(line_comment) @comment +(block_comment) @comment + +; Argument definition +(argument name: (identifier) @parameter) + +; Variables +(local_var name: (identifier) @variable) +(environment_var name:(identifier) @variable.builtin) +(builtin_var) @constant.builtin + +; (variable) @variable + +; Functions +(function_definition + name: (variable) @function) + +; For function calls +(named_argument + name: (identifier) @property) + +; Methods +(method_call + name: (method_name) @method) + +; Classes +(class) @type + +; Literals +(number) @number +(float) @float + +(string) @string +(symbol) @string.special + +; Operators +[ +"&&" +"||" +"&" +"|" +"^" +"==" +"!=" +"<" +"<=" +">" +">=" +"<<" +">>" +"+" +"-" +"*" +"/" +"%" +"=" +] @operator + +; Keywords +[ +"arg" +"classvar" +"const" +; "super" +; "this" +"var" +] @keyword + +; Brackets +[ + "(" + ")" + "[" + "]" + "{" + "}" + "|" +] @punctuation.bracket + +; Delimiters +[ + ";" + "." + "," +] @punctuation.delimiter + +; control structure +(control_structure) @conditional + +(escape_sequence) @string.escape + +; SinOsc.ar()!2 +(duplicated_statement) @repeat diff --git a/bundle/nvim-treesitter/queries/supercollider/indents.scm b/bundle/nvim-treesitter/queries/supercollider/indents.scm new file mode 100644 index 000000000..c0be0cbaa --- /dev/null +++ b/bundle/nvim-treesitter/queries/supercollider/indents.scm @@ -0,0 +1,31 @@ +[ + (function_block) + (binary_expression) + (collection) + (indexed_collection) + (parameter_call_list) + (function_call) + (class_def) + (classvar) + (const) + (instance_var) + (variable_definition) + (variable_definition_sequence (variable_definition)) + (control_structure) + (return_statement) +] @indent + +[ + (parameter_call_list (argument_calls)) + "(" + ")" + "{" + "}" + "[" + "]" +] @branch + +[ + (block_comment) + (line_comment) +] @ignore diff --git a/bundle/nvim-treesitter/queries/supercollider/injections.scm b/bundle/nvim-treesitter/queries/supercollider/injections.scm new file mode 100644 index 000000000..e48ce9af3 --- /dev/null +++ b/bundle/nvim-treesitter/queries/supercollider/injections.scm @@ -0,0 +1,4 @@ +[ + (line_comment) + (block_comment) +] @comment diff --git a/bundle/nvim-treesitter/queries/supercollider/locals.scm b/bundle/nvim-treesitter/queries/supercollider/locals.scm new file mode 100644 index 000000000..f2238b478 --- /dev/null +++ b/bundle/nvim-treesitter/queries/supercollider/locals.scm @@ -0,0 +1,27 @@ +; Scopes +[ +(function_call) +(code_block) +(function_block) +(control_structure) +] @scope + +; Definitions +(argument + name: (identifier) @definition.parameter + (#set! "definition.var.scope" "local") +) + +(variable_definition + name: (variable (local_var (identifier) @definition.var + ))) + +(variable_definition + name: (variable (environment_var (identifier) @definition.var)) + (#set! "definition.var.scope" "global")) + +(function_definition name: (variable) @definition.var + (#set! "definition.var.scope" "parent") +) + +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/surface/folds.scm b/bundle/nvim-treesitter/queries/surface/folds.scm new file mode 100644 index 000000000..994f12e1e --- /dev/null +++ b/bundle/nvim-treesitter/queries/surface/folds.scm @@ -0,0 +1,6 @@ +; Surface folds similar to HTML and includes blocks +[ + (tag) + (component) + (block) +] @fold diff --git a/bundle/nvim-treesitter/queries/surface/highlights.scm b/bundle/nvim-treesitter/queries/surface/highlights.scm new file mode 100644 index 000000000..0144193c9 --- /dev/null +++ b/bundle/nvim-treesitter/queries/surface/highlights.scm @@ -0,0 +1,44 @@ +; Surface text is highlighted as such +(text) @text + +; Surface has two types of comments, both are highlighted as such +(comment) @comment + +; Surface attributes are highlighted as HTML attributes +(attribute_name) @tag.attribute + +; Attributes are highlighted as strings +(quoted_attribute_value) @string + +; Surface blocks are highlighted as keywords +[ + (start_block) + (end_block) + (subblock) +] @keyword + +; Surface supports HTML tags and are highlighted as such +[ + "<" + ">" + "" + "{" + "}" + "" + "{!--" + "--}" +] @tag.delimiter + +; Surface tags are highlighted as HTML +(tag_name) @tag + +; Surface components are highlighted as types (Elixir modules) +(component_name) @type + +; Surface directives are highlighted as keywords +(directive_name) @keyword + +; Surface operators +["="] @operator diff --git a/bundle/nvim-treesitter/queries/surface/indents.scm b/bundle/nvim-treesitter/queries/surface/indents.scm new file mode 100644 index 000000000..dceea9c7e --- /dev/null +++ b/bundle/nvim-treesitter/queries/surface/indents.scm @@ -0,0 +1,14 @@ +; Surface indents like HTML, with the addition of blocks +[ + (component) + (tag) + (block) +] @indent + +; Dedent at the end of each tag, as well as a subblock +[ + (end_tag) + (end_component) + (end_block) + (subblock) +] @branch diff --git a/bundle/nvim-treesitter/queries/surface/injections.scm b/bundle/nvim-treesitter/queries/surface/injections.scm new file mode 100644 index 000000000..928977a34 --- /dev/null +++ b/bundle/nvim-treesitter/queries/surface/injections.scm @@ -0,0 +1,8 @@ +; Surface expressions and components are Elixir code +[ + (expression_value) + (component_name) +] @elixir + +; Surface comments are nvim-treesitter comments +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/svelte/folds.scm b/bundle/nvim-treesitter/queries/svelte/folds.scm new file mode 100644 index 000000000..795c32fc4 --- /dev/null +++ b/bundle/nvim-treesitter/queries/svelte/folds.scm @@ -0,0 +1,9 @@ +[ + (style_element) + (script_element) + (element) + (if_statement) + (else_statement) + (each_statement) + (await_statement) +] @fold diff --git a/bundle/nvim-treesitter/queries/svelte/highlights.scm b/bundle/nvim-treesitter/queries/svelte/highlights.scm new file mode 100644 index 000000000..058682a7c --- /dev/null +++ b/bundle/nvim-treesitter/queries/svelte/highlights.scm @@ -0,0 +1,21 @@ +; inherits: html_tags + +(raw_text_expr) @none + +[ + (special_block_keyword) + (then) + (as) +] @keyword + +[ + "{" + "}" +] @punctuation.bracket + +[ + "#" + ":" + "/" + "@" +] @tag.delimiter diff --git a/bundle/nvim-treesitter/queries/svelte/indents.scm b/bundle/nvim-treesitter/queries/svelte/indents.scm new file mode 100644 index 000000000..2f6f5c32e --- /dev/null +++ b/bundle/nvim-treesitter/queries/svelte/indents.scm @@ -0,0 +1,20 @@ +[ + (element) + (if_statement) + (each_statement) + (await_statement) + (script_element) + (style_element) +] @indent + +[ + (end_tag) + (else_statement) + (if_end_expr) + (each_end_expr) + (await_end_expr) + ">" + "/>" +] @branch + +(comment) @ignore diff --git a/bundle/nvim-treesitter/queries/svelte/injections.scm b/bundle/nvim-treesitter/queries/svelte/injections.scm new file mode 100644 index 000000000..d66530f7a --- /dev/null +++ b/bundle/nvim-treesitter/queries/svelte/injections.scm @@ -0,0 +1,31 @@ +; inherits: html_tags + +( + (style_element + (start_tag + (attribute + (quoted_attribute_value (attribute_value) @_lang))) + (raw_text) @scss) + (#any-of? @_lang "scss" "postcss" "less") +) + +((attribute + (attribute_name) @_attr + (quoted_attribute_value (attribute_value) @css)) + (#eq? @_attr "style")) + +[ + (raw_text_expr) + (raw_text_each) +] @javascript + +( + (script_element + (start_tag + (attribute + (quoted_attribute_value (attribute_value) @_lang))) + (raw_text) @typescript) + (#any-of? @_lang "ts" "typescript") +) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/swift/highlights.scm b/bundle/nvim-treesitter/queries/swift/highlights.scm new file mode 100644 index 000000000..95f38f9ef --- /dev/null +++ b/bundle/nvim-treesitter/queries/swift/highlights.scm @@ -0,0 +1,150 @@ +[ "." ";" ":" "," ] @punctuation.delimiter +[ "\\(" "(" ")" "[" "]" "{" "}"] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special + +; Identifiers +(attribute) @variable +(simple_identifier) @variable +(type_identifier) @type +(self_expression) @variable.builtin + +; Declarations +"func" @keyword.function +[ + (visibility_modifier) + (member_modifier) + (function_modifier) + (property_modifier) + (parameter_modifier) + (inheritance_modifier) +] @keyword + +(function_declaration (simple_identifier) @method) +(function_declaration ["init" @constructor]) +(throws) @keyword +(async) @keyword +(where_keyword) @keyword +(parameter external_name: (simple_identifier) @parameter) +(parameter name: (simple_identifier) @parameter) +(type_parameter (type_identifier) @parameter) +(inheritance_constraint (identifier (simple_identifier) @parameter)) +(equality_constraint (identifier (simple_identifier) @parameter)) + +[ + "typealias" + "struct" + "class" + "enum" + "protocol" + "extension" + "indirect" +] @keyword + +(class_body (property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @property)))) +(protocol_property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @property))) + +(import_declaration ["import" @include]) + +(enum_entry ["case" @keyword]) + +; Function calls +(call_expression (simple_identifier) @function) ; foo() +(call_expression ; foo.bar.baz(): highlight the baz() + (navigation_expression + (navigation_suffix (simple_identifier) @function))) +((navigation_expression + (simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type + (#lua-match? @type "^[A-Z]")) + +(directive) @function.macro +(diagnostic) @function.macro + +; Statements +(for_statement ["for" @repeat]) +(for_statement ["in" @repeat]) +(for_statement item: (simple_identifier) @variable) +(else) @keyword +(as_operator) @keyword + +["while" "repeat" "continue" "break"] @repeat + +["let" "var"] @keyword +(non_binding_pattern (simple_identifier) @variable) + +(guard_statement ["guard" @conditional]) +(if_statement ["if" @conditional]) +(switch_statement ["switch" @conditional]) +(switch_entry ["case" @keyword]) +(switch_entry ["fallthrough" @keyword]) +(switch_entry (default_keyword) @keyword) +"return" @keyword.return +(ternary_expression + ["?" ":"] @conditional) + +["do" (throw_keyword) (catch_keyword)] @keyword + +(statement_label) @label + +; Comments +(comment) @comment +(multiline_comment) @comment + +; String literals +(line_str_text) @string +(str_escaped_char) @string +(multi_line_str_text) @string +(raw_str_part) @string +(raw_str_end_part) @string +(raw_str_interpolation_start) @punctuation.special +["\"" "\"\"\""] @string + +; Lambda literals +(lambda_literal ["in" @keyword.operator]) + +; Basic literals +[ + (integer_literal) + (hex_literal) + (oct_literal) + (bin_literal) +] @number +(real_literal) @float +(boolean_literal) @boolean +"nil" @variable.builtin + +; Operators +(custom_operator) @operator +[ + "try" + "try?" + "try!" + "!" + "+" + "-" + "*" + "/" + "%" + "=" + "+=" + "-=" + "*=" + "/=" + "<" + ">" + "<=" + ">=" + "++" + "--" + "&" + "~" + "%=" + "!=" + "!==" + "==" + "===" + "??" + + "->" + + "..<" + "..." +] @operator diff --git a/bundle/nvim-treesitter/queries/swift/locals.scm b/bundle/nvim-treesitter/queries/swift/locals.scm new file mode 100644 index 000000000..dfe1c83b1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/swift/locals.scm @@ -0,0 +1,18 @@ +(import_declaration (identifier) @definition.import) +(function_declaration name: (simple_identifier) @definition.function) + +; Scopes +[ + (statements) + (for_statement) + (while_statement) + (repeat_while_statement) + (do_statement) + (if_statement) + (guard_statement) + (switch_statement) + (property_declaration) + (function_declaration) + (class_declaration) + (protocol_declaration) +] @scope diff --git a/bundle/nvim-treesitter/queries/teal/folds.scm b/bundle/nvim-treesitter/queries/teal/folds.scm new file mode 100644 index 000000000..4583057cf --- /dev/null +++ b/bundle/nvim-treesitter/queries/teal/folds.scm @@ -0,0 +1,13 @@ +[ +(do_statement) +(numeric_for_statement) +(generic_for_statement) +(while_statement) +(repeat_statement) +(if_statement) +(function_statement) +(record_declaration) +(enum_declaration) +(anon_function) +(table_constructor) +] @fold diff --git a/bundle/nvim-treesitter/queries/teal/highlights.scm b/bundle/nvim-treesitter/queries/teal/highlights.scm new file mode 100644 index 000000000..c12fcb53d --- /dev/null +++ b/bundle/nvim-treesitter/queries/teal/highlights.scm @@ -0,0 +1,131 @@ + +;; Primitives +(boolean) @boolean +(comment) @comment +(shebang_comment) @comment +(identifier) @variable +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) +(nil) @constant.builtin +(number) @number +(string) @string +(table_constructor ["{" "}"] @constructor) +(varargs "..." @constant.builtin) +[ "," "." ":" ";" ] @punctuation.delimiter + +(escape_sequence) @string.escape +(format_specifier) @string.escape + +;; Basic statements/Keywords +[ "if" "then" "elseif" "else" ] @conditional +[ "for" "while" "repeat" "until" ] @repeat +"return" @keyword.return +[ "in" "local" (break) (goto) "do" "end" ] @keyword +(label) @label + +;; Global isn't a real keyword, but it gets special treatment in these places +(var_declaration "global" @keyword) +(type_declaration "global" @keyword) +(function_statement "global" @keyword) +(record_declaration "global" @keyword) +(enum_declaration "global" @keyword) + +;; Ops +(bin_op (op) @operator) +(unary_op (op) @operator) +[ "=" "as" ] @operator + +;; Functions +(function_statement + "function" @keyword.function + . name: (_) @function) +(anon_function + "function" @keyword.function) +(function_body "end" @keyword.function) + +(arg name: (identifier) @parameter) + +(function_signature + (arguments + . (arg name: (identifier) @variable.builtin)) + (#eq? @variable.builtin "self")) + +(typeargs + "<" @punctuation.bracket + . (_) @parameter + . ("," . (_) @parameter)* + . ">" @punctuation.bracket) + +(function_call + (identifier) @function . (arguments)) +(function_call + (index (_) key: (identifier) @function) . (arguments)) +(function_call + (method_index (_) key: (identifier) @function) . (arguments)) + +;; Types +(record_declaration + . "record" @keyword + name: (identifier) @type) +(anon_record . "record" @keyword) +(record_body + (record_declaration + . [ "record" ] @keyword + . name: (identifier) @type)) +(record_body + (enum_declaration + . [ "enum" ] @keyword + . name: (identifier) @type)) +(record_body + (typedef + . "type" @keyword + . name: (identifier) @type . "=")) +(record_body + (metamethod "metamethod" @keyword)) +(record_body + (userdata) @keyword) + +(enum_declaration + "enum" @keyword + name: (identifier) @type) + +(type_declaration "type" @keyword) +(type_declaration (identifier) @type) +(simple_type name: (identifier) @type) +(type_index (identifier) @type) +(type_union "|" @operator) +(function_type "function" @type) + +;; The rest of it +(var_declaration + declarators: (var_declarators + (var name: (identifier) @variable))) +(var_declaration + declarators: (var_declarators + (var + "<" @punctuation.bracket + . attribute: (attribute) @attribute + . ">" @punctuation.bracket))) +[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket + +;; Only highlight format specifiers in calls to string.format +;; string.format('...') +;(function_call +; called_object: (index +; (identifier) @base +; key: (identifier) @entry) +; arguments: (arguments . +; (string (format_specifier) @string.escape)) +; +; (#eq? @base "string") +; (#eq? @entry "format")) + +;; ('...'):format() +;(function_call +; called_object: (method_index +; (string (format_specifier) @string.escape) +; key: (identifier) @func-name) +; (#eq? @func-name "format")) + + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/teal/indents.scm b/bundle/nvim-treesitter/queries/teal/indents.scm new file mode 100644 index 000000000..b199015a6 --- /dev/null +++ b/bundle/nvim-treesitter/queries/teal/indents.scm @@ -0,0 +1,18 @@ +[ + (record_declaration) + (anon_function) + (function_body) + (table_constructor) + (if_statement) + (return_statement) + (while_statement) +] @indent + +[ + "{" + "}" + "(" + ")" + "end" + "then" +] @branch diff --git a/bundle/nvim-treesitter/queries/teal/injections.scm b/bundle/nvim-treesitter/queries/teal/injections.scm new file mode 100644 index 000000000..f37f4d747 --- /dev/null +++ b/bundle/nvim-treesitter/queries/teal/injections.scm @@ -0,0 +1,27 @@ +( + (function_call + (index + (identifier) @_cdef_identifier) + (arguments + (string) @c) + ) + + (#eq? @_cdef_identifier "cdef") + (#lua-match? @c "^[\"']") + (#offset! @c 0 1 0 -1) +) + +( + (function_call + (index + (identifier) @_cdef_identifier) + (arguments + (string) @c) + ) + + (#eq? @_cdef_identifier "cdef") + (#lua-match? @c "^%[%[") + (#offset! @c 0 2 0 -2) +) + +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/teal/locals.scm b/bundle/nvim-treesitter/queries/teal/locals.scm new file mode 100644 index 000000000..431e659a1 --- /dev/null +++ b/bundle/nvim-treesitter/queries/teal/locals.scm @@ -0,0 +1,23 @@ +(var_declaration + declarators: (var_declarators + (var (identifier)) @definition.var)) + +(var_assignment + variables: (assignment_variables + (var (identifier) @definition.var) @definition.associated)) + +(arg name: (identifier) @definition.parameter) + +(anon_function) @scope +((function_statement + (function_name) @definition.function) @scope) + +(program) @scope +(if_statement) @scope +(generic_for_statement (for_body) @scope) +(numeric_for_statement (for_body) @scope) +(repeat_statement) @scope +(while_statement (while_body) @scope) +(do_statement) @scope + +(identifier) @reference diff --git a/bundle/nvim-treesitter/queries/tlaplus/folds.scm b/bundle/nvim-treesitter/queries/tlaplus/folds.scm new file mode 100644 index 000000000..2ca0168c0 --- /dev/null +++ b/bundle/nvim-treesitter/queries/tlaplus/folds.scm @@ -0,0 +1,5 @@ +[ + (extramodular_text) + (block_comment) + (non_terminal_proof) +] @fold diff --git a/bundle/nvim-treesitter/queries/tlaplus/highlights.scm b/bundle/nvim-treesitter/queries/tlaplus/highlights.scm new file mode 100644 index 000000000..98901ef61 --- /dev/null +++ b/bundle/nvim-treesitter/queries/tlaplus/highlights.scm @@ -0,0 +1,232 @@ +; ; Intended for consumption by nvim-treesitter +; ; Default capture names for nvim-treesitter found here: +; ; https://github.com/nvim-treesitter/nvim-treesitter/blob/e473630fe0872cb0ed97cd7085e724aa58bc1c84/lua/nvim-treesitter/highlight.lua#L14-L104 + +; Keywords +[ + "ACTION" + "ASSUME" + "ASSUMPTION" + "AXIOM" + "BY" + "CASE" + "CHOOSE" + "CONSTANT" + "CONSTANTS" + "COROLLARY" + "DEF" + "DEFINE" + "DEFS" + "DOMAIN" + "ELSE" + "ENABLED" + "EXCEPT" + "EXTENDS" + "HAVE" + "HIDE" + "IF" + "IN" + "INSTANCE" + "LAMBDA" + "LEMMA" + "LET" + "LOCAL" + "MODULE" + "NEW" + "OBVIOUS" + "OMITTED" + "ONLY" + "OTHER" + "PICK" + "PROOF" + "PROPOSITION" + "PROVE" + "QED" + "RECURSIVE" + "SF_" + "STATE" + "SUBSET" + "SUFFICES" + "TAKE" + "TEMPORAL" + "THEN" + "THEOREM" + "UNCHANGED" + "UNION" + "USE" + "VARIABLE" + "VARIABLES" + "WF_" + "WITH" + "WITNESS" + (address) + (all_map_to) + (assign) + (case_arrow) + (case_box) + (def_eq) + (exists) + (forall) + (gets) + (label_as) + (maps_to) + (set_in) + (temporal_exists) + (temporal_forall) +] @keyword +; Pluscal keywords +[ + (pcal_algorithm_start) + "algorithm" + "assert" + "await" + "begin" + "call" + "define" + "end" + "fair" + "goto" + "macro" + "or" + "procedure" + "process" + "skip" + "variable" + "variables" + "when" + "with" +] @keyword +(pcal_with ("=") @keyword) +(pcal_process ("=") @keyword) +[ + "if" + "then" + "else" + "elsif" + (pcal_end_if) + "either" + (pcal_end_either) +] @conditional +[ + "while" + "do" + (pcal_end_while) + "with" + (pcal_end_with) +] @repeat +("return") @keyword.return +("print") @function.macro + + +; Literals +(binary_number (format) @keyword) +(binary_number (value) @number) +(boolean) @boolean +(boolean_set) @type +(hex_number (format) @keyword) +(hex_number (value) @number) +(int_number_set) @type +(nat_number) @number +(nat_number_set) @type +(octal_number (format) @keyword) +(octal_number (value) @number) +(real_number) @number +(real_number_set) @type +(string) @string +(escape_char) @string.escape +(string_set) @type + +; Namespaces and includes +(extends (identifier_ref) @include) +(module name: (_) @namespace) +(pcal_algorithm name: (identifier) @namespace) + +; Operators and functions +(bound_infix_op symbol: (_) @function.builtin) +(bound_nonfix_op (infix_op_symbol) @operator) +(bound_nonfix_op (postfix_op_symbol) @operator) +(bound_nonfix_op (prefix_op_symbol) @operator) +(bound_postfix_op symbol: (_) @function.builtin) +(bound_prefix_op symbol: (_) @function.builtin) +(function_definition name: (identifier) @function) +(module_definition name: (identifier) @function) +(operator_definition name: (_) @operator) +(pcal_macro_decl name: (identifier) @function.macro) +(pcal_macro_call name: (identifier) @function.macro) +(pcal_proc_decl name: (identifier) @function.macro) +(pcal_process name: (identifier) @function) +(recursive_declaration (identifier) @operator) +(recursive_declaration (operator_declaration name: (_) @operator)) + +; Constants and variables +(constant_declaration (identifier) @constant.builtin) +(constant_declaration (operator_declaration name: (_) @constant.builtin)) +(pcal_var_decl (identifier) @variable.builtin) +(pcal_with (identifier) @parameter) +((".") . (identifier) @attribute) +(record_literal (identifier) @attribute) +(set_of_records (identifier) @attribute) +(variable_declaration (identifier) @variable.builtin) + +; Parameters +(quantifier_bound (identifier) @parameter) +(quantifier_bound (tuple_of_identifiers (identifier) @parameter)) +(lambda (identifier) @parameter) +(module_definition (operator_declaration name: (_) @parameter)) +(module_definition parameter: (identifier) @parameter) +(operator_definition (operator_declaration name: (_) @parameter)) +(operator_definition parameter: (identifier) @parameter) +(pcal_macro_decl parameter: (identifier) @parameter) +(pcal_proc_var_decl (identifier) @parameter) + +; Delimiters +[ + (langle_bracket) + (rangle_bracket) + (rangle_bracket_sub) + "{" + "}" + "[" + "]" + "]_" + "(" + ")" +] @punctuation.bracket +[ + "," + ":" + "." + "!" + ";" + (bullet_conj) + (bullet_disj) + (prev_func_val) + (placeholder) +] @punctuation.delimiter + +; Proofs +(proof_step_id "<" @punctuation.bracket) +(proof_step_id (level) @label) +(proof_step_id (name) @label) +(proof_step_id ">" @punctuation.bracket) +(proof_step_ref "<" @punctuation.bracket) +(proof_step_ref (level) @label) +(proof_step_ref (name) @label) +(proof_step_ref ">" @punctuation.bracket) + +; Comments and tags +(block_comment "(*" @comment) +(block_comment "*)" @comment) +(block_comment_text) @comment +(comment) @comment +(single_line) @comment +(_ label: (identifier) @label) +(label name: (_) @label) +(pcal_goto statement: (identifier) @label) + +; Reference highlighting with the same color as declarations. +; `constant`, `operator`, and others are custom captures defined in locals.scm +((identifier_ref) @constant.builtin (#is? @constant.builtin constant)) +((identifier_ref) @operator (#is? @operator function)) +((identifier_ref) @parameter (#is? @parameter parameter)) +((identifier_ref) @variable.builtin (#is? @variable.builtin var)) diff --git a/bundle/nvim-treesitter/queries/tlaplus/injections.scm b/bundle/nvim-treesitter/queries/tlaplus/injections.scm new file mode 100644 index 000000000..4d0833e1b --- /dev/null +++ b/bundle/nvim-treesitter/queries/tlaplus/injections.scm @@ -0,0 +1,4 @@ +[ + (comment) + (block_comment_text) +] @comment diff --git a/bundle/nvim-treesitter/queries/tlaplus/locals.scm b/bundle/nvim-treesitter/queries/tlaplus/locals.scm new file mode 100644 index 000000000..7687c5110 --- /dev/null +++ b/bundle/nvim-treesitter/queries/tlaplus/locals.scm @@ -0,0 +1,42 @@ +; Scopes +[ + (bounded_quantification) + (function_definition) + (lambda) + (module) + (module_definition) + (pcal_algorithm) + (pcal_macro) + (pcal_procedure) + (pcal_with) + (unbounded_quantification) +] @scope + +; Definitions +(constant_declaration (identifier) @definition.constant) +(function_definition name: (identifier) @definition.function) +(lambda (identifier) @definition.parameter) +(operator_definition name: (identifier) @definition.function) +(operator_definition parameter: (identifier) @definition.parameter) +(pcal_macro_decl parameter: (identifier) @definition.parameter) +(pcal_proc_var_decl (identifier) @definition.parameter) +(pcal_var_decl (identifier) @definition.var) +(pcal_with (identifier) @definition.parameter) +(quantifier_bound (identifier) @definition.parameter) +(quantifier_bound (tuple_of_identifiers (identifier) @definition.parameter)) +(variable_declaration (identifier) @definition.var) + +; Builtin variables +(pcal_algorithm_body + [ + (_ (identifier_ref) @definition.var) + (_ (_ (identifier_ref) @definition.var)) + (_ (_ (_ (identifier_ref) @definition.var))) + (_ (_ (_ (_ (identifier_ref) @definition.var)))) + (_ (_ (_ (_ (_ (identifier_ref) @definition.var))))) + ] + (#vim-match? @definition.var "^(self|pc|stack)$") +) + +; References +(identifier_ref) @reference diff --git a/bundle/nvim-treesitter/queries/todotxt/highlights.scm b/bundle/nvim-treesitter/queries/todotxt/highlights.scm new file mode 100644 index 000000000..37f91b8a7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/todotxt/highlights.scm @@ -0,0 +1,6 @@ +(done_task) @comment +(task (priority) @keyword) +(task (date) @comment) +(task (kv) @comment) +(task (project) @string) +(task (context) @type) diff --git a/bundle/nvim-treesitter/queries/toml/folds.scm b/bundle/nvim-treesitter/queries/toml/folds.scm new file mode 100644 index 000000000..a58aae4ca --- /dev/null +++ b/bundle/nvim-treesitter/queries/toml/folds.scm @@ -0,0 +1,5 @@ +[ + (table) + (array) + (table_array_element) +] @fold diff --git a/bundle/nvim-treesitter/queries/toml/highlights.scm b/bundle/nvim-treesitter/queries/toml/highlights.scm new file mode 100644 index 000000000..17c83d547 --- /dev/null +++ b/bundle/nvim-treesitter/queries/toml/highlights.scm @@ -0,0 +1,35 @@ +; Properties +;----------- + +(bare_key) @property +(quoted_key) @string + +; Literals +;--------- + +(boolean) @boolean +(comment) @comment +(string) @string +(integer) @number +(float) @float +(offset_date_time) @string.special +(local_date_time) @string.special +(local_date) @string.special +(local_time) @string.special + +; Punctuation +;------------ + +"." @punctuation.delimiter +"," @punctuation.delimiter + +"=" @operator + +"[" @punctuation.bracket +"]" @punctuation.bracket +"[[" @punctuation.bracket +"]]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/toml/indents.scm b/bundle/nvim-treesitter/queries/toml/indents.scm new file mode 100644 index 000000000..ae5a84344 --- /dev/null +++ b/bundle/nvim-treesitter/queries/toml/indents.scm @@ -0,0 +1,11 @@ +[ + (array) + (inline_table) +] @indent + +[ + "[" + "]" + "{" + "}" +] @branch diff --git a/bundle/nvim-treesitter/queries/toml/injections.scm b/bundle/nvim-treesitter/queries/toml/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/toml/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/toml/locals.scm b/bundle/nvim-treesitter/queries/toml/locals.scm new file mode 100644 index 000000000..d3dda77b4 --- /dev/null +++ b/bundle/nvim-treesitter/queries/toml/locals.scm @@ -0,0 +1,4 @@ +[ + (table) + (table_array_element) +] @scope diff --git a/bundle/nvim-treesitter/queries/tsx/folds.scm b/bundle/nvim-treesitter/queries/tsx/folds.scm new file mode 100644 index 000000000..07391231c --- /dev/null +++ b/bundle/nvim-treesitter/queries/tsx/folds.scm @@ -0,0 +1 @@ +; inherits: typescript,jsx diff --git a/bundle/nvim-treesitter/queries/tsx/highlights.scm b/bundle/nvim-treesitter/queries/tsx/highlights.scm new file mode 100644 index 000000000..07391231c --- /dev/null +++ b/bundle/nvim-treesitter/queries/tsx/highlights.scm @@ -0,0 +1 @@ +; inherits: typescript,jsx diff --git a/bundle/nvim-treesitter/queries/tsx/indents.scm b/bundle/nvim-treesitter/queries/tsx/indents.scm new file mode 100644 index 000000000..07391231c --- /dev/null +++ b/bundle/nvim-treesitter/queries/tsx/indents.scm @@ -0,0 +1 @@ +; inherits: typescript,jsx diff --git a/bundle/nvim-treesitter/queries/tsx/injections.scm b/bundle/nvim-treesitter/queries/tsx/injections.scm new file mode 100644 index 000000000..04328f099 --- /dev/null +++ b/bundle/nvim-treesitter/queries/tsx/injections.scm @@ -0,0 +1 @@ +; inherits: ecma diff --git a/bundle/nvim-treesitter/queries/tsx/locals.scm b/bundle/nvim-treesitter/queries/tsx/locals.scm new file mode 100644 index 000000000..07391231c --- /dev/null +++ b/bundle/nvim-treesitter/queries/tsx/locals.scm @@ -0,0 +1 @@ +; inherits: typescript,jsx diff --git a/bundle/nvim-treesitter/queries/turtle/folds.scm b/bundle/nvim-treesitter/queries/turtle/folds.scm new file mode 100644 index 000000000..863e442a7 --- /dev/null +++ b/bundle/nvim-treesitter/queries/turtle/folds.scm @@ -0,0 +1,4 @@ +[ + (statement) + (blank_node_property_list) +] @fold diff --git a/bundle/nvim-treesitter/queries/turtle/highlights.scm b/bundle/nvim-treesitter/queries/turtle/highlights.scm new file mode 100644 index 000000000..0608f96ae --- /dev/null +++ b/bundle/nvim-treesitter/queries/turtle/highlights.scm @@ -0,0 +1,58 @@ +(string) @string + +(lang_tag) @type + +[ + "_:" + "<" + ">" + (namespace) +] @namespace + +[ + (iri_reference) + (prefixed_name) +] @variable + +(blank_node_label) @variable + +"a" @variable.builtin + +(integer) @number + +[ + (decimal) + (double) +] @float + +(boolean_literal) @boolean + +[ + "BASE" + "PREFIX" + "@prefix" + "@base" +] @keyword + +[ + "." + "," + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + (anon) +] @punctuation.bracket + +(comment) @comment + +(echar) @string.escape + + +(rdf_literal + "^^" @type + datatype: (_ ["<" ">" (namespace)] @type) @type) diff --git a/bundle/nvim-treesitter/queries/turtle/indents.scm b/bundle/nvim-treesitter/queries/turtle/indents.scm new file mode 100644 index 000000000..839f50c71 --- /dev/null +++ b/bundle/nvim-treesitter/queries/turtle/indents.scm @@ -0,0 +1,10 @@ +[ + (statement) + (blank_node_property_list) + (collection) +] @indent +[ + "]" + ")" +] @branch + diff --git a/bundle/nvim-treesitter/queries/turtle/injections.scm b/bundle/nvim-treesitter/queries/turtle/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/turtle/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/turtle/locals.scm b/bundle/nvim-treesitter/queries/turtle/locals.scm new file mode 100644 index 000000000..e791f0bbd --- /dev/null +++ b/bundle/nvim-treesitter/queries/turtle/locals.scm @@ -0,0 +1,12 @@ +(turtle_doc) @scope + +(subject + [ + (prefixed_name) + (iri_reference) + ] @definition.var) + +[ + (prefixed_name) + (iri_reference) +] @reference diff --git a/bundle/nvim-treesitter/queries/typescript/folds.scm b/bundle/nvim-treesitter/queries/typescript/folds.scm new file mode 100644 index 000000000..dced30d9a --- /dev/null +++ b/bundle/nvim-treesitter/queries/typescript/folds.scm @@ -0,0 +1,7 @@ +; inherits: ecma + +[ + (interface_declaration) + (internal_module) + (type_alias_declaration) +] @fold diff --git a/bundle/nvim-treesitter/queries/typescript/highlights.scm b/bundle/nvim-treesitter/queries/typescript/highlights.scm new file mode 100644 index 000000000..26725f821 --- /dev/null +++ b/bundle/nvim-treesitter/queries/typescript/highlights.scm @@ -0,0 +1,80 @@ +; inherits: ecma +[ +"abstract" +"declare" +"enum" +"export" +"implements" +"interface" +"keyof" +"namespace" +"private" +"protected" +"public" +"type" +"readonly" +] @keyword + +; types + +(type_identifier) @type +(predefined_type) @type.builtin + +(import_statement "type" + (import_clause + (named_imports + ((import_specifier + name: (identifier) @type))))) + +; punctuation + +(type_arguments + "<" @punctuation.bracket + ">" @punctuation.bracket) + +(union_type + "|" @punctuation.delimiter) + +(intersection_type + "&" @punctuation.delimiter) + +(type_annotation + ":" @punctuation.delimiter) + +(pair + ":" @punctuation.delimiter) + +(property_signature "?" @punctuation.special) +(optional_parameter "?" @punctuation.special) + +; Variables + +(undefined) @variable.builtin + +;;; Parameters +(required_parameter (identifier) @parameter) +(optional_parameter (identifier) @parameter) + +(required_parameter + (rest_pattern + (identifier) @parameter)) + +;; ({ a }) => null +(required_parameter + (object_pattern + (shorthand_property_identifier_pattern) @parameter)) + +;; ({ a: b }) => null +(required_parameter + (object_pattern + (pair_pattern + value: (identifier) @parameter))) + +;; ([ a ]) => null +(required_parameter + (array_pattern + (identifier) @parameter)) + +;; a => null +(arrow_function + parameter: (identifier) @parameter) diff --git a/bundle/nvim-treesitter/queries/typescript/indents.scm b/bundle/nvim-treesitter/queries/typescript/indents.scm new file mode 100644 index 000000000..d7f9cbc2a --- /dev/null +++ b/bundle/nvim-treesitter/queries/typescript/indents.scm @@ -0,0 +1,7 @@ +; inherits: ecma + +[ + (enum_declaration) + (interface_declaration) + (object_type) +] @indent diff --git a/bundle/nvim-treesitter/queries/typescript/injections.scm b/bundle/nvim-treesitter/queries/typescript/injections.scm new file mode 100644 index 000000000..04328f099 --- /dev/null +++ b/bundle/nvim-treesitter/queries/typescript/injections.scm @@ -0,0 +1 @@ +; inherits: ecma diff --git a/bundle/nvim-treesitter/queries/typescript/locals.scm b/bundle/nvim-treesitter/queries/typescript/locals.scm new file mode 100644 index 000000000..efbcaecaa --- /dev/null +++ b/bundle/nvim-treesitter/queries/typescript/locals.scm @@ -0,0 +1,27 @@ +; inherits: ecma +(required_parameter (identifier) @definition) +(optional_parameter (identifier) @definition) + +; x => x +(arrow_function + parameter: (identifier) @definition.parameter) + +;; ({ a }) => null +(required_parameter + (object_pattern + (shorthand_property_identifier_pattern) @definition.parameter)) + +;; ({ a: b }) => null +(required_parameter + (object_pattern + (pair_pattern + value: (identifier) @definition.parameter))) + +;; ([ a ]) => null +(required_parameter + (array_pattern + (identifier) @definition.parameter)) + +(required_parameter + (rest_pattern + (identifier) @definition.parameter)) diff --git a/bundle/nvim-treesitter/queries/vala/highlights.scm b/bundle/nvim-treesitter/queries/vala/highlights.scm new file mode 100644 index 000000000..d1be32530 --- /dev/null +++ b/bundle/nvim-treesitter/queries/vala/highlights.scm @@ -0,0 +1,297 @@ +; Identifiers + +((identifier) @constant (#match? @constant "^[A-Z][A-Z\\d_]+$")) + +(namespaced_identifier + left: [ + ; Lowercased names in lhs typically are variables, while camel cased are namespaces + ; ((identifier) @namespace (#match? @namespace "^[A-Z]+[a-z]+$")) + ((identifier) @variable (#match? @variable "^[a-z]")) + (_) + ] + right: [ + ; Lowercased are variables, camel cased are types + ; ((identifier) @parameter (#match? @parameter "^[a-z]")) + ((identifier) @type (#match? @type "^[A-Z]+[a-z]+$")) + (_) + ] +) + +((identifier) @constructor (#match? @constructor "^[A-Z]*[a-z]+")) + +; Pointers + +(address_of_identifier "&" @symbol) +(pointer_type "*" @symbol) +(indirection_identifier "*" @symbol) + +; Misc + +(number) @number + +[ + "{" + "}" + "(" + ")" + "[" + "]" +] @punctuation.bracket + +[ + ";" + ":" + "." + "," + "->" +] @punctuation.delimiter + +; Reserved keywords + +[ + "return" + "yield" + "break" +] @keyword.return + + +(null) @constant.builtin + +[ + "typeof" + "is" +] @keyword.operator + +[ + (modifier) + "var" + "class" + "interface" + (property_parameter) + (this) + "enum" + "new" + "in" + "as" + "try" + "catch" + "requires" + "ensures" + "owned" + "throws" + "delete" + "#if" + "#elif" + (preproc_else) + (preproc_endif) +] @keyword + +"throw" @exception + +[ + "if" + "else" + "switch" + "case" + "default" +] @conditional + +[ + "for" + "foreach" + "while" + "do" +] @repeat + +[ + (true) + (false) +] @boolean + +; Operators + +(binary_expression + [ + "*" + "/" + "+" + "-" + "%" + "<" + "<=" + ">" + ">=" + "==" + "!=" + "+=" + "-=" + "*=" + "/=" + "%=" + "&&" + "||" + "&" + "|" + "^" + "~" + "|=" + "&=" + "^=" + "??" + "=" + ] @operator +) + +(unary_expression + [ + "-" + "!" + "--" + "++" + ] @operator +) + +; Declaration + +(declaration + type_name: (_) @type +) + +; Methods + +(function_definition + type: (_) @type + name: [ + (identifier) @method + (generic_identifier (_) @type) + ] +) + +(function_call + identifier: [ + (identifier) @method + (generic_identifier (_) @type) + ] +) + +(member_function + identifier: [ + (identifier) @method + (generic_identifier (_) @type) + ] +) + +; Types + +(primitive_type) @type + +(nullable_type + (_) @type + "?" @symbol +) + +; Comments + +(comment) @comment + +; Namespace + +(namespace + "namespace" @include + (_) @namespace +) + +"global::" @namespace + +(using + "using" @include + (_) @namespace +) + +; Classes + +(class_declaration) @type + +(class_constructor_definition + name: [ + (_) + (namespaced_identifier (_) @constructor .) + ] @constructor +) + +(class_destructor + "~" @symbol + (_) @constructor +) + +; Interfaces + +(interface_declaration) @type + +; Strings and escape sequences + +(string_literal) @string +(verbatim) @string +(escape_sequence) @string.escape + +(string_template + "@" @symbol +) @string + +(string_template_variable) @variable + +(string_template_expression) @variable + +; New instance from Object + +(new_instance + "new" @keyword +) + +; GObject construct + +(gobject_construct + "construct" @keyword +) + +; Try statement + +(try_statement + exception: (parameter_list (declaration_parameter + (_) @exception + (_) @variable + )) +) + +; Enum + +(enum_declaration + name: (identifier) @type +) + +; Loop + +(foreach_statement + loop_item: (identifier) @variable +) + +; Casting + +(static_cast + type: (_) @type +) + +(dynamic_cast + type: (_) @type +) + +; Regex + +(regex_literal) @string.regex + +; Code attribute + +(code_attribute + name: (identifier) @attribute + param: (_) @attribute +) @attribute diff --git a/bundle/nvim-treesitter/queries/verilog/folds.scm b/bundle/nvim-treesitter/queries/verilog/folds.scm new file mode 100644 index 000000000..efc0ac66b --- /dev/null +++ b/bundle/nvim-treesitter/queries/verilog/folds.scm @@ -0,0 +1,6 @@ +[ + (seq_block) + (function_body_declaration) + (task_body_declaration) + (generate_block) +] @fold diff --git a/bundle/nvim-treesitter/queries/verilog/highlights.scm b/bundle/nvim-treesitter/queries/verilog/highlights.scm new file mode 100644 index 000000000..ba282aa07 --- /dev/null +++ b/bundle/nvim-treesitter/queries/verilog/highlights.scm @@ -0,0 +1,311 @@ +; Keywords + +[ + ; block delimeters + (module_keyword) + "endmodule" + "program" + "endprogram" + "class" + "endclass" + "interface" + "endinterface" + "package" + "endpackage" + "checker" + "endchecker" + "config" + "endconfig" + + "pure" + "virtual" + "extends" + "implements" + "super" + (class_item_qualifier) + + "parameter" + "localparam" + "defparam" + "assign" + "typedef" + "modport" + "fork" + "join" + "join_none" + "join_any" + "default" + "break" + "assert" + (unique_priority) + "tagged" + "extern" +] @keyword + +[ + "function" + "endfunction" + + "task" + "endtask" +] @keyword.function + +"return" @keyword.return + +[ + "begin" + "end" +] @label + +[ + (always_keyword) + "generate" + "for" + "foreach" + "repeat" + "forever" + "initial" + "while" +] @repeat + +[ + "if" + "else" + (case_keyword) + "endcase" +] @conditional + +(comment) @comment + +(include_compiler_directive) @constant.macro +(package_import_declaration + "import" @include) + +(package_import_declaration + (package_import_item + (package_identifier + (simple_identifier) @constant))) + +(text_macro_identifier + (simple_identifier) @constant.macro) + +(package_scope + (package_identifier + (simple_identifier) @constant)) + +(package_declaration + (package_identifier + (simple_identifier) @constant)) + +(parameter_port_list + "#" @constructor) + +[ + "=" + "-" + "+" + "/" + "*" + "^" + "&" + "|" + "&&" + "||" + ":" + (unary_operator) + "{" + "}" + "'{" + "<=" + "@" + "or" + "and" + "==" + "!=" + "===" + "!==" + "-:" + "<" + ">" + ">=" + "%" + ">>" + "<<" + "|=" + (inc_or_dec_operator) +] @operator + +(cast + ["'" "(" ")"] @operator) + +(edge_identifier) @attribute + +(port_direction) @label +(port_identifier + (simple_identifier) @variable) + +[ + (net_type) + (integer_vector_type) + (integer_atom_type) +] @type.builtin + +[ + "signed" + "unsigned" +] @label + +(data_type + (simple_identifier) @type) + +(method_call_body + (method_identifier) @field) + +(interface_identifier + (simple_identifier) @type) + +(modport_identifier + (modport_identifier + (simple_identifier) @field)) + +(net_port_type1 + (simple_identifier) @type) + +[ + (double_quoted_string) + (string_literal) +] @string + +[ + (include_compiler_directive) + (default_nettype_compiler_directive) + (timescale_compiler_directive) +] @constant.macro + +; begin/end label +(seq_block + (simple_identifier) @comment) + +[ + ";" + "::" + "," + "." +] @punctuation.delimiter + + +(default_nettype_compiler_directive + (default_nettype_value) @string) + +(text_macro_identifier + (simple_identifier) @constant) + +(module_declaration + (module_header + (simple_identifier) @constructor)) + +(class_constructor_declaration + "new" @constructor) + +(parameter_identifier + (simple_identifier) @parameter) + +[ + (integral_number) + (unsigned_number) + (unbased_unsized_literal) +] @number + +(time_unit) @attribute + +(checker_instantiation + (checker_identifier + (simple_identifier) @constructor)) + +(module_instantiation + (simple_identifier) @constructor) + +(name_of_instance + (instance_identifier + (simple_identifier) @variable)) + +(interface_port_declaration + (interface_identifier + (simple_identifier) @type)) + +(net_declaration + (simple_identifier) @type) + +(lifetime) @label + +(function_identifier + (function_identifier + (simple_identifier) @function)) + +(function_subroutine_call + (subroutine_call + (tf_call + (simple_identifier) @function))) + +(function_subroutine_call + (subroutine_call + (system_tf_call + (system_tf_identifier) @function.builtin))) + +(task_identifier + (task_identifier + (simple_identifier) @method)) + +;;TODO: fixme +;(assignment_pattern_expression + ;(assignment_pattern + ;(parameter_identifier) @field)) + +(type_declaration + (data_type ["packed"] @label)) + +(struct_union) @type + +[ + "enum" +] @type + +(enum_name_declaration + (enum_identifier + (simple_identifier) @constant)) + +(type_declaration + (simple_identifier) @type) + +[ + (integer_atom_type) + (non_integer_type) + "genvar" +] @type.builtin + +(struct_union_member + (list_of_variable_decl_assignments + (variable_decl_assignment + (simple_identifier) @field))) + +(member_identifier + (simple_identifier) @field) + +(struct_union_member + (data_type_or_void + (data_type + (simple_identifier) @type))) + +(type_declaration + (simple_identifier) @type) + +(generate_block_identifier) @comment + +[ + "[" + "]" + "(" + ")" +] @punctuation.bracket + +(ERROR) @error diff --git a/bundle/nvim-treesitter/queries/verilog/injections.scm b/bundle/nvim-treesitter/queries/verilog/injections.scm new file mode 100644 index 000000000..4bb7d675d --- /dev/null +++ b/bundle/nvim-treesitter/queries/verilog/injections.scm @@ -0,0 +1 @@ +(comment) @comment diff --git a/bundle/nvim-treesitter/queries/verilog/locals.scm b/bundle/nvim-treesitter/queries/verilog/locals.scm new file mode 100644 index 000000000..507ddea44 --- /dev/null +++ b/bundle/nvim-treesitter/queries/verilog/locals.scm @@ -0,0 +1,61 @@ +[ + (loop_generate_construct) + (loop_statement) + (conditional_statement) + (case_item) + (function_declaration) + (always_construct) + (module_declaration) +] @scope + +(data_declaration + (list_of_variable_decl_assignments + (variable_decl_assignment + (simple_identifier) @definition.var))) + +(genvar_initialization + (genvar_identifier + (simple_identifier) @definition.var)) + +(for_initialization + (for_variable_declaration + (simple_identifier) @definition.var)) + +(net_declaration + (list_of_net_decl_assignments + (net_decl_assignment + (simple_identifier) @definition.var))) + +(ansi_port_declaration + (port_identifier + (simple_identifier) @definition.var)) + +(parameter_declaration + (list_of_param_assignments + (param_assignment + (parameter_identifier + (simple_identifier) @definition.parameter)))) + +(local_parameter_declaration + (list_of_param_assignments + (param_assignment + (parameter_identifier + (simple_identifier) @definition.parameter)))) + +;; TODO: fixme +;(function_declaration + ;(function_identifier + ;(simple_identifier) @definition.function)) + +(function_declaration + (function_body_declaration + (function_identifier + (function_identifier + (simple_identifier) @definition.function)))) + +(tf_port_item1 + (port_identifier + (simple_identifier) @definition.parameter)) + +; too broad, now includes types etc +(simple_identifier) @reference diff --git a/bundle/nvim-treesitter/queries/vim/highlights.scm b/bundle/nvim-treesitter/queries/vim/highlights.scm new file mode 100644 index 000000000..64120e14a --- /dev/null +++ b/bundle/nvim-treesitter/queries/vim/highlights.scm @@ -0,0 +1,219 @@ +(identifier) @variable +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + +;; Keywords + +[ + "if" + "else" + "elseif" + "endif" +] @conditional + +[ + "try" + "catch" + "finally" + "endtry" + "throw" +] @exception + +[ + "for" + "endfor" + "in" + "while" + "endwhile" +] @repeat + +[ + "function" + "endfunction" +] @keyword.function + +;; Function related +(function_declaration name: (_) @function) +(call_expression function: (identifier) @function) +(parameters (identifier) @parameter) +(default_parameter (identifier) @parameter) + +[ (bang) (spread) (at) ] @punctuation.special + +[ (no_option) (inv_option) (default_option) (option_name) ] @variable.builtin +[ + (scope) + "a:" + "$" +] @namespace + +;; Commands and user defined commands + +[ + "let" + "unlet" + "call" + "execute" + "normal" + "set" + "setlocal" + "silent" + "echo" + "echomsg" + "autocmd" + "augroup" + "return" + "syntax" + "lua" + "ruby" + "perl" + "python" + "highlight" + "delcommand" + "comclear" + "colorscheme" + "startinsert" + "stopinsert" + "global" + "runtime" + "wincmd" +] @keyword +(map_statement cmd: _ @keyword) +(command_name) @function.macro + +;; Syntax command + +(syntax_statement (keyword) @string) +(syntax_statement [ + "enable" + "on" + "off" + "reset" + "case" + "spell" + "foldlevel" + "iskeyword" + "keyword" + "match" + "cluster" + "region" +] @keyword) + +(syntax_argument name: _ @keyword) + +[ + "" + "" + "" + "