-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support relative paths in interceptors #71879
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
26fe473
Resolve interceptor file path relative to containing file
RikkiGibson 92927a8
unix adjustments
RikkiGibson 81a7a60
unix adjustments
RikkiGibson 462ff45
minor adjustments and add end to end tests
RikkiGibson 805bb13
Add end to end tests with pathmap
RikkiGibson b7eafa7
remove unneeded usings
RikkiGibson 7d11582
Address feedback
RikkiGibson 714b2df
Merge remote-tracking branch 'upstream/main' into generated-file-path
RikkiGibson b40ad6c
restore GeneratorDriverState fields
RikkiGibson 9f2c0c0
Apply suggestions from code review
RikkiGibson 826168f
Address feedback
RikkiGibson cd0d5a7
fix unix test
RikkiGibson 3681998
Clarify plan for file paths in doc
RikkiGibson f59f20a
Merge branch 'generated-file-path' of https://github.com/RikkiGibson/…
RikkiGibson aa52b66
Do not perform pathmap substitution when normalizing relative paths
RikkiGibson b18f5a2
unix test baselines
RikkiGibson 9dab4fa
Add tracking issue
RikkiGibson 82dc78a
Address feedback
RikkiGibson 551cfc1
Update src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs
RikkiGibson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,13 @@ internal Conversions Conversions | |
/// </summary> | ||
private readonly ConcurrentCache<TypeSymbol, NamedTypeSymbol> _typeToNullableVersion = new ConcurrentCache<TypeSymbol, NamedTypeSymbol>(size: 100); | ||
|
||
/// <summary>Lazily caches SyntaxTrees by their mapped path. Used to look up the syntax tree referenced by an interceptor. <see cref="TryGetInterceptor"/></summary> | ||
/// <summary>Lazily caches SyntaxTrees by their mapped path. Used to look up the syntax tree referenced by an interceptor (temporary compat behavior).</summary> | ||
/// <remarks>Must be removed prior to interceptors stable release.</remarks> | ||
private ImmutableSegmentedDictionary<string, OneOrMany<SyntaxTree>> _mappedPathToSyntaxTree; | ||
|
||
/// <summary>Lazily caches SyntaxTrees by their path. Used to look up the syntax tree referenced by an interceptor.</summary> | ||
private ImmutableSegmentedDictionary<string, OneOrMany<SyntaxTree>> _pathToSyntaxTree; | ||
|
||
public override string Language | ||
{ | ||
get | ||
|
@@ -1042,6 +1046,9 @@ internal override int GetSyntaxTreeOrdinal(SyntaxTree tree) | |
|
||
internal OneOrMany<SyntaxTree> GetSyntaxTreesByMappedPath(string mappedPath) | ||
{ | ||
// This method supports a "compat" behavior for interceptor file path resolution. | ||
// It must be removed prior to stable release. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: consider adding link to |
||
|
||
// We could consider storing this on SyntaxAndDeclarationManager instead, and updating it incrementally. | ||
// However, this would make it more difficult for it to be "pay-for-play", | ||
// i.e. only created in compilations where interceptors are used. | ||
|
@@ -1067,6 +1074,32 @@ ImmutableSegmentedDictionary<string, OneOrMany<SyntaxTree>> computeMappedPathToS | |
} | ||
} | ||
|
||
internal OneOrMany<SyntaxTree> GetSyntaxTreesByPath(string path) | ||
{ | ||
// We could consider storing this on SyntaxAndDeclarationManager instead, and updating it incrementally. | ||
// However, this would make it more difficult for it to be "pay-for-play", | ||
// i.e. only created in compilations where interceptors are used. | ||
var pathToSyntaxTree = _pathToSyntaxTree; | ||
if (pathToSyntaxTree.IsDefault) | ||
{ | ||
RoslynImmutableInterlocked.InterlockedInitialize(ref _pathToSyntaxTree, computePathToSyntaxTree()); | ||
pathToSyntaxTree = _pathToSyntaxTree; | ||
} | ||
|
||
return pathToSyntaxTree.TryGetValue(path, out var value) ? value : OneOrMany<SyntaxTree>.Empty; | ||
|
||
ImmutableSegmentedDictionary<string, OneOrMany<SyntaxTree>> computePathToSyntaxTree() | ||
{ | ||
var builder = ImmutableSegmentedDictionary.CreateBuilder<string, OneOrMany<SyntaxTree>>(); | ||
foreach (var tree in SyntaxTrees) | ||
{ | ||
var path = FileUtilities.GetNormalizedPathOrOriginalPath(tree.FilePath, basePath: null); | ||
builder[path] = builder.ContainsKey(path) ? builder[path].Add(tree) : OneOrMany.Create(tree); | ||
} | ||
return builder.ToImmutable(); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region References | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's file a bug to track removing this work around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#72265