slint/editors/tree-sitter-slint
2025-05-26 09:17:22 +02:00
..
corpus tree-sitter: Incorporate feedback from nvim review 2024-02-07 15:12:14 +01:00
.gitignore tools: Tree sitter update for 1.0 (#2144) 2023-02-10 14:46:47 +01:00
CONTRIBUTING.md Simplify commercial license (#3063) 2024-05-31 14:06:17 +02:00
grammar.js Transition: Introduce in-out to allow writing symmetry animation (#8509) 2025-05-26 09:17:22 +02:00
README.md Simplify commercial license (#3063) 2024-05-31 14:06:17 +02:00
test-to-corpus.py Simplify commercial license (#3063) 2024-05-31 14:06:17 +02:00

tree-sitter support for SLint

Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited.

                                            (taken from tree-sitter page)

Use with vim/helix/... other editors.

Inject into Rust

This tree-sitter configuration can be injected into rust, so that the slint! macro gets highlighted.

In neovim with the nvim-treesitter plugin this is done with the

:TSEditQueryUserAfter injections rust to create/edit the rust injection configuration. Copy and paste this into the new file:

;; Inject the slint language into the `slint!` macro:
(macro_invocation
  macro: [
    (
      (scoped_identifier
        path: (_) @_macro_path
        name: (_) @_macro_name
      )
    )
    ((identifier) @_macro_name @macro_path)
  ]
  ((token_tree) @injection.content
  (#eq? @_macro_name "slint")
  (#eq? @_macro_path "slint")
  (#offset! @injection.content 0 1 0 -1)
  (#set! injection.language "slint")
  (#set! injection.combined)
  (#set! injection.include-children)
  )
)

Please send PRs when you find out how to do the same with other editors.