fix(code-block): stop painting Go type names as function names #831
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority/Critical
Priority/High
Priority/Low
Priority/Medium
Reviewed/Confirmed
Reviewed/Duplicate
Reviewed/Invalid
Reviewed/Won't Fix
Status/Abandoned
Status/Blocked
Status/Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
project-halkyon/halkyon-learn!831
Loading…
Reference in a new issue
No description provided.
Delete branch "refs/pull/831/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In a Go block the same identifier came out two different colours depending
on which type expression it appeared in:
The grey one is right. Go's grammar in the
highlightpackage classifiesno user-defined name — not a struct, not a type alias — so every blue
identifier here is a false positive. Its function mode opens on the
keyword
funcand runs to{or end of line with a bare-identifier titlemode inside, and a title can match anywhere in that span, including after
the parameter list where Go puts the return type. The reported case is the
mildest one. It also titled the return type of ordinary declarations, and
func Greet(n string) stringcame back with the secondstringblue andthe first purple — one keyword, two colours, in one signature.
The region is narrowed to the only span that can hold a name.
beginbecomes
funcnot immediately followed by(, optionally plus a receivergroup: that skips anonymous
funcs, which have no name to find, whilestill admitting methods, whose name sits after the receiver. The parameter
list then ends the region, so nothing past the closing paren can be
titled, and the return type falls back to the top level where the language
keywords colour
stringandintproperly again. Across a corpus ofdeclarations, methods, func types, func literals and multi-value returns,
exactly the declared names are titled and nothing else.
Not fixed the obvious way — a lookahead on the title itself — because the
engine re-tests a mode's
beginagainst the matched lexeme in isolation(
Highlight._subMode), where the following(is not there: the titlewould match while scanning and then fail the re-test, and no title would
ever be produced. Only self-contained patterns survive that round trip. A
negative lookahead does, passing vacuously at end of input, which is why
the
beginside works.Built by copying rather than mutating.
gois a package-level singletonand compiling a grammar rewrites its Mode tree in place, so patching it
directly would leak into any other importer; if a package upgrade reshapes
the grammar past recognition, the unpatched grammar is used and colouring
stays as upstream ships it.
Separately, the language menu now writes each language the way it is
actually spelled — Go, Python, C#, C++, JavaScript, SQL — instead of the
bare tag.
csharpis not a name anybody writes. The tag itself isuntouched: it is persisted on the node and keys the grammar lookup, so
this is presentation only, and a tag from outside the menu (imported decks
carry those) falls back to itself rather than being auto-capitalised into
a name its community doesn't use. The block's header label reads the same
way, since it is an echo of the menu choice.
Signed-off-by: Tizian 「ティツィアーン」 raisondetredev@pm.me