CotEditor icon indicating copy to clipboard operation
CotEditor copied to clipboard

tree-sitter-based syntax highlighting

Open omasanori opened this issue 4 months ago • 1 comments

Current issue

Syntax highlighting in CotEditor is described in a YAML-based CotEditor-specific language. While the language itself is not complex, we can't reuse syntax highlight definitions developed elsewhere without error-prone conversions.

The solution you'd like

tree-sitter is a tool for generating incremental parsers suitable for syntax highlighting. tree-sitter has already been used by GNU Emacs, Helix, Neovim, Zed and others. We will be able to share bug fixes and enhancements for syntax highlighting parsers with other editors. Unlike regex-based parsers, tree-sitter-based parsers support nested syntax (https://github.com/coteditor/CotEditor/issues/617) properly by language injection.

SwiftTreeSitter combined with (or without) Neon can be used to integrate tree-sitter to Swift programs. For reference, CodeEditSourceEditor, Runestone, TreeSitterKit and TreeSitterTextView may be useful too.

Alternatives you've considered

No response

CotEditor version

5.2.3

macOS version

15.6.1

Additional context

tree-sitter integration would be useful not only for syntax highlighting, but also for code folding (https://github.com/coteditor/CotEditor/issues/459), navigation, outlining, structural editing (ex. selecting the surrounding block), syntax-aware automatic indentation (https://github.com/coteditor/CotEditor/issues/569, https://github.com/coteditor/CotEditor/issues/752), and so on.

omasanori avatar Aug 29 '25 06:08 omasanori

Actually, I’m already considering that. However, it will take some time since the CotEditor project currently has numerous tasks and migrations to complete before we can begin.

1024jp avatar Aug 31 '25 05:08 1024jp