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

Reformat indentation on paste #4702

Merged
merged 10 commits into from
Oct 17, 2018

Conversation

saul
Copy link
Contributor

@saul saul commented Apr 8, 2018

paste

Notice how in the GIF indentation is automatically restructured depending on where you paste. The lack of this feature has been bothering me since day 1 as I cut/paste code around into different scopes often. Near enough feature complete already.

Todo:

  • Write tests
  • Fix indentation when next line should be indented
  • Add "Automatically format on paste" to the F# options

@saul saul changed the title [WIP] Format indentation on paste [WIP] Reformat indentation on paste Apr 8, 2018
@@ -22,6 +23,10 @@ type internal FSharpEditorFormattingService
checkerProvider: FSharpCheckerProvider,
projectInfoManager: FSharpProjectOptionsManager
) =

static let toIList (xs : 'a seq) : IList<'a> = ResizeArray(xs) :> _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit: do static let toIList (xs : 'a seq) = ResizeArray(xs) :> IList<'a>

@TIHan
Copy link
Contributor

TIHan commented Apr 10, 2018

This is cool! It will make the experience much better. :)


static let toIList (xs : 'a seq) : IList<'a> = ResizeArray(xs) :> _

static let getIndentation : string -> int = Seq.takeWhile ((=) ' ') >> Seq.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is just after Don's talk where he said "do not use point free, just don't" ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven’t watched it yet... my apologies to Don!

let nextLineShouldBeIndented = FSharpIndentationService.IndentShouldFollow(documentId, sourceText, filePath, span.Start, parsingOptions)

let removeIndentation =
let nextLineIndent = fixedPasteText.Lines.[1].ToString() |> getIndentation
Copy link
Contributor

@vasily-kirichenko vasily-kirichenko Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .[1] safe here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s a check above that checks that the span is multi line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems difficult to see that check. Can we explicitly guard right before it for sanity?

if not (String.IsNullOrEmpty(previousLine.ToString())) then
Some previousLine
else
tryFindPreviousNonEmptyLine (l - 1)
Copy link
Contributor

@vasily-kirichenko vasily-kirichenko Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let tryFindPreviousNonEmptyLine l =            
    seq { for i in [l - 1 .. -1 .. 0] -> sourceText.Lines.[i] }
    |> Seq.tryFind (not << String.IsNullOrEmpty)

A bit more safe variant :)

@vasily-kirichenko
Copy link
Contributor

It does not work for me:

untitled

@saul
Copy link
Contributor Author

saul commented Apr 11, 2018

Do you have indentation mode set to 'Smart'?

@vasily-kirichenko
Copy link
Contributor

Yes.

@vasily-kirichenko
Copy link
Contributor

I've restarted VS, the same behaviour.

@vasily-kirichenko
Copy link
Contributor

The vsix seems to be installed:

image

@vasily-kirichenko
Copy link
Contributor

image

@saul
Copy link
Contributor Author

saul commented Apr 11, 2018

paste2

Your code works on my machine 🤷‍♂️

@vasily-kirichenko
Copy link
Contributor

But the code looks like this at one moment:

image

Is it ok?..

@vasily-kirichenko
Copy link
Contributor

Sorry, maybe I don't understand how the feature should work...

@saul
Copy link
Contributor Author

saul commented Apr 11, 2018

Well that's where my caret was when I hit paste. I did have to manually de-indent to that level... I was copying your GIF verbatim.

To answer your question as to how it should work, code is re-indented so that it matches the indentation level of your caret when you paste. It would be easy to swap it around so that it used the correct indentation level but that's where the caret naturally ends up anyway (thanks for the indentation service).

@vasily-kirichenko
Copy link
Contributor

I'm lost :( So, everything is OK?

@nosami
Copy link
Contributor

nosami commented Apr 11, 2018

This looks to be how it works in VS for Mac too. Indentation of the paste is adjusted to the caret column. Was one of the first things I worked on.

@saul
Copy link
Contributor Author

saul commented Apr 11, 2018

@vasily-kirichenko maybe this GIF demonstrates what I'm trying to say better. Notice where the caret is when I hit paste - that's the only thing that matters:

paste3

@nosami
Copy link
Contributor

nosami commented Apr 11, 2018

I can't tell from the gif, but does it also work when the selection is irregular like this (the selection doesn't start from column 0, but subsequent lines do) ?

indent

@saul
Copy link
Contributor Author

saul commented Apr 11, 2018

Indeed it does - see the GIF in the PR description.

@vasily-kirichenko
Copy link
Contributor

@saul Ah, I see. Thanks :)

@cartermp
Copy link
Contributor

Tet failure is in Async and seems unrelated to this PR. @dsyme?

@cartermp
Copy link
Contributor

@KevinRansom is still on point to clean out the bit rot in some legacy tests. Until then, no updates.

@saul
Copy link
Contributor Author

saul commented May 28, 2018

But a load of otherwise functioning tests have been disabled?

@vasily-kirichenko
Copy link
Contributor

I find it absolutely unacceptable to happily merge PRs having a lot of tests disabled.

/cc @dsyme

@saul
Copy link
Contributor Author

saul commented May 28, 2018

This PR is also blocked on the fact that I want to write unit tests for new functionality but can't actually test it 😢

@vasily-kirichenko
Copy link
Contributor

@saul it's even more strange that some tests from Roslyn folder are passed locally (e.g. ColorizationServiceTests), but are not enabled on CI.

@cartermp
Copy link
Contributor

@saul

But a load of otherwise functioning tests have been disabled?

I'll have to defer to @KevinRansom on the best way to proceed w.r.t tests, as this isn't my call. Most tests should be just fine, and I believe the Roslyn-based ones have no issues with bit-rot at all, since they're the ones which have been actively developed.

@KevinRansom
Copy link
Member

@saul -- I'm sorry you are blocked. I had to switch away to 4.5 for a short while.

@cartermp
Copy link
Contributor

@dotnet-bot test this please

@cartermp
Copy link
Contributor

@saul now that IDE tests are back up and running in CI we can take this (assuming approval)

@saul
Copy link
Contributor Author

saul commented Jul 21, 2018

I’m on vacation for 10 days - I’ll take a look at this when I get back. I really want this in!

@cartermp
Copy link
Contributor

cartermp commented Jul 21, 2018 via email

@saul
Copy link
Contributor Author

saul commented Jul 30, 2018

@dotnet-bot test this please

@cartermp
Copy link
Contributor

@saul We'd love to take this for VS 2019 Previews. Do you want to resolve conflicts?

@saul
Copy link
Contributor Author

saul commented Sep 13, 2018

This is pretty much finished - I’ll try running (and fixing) the tests when I’m back from NY.

Edit: Just realised that was my excuse 2 months ago... maybe I should stop going on vacation!

@cartermp
Copy link
Contributor

You should never stop going on vacation (especially if you ever end up working in the US, where vacation is a rarity)! No pressure at all.

@cartermp cartermp added this to the 16.0 milestone Oct 16, 2018
@saul
Copy link
Contributor Author

saul commented Oct 16, 2018

Tests are green, this is ready to merge @cartermp.

BTW - haven't really done any work in this repo for a few months, but the Azure DevOps is way nicer than what was there before. Also being able to run unit tests in the IDE (instead of them being EXEs) made debugging this significantly easier. A lot of contributor pain has gone since I last worked on this repo! Great work guys.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some FSComp changes are getting pulled in when they shouldn't be. Can you undo these?

Separately, @brettfo @KevinRansom this isn't the first time a local change to these files got pulled in by a pull request. Is there something funky going on with these files?

@KevinRansom
Copy link
Member

probably needs rebasing, I'll take care of it.

@KevinRansom KevinRansom merged commit a58d9e6 into dotnet:master Oct 17, 2018
@cartermp
Copy link
Contributor

@KevinRansom This now implicitly reverted multiple compiler message changes that we've taken over time. Looking at things a bit more deeply, we've merged in multiple such changes that have caused some compiler messages to be the new ones, and some being reverted back to older ones. This PR actually included a change that brought back an improvement while regressing in others. Can we please revert this PR until we take care of that file?

@KevinRansom
Copy link
Member

@cartermp,

I will go through the resources files and fix them up.

@cartermp
Copy link
Contributor

Spoke with @KevinRansom and these files are build outputs that are an unfortunate consequence of our build today. This issue shouldn't persist once the .NET SDK work is completed.

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* Format indentation on paste

* Fix pasting when next line should be indented

* Initial pass at 'Formatting' page

* Add some tests

* Fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants