-
Notifications
You must be signed in to change notification settings - Fork 250
Description
This behavior is specially annoying with sourcekit-lsp's experimental on-type formatting enabled.
Current behavior with one dot:
echo "String(decoding: data, as: UTF8.self)" | swift format format -
String(decoding: data, as: UTF8.self)
Doesn't touch the code, which makes sense.
Current behavior with 2 dots:
$ echo "String(decoding: data, as: UTF8..self)" | swift format format -
String(decoding: data, as: UTF8 .. self)
Inserts a whitespace before, and a whitespace after ..
.
This simply should just not happen. Swift format should take no action on the code above.
I experience this behavior when I'm trying to add something to the code.
For example when I have my.thing
then I write my..thing
so I can continue to write my.some.thing
, but the on-type formatting turns my..thing
into my .. thing
which is not the end of the world, but definitely undesired and takes steps to reverse.
There is also a question of should on-type formatting be triggered at all in this situation?
The way on-type formatting works is that we register characters for which we should get notified of code changes in the specific changed line,
and when a notification happens, sourcekit-lsp tries to format that line using swift-format's relatively-new selection-formatting support.
.
is registered as one of those characters so that triggers the on-type formatting, and then swift-format messes up the formatting when asked to format the line.
Possibly both. I don't see why swift-format should exhibit this behavior, but at the same time maybe sourcekit-lsp should not watch for .
insertions for on-type formatting.
The current list of characters that sourcekit-lsp watches for are inspired by Xcode (see this comment), so perhaps we should just fix swift-format and move on.
Off-hand I can't tell what watching for .
can be helpful for, but that doesn't mean it's not helpful.
cc @ahoppen