Skip to content

szebniok/tree-sitter-wgsl

Repository files navigation

tree-sitter-wgsl

WebGPU Shading Language (WGSL) grammar for tree-sitter parser

About

The goal of this project is to provide a grammar for WebGPU Shading Lanugage (WGSL) that would enable tree-sitter to efficiently bulid a syntax tree for a source file.

WGSL is a shading language created as a part of WebGPU — future web standard that aims to provide "modern 3D graphics and computation capabilities".

Please note that both the WebGPU and WGSL spec are still under development.

Showcase

Code highlighting

Code highlighting

Incremental selection

Incremental selection

Folding

Folding

Setup

The instructions below are provided for Neovim 0.5 and nvim-treesitter, but it should be possible to get it running in any environment supporting tree-sitter parsers. I am making an assumption that you are using init.lua config file

  1. Begin by installing nvim-treesitter using your favorite package manager. E.g., if you are using packer.nvim:

    require('packer').startup(function()
        -- ...some other packages...
        use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
    end)
  2. Add the following snippet to your config file:

    vim.filetype.add({extension = {wgsl = "wgsl"}})
    
    local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
    parser_config.wgsl = {
        install_info = {
            url = "https://github.com/szebniok/tree-sitter-wgsl",
            files = {"src/parser.c"}
        },
    }
    
    require'nvim-treesitter.configs'.setup {
        ensure_installed = {"wgsl"},
        highlight = {
            enable = true
        },
        incremental_selection = {
            enable = true,
            keymaps = {
                init_selection = "gnn",
                node_incremental = "grn",
                scope_incremental = "grc",
                node_decremental = "grm",
            },
        },
    }
    
    vim.wo.foldmethod = "expr"
    vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
    vim.o.foldlevelstart = 99 -- do not close folds when a buffer is opened
  3. Copy / Symlink / Whatever the files from queries folder to $LOCATION_OF_YOUR_CONFIG_FILE/queries/wgsl folder

  4. Start nvim — the installation of wgsl grammar should begin automatically

  5. Restart nvim — all *.wgsl files should be handled properly now.

License

Distributed under the MIT License. See LICENSE for more information.

References

About

WebGPU Shading Language grammar for tree-sitter parser

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •