Vannevelj / VSDiagnostics

A collection of static analyzers based on Roslyn that integrate with VS
GNU General Public License v2.0
65 stars 16 forks source link

Naming doesn't update references #126

Closed Hosch250 closed 9 years ago

Hosch250 commented 9 years ago

Say I have this:

public class foo
{

}

class Program
{
    static void Goo()
    {
        var f = new foo();
    }

    static void Main(string[] args)
    {
        var f = new foo();
    }
}

And I apply the Rename fix to foo at the definition. I get:

public class Foo
{

}

class Program
{
    static void Goo()
    {
        var f = new foo();
    }

    static void Main(string[] args)
    {
        var f = new foo();
    }
}
Hosch250 commented 9 years ago

This might shed some light on how to fix this: http://marcinjuraszek.com/2014/05/solution-wide-rename-from-code-fix-provider-fix-async-method-naming.html

Vannevelj commented 9 years ago

This affects two analyzers:

Hosch250 commented 9 years ago

I tried to implement this, and succeeded to a certain extent. However, certain of the tests are failing because semanticModel.GetDeclaredSymbol(identifierParent, cancellationToken); returns null. This appears to only happen for variable/field types. A related issue is that context.SemanticModel.GetDeclaredSymbol(declarationExpression); returns null for fields and event fields (which I discovered while working on #87). Is this an expected result, or should I create an issue on Roslyn?

Hosch250 commented 9 years ago

A potential alternative solution is: https://social.msdn.microsoft.com/Forums/en-US/82092185-bf21-4802-9f04-b6238a47cebd/finding-usage-of-a-symbol?forum=roslyn. Specifically, the first answer.

Vannevelj commented 9 years ago

If I recall correctly, this might be because GetDeclaredSymbol() only works on (certain?) declarations. You might need to use another GetSymbol() method for certain types. However can't you use the Renamer for this?

Hosch250 commented 9 years ago

I was using the Renamer. The Renamer needs to have the symbol passed in, and fields/event fields return null.

Vannevelj commented 9 years ago

Did you try it with GetSymbolInfo() as well?