Skip to content

Commit

Permalink
Revert "Merge pull request dotnet#20558 from Pilchie/Fix19968-Duplica…
Browse files Browse the repository at this point in the history
…teSourceAndAdditionalFiles-DistinctIds"

This reverts commit 6f5b2d4, reversing
changes made to 66362df.
  • Loading branch information
Ravi Chande committed Jul 6, 2017
1 parent 7c36f88 commit d03cde8
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 157 deletions.
7 changes: 1 addition & 6 deletions src/EditorFeatures/Core/Shared/Preview/PreviewWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void OpenDocument(DocumentId documentId, bool activate = true)
{
if (this.CurrentSolution.ContainsAdditionalDocument(documentId))
{
OpenAdditionalDocument(documentId);
OpenAdditionalDocument(documentId, activate);
return;
}

Expand All @@ -60,11 +60,6 @@ public override void OpenDocument(DocumentId documentId, bool activate = true)
this.OnDocumentOpened(documentId, text.Container);
}

/// <summary>
/// Puts the specified additional document into the open state.
/// </summary>
/// <param name="documentId">The <see cref="DocumentId"/> to open.</param>
/// <param name="activate">Ignored - not necessary for additional documents.</param>
public override void OpenAdditionalDocument(DocumentId documentId, bool activate = true)
{
var document = this.CurrentSolution.GetAdditionalDocument(documentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 document, int refCount)> _documentMonikers = new Dictionary<string, (IVisualStudioHostDocument, int)>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, IVisualStudioHostDocument> _documentMonikers = new Dictionary<string, IVisualStudioHostDocument>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, VisualStudioAnalyzer> _analyzers = new Dictionary<string, VisualStudioAnalyzer>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<DocumentId, IVisualStudioHostDocument> _additionalDocuments = new Dictionary<DocumentId, IVisualStudioHostDocument>();

Expand Down Expand Up @@ -410,9 +410,8 @@ public IVisualStudioHostDocument GetCurrentDocumentFromPath(string filePath)
{
lock (_gate)
{
return _documentMonikers.TryGetValue(filePath, out var value)
? value.document
: null;
_documentMonikers.TryGetValue(filePath, out var document);
return document;
}
}

Expand Down Expand Up @@ -893,7 +892,7 @@ private static void OnDocumentUpdatedOnDisk(object sender, EventArgs e)
}
}

private static void OnAdditionalDocumentOpened(object sender, bool isCurrentContextIgnored)
private static void OnAdditionalDocumentOpened(object sender, bool isCurrentContext)
{
IVisualStudioHostDocument document = (IVisualStudioHostDocument)sender;
AbstractProject project = (AbstractProject)document.Project;
Expand All @@ -902,7 +901,7 @@ private static void OnAdditionalDocumentOpened(object sender, bool isCurrentCont

if (project._pushingChangesToWorkspaceHosts)
{
project.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer()));
project.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
}
else
{
Expand Down Expand Up @@ -952,7 +951,6 @@ protected void AddFile(
filePath: filename,
sourceCodeKind: sourceCodeKind,
getFolderNames: getFolderNames,
isAdditionalFile: false,
canUseTextBuffer: CanUseTextBuffer,
updatedOnDiskHandler: s_documentUpdatedOnDiskEventHandler,
openedHandler: s_documentOpenedEventHandler,
Expand Down Expand Up @@ -1016,7 +1014,7 @@ internal void AddDocument(IVisualStudioHostDocument document, bool isCurrentCont
lock (_gate)
{
_documents.Add(document.Id, document);
AddMoniker(document);
_documentMonikers.Add(document.Key.Moniker, document);
}

if (_pushingChangesToWorkspaceHosts)
Expand Down Expand Up @@ -1055,22 +1053,22 @@ internal void RemoveDocument(IVisualStudioHostDocument document)
lock (_gate)
{
_documents.Remove(document.Id);
RemoveMoniker(document);
_documentMonikers.Remove(document.Key.Moniker);
}

UninitializeDocument(document);
OnDocumentRemoved(document.Key.Moniker);
}
}

internal void AddAdditionalDocument(IVisualStudioHostDocument document)
internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext)
{
AssertIsForeground();

lock (_gate)
{
_additionalDocuments.Add(document.Id, document);
AddMoniker(document);
_documentMonikers.Add(document.Key.Moniker, document);
}

if (_pushingChangesToWorkspaceHosts)
Expand All @@ -1079,7 +1077,7 @@ internal void AddAdditionalDocument(IVisualStudioHostDocument document)

if (document.IsOpen)
{
this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer()));
this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext));
}
}

Expand All @@ -1098,48 +1096,12 @@ internal void RemoveAdditionalDocument(IVisualStudioHostDocument document)
lock (_gate)
{
_additionalDocuments.Remove(document.Id);
RemoveMoniker(document);
_documentMonikers.Remove(document.Key.Moniker);
}

UninitializeAdditionalDocument(document);
}

private void AddMoniker(IVisualStudioHostDocument document)
{
var moniker = document.Key.Moniker;
if (_documentMonikers.TryGetValue(moniker, out var value))
{
value.refCount++;
_documentMonikers[moniker] = (value.document, value.refCount);
}
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);
}
}
else
{
Debug.Fail($"Couldn't find '{moniker}' in {nameof(_documentMonikers)} to remove it.");
}
}

public virtual void Disconnect()
{
AssertIsForeground();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public void AddAdditionalFile(string additionalFilePath, Func<IVisualStudioHostD
sourceCodeKind: SourceCodeKind.Regular,
getFolderNames: _ => SpecializedCollections.EmptyReadOnlyList<string>(),
canUseTextBuffer: _ => true,
isAdditionalFile: true,
updatedOnDiskHandler: s_additionalDocumentUpdatedOnDiskEventHandler,
openedHandler: s_additionalDocumentOpenedEventHandler,
closingHandler: s_additionalDocumentClosingEventHandler);
Expand All @@ -147,7 +146,7 @@ public void AddAdditionalFile(string additionalFilePath, Func<IVisualStudioHostD
return;
}

AddAdditionalDocument(document);
AddAdditionalDocument(document, isCurrentContext: getIsInCurrentContext(document));
}

public void RemoveAdditionalFile(string additionalFilePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Shell.Interop;
Expand All @@ -15,47 +14,38 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
///
/// Immutable, since this object is used as a key into some dictionaries.
/// </summary>
[DebuggerDisplay("{GetDebuggerDisplay(),nq")]
internal class DocumentKey : IEquatable<DocumentKey>
{
public IVisualStudioHostProject HostProject { get; }
public string Moniker { get; }
public bool IsAdditionalFile { get; }
private readonly IVisualStudioHostProject _hostProject;
private readonly string _moniker;

public DocumentKey(IVisualStudioHostProject hostProject, string moniker, bool isAdditionalFile)
public IVisualStudioHostProject HostProject { get { return _hostProject; } }
public string Moniker { get { return _moniker; } }

public DocumentKey(IVisualStudioHostProject hostProject, string moniker)
{
Contract.ThrowIfNull(hostProject);
Contract.ThrowIfNull(moniker);

HostProject = hostProject;
Moniker = moniker;
IsAdditionalFile = isAdditionalFile;
_hostProject = hostProject;
_moniker = moniker;
}

public bool Equals(DocumentKey other)
{
return other != null &&
HostProject == other.HostProject &&
Moniker.Equals(other.Moniker, StringComparison.OrdinalIgnoreCase) &&
IsAdditionalFile.Equals(other.IsAdditionalFile);
Moniker.Equals(other.Moniker, StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode()
{
return Hash.Combine(HostProject.GetHashCode(),
Hash.Combine(
StringComparer.OrdinalIgnoreCase.GetHashCode(Moniker),
IsAdditionalFile.GetHashCode()));
return Hash.Combine(HostProject.GetHashCode(), StringComparer.OrdinalIgnoreCase.GetHashCode(Moniker));
}

public override bool Equals(object obj)
{
return this.Equals(obj as DocumentKey);
}

private string GetDebuggerDisplay()
{
return $"{Moniker} (additional: {IsAdditionalFile})";
}
}
}
Loading

0 comments on commit d03cde8

Please sign in to comment.