Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 8, 2025

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

  1. Incorrect Language Configuration: The configuration field in package.json was 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.

  2. 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 (^, ^^).

  3. Missing Language Features: No support for proper indentation rules, word patterns, or comprehensive bracket handling.

Changes Made

Fixed Configuration Structure

  • Created proper language-configuration.json with comment definitions, bracket pairs, auto-closing pairs, and indentation rules
  • Updated package.json to correctly reference the language configuration file

Enhanced TextMate Grammar

Completely rewrote syntaxes/sage.tmLanguage.json with comprehensive pattern matching for:

  • Number Systems & Rings: ZZ, QQ, RR, CC, GF, Zmod, NumberField, etc.
  • Algebraic Structures: PolynomialRing, MatrixSpace, VectorSpace, FiniteField
  • Built-in Functions: var, solve, diff, integrate, plot, matrix, factor, mathematical functions
  • Mathematical Constants: pi, e, I, infinity, oo, golden_ratio
  • Special Operators: ^ (exponentiation), ^^ (XOR), .. (range notation)
  • Ring Notation: Support for R.<x,y> = PolynomialRing(QQ) syntax

Maintained 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:

# Variable declarations and number systems
var('x y z')
R = ZZ
Q = QQ

# Polynomial rings with proper syntax
R.<x,y> = PolynomialRing(QQ)

# Mathematical expressions with operators
f = x^2 + sin(pi*x) + e^x
derivative = diff(f, x)
roots = solve(f == 0, x)

# Matrix operations and plotting
M = matrix(QQ, [[1, 2], [3, 4]])
plot(f, (x, -pi, pi))

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.com
    • Triggering command: npm install (dns block)
    • Triggering command: 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.

Copilot AI and others added 2 commits August 8, 2025 23:41
Co-authored-by: n-WN <30841158+n-WN@users.noreply.github.com>
Co-authored-by: n-WN <30841158+n-WN@users.noreply.github.com>
Copilot AI changed the title [WIP] 语法高亮不能正常显示 Fix SageMath syntax highlighting configuration and enhance grammar patterns Aug 8, 2025
Copilot AI requested a review from n-WN August 8, 2025 23:49
Copilot finished work on behalf of n-WN August 8, 2025 23:49
@RedCMD
Copy link

RedCMD commented Sep 30, 2025

@copilot please use multi-line begin/end for strings instead of match
and take escapes into account as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

语法高亮不能正常显示

3 participants