-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Completion should automatically add backquotes around names that conflict with keywords #4406
Comments
Hi folks. Interested in tackling this one, will be my first time contributing. Any advice on how to approach? |
Welcome! The code that decides which completions to show is in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/interactive/Completion.scala, looking around quickly, it doesn't look like we have a convenience method to identifiy if a given string is a valid identifier or not, but you can easily make one from |
Perfect, thanks! |
If you don't mind, can you dive a bit deeper into what the requirements are to construct a convenience method for validating identifiers from |
An identifier that can be written without backquotes is one where |
Perfect, just making sure there was nothing else to take into account. |
To clarify - I only want to wrap the name in backticks if it is a valid identifier but clashes with a keyword, correct? |
a name needs to be wrapped in backticks if it's not a valid identifier, which is the case when it's a keyword or when it can only be written with backticks (e.g. if you write |
Is there a convenience method to determine whether an arbitrary string is a keyword in existence yet? I see all keywords defined in |
I don't think there is one. |
Ok, thanks for responding so quickly! I've made some changes and added the following test to
This passes, but I've taken a couple of tests out with the change: |
Ah, looks like isIdentifierStart/Part are not enough indeed, looks like you need to use |
Thanks! |
Actually, I don't think the problem was with not using |
I'm not sure I understand your question, in Scala users are free to define operators like |
Sure, I understand that. I'm more wondering if there's a case where there can be 2 valid symbols in scope, where we capture one in backticks but both are valid completions? |
Can you give a full example of the case you have in mind ? |
This PR adds in the functionality to add in backticks when needed when giving back completions and also correctly returning completions when the user has already started typing a backtick. Fixes: scala#4406, scala#14006
This PR adds in the functionality to add in backticks when needed when giving back completions and also correctly returning completions when the user has already started typing a backtick. Fixes: scala#4406, scala#14006
Sometimes we will encounter names that conflict with keywords. When we complete such names, I think we should automatically add `` prevent conflicts for these names.
The text was updated successfully, but these errors were encountered: