Skip to content

Commit

Permalink
use GetInterceptorFilePath preferred implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Oct 22, 2023
1 parent bd6ab89 commit 52fa213
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,12 @@ internal void Generate(in GenerateState ctx)
var loc = op.Location.GetLineSpan();
var start = loc.StartLinePosition;
sb.Append("[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(")
.AppendVerbatimLiteral(loc.Path).Append(", ").Append(start.Line + 1).Append(", ").Append(start.Character + 1).Append(")]").NewLine();
.AppendVerbatimLiteral(ctx.GetInterceptorFilePath(op.Location.SourceTree)).Append(", ").Append(start.Line + 1).Append(", ").Append(start.Character + 1).Append(")]").NewLine();
usageCount++;
}



if (usageCount == 0)
{
continue; // empty group?
Expand Down
8 changes: 8 additions & 0 deletions src/Dapper.AOT.Analyzers/CodeAnalysis/ParseState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Collections.Immutable;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -105,6 +106,13 @@ internal void AddSource(string hintName, string text)
ctx.AddSource(hintName, SourceText.From(text, Encoding.UTF8));
}
}

// see https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md#file-paths
internal string GetInterceptorFilePath(SyntaxTree? tree)
{
if (tree is null) return "";
return Compilation.Options.SourceReferenceResolver?.NormalizePath(tree.FilePath, baseFilePath: null) ?? tree.FilePath;
}
}


Expand Down

0 comments on commit 52fa213

Please sign in to comment.