-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add KDL syntax highlighting #3549
base: master
Are you sure you want to change the base?
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 also have a KDL syntax file in my dotfiles as I use it as a configuration format in some of my projects. It would be nice to have the support built-in to the editor.
# Integer | ||
- constant.number: '[-+]?(\d+)' | ||
# Float | ||
- constant.number: '[-+]?(\d+)\.\d*' |
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.
KDL supports integer literals in base-2, base-8, and base-16, and the digits may be separated with underscores. Float literals may additionally use scientific notation (which I have not fixed here). 1
# Integer | |
- constant.number: '[-+]?(\d+)' | |
# Float | |
- constant.number: '[-+]?(\d+)\.\d*' | |
# Integer | |
- constant.number: '[-+]?([0-9][0-9_]*|0b[01][01_]*|0o[0-7][0-7_]*|0x[0-9A-Fa-f][0-9A-Fa-f_]+)' | |
# Float | |
- constant.number: '[-+]?(\d+)\.\d*' |
Footnotes
runtime/kdl.yaml
Outdated
# Slashdash comments | ||
# https://github.com/kdl-org/kdl/blob/de1dbd2c330c9193b836499db241787484627c3b/SPEC.md#L77-L79 | ||
# vscode extension realizes this with lookahead and lookbehind, the regex feature cannot be used in micro | ||
# https://github.com/kdl-org/vscode-kdl/blob/646d7b819d72b2f0d9dd05102a305506bafa3cf6/syntaxes/kdl.tmLanguage.json#L182-L199 | ||
# https://github.com/zyedidia/micro/issues/901#issuecomment-354931928 | ||
# So simplified it, it means this is inaccurate | ||
- comment.block: | ||
start: '^\s*/-' | ||
end: '\s' | ||
rules: [] |
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 wonder if it would be better to not even attempt to highlight slashdash comments? I think this implementation would just highlight it wrong most of the time, and there's no good way to fix it.
# These definitions are not correct, ideally `#` should be same count for both begin and end, but it should be programmable as captured \1 | ||
# In my understanding, this is a micro editor restriction. See https://github.com/zyedidia/micro/blob/21bb61c5ff3cd4cd11adbd521657df90d50f54c7/runtime/syntax/jsonnet.yaml#L61-L78 | ||
# So, I defined some typical cases here, supporting only for 0-3 "#" |
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 used the same workaround for Rust highlighting in #3192 👍
- constant.number: '[-+]?(\d+)' | ||
# Float | ||
- constant.number: '[-+]?(\d+)\.\d*' | ||
# Boolean and inf, nan without sign |
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.
inf, nan? I can't find them in the spec and they don't appear in this syntax definition either so I'm not sure what this comment is about.
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.
These are part of the kdl v2 spec that's becoming the main spec soonish: https://github.com/kdl-org/kdl/blob/kdl-v2/CHANGELOG.md
- constant.string: | ||
start: '"' | ||
end: '"' | ||
skip: '(\\\\\|\\")' |
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'm not entirely sure what the first part of this regex is trying to do? It also doesn't seem to skip escaped duoble quotes properly. Try highlighting the following:
"abc\"def" ghi
Thanks for your dedicated reviews! It much helps. |
Co-authored-by: Mikko <[email protected]>
Co-authored-by: Mikko <[email protected]>
zellij is using KDL for the config file.
How about adding the definition here?
I've been using this file these days, and it seems to be working at least in my use.
This PR is just based on https://github.com/kachick/micro-kdl, intentionally keeping the comments.
I can remove or revise them if necessary.
Should I send a PR to https://github.com/micro-editor/plugin-channel first?