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

Respect line directives in SARIF logger #71454

Merged
merged 4 commits into from
Jan 4, 2024

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Jan 3, 2024

Closes #71449

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 3, 2024
@RikkiGibson RikkiGibson changed the base branch from main to release/dev17.9 January 4, 2024 03:58
@RikkiGibson RikkiGibson marked this pull request as ready for review January 4, 2024 04:02
@RikkiGibson RikkiGibson requested a review from a team as a code owner January 4, 2024 04:02
Comment on lines 698 to 700
"version": "42.42.42.42",
"fileVersion": "4.9.0-dev (<developer build>)",
"semanticVersion": "42.42.42",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't hard code these values cause they will change. Even the version will change between local and CI (-dev vs. -ci). Need to either filter these out or fill them with interpolation.

var source = $$"""
public class C
{
#line 123 "D:\otherfile.cs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a bit nervous cause there are cases where #line can behave differently if it can / can't find a file. Hard coding a path like this means it's possible on some machines the file may exist while on others it won't. Prefer instead if we definitively do / don't put a file on disk at this location via Temp.CreateDirectory().CreateFile and then use interpolation to put the known file path.

FileLinePositionSpan span = diagnosticLocation.GetMappedLineSpan();
var path = diagnosticLocation.SourceTree is { } tree
? tree.GetDisplayPath(diagnosticLocation.SourceSpan, resolver)
: span.Path;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to use mapped paths here? Thhe mental model I had for this change is that the sarif location should match the location that we print on the command line for errors. I didn't think that we used mapped paths for that (could be wrong)

Copy link
Contributor Author

@RikkiGibson RikkiGibson Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mistaken. I had an impression that /pathmap was used to report diagnostics on the command line. The ambiguity between "path mapping" for line directives and the command line doesn't help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Analysis results paths are pointing to generated code instead of the Razor files
3 participants