You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Feature Request: Automatically add brackets for interpolated strings. #200
I thought I would comment and provide a visual on how this works in Sublime Text 3, and what I would want to see in vscode-ruby. I think this is what you intended @goronfreeman, but if it isn't please disregard. 😄
Reacted by Andrew Dang, Taavi Kala, Joe Acklin, lxsndl, Villu Orav, sambit, Josh Porter, Andrew Cox, James Ostrander, Max and 13 more
The only missing part I can see here is the ability to know whether we are inside a string or not. Code doesn't expose token info so we may probably need to rely on a parser to get the info.
@castwide can solargraph provide token info considering it's using parser as backend?
@rebornix There might be a trick to it, but it's possible. It can already determine whether a position in the code is inside a string token. With a little more work, it should be able to identify the notation and gracefully handle incomplete brackets. The call to check the token would have to be asynchronous; I don't know if that's a problem or not.
Right now there is no such thing that you type something and Code autocompletes immediately, Code always shows the auto complete dropdown list. So for this feature, an ideal solution is
Users type # in string
Code ask solargraph extension for the completion list as it registers a completion provider
solargraph provides the auto completions. In addition, in solargraph extension, we ask the native server what's the scope type, if it's string, and the character users just typed is #, we add one more entry #{} to the completion list
As provideCompletionItems can be async, so it's not a problem. IMHO we need to add this feature to your extension as that's where the language service runs. I'll take a look at all issues we have and see what's more we can do in solargraph extension.
I imagined this feature would work like auto closing bracket pairs. Adding #{} to the completion items is more in line with Solargraph's functionality, but it still poses a challenge. The suggestions are currently assumed to be whole words, so the cursor would get positioned after the closing bracket. One possible solution is to make the completion item a snippet. I've experimented with that before.
I'll go through those other issues and see which ones can be resolved by Solargraph. It looks like some of them already are.
I'm in the process of adding LSP support to the Solargraph gem. It should be able to handle this feature using the protocol's textDocument/onTypeFormatting message. In my tests, it's able to 1) detect when it's inside a string and close an interpolation's bracket; and 2) detect when it's inside the interpolation and provide completion items.
Reacted by Mark Pan, Alex Shelmire, Matthew Mario Di Pasquale, KING SABRI, Dragosh Rusea, Elliott Grieco, Slobodan Erak, Luiz Carvalho, Michael, Mateusz Konieczny and 5 more
Reacted by KING SABRI, Dragosh Rusea, Antônio Augusto, Ryan Shaw, Slobodan Erak, Luiz Carvalho, Michael, Mateusz Konieczny, Jarrett Lusso, Brandon Caplan and 6 more
Activity
ianneub commentedon Sep 20, 2017
I thought I would comment and provide a visual on how this works in Sublime Text 3, and what I would want to see in
vscode-ruby. I think this is what you intended @goronfreeman, but if it isn't please disregard. 😄jporter-dev commentedon Nov 14, 2017
+1 on this issue. The way Sublime handles this is perfect.
Macpeters commentedon Nov 16, 2017
+1 - atom has this feature as well - missing it in vscode for ruby and js
Uepsilon commentedon Jan 3, 2018
+1, coming from sublime, this really is uncommon and I keep removing my variables
rebornix commentedon Jan 31, 2018
The only missing part I can see here is the ability to know whether we are inside a string or not. Code doesn't expose token info so we may probably need to rely on a parser to get the info.
@castwide can solargraph provide token info considering it's using
parseras backend?castwide commentedon Feb 1, 2018
@rebornix There might be a trick to it, but it's possible. It can already determine whether a position in the code is inside a string token. With a little more work, it should be able to identify the notation and gracefully handle incomplete brackets. The call to check the token would have to be asynchronous; I don't know if that's a problem or not.
rebornix commentedon Feb 1, 2018
Right now there is no such thing that you type something and Code autocompletes immediately, Code always shows the auto complete dropdown list. So for this feature, an ideal solution is
#in stringsolargraphprovides the auto completions. In addition, in solargraph extension, we ask the native server what's the scope type, if it's string, and the character users just typed is#, we add one more entry#{}to the completion listAs
provideCompletionItemscan be async, so it's not a problem. IMHO we need to add this feature to your extension as that's where the language service runs. I'll take a look at all issues we have and see what's more we can do insolargraphextension.rebornix commentedon Feb 1, 2018
@castwide we have a dozen auto complete related issues https://github.com/rubyide/vscode-ruby/issues?q=is%3Aopen+is%3Aissue+label%3Aautocomplete here, would like to see how they go in your extension.
castwide commentedon Feb 1, 2018
I imagined this feature would work like auto closing bracket pairs. Adding
#{}to the completion items is more in line with Solargraph's functionality, but it still poses a challenge. The suggestions are currently assumed to be whole words, so the cursor would get positioned after the closing bracket. One possible solution is to make the completion item a snippet. I've experimented with that before.I'll go through those other issues and see which ones can be resolved by Solargraph. It looks like some of them already are.
castwide commentedon Feb 16, 2018
I'm in the process of adding LSP support to the Solargraph gem. It should be able to handle this feature using the protocol's textDocument/onTypeFormatting message. In my tests, it's able to 1) detect when it's inside a string and close an interpolation's bracket; and 2) detect when it's inside the interpolation and provide completion items.
wingrunr21 commentedon Apr 3, 2018
Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.
garyking commentedon Apr 10, 2018
Is this issue tracked anywhere else, if it's closed here? It's still needed.
wingrunr21 commentedon Apr 10, 2018
This would fall under formatting in #317
aliariff commentedon Jul 19, 2018
Hi, I created a solution specifically for this issue. Feel free to try it out.
https://marketplace.visualstudio.com/items?itemName=aliariff.auto-add-brackets
s2t2 commentedon Sep 23, 2018
Auto add brackets is out of date?
antoniosb commentedon Oct 16, 2018
@aliariff extension is working like a charm!
matkoniecz commentedon Jun 11, 2019
#317 is now closed as implemented, but this feature is not present - would it be possible to reopen it?
EDIT: Thanks!