提交 e1af7d9a 编写于 作者: H Heejae Chang

removed SharedHierarchy and added Guid to IVisualStudioHostProject

we will move away from IVsHierarchy and start to use ProjectIdGuid instead.
上级 2a80dc8b
...@@ -80,6 +80,13 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject ...@@ -80,6 +80,13 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject
private bool _pushingChangesToWorkspaceHosts; private bool _pushingChangesToWorkspaceHosts;
/// <summary>
/// Guid of the _hierarchy
///
/// it is not readonly since it can be changed while loading project
/// </summary>
private Guid _guid;
// PERF: Create these event handlers once to be shared amongst all documents (the sender arg identifies which document and project) // PERF: Create these event handlers once to be shared amongst all documents (the sender arg identifies which document and project)
private static readonly EventHandler<bool> s_documentOpenedEventHandler = OnDocumentOpened; private static readonly EventHandler<bool> s_documentOpenedEventHandler = OnDocumentOpened;
private static readonly EventHandler<bool> s_documentClosingEventHandler = OnDocumentClosing; private static readonly EventHandler<bool> s_documentClosingEventHandler = OnDocumentClosing;
...@@ -101,18 +108,22 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject ...@@ -101,18 +108,22 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject
{ {
Contract.ThrowIfNull(projectSystemName); Contract.ThrowIfNull(projectSystemName);
_language = language;
this.ServiceProvider = serviceProvider; this.ServiceProvider = serviceProvider;
_language = language;
_hierarchy = hierarchy; _hierarchy = hierarchy;
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); // get project id guid
_guid = GetProjectIDGuid(hierarchy);
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
_contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>(); _contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
this.DisplayName = projectSystemName;
this.ProjectTracker = projectTracker;
this.DisplayName = _projectSystemName;
_projectSystemName = projectSystemName; _projectSystemName = projectSystemName;
this.ProjectTracker = projectTracker;
_miscellaneousFilesWorkspaceOpt = miscellaneousFilesWorkspaceOpt; _miscellaneousFilesWorkspaceOpt = miscellaneousFilesWorkspaceOpt;
_visualStudioWorkspaceOpt = visualStudioWorkspaceOpt; _visualStudioWorkspaceOpt = visualStudioWorkspaceOpt;
_hostDiagnosticUpdateSourceOpt = hostDiagnosticUpdateSourceOpt; _hostDiagnosticUpdateSourceOpt = hostDiagnosticUpdateSourceOpt;
...@@ -139,6 +150,17 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject ...@@ -139,6 +150,17 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject
SetIsWebstite(hierarchy); SetIsWebstite(hierarchy);
} }
private Guid GetProjectIDGuid(IVsHierarchy hierarchy)
{
Guid guid;
if (hierarchy.TryGetGuidProperty(__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid))
{
return guid;
}
return Guid.Empty;
}
private void SetIsWebstite(IVsHierarchy hierarchy) private void SetIsWebstite(IVsHierarchy hierarchy)
{ {
EnvDTE.Project project; EnvDTE.Project project;
...@@ -178,53 +200,30 @@ private static bool TryGetProjectDisplayName(IVsHierarchy hierarchy, out string ...@@ -178,53 +200,30 @@ private static bool TryGetProjectDisplayName(IVsHierarchy hierarchy, out string
/// <summary> /// <summary>
/// A full path to the project obj output binary, or null if the project doesn't have an obj output binary. /// A full path to the project obj output binary, or null if the project doesn't have an obj output binary.
/// </summary> /// </summary>
internal string TryGetObjOutputPath() internal string TryGetObjOutputPath() => _objOutputPathOpt;
{
return _objOutputPathOpt;
}
/// <summary> /// <summary>
/// A full path to the project bin output binary, or null if the project doesn't have an bin output binary. /// A full path to the project bin output binary, or null if the project doesn't have an bin output binary.
/// </summary> /// </summary>
internal string TryGetBinOutputPath() internal string TryGetBinOutputPath() => _binOutputPathOpt;
{
return _binOutputPathOpt;
}
internal VisualStudioWorkspaceImpl VisualStudioWorkspace internal VisualStudioWorkspaceImpl VisualStudioWorkspace => _visualStudioWorkspaceOpt;
{
get { return _visualStudioWorkspaceOpt; }
}
internal IRuleSetFile RuleSetFile internal IRuleSetFile RuleSetFile => this.ruleSet;
{
get { return this.ruleSet; }
}
internal HostDiagnosticUpdateSource HostDiagnosticUpdateSource internal HostDiagnosticUpdateSource HostDiagnosticUpdateSource => _hostDiagnosticUpdateSourceOpt;
{
get { return _hostDiagnosticUpdateSourceOpt; }
}
public ProjectId Id public ProjectId Id => _id;
{
get { return _id; }
}
public string Language public string Language => _language;
{
get { return _language; }
}
public IVsHierarchy Hierarchy public IVsHierarchy Hierarchy => _hierarchy;
{
get { return _hierarchy; }
}
public Workspace Workspace public Guid Guid => _guid;
{
get { return (Workspace)_visualStudioWorkspaceOpt ?? _miscellaneousFilesWorkspaceOpt; } public Workspace Workspace => (Workspace)_visualStudioWorkspaceOpt ?? _miscellaneousFilesWorkspaceOpt;
}
public VersionStamp Version => _version;
/// <summary> /// <summary>
/// The containing directory of the project. Null if none exists (consider Venus.) /// The containing directory of the project. Null if none exists (consider Venus.)
...@@ -244,11 +243,6 @@ protected string ContainingDirectoryPathOpt ...@@ -244,11 +243,6 @@ protected string ContainingDirectoryPathOpt
} }
} }
public VersionStamp Version
{
get { return _version; }
}
/// <summary> /// <summary>
/// The public display name of the project. This name is not unique and may be shared /// The public display name of the project. This name is not unique and may be shared
/// between multiple projects, especially in cases like Venus where the intellisense /// between multiple projects, especially in cases like Venus where the intellisense
......
...@@ -69,6 +69,13 @@ int IVsHierarchyEvents.OnPropertyChanged(uint itemid, int propid, uint flags) ...@@ -69,6 +69,13 @@ int IVsHierarchyEvents.OnPropertyChanged(uint itemid, int propid, uint flags)
UpdateProjectDisplayNameAndFilePath(); UpdateProjectDisplayNameAndFilePath();
} }
if ((propid == (int)__VSHPROPID.VSHPROPID_ProjectIDGuid) &&
itemid == (uint)VSConstants.VSITEMID.Root)
{
// this should happen whle project loading if it ever happens
_guid = GetProjectIDGuid(_hierarchy);
}
return VSConstants.S_OK; return VSConstants.S_OK;
} }
} }
......
...@@ -44,11 +44,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS ...@@ -44,11 +44,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS
public SourceCodeKind SourceCodeKind { get; } public SourceCodeKind SourceCodeKind { get; }
public DocumentKey Key { get; } public DocumentKey Key { get; }
/// <summary>
/// <see cref="IVsHierarchy"/> of shared or project k project.
/// </summary>
public IVsHierarchy SharedHierarchy { get; }
public event EventHandler UpdatedOnDisk; public event EventHandler UpdatedOnDisk;
public event EventHandler<bool> Opened; public event EventHandler<bool> Opened;
public event EventHandler<bool> Closing; public event EventHandler<bool> Closing;
...@@ -72,11 +67,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS ...@@ -72,11 +67,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS
this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker); this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
this.Folders = project.GetFolderNames(itemId); this.Folders = project.GetFolderNames(itemId);
// TODO:
// this one doesn't work for asynchronous project load situation where shared projects is loaded after one uses shared file.
// we need to figure out what to do on those case. but this works for project k case.
// opened an issue to track this issue - https://github.com/dotnet/roslyn/issues/1859
this.SharedHierarchy = project.Hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(project.Hierarchy, itemId);
_documentProvider = documentProvider; _documentProvider = documentProvider;
this.Key = documentKey; this.Key = documentKey;
......
...@@ -96,12 +96,6 @@ internal interface IVisualStudioHostDocument : IDisposable ...@@ -96,12 +96,6 @@ internal interface IVisualStudioHostDocument : IDisposable
/// </summary> /// </summary>
uint GetItemId(); uint GetItemId();
/// <summary>
/// Returns <see cref="IVsHierarchy"/> of the shared (or project k) project this <see cref="IVisualStudioHostDocument"/> belongs to.
/// it will return null if it belongs to a normal project.
/// </summary>
IVsHierarchy SharedHierarchy { get; }
/// <summary> /// <summary>
/// Gets the text container associated with the document when it is in an opened state. /// Gets the text container associated with the document when it is in an opened state.
/// </summary> /// </summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Collections.Generic; using System.Collections.Generic;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.Interop;
...@@ -14,7 +15,10 @@ internal interface IVisualStudioHostProject ...@@ -14,7 +15,10 @@ internal interface IVisualStudioHostProject
{ {
ProjectId Id { get; } ProjectId Id { get; }
string Language { get; } string Language { get; }
IVsHierarchy Hierarchy { get; } IVsHierarchy Hierarchy { get; }
Guid Guid { get; }
Workspace Workspace { get; } Workspace Workspace { get; }
string ProjectSystemName { get; } string ProjectSystemName { get; }
......
...@@ -61,20 +61,13 @@ public ProjectInfo CreateProjectInfoForCurrentState() ...@@ -61,20 +61,13 @@ public ProjectInfo CreateProjectInfoForCurrentState()
hostObjectType: null); hostObjectType: null);
} }
public Microsoft.VisualStudio.Shell.Interop.IVsHierarchy Hierarchy public Microsoft.VisualStudio.Shell.Interop.IVsHierarchy Hierarchy => null;
{
get { return null; }
}
public Workspace Workspace public Guid Guid => Guid.Empty;
{
get { return _workspace; }
}
public string ProjectSystemName public Workspace Workspace => _workspace;
{
get { return "MiscellaneousFiles"; } public string ProjectSystemName => "MiscellaneousFiles";
}
public IVisualStudioHostDocument GetDocumentOrAdditionalDocument(DocumentId id) public IVisualStudioHostDocument GetDocumentOrAdditionalDocument(DocumentId id)
{ {
......
...@@ -212,7 +212,7 @@ protected string GetProjectName(Workspace workspace, ProjectId projectId) ...@@ -212,7 +212,7 @@ protected string GetProjectName(Workspace workspace, ProjectId projectId)
return project.Name; return project.Name;
} }
protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId, DocumentId documentId) protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId)
{ {
if (projectId == null) if (projectId == null)
{ {
...@@ -225,18 +225,6 @@ protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId, Do ...@@ -225,18 +225,6 @@ protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId, Do
return null; return null;
} }
if (documentId != null)
{
// document doesn't actually exist in the workspace
var document = vsWorkspace.GetHostDocument(documentId);
if (document == null)
{
return null;
}
return document.SharedHierarchy ?? document.Project.Hierarchy;
}
return vsWorkspace.GetHierarchy(projectId); return vsWorkspace.GetHierarchy(projectId);
} }
......
...@@ -312,7 +312,7 @@ public override bool TryGetValue(int index, string columnName, out object conten ...@@ -312,7 +312,7 @@ public override bool TryGetValue(int index, string columnName, out object conten
content = GetProjectName(_factory._workspace, _factory._projectId); content = GetProjectName(_factory._workspace, _factory._projectId);
return content != null; return content != null;
case StandardTableKeyNames.Project: case StandardTableKeyNames.Project:
content = GetHierarchy(_factory._workspace, _factory._projectId, _factory._documentId); content = GetHierarchy(_factory._workspace, _factory._projectId);
return content != null; return content != null;
default: default:
content = null; content = null;
......
...@@ -188,7 +188,7 @@ public override bool TryGetValue(int index, string columnName, out object conten ...@@ -188,7 +188,7 @@ public override bool TryGetValue(int index, string columnName, out object conten
content = GetProjectName(_factory._workspace, _factory._documentId.ProjectId); content = GetProjectName(_factory._workspace, _factory._documentId.ProjectId);
return content != null; return content != null;
case StandardTableKeyNames.Project: case StandardTableKeyNames.Project:
content = GetHierarchy(_factory._workspace, _factory._documentId.ProjectId, _factory._documentId); content = GetHierarchy(_factory._workspace, _factory._documentId.ProjectId);
return content != null; return content != null;
case StandardTableKeyNames.TaskCategory: case StandardTableKeyNames.TaskCategory:
content = VSTASKCATEGORY.CAT_COMMENTS; content = VSTASKCATEGORY.CAT_COMMENTS;
......
...@@ -70,7 +70,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi ...@@ -70,7 +70,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
private readonly ReiteratedVersionSnapshotTracker _snapshotTracker; private readonly ReiteratedVersionSnapshotTracker _snapshotTracker;
private readonly IFormattingRule _vbHelperFormattingRule; private readonly IFormattingRule _vbHelperFormattingRule;
private readonly string _itemMoniker; private readonly string _itemMoniker;
private readonly IVsHierarchy _sharedHierarchy;
public AbstractProject Project { get { return _containedLanguage.Project; } } public AbstractProject Project { get { return _containedLanguage.Project; } }
public bool SupportsRename { get { return _hostType == HostType.Razor; } } public bool SupportsRename { get { return _hostType == HostType.Razor; } }
...@@ -80,14 +79,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi ...@@ -80,14 +79,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
public TextLoader Loader { get; } public TextLoader Loader { get; }
public DocumentKey Key { get; } public DocumentKey Key { get; }
public IVsHierarchy SharedHierarchy
{
get
{
return _sharedHierarchy;
}
}
public ContainedDocument( public ContainedDocument(
AbstractContainedLanguage containedLanguage, AbstractContainedLanguage containedLanguage,
SourceCodeKind sourceCodeKind, SourceCodeKind sourceCodeKind,
...@@ -108,11 +99,12 @@ public IVsHierarchy SharedHierarchy ...@@ -108,11 +99,12 @@ public IVsHierarchy SharedHierarchy
var rdt = (IVsRunningDocumentTable)componentModel.GetService<SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable)); var rdt = (IVsRunningDocumentTable)componentModel.GetService<SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));
IVsHierarchy sharedHierarchy;
uint itemIdInSharedHierarchy; uint itemIdInSharedHierarchy;
var isSharedHierarchy = LinkedFileUtilities.TryGetSharedHierarchyAndItemId(hierarchy, itemId, out _sharedHierarchy, out itemIdInSharedHierarchy); var isSharedHierarchy = LinkedFileUtilities.TryGetSharedHierarchyAndItemId(hierarchy, itemId, out sharedHierarchy, out itemIdInSharedHierarchy);
var filePath = isSharedHierarchy var filePath = isSharedHierarchy
? rdt.GetMonikerForHierarchyAndItemId(_sharedHierarchy, itemIdInSharedHierarchy) ? rdt.GetMonikerForHierarchyAndItemId(sharedHierarchy, itemIdInSharedHierarchy)
: rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId); : rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);
// we couldn't look up the document moniker in RDT for a hierarchy/item pair // we couldn't look up the document moniker in RDT for a hierarchy/item pair
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册