dotnet/roslyn

Improve file locations in the Roslyn Sarif reports for source generator files

Aperta

#51.773 aperta il 10 mar 2021

 (2 commenti) (2 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersBugFeature - Source Generatorshelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Hello,

In the Roslyn Sarif reports the file locations for source generator code are not pointing to the right location on disk, even if EmitCompilerGeneratedFiles is set to true.

In SonarSource we parse these reports in order to import the raised issues and having the full path in the report (similar with the one for non generated code) will help us and the community write better tools which handle these files.

Expected Behavior:

{
  "ruleId": "S1144",
  "level": "warning",
  "message": "Remove the unused private method 'UnusedMethod'.",
  "locations": [
	{
	  "resultFile": {
		"uri": "file:///c:/src/SourceGeneratorPOC\SourceGeneratorPOC\obj\Debug\netcoreapp3.1\generated\SourceGeneratorPOC.Generators\SourceGeneratorPOC.SourceGenerator\Greetings.cs",
		"region": {
		  "startLine": 7,
		  "startColumn": 9,
		  "endLine": 7,
		  "endColumn": 47
		}
	  }
	}
  ],
}

Actual Behavior:

{
  "ruleId": "S1144",
  "level": "warning",
  "message": "Remove the unused private method 'UnusedMethod'.",
  "locations": [
	{
	  "resultFile": {
		"uri": "SourceGeneratorPOC.Generators/SourceGeneratorPOC.SourceGenerator/Greetings.cs",
		"region": {
		  "startLine": 7,
		  "startColumn": 9,
		  "endLine": 7,
		  "endColumn": 47
		}
	  }
	}
  ],
}

Thank you!

Guida contributor