Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Feature Request: Automatically add brackets for interpolated strings. #200

Open
goronfreeman opened this issue Aug 16, 2017 · 17 comments
Open
Labels
autocomplete feature-request Adds currently unsupported functionality

Comments

@goronfreeman
Copy link

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 #
@ianneub
Copy link

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

Screen capture example

@jporter-dev
Copy link

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

@Macpeters
Copy link

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

@Uepsilon
Copy link

Uepsilon commented Jan 3, 2018

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

@rebornix rebornix added the feature-request Adds currently unsupported functionality label Jan 31, 2018
@rebornix
Copy link
Member

rebornix commented 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 parser as backend?

@castwide
Copy link
Contributor

castwide commented 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
Copy link
Member

rebornix commented 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

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

@rebornix
Copy link
Member

rebornix commented 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
Copy link
Contributor

castwide commented 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
Copy link
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.

@wingrunr21
Copy link
Collaborator

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

@garyking
Copy link

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

@wingrunr21
Copy link
Collaborator

This would fall under formatting in #317

@aliariff
Copy link

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
Copy link

s2t2 commented Sep 23, 2018

Auto add brackets is out of date?

@antoniosb
Copy link

@aliariff extension is working like a charm!

@matkoniecz
Copy link

matkoniecz commented Jun 11, 2019

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!

@wingrunr21 wingrunr21 reopened this Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autocomplete feature-request Adds currently unsupported functionality
Projects
None yet
Development

No branches or pull requests