-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add syntax highlighting for Pkl files #61478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel confident to approve this, but I don't see anything that screams wrong at me, and it works so..
I'll defer for final approval to the Graph team :)
Thanks for tagging me for the learning experience, and congrats on shipping a customer request in <48h after we heard about it on a call!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. I appreciate your enthusiasm to get your hands dirty and help out.
I noticed that there are lots of test cases missing. During the first pass, we should be aiming for coverage of as many of the various syntax features as possible, so that we don't have to keep coming back to fix small things (it's also quite likely that if some things work and other don't, users won't like the UX but they won't dislike it enough to complain about it).
I've outlined some in the inline comments, some more that are missing (non-exhaustive):
- Type annotations (simple identifiers as well as generic types)
- Escaped identifiers such as
`class`
. - Chained amends expression
- Field accesses
- Class definitions
- Method definitions
- Method calls
new
expressions- Various property keywords such as
fixed
,hidden
,local
,const
etc. - Annotations such as
@Deprecated
You can go through the language reference (https://pkl-lang.org/main/current/language-reference/index.html) and add test cases for these.
If it's not possible to pick out some syntax features based on the grammar, we should still add a test case for that and note in a comment that it is because of an upstream limitation.
I do not feel comfortable merging this in its current state given the low coverage. Please re-request code review once you've made the suggested changes.
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/locals.scm
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/src/highlighting.rs
Outdated
Show resolved
Hide resolved
@varungandhi-src Thanks for the thorough review ( I was eager for you to show me the ropes here ). Couple questions /comments
|
I skimmed through the language reference (https://pkl-lang.org/main/current/language-reference/index.html) and noted things which looked missing. I did not look at everything in the language reference. When you're adding test cases, you should add test cases for the different syntactic features as written in the language reference (my list is a subset). Generally, it is also good to add test cases for "interesting" combinations of features, e.g. how I wrote "Multiline strings, with and without interpolation, with and without leading whitespace." What exactly is an "interesting" combination is hard to define, but it's useful to think through variations. You may also want to look at the grammar.js file directly for inspiration, or the test cases in the tree-sitter-pkl repo. (https://github.com/apple/tree-sitter-pkl/tree/main/corpus)
|
@varungandhi-src Thanks for your detailed information. I made a second attempt to address as much of your feedback as I could figure out. |
docker-images/syntax-highlighter/crates/syntax-analysis/src/highlighting/tree_sitter.rs
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/src/highlighting/tree_sitter.rs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking much better, will do a further pass later.
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Show resolved
Hide resolved
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still a couple of small things which needs addressing, but approving so you can merge once those are fixed.
...is/src/highlighting/snapshots/syntax_analysis__highlighting__tree_sitter__test__pkl.pkl.snap
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
docker-images/syntax-highlighter/crates/syntax-analysis/queries/pkl/highlights.scm
Outdated
Show resolved
Hide resolved
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
…s/pkl/highlights.scm Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
…s/pkl/highlights.scm Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
…s/pkl/highlights.scm Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
Fixes PRIV-2879
Adds syntax highlighting for the Pkl configuration language.
This does NOT add pkl files to the
lang:
filter.Key Changes/Notes/Questions
pkl
files ingosyntect/langauges.go
andhighlight/languages.go
to ensure it is picked up properly since pkl does not exist in go-enry.What about updating the Docs?
If we agree these are the minimal steps to add a highlighter, I can update the docs with these steps. The one wrinkle is handling if the given language exists in
If they do or don't exist in those places some of the steps may change a tiny bit I think.
Test plan