Repository navigation
Conversation
Add the tree-sitter grammar and associated highlight and folding queries for the Diff language to expand language support. Omit the editor-specific `spell` capture and punctuation patterns in highlighting, since `priority` is not recognized by Runestone. Integrate syntax highlighting validation into existing tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the tree-sitter grammar and associated highlight and folding queries for the Diff language.
The source files for the parser were imported from tree-sitter-grammars/tree-sitter-diff, and
Query.swift+TreeSitterLanguage+Helpers.swiftwere modeled after the corresponding Nix/XML files (since those were the most recent language implementations I noticed).highlights.scmwas pulled from nvim-treesitter along withfolds.scm.Highlighting validation was integrated into the existing tests, with
RequestedLanguageHighlightTests#textColorbeing updated to include explicit checks for"diff.*"and"punctuation.special"names to display accurate diff coloring.While looking into other PR's, I noticed "...editor integration, filename/import handling, and actual highlighting assertions are in simonbs/RunestoneEditor...". Since this repo is private, any integration with Runestone has intentionally been omitted. I'm not sure if this would require any changes in simonbs/Runestone since Diff highlighting should have different HighlightName's (at least from what I could tell), but I've avoided making any changes prematurely. If there are any changes that should be made there, I'm fine with doing that as well, just figured that I should inquire about how you would want that implemented; otherwise, I'll leave that to you.
Adaptations
Highlighting was explicitly modified from upstream, as the punctuation marker captures were removed due to Runestone not supporting
priority; this is documented inDiff.json'squery_adaptations. The@spellcapture was also removed, as it is independent from Runestone's spell checking and has no effect. Both of these adaptations have been documented in the relevant section withinLANGUAGE_SOURCES.md.Testing
Passed
git diff --check, existing scripts passed.Testing output
Also ran
Tests/Compatibility/test.pyandTests/Folding/test.pyin full without specifying language; both passed, the only error output was from an unrelated Lua runtime error fortree_sitter_lua_external_scanner_createin the compatibility test.For clarity, all XCode tests including
xcodebuildwere not performed, as I'm on Linux and do not have access to a MacOS environment. The existing suite was used for all tests that could be performed on my machine, but I'm relying on CI'sbuildjob for iOS integration testing (edit: seems CI only triggers onpull_requestinstead ofpull_request_target, so this needs to be approved by a maintainer first for it to run).The native folding check also proved parsing and query execution, but it does not assert the exact collapsed ranges or any UI behavior; that would still need to be confirmed by a maintainer.
Motivation
I use Runestone regularly on mobile, and have thoroughly enjoyed it; it's by far the best editor out of the many I've tried. One feature that I've been missing though has been Diff syntax highlighting for
.diffand.patchfiles. Looked around and realized the framework was open source, so figured if I wanted something then I should at least put in the effort for it 😄.While most of this wasn't very difficult as the majority of these files were derived from upstream sources, I will admit that I'm not proficient in Swift or well-versed with the repository. I read through everything I saw to ensure the implementation aligned with the existing ones; if there's anything here that should be done differently, I'll be glad to update this and resolve any issues.