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

Simplifier removes trivia when eliminating 'this.' uses. #50

Closed
jaredpar opened this issue Jan 21, 2015 · 3 comments · Fixed by #1965
Closed

Simplifier removes trivia when eliminating 'this.' uses. #50

jaredpar opened this issue Jan 21, 2015 · 3 comments · Fixed by #1965

Comments

@jaredpar
Copy link
Member

Consider the following code:

class C1
{
    int _field;

    void M()
    {
        this. /* comment1 */ _field /* comment 2 */ = 0;
    }
}

If the MemerAccessExpressionSyntax for the field access is tagged with Simplifier.Annotation and the result run through the Simplifier the code will be transformed into.

class C1
{
    int _field;

    void M()
    {
        _field /* comment 2 */ = 0;
    }
}

Notice that /* comment 1 */ has been removed. That seems like a bug. Removing non-comment trivia seems acceptable here but removing comments is potentially removing valuable documentation during the act of simplification. At the least it seems like there should be an option to prevent this from happening.

@srivatsn srivatsn added this to the 1.0 milestone Jan 21, 2015
@srivatsn srivatsn added the Bug label Jan 21, 2015
@srivatsn srivatsn modified the milestones: 1.0 (stable), 1.0-rc2 Jan 29, 2015
@srivatsn srivatsn modified the milestones: 1.0 (stable), 1.0-rc2 Feb 10, 2015
shyamnamboodiripad added a commit to shyamnamboodiripad/roslyn that referenced this issue Apr 14, 2015
shyamnamboodiripad added a commit to shyamnamboodiripad/roslyn that referenced this issue Apr 21, 2015
shyamnamboodiripad added a commit that referenced this issue Apr 21, 2015
…movingThisQualification

Preserve trivia when simplifier removes unnecessary this / Me keywords.

Fixes #50
@shyamnamboodiripad
Copy link
Contributor

@jaredpar The particular issue mentioned in this bug should be fixed - however, other cases exist where simplifier won't preserve trivia. I have logged #2142 to track these cases.

@srivatsn srivatsn assigned ghost and unassigned jaredpar Jun 4, 2015
@ghost
Copy link

ghost commented Jun 4, 2015

It no longer removes the comment but it does add a line break. This is probably the right behavior per formatting conventions:

public class Class1
{
    int _field;

    void M()
    {
        /* comment1 */
        _field /* comment 2 */ = 0;
    }
}

@ghost ghost added the Verified label Jun 4, 2015
@ghost
Copy link

ghost commented Jun 4, 2015

Verified as fixed.

dibarbet added a commit to dibarbet/roslyn that referenced this issue Mar 1, 2023
Add basic project implementation to unblock progress on LSP handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants