Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with FormatOnPaste into Visual F# editor #12158

Open
vsfeedback opened this issue Sep 15, 2021 · 12 comments
Open

Issues with FormatOnPaste into Visual F# editor #12158

vsfeedback opened this issue Sep 15, 2021 · 12 comments
Labels
Area-VS-Editor VS editor support for F# code, not covered elsewhere Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
This is similar to https://developercommunity2.visualstudio.com/t/Problem-with-indentation-in-F/719085?entry=problem&ref=native&refTime=1630938135591&refUserId=a2d84250-89b4-6645-9bad-35b10b01efbb but that is marked closed, and this is in the latest daily's

  • If you cut a line with Ctl-L and then paste with Ctl-V, the line loses it's indentation (it is incorrectly flush with the left margin)
  • If you add an "open" line via Ctl-. it is not indented correctly (it is incorrectly flush with the left margin)

Because F# is a indentation oriented language, this is not a minor formatting issue but a major issue that causes errors that must be manually fixed, and there is no adequate Ctl-K-D to fix it all up for you.


Original Comments

Feedback Bot on 9/7/2021, 00:27 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@dsyme dsyme changed the title Issues with F# indentation Issues with paste into F# editor Sep 16, 2021
@dsyme dsyme changed the title Issues with paste into F# editor Issues with paste into Visual F# editor Sep 16, 2021
@dsyme dsyme added Area-VS-Editor VS editor support for F# code, not covered elsewhere Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Sep 16, 2021
@dsyme
Copy link
Contributor

dsyme commented Sep 16, 2021

I've noticed this strange loss of indentation on paster too in Visual Studio and it's really problematic. I can't believe we want it to be like this, so labelling as impact high

@dsyme dsyme added Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. and removed Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Sep 16, 2021
@jonsequitur jonsequitur mentioned this issue Oct 7, 2021
13 tasks
@KevinRansom
Copy link
Member

@dsyme , I think what we do is correct ...

  1. We paste into the code at the current cursor position, and keep the indentation relative to the cursor position.

For example:
Animation1

For refactoring functions this is great:
Animation3

Where it feels incorrect is when pasting to a new line:
Animation4

However, I don't really know of a heuristic to use that wouldn't be surprising in this case. I think we have perhaps done a bad job of educating, ourselves and others as to the paste behaviour. We should consider fixing the education, because the existing behaviour is reasonable and usefull. The alternative would be for us to blindly copy and paste ignoring indentation and simply reproducing whatever indentation exists in the code. I suspect that doing that would result in more work re-aligning than with the existing system.

@dsyme
Copy link
Contributor

dsyme commented Nov 4, 2021

Can you look at the video below? I Ctrl-C to copy a line, then try to paste it at different column positions. Why does it lose indentation when I paste at column 0 and not at anywhere else?

FSharp.-.Microsoft.Visual.Studio.Preview.Administrator.2021-11-04.21-49-51.mp4

In this case, it's surely a bug that pasting at column zero is so different (and wrong).

@dsyme
Copy link
Contributor

dsyme commented Nov 4, 2021

Note the behaviour is different when you select a line and when you Ctrl-C a line. The "select a line" results in an immensely confusing paste. I literally have no idea what I'm going to get:

FSharp.-.Microsoft.Visual.Studio.Preview.Administrator.2021-11-04.21-54-26.mp4

In this case the whole behaviour feels wrong. I just don't know what we're trying to achieve here or what the cognitive model is for what the user has copied. It seems the expectation that the user manually move the cursor to a column hoping that the paste will then indent, rather than the user pasting according to normal editor rules (e.g. VSCode) and then indenting manually.

I really doubt there's any value in differing from VSCode for something so basic. It feels like we're trying to get structure-aware paste when we're just crossing our fingers that it's the right thing to do.

Basically, it feels to me like we should turn this off. When did we even implement this and why?

@KevinRansom
Copy link
Member

No idea when it was implemented, although I'm sure I could look.

  • What you see in the second video is it stripping leading spaces from the one line you copied and copying the text at the cursor point.

  • In the first video, I can't see what you have selected, but perhaps it was shift+alt+line down to copy line below. Which perhaps includes the previous lines terminator, which probably should have been stripped. Although I won't actually know, until I look at the code, and try to reproduce what you see.

I am fairly confident the current algorithm is to strip whitespace up to the first text of the first line and then insert to all remaining lines padding to match the current cursor position. We can certainly eliminate, all smarts and just do copy and paste of the text, which is certainly preferable in the copying line scenario, as I mentioned above. I'm not sure it's preferable with block copies. Indeed, I think the existing behaviour is likely preferable there, although you do have to know how it behaves. C# does auto formatting on paste.

Heck I don't know!!!, the one good thing about simply copy and pasting text unprocessed, is you don't have to explain why it's all miss-aligned.

@KevinRansom
Copy link
Member

So the PR that introduced it is here:

Here is an issue that says it's basically broken:

And another that ends up saying they like it:

@dsyme
Copy link
Contributor

dsyme commented Nov 5, 2021

Thanks for digging up the context!

In the first video, I selected the line with "Ctrl-C" (without any selection active). I do that a lot. In that case, the trouble occurs only when I paste at column 0.

For the second video, the weird thing is how absolutely none of the column positions do anything useful - especially column 0. If I select some lines and paste them at column zero I expect the lines to be inserted unchanged, without any attempt at being smart.

I note this comment, which said the feature should have been off by default or in preview: #9875 (comment)

As an aside: I don't know much about copy-and-paste logic, but it seems pressing Ctrl-C without any selection active (which I do in the first) must create a logically different selection to selecting the line then Ctrl-C (which I do in the second). This also shows in VS Code, where a line selection initiated with Ctrl-C ignores the column on paste.

Anyway I vote for turning this feature off by default. It's always felt broken. // cc @saul

@dsyme
Copy link
Contributor

dsyme commented Nov 20, 2021

@KevinRansom and I talked and we agreed to put this pasting feature back into preview

@KevinRansom
Copy link
Member

No description provided.

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 25, 2021

Shall we just go ahead and disable it by default?

[<CLIMutable>]
type FormattingOptions =
{ FormatOnPaste: bool }
static member Default =
{ FormatOnPaste = true }

@dsyme
Copy link
Contributor

dsyme commented Nov 25, 2021

Shall we just go ahead and disable it by default?

Yes, that is fine

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 25, 2021

Shall we just go ahead and disable it by default?

Yes, that is fine

Disabling it here (+ Added an 'Experimental' suffix to it, as we do with CodeLens): #12454
We should keep this issue open probably, to track a proper fix.

@jonsequitur jonsequitur added Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. and removed Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. labels Jan 31, 2022
@dsyme dsyme changed the title Issues with paste into Visual F# editor Issues with FormatOnPaste into Visual F# editor Mar 30, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@vzarytovskii vzarytovskii added this to the Backlog milestone Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VS-Editor VS editor support for F# code, not covered elsewhere Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

5 participants