Suggestions for syntax highlighting improvements
jwortmann opened this issue · comments
Here are a few suggestions and problems that I noticed:
It seems like the scope names for labels and references were chosen based on highlighting colors in the Mariana color scheme. They look good, but they are not really the correct scopes, and it might look worse in different color schemes - e.g. many other color schemes don't highlight the punctuation.definition
scope.
References in the LaTeX syntax use constant.other.reference
, so my suggestions for proper scopes would be
<label>
//^ punctuation.definition.label.begin.typst
// ^^^^^ entity.name.label.typst
// ^ punctuation.definition.label.end.typst
@label
//^^^^^^ constant.other.reference.typst
//^ punctuation.definition.reference.typst
// ^^^^^ - punctuation
Unfortunately Mariana doesn't highlight entity.name.label
, so maybe it would be acceptable in this case to keep the storage.modifier
scope.
In math blocks, not every letter should get support.function.math
.
Ideally this scope should only be used for known functions, and single letters should probably get variable.other.math
- if it should follow the LaTeX syntax. And I would probably use support.constant
for the known symbols, e.g. phi
(this is indeed keyword
in LaTeX, but I think it is wrong):
$ F_n = round(1 / sqrt(5) phi.alt^n) $
//^ variable.other.math
// ^ variable.other.math
// ^^^^^ support.function.math
// ^^^^^^^ support.constant
But I don't know if this is feasible, because there are a lot of built-in symbols and functions, and it would be annoying to manually type them all into the syntax. Maybe it could use variable.other.math
for single letters and support.function.math
for 2 or more letters, as a simple heuristic.
I would probably use variable.other
for single variables in markup, instead of constant.other.symbol
, and keyword
for let
, set
, etc., like this:
#let name = "Typst"
//^^^^^^^^^^^^^^^^^^^ meta.expression.typst
//^ punctuation.definition.expression.typst
// ^^^ keyword.declaration.typst
This is #name's documentation.
// ^^^^^ variable.other.typst
// ^ punctuation.definition.variable.typst
But the variable.other
would probably make highlighting worse in most color schemes, because often it is not highlighted...
First of all, thank you for your patience on keeping improving this plugin!
I basically implemented your suggestions in the past few commits. Some differences:
- Labels still get a
storage.modifier
to make it colored in other color schemes - Added
string.other
scope to$
like LaTeX to make it colored in other color schemes - Added
keyword.other
scope to#
to make it colored in other color schemes - Not using
variable.other
as they are almost not colored, keepingconstant.other.symbol
.
Excellent, closing as resolved.
If I find any other possible improvements, I can provide a PR, but the highlighting looks very good already.