-
Notifications
You must be signed in to change notification settings - Fork 5
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
Completions inside of backticks #418
Comments
I'm opening a feature request instead of a PR mostly because I wanted to be in agreement on the above behavior being desirable before putting in the work to make the above also work for Scala 3 (though in that case a Scala compiler patch probably won't be needed). If all of this sounds reasonable, I'll polish up the above, make it work for Scala 3 and open a PR. |
I think this looks quite reasonable. As for Scala 3, we actually moved most of the code the compiler. The metals codebase retains the 3.3.3 version, later versions all have the code behind mtags interfaces in it. So might worth to see if it maybe already works in later Scala version. In that case I wouldn't bother fixing it for 3.3.3, since we are already almost at 3.3.5 for LTS. If it doesn't work, you can for sure fix it here and we can port it to the compiler later on. Fixing it in the compiler is another option, but it's a bigger codebase and harder to set up. |
This improves the presentation compiler name completions inside of backticks. The existing gaps which motivate doing this are outlined in [this Metals feature request][0]. [0]: scalameta/metals-feature-requests#418
Made the 3.x changes here: scala/scala3#22555. Once this gets merged I'll focus on getting a backport to 2.13 (just so then the feature is in both the latest 2.x and 3.x versions). |
This improves the presentation compiler name completions inside of backticks. The existing gaps which motivate doing this are outlined in [this Metals feature request][0]. [0]: scalameta/metals-feature-requests#418
Scala 2 only - the [corresponding Scala 3 change][0] has already been merged. Completions can now be triggered from inside of backticks. In addition, the backtick itself is added as a completion character. Especially when the editor is configured to auto-close backticks, this plays nicely with completions now producing useful results inside of backticks. Closes [this feature request][1] [0]: scala/scala3#22555 [1]: scalameta/metals-feature-requests#418
Scala 2 only - the [corresponding Scala 3 change][0] has already been merged. Completions can now be triggered from inside of backticks. In addition, the backtick itself is added as a completion character. Especially when the editor is configured to auto-close backticks, this plays nicely with completions now producing useful results inside of backticks. Closes [this feature request][1] [0]: scala/scala3#22555 [1]: scalameta/metals-feature-requests#418
Scala 2 only - the [corresponding Scala 3 change][0] has already been merged. Completions can now be triggered from inside of backticks. In addition, the backtick itself is added as a completion character. Especially when the editor is configured to auto-close backticks, this plays nicely with completions now producing useful results inside of backticks. Closes [this feature request][1] [0]: scala/scala3#22555 [1]: scalameta/metals-feature-requests#418
Scala 2 only - the [corresponding Scala 3 change][0] has already been merged. Completions can now be triggered from inside of backticks. In addition, the backtick itself is added as a completion character. Especially when the editor is configured to auto-close backticks, this plays nicely with completions now producing useful results inside of backticks. Closes [this feature request][1] [0]: scala/scala3#22555 [1]: scalameta/metals-feature-requests#418
Scala 2 only - the [corresponding Scala 3 change][0] has already been merged. Completions can now be triggered from inside of backticks. In addition, the backtick itself is added as a completion character. Especially when the editor is configured to auto-close backticks, this plays nicely with completions now producing useful results inside of backticks. Closes [this feature request][1] [0]: scala/scala3#22555 [1]: scalameta/metals-feature-requests#418
Is your feature request related to a problem? Please describe.
Metals does a good job of suggesting identifier completions when the prefix for the identifier is not backticked. However, once backticks come into play, the experience degrades a bit.
For example, in the following code snippet, the
This is a method name
completion might or might not still be present. If the initial completion list was incomplete, then typing up toThis is a
may trigger VS code to ask fordocument/textCompletions
again, but now the text buffer no longer contains a single valid identifier.The solution I'd expect to have for the above is that as a user I might need to write the backticks upfront and then trigger completions inside the backticks. That way, as I type the prefix for my method, I stay in the intermediate state of having a valid preceding identifier:
However, in this case, Metals gives no completions (not even when just at
this.`@@`
orthis.`T@@`
)(I'm not sure how widespread this (ab)use of backticks is, but I'm working in codebases where there's a fluent-like DSL that heavily encourages these English sentence form names, so completions there are a bit miserable).
Describe the solution you'd like
Solution I think is coherent:
`@@`
ormyObj.`@@`
(with Auto-close backticks scala/vscode-scala-syntax#280, this means that you get put into this completing state just by typing a single`
)I went and implemented this for 2.13.x to see how it felt (harpocrates/metals@98d2ce5, though you'll need a small Scala compiler patch as well - see commit). Here's what it looks like:
Basic completions inside of backicks
![Image](https://private-user-images.githubusercontent.com/10766081/406901205-cc9b1e3c-2e3d-4663-8cdf-f8c77d556d0c.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Njk2NzAsIm5iZiI6MTczOTY2OTM3MCwicGF0aCI6Ii8xMDc2NjA4MS80MDY5MDEyMDUtY2M5YjFlM2MtMmUzZC00NjYzLThjZGYtZjhjNzdkNTU2ZDBjLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDAxMjkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRlNTcyZmNhM2ZhZWYzZjFmNmUxMGZiNzIyYWFkZDE2Y2Y5MDRkOTBiYjM4ZTE5ZTQ2NDcxYTZjNDNhYTU4NWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.qTGwhk6Gin6IDm9L_CXFULi8l4LNeYlkSeofzqtjito)
Manually re-triggering the completion after a space character (mocking up the case where VS code might do this automatically because the original completions were incomplete)
![Image](https://private-user-images.githubusercontent.com/10766081/406901253-43c09800-15e8-4ec8-9bf9-ed9cc3da72de.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Njk2NzAsIm5iZiI6MTczOTY2OTM3MCwicGF0aCI6Ii8xMDc2NjA4MS80MDY5MDEyNTMtNDNjMDk4MDAtMTVlOC00ZWM4LTliZjktZWQ5Y2MzZGE3MmRlLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDAxMjkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVkZGNjMmYzZTY2YjM5YWY5ZmYyYjQwMzBhZjdmZDY1ZGI0MjFiMGM4YmQzZWViMzBmYTFhYjE3NjE2NWUxNGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.wS56t5GQRMolP2s12oHExW5XC2TBUJfGGtnX_9V9WNo)
Once inside backticks, completing a non-backticked identifier still leaves the backticks
![Image](https://private-user-images.githubusercontent.com/10766081/406901340-5a79c95d-da1c-4f46-b7c2-cd16778b8274.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Njk2NzAsIm5iZiI6MTczOTY2OTM3MCwicGF0aCI6Ii8xMDc2NjA4MS80MDY5MDEzNDAtNWE3OWM5NWQtZGExYy00ZjQ2LWI3YzItY2QxNjc3OGI4Mjc0LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDAxMjkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU5M2U3YTRjZjM5ZTFhMDE5YmJhZWQ3NmE5NDllZjkwNTdjMjYzNDQyNmZkMDc1YTk5MjIzODBlM2VmNTcxMzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3HKmMf_QHf3M724Mv82xBtHmywt7oDgMtH8WgEwk2mM)
All of the above should hold for backticked select's as well
![Image](https://private-user-images.githubusercontent.com/10766081/406901372-cc143eb2-e2af-460f-a780-1403ec06c7b2.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2Njk2NzAsIm5iZiI6MTczOTY2OTM3MCwicGF0aCI6Ii8xMDc2NjA4MS80MDY5MDEzNzItY2MxNDNlYjItZTJhZi00NjBmLWE3ODAtMTQwM2VjMDZjN2IyLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDAxMjkzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFlNjY1YTA0OTdmYWEzM2Y3NjQxYjlkZWQ2YzJkMTdhYTEyM2M3MzcwNGViMmYxYjZiZjA2ZTJkYWIzZDM2MzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.HxgO4saXidfZQlYofhETgRrHm8iZeCPVI9WoGN674Qc)
Describe alternatives you've considered
We could continue not showing any completions when the identifier prefix under the cursor is backticked. 😄
Additional context
No response
Search terms
completions backticks
The text was updated successfully, but these errors were encountered: