Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement semantic coloring #483

Merged
merged 4 commits into from
Jun 10, 2022
Merged

Conversation

nguerrera
Copy link
Contributor

@nguerrera nguerrera commented Apr 27, 2022

Fix #310. Colors are much nicer in the playground now.

Sorry for moving so many files around. I wanted to share test code for semantic coloring and tmlanguage and I ran into esm/commonjs hell so I moved tmlanguage to compiler and we copy it over to vscode.

@azure-pipelines
Copy link

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/483/

@nguerrera nguerrera changed the title *NO MERGE* Work in progress on semantic coloring Work in progress on semantic coloring May 6, 2022
@nguerrera nguerrera force-pushed the semantic-colors branch 3 times, most recently from 916f3b9 to 1e5a0fa Compare June 9, 2022 22:22
@nguerrera nguerrera changed the title Work in progress on semantic coloring Implement semantic coloring Jun 9, 2022
@nguerrera nguerrera force-pushed the semantic-colors branch 3 times, most recently from dcbe2cf to 4b3152f Compare June 9, 2022 23:16
Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

This looks great!!

import { copyFile } from "fs/promises";

await copyFile(
"node_modules/@cadl-lang/compiler/dist/cadl.tmLanguage",
Copy link
Member

Choose a reason for hiding this comment

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

Nice to compute the projectRoot and resolve relative to that instead of depending on the cwd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. We have this in a few other scripts/. I'll fix them all together in follow-up PR.

Comment on lines +82 to +83
testColorization("semantic colorization", tokenizeSemantic);
testColorization("tmlanguage", tokenizeTMLanguage);
Copy link
Member

Choose a reason for hiding this comment

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

So the semantic coloring basically changes how we resolve the color token but in the end it still create the same token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has a bit more detail available already, but that's collapsed in tokenizeSemantic to map to tokenizeTMLanguage. In practice, the bits of more detail (for example, this is a namespace, and this is an interface vs. just "type" don't actually change the colors in any VS Code theme I've tried. Eventually, we probably want to test this precision better, but my main goal here was parity with tmlanguage to make the playground pretty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably, there isn't much value yet in calling this code in VS Code or other editors with tmlanguage support, but I'm leaving it in so that we get some dogfooding coverage and people will see if there are problems with this in more places.

@nguerrera
Copy link
Contributor Author

@daviwil, does emacs lsp-mode call the semantic coloring by chance?

@nguerrera nguerrera merged commit 192816f into microsoft:main Jun 10, 2022
@nguerrera nguerrera deleted the semantic-colors branch June 10, 2022 17:21
@daviwil
Copy link
Contributor

daviwil commented Jul 25, 2022

@nguerrera Just caught this in my notifications from a while back. Looks like lsp-mode for Emacs supports in in version 7 onward: https://emacs-lsp.github.io/lsp-mode/blog/2020/7.0-release/#semantic-highlights

@daviwil
Copy link
Contributor

daviwil commented Jul 25, 2022

Looks like it's also in PR for the LSP package I use called eglot: joaotavora/eglot#839. lsp-mode is the much more commonly-used package, though

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.

[IDE] Semantic colorization
3 participants