Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
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

Open

Description

@goronfreeman

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 #

Activity

  1. ianneub commented on Sep 20, 2017

    @ianneub

    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

  2. jporter-dev commented on Nov 14, 2017

    @jporter-dev

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

  3. Macpeters commented on Nov 16, 2017

    @Macpeters

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

  4. Uepsilon commented on Jan 3, 2018

    @Uepsilon

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

  5. rebornix commented on Jan 31, 2018

    @rebornix
    Member

    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?

  6. castwide commented on Feb 1, 2018

    @castwide
    Contributor

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

  7. rebornix commented on Feb 1, 2018

    @rebornix
    Member

    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.

  8. rebornix commented on Feb 1, 2018

    @rebornix
    Member

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

  9. castwide commented on Feb 1, 2018

    @castwide
    Contributor

    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.

  10. castwide commented on Feb 16, 2018

    @castwide
    Contributor

    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.

  11. wingrunr21 commented on Apr 3, 2018

    @wingrunr21
    Collaborator

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

  12. garyking commented on Apr 10, 2018

    @garyking

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

  13. wingrunr21 commented on Apr 10, 2018

    @wingrunr21
    Collaborator

    This would fall under formatting in #317

  14. aliariff commented on Jul 19, 2018

    @aliariff

    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

  15. s2t2 commented on Sep 23, 2018

    @s2t2

    Auto add brackets is out of date?

  16. antoniosb commented on Oct 16, 2018

    @antoniosb

    @aliariff extension is working like a charm!

  17. matkoniecz commented on Jun 11, 2019

    @matkoniecz

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions