-
Notifications
You must be signed in to change notification settings - Fork 27
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 support for def 'my-function'
syntax highlighting and add tests to it
#182
Conversation
Hi! Does anyone have some time to review this? 😄 Thanks! |
sorry, i'll try to look at it this week sometime. |
No problem! We all have lots of |
@AucaCoyan I spent some time looking at this today and I think the regex changes are not correct. We should be able to capture all groups and using the beginCaptures to highlight them individually. I don't think the groups are correct either. We should also be able to do |
We may need @glcraft to help iron out this regex. This one below is close because it sees --env and --wrapped at the beginning or ending. This is my regex and capture attempt below that doesn't work either because it's uses range 0,2 and therefore is not picking the correct capture names in all instances. "function": {
"begin": "(export)?(\\s+def)(\\s+--\\w+){0,2}(\\s+[\\w\\-]+|\\s+\"[\\w\\- ]+\")(\\s+--\\w+){0,2}",
"beginCaptures": {
"1": { "name": "entity.name.function.nushell" },
"2": { "name": "entity.name.function.nushell" },
"3": { "name": "entity.name.type.nushell" },
"4": { "name": "entity.name.type.nushell" },
"5": { "name": "entity.name.function.nushell" },
"6": { "name": "entity.name.type.nushell" },
"7": { "name": "entity.name.type.nushell" }
}, |
Hi
I know that the textmate grammar is not a linter, but due to the huge number of rules present in this file, we have to be precise in the parsing so the good rules are used in the good place. Now, my previous regex was indeed incomplete. it miss the single quotes function name syntax (and the back quotes too) and I went for one flag only whereas it can be several before and/or after the function name. @fdncred attempt for matching several flags is good. It will parse the flags correctly. But I think we should set the number of occurence to 0 or more, in case nu syntax change and add more flags to def/Export def in the future. What do you think ? I'm going to commit a change to the tmgrammar file. (oh, and sorry for the late about #156, I saw it but I could not fix it at the time and forget about it later 😅) |
I'm good with 0 or more.
No worries at all. Thanks for all your input @glcraft |
Oh, it seems i cannot commit onto this PR branch 🤔 |
Thanks for the response! I added you as a collaborator in my fork, check if you can commit again |
Thanks, but no, I cannot. It says I "don't have permission to push to "AucaCoyan/vscode-nushell-lang" on GitHub". |
Yes you're right. I am able to push now, thanks 👍 |
You are welcome! You are also helping me too 😄 |
Someone just ping me when this is ready to look at again. |
@fdncred I fixed and push the change of the tmgrammar file. Check by your side if it's good 👍 |
@glcraft I think this is much better and we can land it. It doesn't cover use case where --env or --wrapped are after the parameter declaration like this. export def --env my-function [] --wrapped {} I need to check with the team if that's even supposed to be valid syntax. I think it's invalid because of this. |
Thanks! |
fixes #156
The only caveat is the
--flag
after the name will be colored just like the function name