Skip to content

Improve PDB source document project handling#59643

Merged
davidwengier merged 9 commits intodotnet:mainfrom
davidwengier:SourceLinkProjects
Feb 26, 2022
Merged

Improve PDB source document project handling#59643
davidwengier merged 9 commits intodotnet:mainfrom
davidwengier:SourceLinkProjects

Conversation

@davidwengier
Copy link
Copy Markdown
Member

@davidwengier davidwengier commented Feb 18, 2022

Fixes #59138
Part of #55834

The main thing this does is ensure that additional documents found via Source Link are shown in the right project context. The affect is seen when opening a Source Link file other than the first one the user navigated to.

Before:
File is in Misc Files, classification is broken (eg constructer parameters)
image

After:
Show in the right project, with a nice name, and full classification (and in dark mode apparently 😛)
image

This mapping is mostly useless, because there are only two providers, and we know which ones are in use from the Lazy<T>s anyway.
In the case of Source Link its actively harmful, as there can be multiple files downloaded via SourceLink, so we want to give the provider a chance to find each one it downloaded, not just the first one that the user opened in Visual Studio.
@davidwengier davidwengier requested a review from a team as a code owner February 18, 2022 10:48
@ghost ghost added the Area-IDE label Feb 18, 2022
var provider = exportProvider.GetExportedValues<IMetadataAsSourceFileProvider>().OfType<PdbSourceDocumentMetadataAsSourceFileProvider>().Single();
var mappedProject = provider.MapDocument(document);
Assert.NotNull(mappedProject);
Assert.Equal(project.Id, mappedProject!.Id);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No new tests, but this adds an extra verification to all tests in PdbSourceDocumentTests.cs


internal sealed record SourceDocument(string FilePath, SourceHashAlgorithm HashAlgorithm, ImmutableArray<byte> Checksum, byte[]? EmbeddedTextBytes, string? SourceLinkUrl);

internal record struct SourceDocumentInfo(DocumentId DocumentId, Encoding Encoding, ProjectId SourceProjectId, Workspace SourceWorkspace);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Naming these things is hard, but 4 element tuples felt a bit big. Will fix up the names in a follow up (because I have to add another one of these to track tab title and tooltip 🤦‍♂️)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we have both a SourceDocument and a SourceDocumentInfo? How to best think about the difference here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They're info about the same document, but at different stages of the system. One is with info from PDB/SourceLink/etc. before we've loaded the file contents and created the Document, the other is after we've created the Document to store stuff about it and where it came from.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That seems like that might be worth documenting or something?

/// </summary>
private readonly SemaphoreSlim _gate = new(initialCount: 1);

private readonly Dictionary<string, IMetadataAsSourceFileProvider> _tempFileToProviderMap = new(StringComparer.OrdinalIgnoreCase);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Slightly longer explanation for removing this is in the first commit, but TL;DR is:

  • Unnecessary because only two providers
  • Only allows one file per symbol which doesn't hold for PDB source

Comment on lines +200 to +201
if (!provider.IsValueCreated)
continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How expensive do we expect the creation of these providers to be? I would have assumed it was a relatively cheap MEF part. If somebody were to miss a IsValueCreated check in a loop in one of the sites, are we going to break RPS or something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Perhaps not in this spot, but in TryAddDocument..., which is called from an RTD event for every document that is opened, I think its best to avoid the part creation.


internal sealed record SourceDocument(string FilePath, SourceHashAlgorithm HashAlgorithm, ImmutableArray<byte> Checksum, byte[]? EmbeddedTextBytes, string? SourceLinkUrl);

internal record struct SourceDocumentInfo(DocumentId DocumentId, Encoding Encoding, ProjectId SourceProjectId, Workspace SourceWorkspace);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we have both a SourceDocument and a SourceDocumentInfo? How to best think about the difference here?

Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Functionaly seems fine; a comment explaining better the SourceDocument vs. SourceDocumentInfo might be useful. Or maybe not.

@davidwengier
Copy link
Copy Markdown
Member Author

Thanks for the review. Since the snap is Monday and I'm OOF for the week, I'm going to merge and follow up with rename/doc of the records later.

@davidwengier davidwengier merged commit e7bb4c5 into dotnet:main Feb 26, 2022
@ghost ghost added this to the Next milestone Feb 26, 2022
@davidwengier davidwengier deleted the SourceLinkProjects branch February 26, 2022 09:43
333fred added a commit that referenced this pull request Feb 28, 2022
…ures/required-members

* upstream/main: (187 commits)
  Add GlobalOptions.SetBackgroundAnalysisScope and PythiaGlobalOptions External Access API (#59794)
  Update source-build dependency to source-build-externals (#59549)
  Do not retry on Clipboard API for StackTraceExplorer (#59658)
  Remove unnecessary accesses on XML end tag (#59771)
  Threading
  lint
  Improve PDB source document project handling (#59643)
  Disable Auto-Open behavior for Stack Trace Explorer (#59785)
  REmove comment
  Push async up
  Simplify
  Remove stale remarks
  Update src/Tools/ExternalAccess/FSharp/Navigation/FSharpDocumentNavigationService.cs
  Remove unnecessary code
  Simplify threading
  Update tests
  Make the  IDocumentNavigationSerivice entirely async.
  Disable additional text comparer in generator driver (#59776)
  [LSP] Cache parsed xml snippets for razor (#59605)
  Make static
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P2 Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GTD: Better name for project containing files retrieved via Source Link

3 participants