Git Product home page Git Product logo

Comments (5)

ctolkien avatar ctolkien commented on August 20, 2024 3

@feliwir - I'm not working on this, got a newborn 👶 !

from format.

JoeRobich avatar JoeRobich commented on August 20, 2024 1

These details now get logged during --dry-runs. You can try this out with the latest build from MyGet.

dotnet tool install -g dotnet-format --version 3.1.36303 --add-source https://dotnet.myget.org/F/format/api/v3/index.json

from format.

ctolkien avatar ctolkien commented on August 20, 2024

Naive bunch of code from CodeFormatter.cs after a document is formatted:

//get the differences between the formatted document, and the original
var diffs = await formattedDocument.GetTextChangesAsync(document, cancellationToken);
foreach (var item in diffs)
{
    var sourceText = await document.GetTextAsync(cancellationToken);
    var fixedText = await document.GetTextAsync(cancellationToken);

    var linePositionSpan = sourceText.Lines.GetLinePositionSpan(item.Span);

    var sourceLine = sourceText.Lines[linePositionSpan.Start.Line];
    var destinationLine = fixedText.Lines[linePositionSpan.Start.Line];

    logger.Log("log details above");
}

I imagine in practice there is a bunch more considerations to take into account. For instance certain TextChanges can likely apply to multiple lines?

I've also no idea on the correct API's to use here, I was just digging about in intellisense.

Sample output (in this case, the displayed line was indented 4 spaces too many):

Formatting code files in project 'dotnet-format'.
  CodeFormatter.cs 192 "                        var diffs = await formattedDocument.GetTextChangesAsync(document, cancellationToken);". New Text: "                    var diffs = await formattedDocument.GetTextChangesAsync(document, cancellationToken);"

from format.

jmarolf avatar jmarolf commented on August 20, 2024

Well happily accept a PR for this

from format.

feliwir avatar feliwir commented on August 20, 2024

Any work being done on this already?

from format.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.