Skip to content

Add C/C++ highlighting#796

Open
MJKagone wants to merge 2 commits intomicrosoft:mainfrom
MJKagone:main
Open

Add C/C++ highlighting#796
MJKagone wants to merge 2 commits intomicrosoft:mainfrom
MJKagone:main

Conversation

@MJKagone
Copy link
Copy Markdown

@MJKagone MJKagone commented Apr 8, 2026

This adds initial LSH syntax highlighting support for:

  • C
  • C++

It also updates Markdown fenced code block routing accordingly.

Scope

This is a lightweight LSH-only change with no new dependencies.

The changes are limited to syntax definitions and highlighting fixtures:

  • new LSH definitions for the languages above
  • Markdown fenced code block routing updates
  • new / expanded highlighting test samples

Validation

  • cargo test -q

Notes

You may notice this PR is heavily inspired by and modelled after #791. I really like this project but unfortunately don't know any Rust so I figured this would be the best way for me to contribute.

@MJKagone
Copy link
Copy Markdown
Author

MJKagone commented Apr 8, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing this! I'll review this in due time.
To me this PR looks like a solid start with just minor nits perhaps. For instance, at a quick glance I saw the "asm" keyword in the cpp definitions which isn't an official keyword. In the future we could consider adding more complex rules like implementing proper highlighting for struct members or variables. A good reference will be https://github.com/microsoft/vscode/blob/main/extensions/cpp/syntaxes/c.tmLanguage.json and the corresponding cpp file.

@MJKagone
Copy link
Copy Markdown
Author

MJKagone commented Apr 8, 2026

https://en.cppreference.com/w/c/keyword.html
https://en.cppreference.com/w/cpp/keywords.html

These are what I used for the keyword lists, though I did run them through an LLM ("which of these should I include in the highlighter") since I can't exactly claim to be an expert on the languages 😅 but yeah, the VSCode lists are probably the right way to go here.

@lhecker
Copy link
Copy Markdown
Member

lhecker commented Apr 8, 2026

I think replicating the VS Code rules as-is wouldn't be a good idea: They're sometimes very complex because they're defined in a very simple DSL. LSH is much more powerful (or will be in the future if we want to) and so we can express some things much more easily. There are also some constructs which are rather niche and we don't necessarily need for a simpler editor.

But I like using them as a nice guideline for what it could be and to collect overall ideas. 🙂

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.

2 participants