-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
enh(swift) Add support for closure arguments (#2871) #2907
Conversation
Hi @il3ven I kinda fixed this already 😅 I'm trying to redo the entire grammar and am working on a PR that will include a complete grammar for identifiers, which will handle not only closure arguments, but also property wrapper projections. |
@il3ven I hope to tackle most of them yes 🙂 But some are pretty tricky. For example, to fix #2895 I will have to be able to fully parse function declarations, so I can detect a complete declaration, excluding the body (as there is no body in a protocol). But that means first parsing types, identifiers, attributes, operators, etc, which I what I'm working on now. |
@il3ven @joshgoebel An interesting question here is: Do we want to highlight implicit paramters ($0, $1, etc) as variables? According to the grammar, they're just identifiers, so should we highlight them separately? If so, should we also highlight normal identifiers, or just the ones that start with a dollar sign? |
@svanimpe I chose to highlight implicit parameters ($0, $1, etc) as variables because in code they are used as variables and it made the most sense visually. I don't know much about swift and I am getting started with open source. But I think we should only highlight the ones that start with a dollar sign or else we will end up highlighting a lot of words. |
Xcode does highlight a lot of identifiers, but that highlighting is based on information from the compiler, which can tell the difference between different types of variables. That's not possible with a regex highlighter, so I'd also opt for only highlighting 'special' identifiers like this. Here's the grammar I have ready to go for an upcoming PR (but I think I'm flooding @joshgoebel a bit now 😅):
|
That was my first instinct... we don't [generally] tend to highlight "just an identifier"... it needs to have more semantic context... variable, title, function name, built-in, etc... If you look at the higher fidelity #2500 issue it's possible that more categories could be added to extend nuance in some cases, but we'd have to agree on exactly what those things were in order for their support to really be meaningful. |
@joshgoebel In my upcoming PR, I'll only highlight |
MODEs are matched first and then keywords are found inside the "buffer" of content that a mode includes. So modes (done wrong) can definitely break keywords. |
Resolves #2871
Changes
$0
or$1
Checklist
CHANGES.md
AUTHORS.txt
, under Contributors