Fix SageMath syntax highlighting configuration and enhance grammar patterns #16
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.
The syntax highlighting for SageMath (.sage) files was not working properly due to misconfigured language settings and incomplete grammar patterns. Looking at the extension configuration, there were several critical issues:
Issues Fixed
Incorrect Language Configuration: The
configurationfield inpackage.jsonwas incorrectly pointing to the TextMate grammar file (syntaxes/sage.tmLanguage.json) instead of a proper language configuration file. This prevented VS Code from properly recognizing language-specific features like comments, brackets, and auto-closing pairs.Limited SageMath Syntax Coverage: The existing TextMate grammar had only basic patterns and didn't cover many essential SageMath constructs like number systems (ZZ, QQ, CC), built-in functions (var, solve, plot), and mathematical operators (^, ^^).
Missing Language Features: No support for proper indentation rules, word patterns, or comprehensive bracket handling.
Changes Made
Fixed Configuration Structure
language-configuration.jsonwith comment definitions, bracket pairs, auto-closing pairs, and indentation rulespackage.jsonto correctly reference the language configuration fileEnhanced TextMate Grammar
Completely rewrote
syntaxes/sage.tmLanguage.jsonwith comprehensive pattern matching for:ZZ,QQ,RR,CC,GF,Zmod,NumberField, etc.PolynomialRing,MatrixSpace,VectorSpace,FiniteFieldvar,solve,diff,integrate,plot,matrix,factor, mathematical functionspi,e,I,infinity,oo,golden_ratio^(exponentiation),^^(XOR),..(range notation)R.<x,y> = PolynomialRing(QQ)syntaxMaintained Python Compatibility
The grammar still includes Python syntax inheritance via
"include": "source.python", ensuring all Python constructs are properly highlighted while adding SageMath-specific enhancements.Example
With these changes, SageMath code like this will now be properly highlighted:
Fixes #8.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
mirrors.huaweicloud.comnpm install(dns block)npm ci(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.