-
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 having a file be both a document and additional file. #20558
Changes from all commits
5af1d1e
ec766cd
b904ab8
d6cdf10
b4a6e6b
8de15ee
818b0a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ internal abstract partial class AbstractProject : ForegroundThreadAffinitizedObj | |
private readonly List<ProjectReference> _projectReferences = new List<ProjectReference>(); | ||
private readonly List<VisualStudioMetadataReference> _metadataReferences = new List<VisualStudioMetadataReference>(); | ||
private readonly Dictionary<DocumentId, IVisualStudioHostDocument> _documents = new Dictionary<DocumentId, IVisualStudioHostDocument>(); | ||
private readonly Dictionary<string, IVisualStudioHostDocument> _documentMonikers = new Dictionary<string, IVisualStudioHostDocument>(StringComparer.OrdinalIgnoreCase); | ||
private readonly Dictionary<string, (IVisualStudioHostDocument document, int refCount)> _documentMonikers = new Dictionary<string, (IVisualStudioHostDocument, int)>(StringComparer.OrdinalIgnoreCase); | ||
private readonly Dictionary<string, VisualStudioAnalyzer> _analyzers = new Dictionary<string, VisualStudioAnalyzer>(StringComparer.OrdinalIgnoreCase); | ||
private readonly Dictionary<DocumentId, IVisualStudioHostDocument> _additionalDocuments = new Dictionary<DocumentId, IVisualStudioHostDocument>(); | ||
|
||
|
@@ -410,8 +410,9 @@ public IVisualStudioHostDocument GetCurrentDocumentFromPath(string filePath) | |
{ | ||
lock (_gate) | ||
{ | ||
_documentMonikers.TryGetValue(filePath, out var document); | ||
return document; | ||
return _documentMonikers.TryGetValue(filePath, out var value) | ||
? value.document | ||
: null; | ||
} | ||
} | ||
|
||
|
@@ -892,7 +893,7 @@ private static void OnDocumentUpdatedOnDisk(object sender, EventArgs e) | |
} | ||
} | ||
|
||
private static void OnAdditionalDocumentOpened(object sender, bool isCurrentContext) | ||
private static void OnAdditionalDocumentOpened(object sender, bool isCurrentContextIgnored) | ||
{ | ||
IVisualStudioHostDocument document = (IVisualStudioHostDocument)sender; | ||
AbstractProject project = (AbstractProject)document.Project; | ||
|
@@ -901,7 +902,7 @@ private static void OnAdditionalDocumentOpened(object sender, bool isCurrentCont | |
|
||
if (project._pushingChangesToWorkspaceHosts) | ||
{ | ||
project.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); | ||
project.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer())); | ||
} | ||
else | ||
{ | ||
|
@@ -951,6 +952,7 @@ protected void AddFile( | |
filePath: filename, | ||
sourceCodeKind: sourceCodeKind, | ||
getFolderNames: getFolderNames, | ||
isAdditionalFile: false, | ||
canUseTextBuffer: CanUseTextBuffer, | ||
updatedOnDiskHandler: s_documentUpdatedOnDiskEventHandler, | ||
openedHandler: s_documentOpenedEventHandler, | ||
|
@@ -1014,7 +1016,7 @@ internal void AddDocument(IVisualStudioHostDocument document, bool isCurrentCont | |
lock (_gate) | ||
{ | ||
_documents.Add(document.Id, document); | ||
_documentMonikers.Add(document.Key.Moniker, document); | ||
AddMoniker(document); | ||
} | ||
|
||
if (_pushingChangesToWorkspaceHosts) | ||
|
@@ -1053,22 +1055,22 @@ internal void RemoveDocument(IVisualStudioHostDocument document) | |
lock (_gate) | ||
{ | ||
_documents.Remove(document.Id); | ||
_documentMonikers.Remove(document.Key.Moniker); | ||
RemoveMoniker(document); | ||
} | ||
|
||
UninitializeDocument(document); | ||
OnDocumentRemoved(document.Key.Moniker); | ||
} | ||
} | ||
|
||
internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext) | ||
internal void AddAdditionalDocument(IVisualStudioHostDocument document) | ||
{ | ||
AssertIsForeground(); | ||
|
||
lock (_gate) | ||
{ | ||
_additionalDocuments.Add(document.Id, document); | ||
_documentMonikers.Add(document.Key.Moniker, document); | ||
AddMoniker(document); | ||
} | ||
|
||
if (_pushingChangesToWorkspaceHosts) | ||
|
@@ -1077,7 +1079,7 @@ internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isC | |
|
||
if (document.IsOpen) | ||
{ | ||
this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); | ||
this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer())); | ||
} | ||
} | ||
|
||
|
@@ -1096,12 +1098,48 @@ internal void RemoveAdditionalDocument(IVisualStudioHostDocument document) | |
lock (_gate) | ||
{ | ||
_additionalDocuments.Remove(document.Id); | ||
_documentMonikers.Remove(document.Key.Moniker); | ||
RemoveMoniker(document); | ||
} | ||
|
||
UninitializeAdditionalDocument(document); | ||
} | ||
|
||
private void AddMoniker(IVisualStudioHostDocument document) | ||
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. "AddToMonikerToDocumentMap"? |
||
{ | ||
var moniker = document.Key.Moniker; | ||
if (_documentMonikers.TryGetValue(moniker, out var value)) | ||
{ | ||
value.refCount++; | ||
_documentMonikers[moniker] = (value.document, value.refCount); | ||
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. I must admit: using tuples here seems really terrifying and really likely to make a mistake.... 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. Can't the right hand side just be "value" since you already have the tuple in hand though? |
||
} | ||
else | ||
{ | ||
_documentMonikers.Add(moniker, (document, 1)); | ||
} | ||
} | ||
|
||
private void RemoveMoniker(IVisualStudioHostDocument document) | ||
{ | ||
var moniker = document.Key.Moniker; | ||
if (_documentMonikers.TryGetValue(moniker, out var value)) | ||
{ | ||
Debug.Assert(value.document.Equals(document)); | ||
value.refCount--; | ||
if (value.refCount == 0) | ||
{ | ||
_documentMonikers.Remove(moniker); | ||
} | ||
else | ||
{ | ||
_documentMonikers[moniker] = (value.document, value.refCount); | ||
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. Can't the right hand side just be "value" since you already have the tuple in hand though? |
||
} | ||
} | ||
else | ||
{ | ||
Debug.Fail($"Couldn't find '{moniker}' in {nameof(_documentMonikers)} to remove it."); | ||
} | ||
} | ||
|
||
public virtual void Disconnect() | ||
{ | ||
AssertIsForeground(); | ||
|
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.
Isn't the statement for the param here more "this doesn't matter in the preview workspace?"