rubyide / vscode-ruby

Provides Ruby language and debugging support for Visual Studio Code

Home Page:https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Automatically add brackets for interpolated strings.

goronfreeman opened this issue · comments

Your environment

  • vscode-ruby version: 0.14.0
  • Ruby version: 2.4.1
  • VS Code version: 1.15.0
  • Operating System: macOS 10.12.4

Expected behavior

Typing # should automatically expand to #{} with the cursor in between the braces when you are between double quotes.

Actual behavior

Typing # does not add any additional characters.

Steps to reproduce the problem

  1. Open a Ruby file
  2. Open a pair of double quotes
  3. Type #

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. 😄

Screen capture example

+1 on this issue. The way Sublime handles this is perfect.

+1 - atom has this feature as well - missing it in vscode for ruby and js

commented

+1, coming from sublime, this really is uncommon and I keep removing my variables

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.

@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.

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.

Closing for issue cleanup. Apologies if this is still an issue. We are working to improve the core extension experience.

commented

Is this issue tracked anywhere else, if it's closed here? It's still needed.

This would fall under formatting in #317

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

Auto add brackets is out of date?

@aliariff extension is working like a charm!

This would fall under formatting in #317

#317 is now closed as implemented, but this feature is not present - would it be possible to reopen it?

EDIT: Thanks!