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

Add KDL syntax highlighting #3549

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

kachick
Copy link

@kachick kachick commented Nov 26, 2024

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?

Copy link
Contributor

@Andriamanitra Andriamanitra left a 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.

runtime/kdl.yaml Outdated Show resolved Hide resolved
Comment on lines +38 to +41
# Integer
- constant.number: '[-+]?(\d+)'
# Float
- constant.number: '[-+]?(\d+)\.\d*'
Copy link
Contributor

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

Suggested change
# 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

  1. https://github.com/kdl-org/kdl/blob/main/SPEC.md#number

runtime/kdl.yaml Outdated
Comment on lines 51 to 60
# 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: []
Copy link
Contributor

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.

Comment on lines +19 to +21
# 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 "#"
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link

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: '(\\\\\|\\")'
Copy link
Contributor

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

runtime/kdl.yaml Show resolved Hide resolved
@kachick kachick marked this pull request as draft November 26, 2024 11:32
@kachick
Copy link
Author

kachick commented Nov 26, 2024

Thanks for your dedicated reviews! It much helps.
I'll update this PR by checking the points that you have pointed out. 🙏

Co-authored-by: Mikko <Andriamanitra@users.noreply.github.com>
kachick and others added 2 commits November 27, 2024 16:30
Co-authored-by: Mikko <Andriamanitra@users.noreply.github.com>
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.

3 participants