| Issue |
170250
|
| Summary |
Use tree-sitter for syntax highlighting in LLDB
|
| Labels |
lldb
|
| Assignees |
JDevlieghere
|
| Reporter |
JDevlieghere
|
LLDB has built-in syntax highlighting for C-based languages using clang. Other languages that embed (part of) the compiler can take a similar approach; however, I'm not aware of any languages doing so, including Swift, which is the most notable example of that approach. Using the language plugin for highlighting also doesn't work for languages that don't have a language plugin and instead rely on the clang type system, such as Rust or Zig. The same limitation applies to frames created using the new StackFrameProvider, as it can create artificial stack frames in any language that LLDB recognizes but for which a language plugin wouldn't make much sense (e.g. Python).
This issue tracks the idea of using [tree-sitter](https://tree-sitter.github.io/tree-sitter/) for syntax highlighting in LLDB. Its biggest selling points are that:
- The library is general and can work with pretty much any programming language.
- Incomplete code is handled gracefully, as is the case today with clang.
- Grammars can be distributed separately.
The latter means that we can vend/distribute select grammars with LLDB while also allowing users to generate their own for the languages they care about. This workflow is quite common; for example, neovim users should be familiar with this if they're using [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
I have a working prototype that implements this idea and uses tree-sitter for syntax highlighting of C/C++. Most of the code is generic, and supporting another language is a matter of specifying the syntax-highlighting [query](https://tree-sitter.github.io/tree-sitter/using-parsers/queries/index.html) for that language and building the grammar so that LLDB can dlopen the dynamic library.
I'm filing this issue to track the idea and centralize discussion. I'm not sure yet if this is something we really want to pursue and hence it doesn't warrant an RFC yet. There are some considerations that need to be discussed. A few things that come to mind:
- Are we okay to make tree-sitter an (optional) dependency?
- Do we want to vendor grammars or only support users building their own?
- Licensing (Tree-sitter and the grammars under their GitHub organization are MIT licensed)
- Do we make this complementary to the existing Clang syntax highlighting? Behind an option? Replace it?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs