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

How to trigger refactoring? #41

Open
mikesigs opened this issue Jan 18, 2019 · 12 comments
Open

How to trigger refactoring? #41

mikesigs opened this issue Jan 18, 2019 · 12 comments

Comments

@mikesigs
Copy link

First of all, I gotta say how amazing this analyzer is! Thank you for building it!

I cannot figure out how to trigger the refactoring of the LoggerConfiguration though. Judging by the gif in the README, it looks like you must just put the cursor before the parens on CreateLogger() and hit Ctrl+., but that doesn't work for me. I have tried all various ways to trigger and it just ain't workin.

What might I be missing?

@Suchiman
Copy link
Owner

Can you post a snippet on which it does not work?

@mikesigs
Copy link
Author

mikesigs commented Jan 18, 2019

Holy smokes, that was a fast response!

var logger = new LoggerConfiguration()
    .Enrich.WithThreadId()
    .Enrich.WithEnvironmentUserName()
    .WriteTo.Console(
        outputTemplate: "{Timestamp:s} {Level:u12} [{ThreadId}] [{SourceContext}] [{EnvironmentUserName}]{NewLine}{Message}{NewLine}---------------{NewLine}",
        theme: AnsiConsoleTheme.Code)
    .CreateLogger();

@Suchiman
Copy link
Owner

Suchiman commented Jan 18, 2019

It does work for me on this snippet, you can place the cursor anywhere between new and ;.
Are you using VS (2017 / 2019?) or VS Code? Nuget version or the VSIX extension?

It's running into a limitation though on

AnsiConsoleTheme.Code -> Can't statically determine value of expression

"Serilog": {
    "Using": ["Serilog.Enrichers.Environment", "Serilog.Enrichers.Thread", "Serilog.Sinks.Console"],
    "WriteTo": [
    { "Name": "Console", "Args": { "outputTemplate": "{Timestamp:s} {Level:u12} [{ThreadId}] [{SourceContext}] [{EnvironmentUserName}]{NewLine}{Message}{NewLine}---------------{NewLine}", "theme": "?" } }
    ],
    "Enrich": ["WithEnvironmentUserName", "WithThreadId"]
}
<add key="serilog:enrich:WithEnvironmentUserName" />
<add key="serilog:enrich:WithThreadId" />
<add key="serilog:write-to:Console.outputTemplate" value="{Timestamp:s} {Level:u12} [{ThreadId}] [{SourceContext}] [{EnvironmentUserName}]{NewLine}{Message}{NewLine}---------------{NewLine}" />
<add key="serilog:write-to:Console.theme" value="?" />
<add key="serilog:using:Environment" value="Serilog.Enrichers.Environment" />
<add key="serilog:using:Thread" value="Serilog.Enrichers.Thread" />
<add key="serilog:using:Console" value="Serilog.Sinks.Console" />

@mikesigs
Copy link
Author

Here's the details on my VS Installation. It's the most up to date version of 2017.

Microsoft Visual Studio Enterprise 2017
Version 15.9.5
VisualStudio.15.Release/15.9.5+28307.280
Microsoft .NET Framework
Version 4.7.03056
Installed Version: Enterprise

@Suchiman
Copy link
Owner

Are you using the nuget version? It seems that while Analyzers and CodeFixes work, CodeRefactorings do not. If you're using the nuget version, you should be able to workaround the issue by installing from here https://marketplace.visualstudio.com/items?itemName=Suchiman.SerilogAnalyzer

@Suchiman Suchiman added the bug label Jan 19, 2019
@mikesigs
Copy link
Author

Oh yeah, I am using the Nuget version. I just forked the project and will try debugging the issue and try to provide some further info. Although, that will just use the VSIX extension and maybe it won't be a problem... At any rate, I've got a bit of recent experience working with developing analyzers. I'll see what I can see.

@mikesigs
Copy link
Author

mikesigs commented Jan 19, 2019

When I run it through the debugger it shows me the refactoring which appears to include an error. Not sure if that's an issue when running it from nuget? Here's the output:

/*
Errors:
C:\Code\----redacted----\Configuration\SerilogConfig.cs: (18,27)-(18,48): `AnsiConsoleTheme.Code` -> Can't statically determine value of expression

"Serilog": {
    "Using": ["Serilog.Enrichers.Environment", "Serilog.Enrichers.Thread", "Serilog.Sinks.Console"],
    "WriteTo": [
    { "Name": "Console", "Args": { "outputTemplate": "{Timestamp:s} {Level:u12} [{ThreadId}] [{SourceContext}] [{EnvironmentUserName}]{NewLine}{Message}{NewLine}---------------{NewLine}", "theme": "?" } }
    ],
    "Enrich": ["WithEnvironmentUserName", "WithThreadId"]
}
*/

@Suchiman
Copy link
Owner

@mikesigs that is nothing to worry about (in terms of analyzing), that just means that Code is a getter on AnsiConsoleTheme for which it cannot generate a constant value that can be copied into the config.

@mikesigs
Copy link
Author

mikesigs commented Jan 19, 2019

In my own analyzer I added some custom logging (writing to a file basically) to help diagnose some issues.
I am going add that in here and see what it produces from the Nuget version.

Also, it looks like you can put the themes in configuration like this:
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",

Totally unrelated, but perhaps a feature suggestion ;)

@Suchiman
Copy link
Owner

Yes i need to catch up with improvements to the config system of serilog 😉

@mikesigs
Copy link
Author

It's possible I am not nuget packing this thing correctly. And I've never worked with PCL's before.

But when I create a nuget package locally and try to reference it, I get a bunch of warnings stating that Microsoft.CodeAnalysis... 1.0.0 was restored using .NETFramework 4.6.1 instead of .NETCoreApp.

But when I use your version from Nuget, it doesn't display those warnings.

But perhaps this is a .NET Core compatibility thing underneath somehow??

If that's the case, it might require updating to .NET Standard.

Let me know if you'd like some help with that.

For now, I am gonna just move forward without the refactoring part. Or... if I need it, I'll install the VSIX.

@Suchiman
Copy link
Owner

So actually this is by design from roslyn, code refactorings only get loaded from VSIX packages, see explanation here dotnet/roslyn#32705 (comment)

@Suchiman Suchiman added enhancement and removed bug labels Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants