-
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
(Swift) Letter c is a built-in? #2847
Comments
This seems to result from highlight.js/src/languages/swift.js Line 26 in 760dcd6
No idea what that |
I asked @mportiz08 if they know anything about this and whether it could be merged into their PR. If no one knows what it's for then does seem like something we could just yank. |
I'd be ok with a PR to remove this it's definitely not a general purpose keyword. |
@joshgoebel When I finish the project I'm working on, I'll see if I can fix some of the Swift issues I've reported myself. |
@joshgoebel What do you think about removing the list of built-ins all together? I looked into updating them, however, I now feel like we should just remove them. In Swift, functions can be overloaded not only on the number and types of their parameters, but also on the return type and on the parameter names. Using only a function's base name to highlight it will lead to many false matches. Proper highlighting would require a type checker. |
Removing a large swath of keywords makes auto-detection worse for the whole library, so generally it's frowned upon. Can you give a few specific examples of the type of issues you're imagining? Or is this |
I'm only talking about the global functions in the Standard Library here, not keywords. The problem is that Swift has now moved most functions into types as methods, and the few functions that remain global often have general names such as For example, here's my best attempt at generating a current list of public global functions in the standard library. These show the number of parameters and their argument labels (
I don't think a regex grammar can match these correctly, and false positives are extremely confusing for new learners, which is why I'd rather not see them highlighted at all. |
Yes, I understood.
It might actually be fun to try with some type of fuzzy look-ahead actually, but I take your larger point.
Now highlighting them or not is a different question entirely. :-) Though my fear with that line of thinking is that without any visual indication it becomes harder to keep the grammar up-to-date over time (as the language evolves, etc). |
@joshgoebel Is there a way to tell the parser to only match built-ins if they are followed by an opening brace? I only see one If not, can I just make a separate mode for these, like this (works for me):
Also, feel free to assign this to me, I'll fix it anyway now that I have a list of built-ins :) |
Nope, you'd need a rule for that kind of customization, as you've already realized. Also related: #2500 I'd rather see us go ahead and just add a matcher for |
Would you accept the suggested rule above for now? It solves 99% of the issues I have with built-ins being incorrectly highlighted. The remaining 1% would be overloads with the same name as a built-in, which I don't think we can detect with regexes. |
I suggested what I did because often that's how we prefer to solve this. For example see JS:
This is much easier to understand (since you're version would even be simpler): { // consume .built_in to prevent highlight
begin: concat(/\./, either(...builtIns), /\(/)
relevance: 0,
} A ruleset with more rules but simpler rules is far better than a rule set with fewer but very complex rules. And again this is also very compatible with the future direction to turn this into a "dispatch" rule... in fact you might not even need |
Fixed in #2908 |
In the following snippet:
The parameter c is incorrectly highlighted as a built-in.
The text was updated successfully, but these errors were encountered: