Giter Site home page Giter Site logo

Comments (5)

DannySliekers avatar DannySliekers commented on August 18, 2024 1

Hey, can i pick this up if possible?

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on August 18, 2024 1

@DannySliekers i would just work on a fix that resolves exactly the case reported.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on August 18, 2024

@DannySliekers Absolutely!

from roslyn.

DannySliekers avatar DannySliekers commented on August 18, 2024

So I did some investigating and found that the issue seems to lie at the removal of the LocalDeclarationStatement, as none of the leading and trailing trivia gets preserved:

// Remove the actual declaration of the builder.
subEditor.RemoveNode(analysisResult.LocalDeclarationStatement);

For the case of leading trivia i assume we want to include all leading trivia in the fixed code, right?
Example with trivia on same line:

// Code with violation.
/* test */ var builder = ImmutableArray.CreateBuilder<int>();
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable();

// Desired code
/* test */ ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }];

For the case in which the declaration of the builder contains trailing trivia seems to be a little bit more complicated.
This seems like a desired result to me:

// Code with violation.
var builder = ImmutableArray.CreateBuilder<int>(); // test
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable();

//Desired code
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test

If the fix in the code above is desired, there is a case where there would be multiple options of preserving trivia:

var builder = ImmutableArray.CreateBuilder<int>(); // test
builder.Add(1);
builder.AddRange(new int[] { 5, 6, 7 });
ImmutableArray<int> i = builder.ToImmutable(); // test2

//Desired code #1? 
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test2 // test

//Desired code #2? 
ImmutableArray<int> i = [1, .. new int[] { 5, 6, 7 }]; // test // test2

Seems to me like there are multiple options in the case of trailing trivia at the declaration of the builder, and I would like to know what would be desirable.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on August 18, 2024

For the case of leading trivia i assume we want to include all leading trivia in the fixed code, right?

We try to handle reasonable code patterns, and we don't expend effort on uncommon ones.

So, for example, this is not common: /* test */ var builder = ImmutableArray.CreateBuilder<int>();.

from roslyn.

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.