IDE (IntelliJ IDEA) support for Raw String Literals
maurizio.cimadamore at oracle.com
Tue Apr 24 10:30:25 UTC 2018
I think I personally prefer (1), even if it leads to nonsensical code,
as I find that the usefulness of auto-format performed by IDEs tend to
decrease as the locality of the change also decreases. For instance, I'm
always baffled when adding a 'case' to an existing switch statement
causes reformatting of the entire (possibly very big) switch. In this
case, it is not clear what it should happen, whether the user had made
an irrecoverable mistake, or whether the user just wanted to quote the
whole thing. So I prefer to call it borked, and to go with 1.
In other cases (e.g. copy/paste), where user action is more deliberate
(as discussed in this thread), I think it's ok for the IDE to attempt
less global refactoring, as it already happens when you try to
copy/paste multiline strings into the IDE today.
As an example as to why I think (1) is preferable, think of this case:
* start situation:
* end situation:
`a` + msg("Hello") + `b`
Now, if you go from the thing on top, to the thing on the bottom, and
you adopt (2), I think the IDE will fight against you, by adding double
2) ``a` + b``
3) ``a` + msg("Hello") + b``
Which is not what the user wanted - e.g. it's a quote of the entire
concatenation, not a concatenation.
On 20/04/18 17:36, Anna Kozlova wrote:
> Hi guys,
> we started developing the support for raw literals and would like to ask
> what do you think.
> Given a string `a<caret>b` and press ` at <caret>, what is the expected
> 1. Just insert tick: result is `a`b` where it would be parsed as raw
> literal (`a`), unknown identifier (b) and new raw literal till the end of
> file. Second ` at the same position will fix parsing. If one tick was
> intended, one would need to call an intention to fix the number of quotes
> around initial raw literal.
> 2. Add additional quotes around initial raw literal: result is ``a`b``.
> Literal is valid but to get `a` + `b` expression, one need to go to the
> string start/end and change the number of ticks or call an intention.
> It looks like to me that (1) would be needed more often, like each time
> when one needs to dynamically compose a string. (2) is more about injected
> code in the raw strings which IDE could treat differently anyway. (It's
> possible to create an IDE switcher between these strategies but still the
> default value would be needed.) I would love to see other use cases as
> Thank you,
More information about the amber-dev