提交 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
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)
private static readonly EventHandler<bool> s_documentOpenedEventHandler = OnDocumentOpened;
private static readonly EventHandler<bool> s_documentClosingEventHandler = OnDocumentClosing;
......@@ -101,18 +108,22 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject
{
Contract.ThrowIfNull(projectSystemName);
_language = language;
this.ServiceProvider = serviceProvider;
_language = language;
_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>();
this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
this.DisplayName = projectSystemName;
this.ProjectTracker = projectTracker;
this.DisplayName = _projectSystemName;
_projectSystemName = projectSystemName;
this.ProjectTracker = projectTracker;
_miscellaneousFilesWorkspaceOpt = miscellaneousFilesWorkspaceOpt;
_visualStudioWorkspaceOpt = visualStudioWorkspaceOpt;
_hostDiagnosticUpdateSourceOpt = hostDiagnosticUpdateSourceOpt;
......@@ -139,6 +150,17 @@ internal abstract partial class AbstractProject : IVisualStudioHostProject
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)
{
EnvDTE.Project project;
......@@ -178,53 +200,30 @@ private static bool TryGetProjectDisplayName(IVsHierarchy hierarchy, out string
/// <summary>
/// A full path to the project obj output binary, or null if the project doesn't have an obj output binary.
/// </summary>
internal string TryGetObjOutputPath()
{
return _objOutputPathOpt;
}
internal string TryGetObjOutputPath() => _objOutputPathOpt;
/// <summary>
/// A full path to the project bin output binary, or null if the project doesn't have an bin output binary.
/// </summary>
internal string TryGetBinOutputPath()
{
return _binOutputPathOpt;
}
internal string TryGetBinOutputPath() => _binOutputPathOpt;
internal VisualStudioWorkspaceImpl VisualStudioWorkspace
{
get { return _visualStudioWorkspaceOpt; }
}
internal VisualStudioWorkspaceImpl VisualStudioWorkspace => _visualStudioWorkspaceOpt;
internal IRuleSetFile RuleSetFile
{
get { return this.ruleSet; }
}
internal IRuleSetFile RuleSetFile => this.ruleSet;
internal HostDiagnosticUpdateSource HostDiagnosticUpdateSource
{
get { return _hostDiagnosticUpdateSourceOpt; }
}
internal HostDiagnosticUpdateSource HostDiagnosticUpdateSource => _hostDiagnosticUpdateSourceOpt;
public ProjectId Id
{
get { return _id; }
}
public ProjectId Id => _id;
public string Language
{
get { return _language; }
}
public string Language => _language;
public IVsHierarchy Hierarchy
{
get { return _hierarchy; }
}
public IVsHierarchy Hierarchy => _hierarchy;
public Workspace Workspace
{
get { return (Workspace)_visualStudioWorkspaceOpt ?? _miscellaneousFilesWorkspaceOpt; }
}
public Guid Guid => _guid;
public Workspace Workspace => (Workspace)_visualStudioWorkspaceOpt ?? _miscellaneousFilesWorkspaceOpt;
public VersionStamp Version => _version;
/// <summary>
/// The containing directory of the project. Null if none exists (consider Venus.)
......@@ -244,11 +243,6 @@ protected string ContainingDirectoryPathOpt
}
}
public VersionStamp Version
{
get { return _version; }
}
/// <summary>
/// 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
......
......@@ -69,6 +69,13 @@ int IVsHierarchyEvents.OnPropertyChanged(uint itemid, int propid, uint flags)
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;
}
}
......
......@@ -44,11 +44,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS
public SourceCodeKind SourceCodeKind { 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<bool> Opened;
public event EventHandler<bool> Closing;
......@@ -72,11 +67,6 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS
this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
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;
this.Key = documentKey;
......
......@@ -96,12 +96,6 @@ internal interface IVisualStudioHostDocument : IDisposable
/// </summary>
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>
/// Gets the text container associated with the document when it is in an opened state.
/// </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.
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.Shell.Interop;
......@@ -14,7 +15,10 @@ internal interface IVisualStudioHostProject
{
ProjectId Id { get; }
string Language { get; }
IVsHierarchy Hierarchy { get; }
Guid Guid { get; }
Workspace Workspace { get; }
string ProjectSystemName { get; }
......
......@@ -61,20 +61,13 @@ public ProjectInfo CreateProjectInfoForCurrentState()
hostObjectType: null);
}
public Microsoft.VisualStudio.Shell.Interop.IVsHierarchy Hierarchy
{
get { return null; }
}
public Microsoft.VisualStudio.Shell.Interop.IVsHierarchy Hierarchy => null;
public Workspace Workspace
{
get { return _workspace; }
}
public Guid Guid => Guid.Empty;
public string ProjectSystemName
{
get { return "MiscellaneousFiles"; }
}
public Workspace Workspace => _workspace;
public string ProjectSystemName => "MiscellaneousFiles";
public IVisualStudioHostDocument GetDocumentOrAdditionalDocument(DocumentId id)
{
......
......@@ -212,7 +212,7 @@ protected string GetProjectName(Workspace workspace, ProjectId projectId)
return project.Name;
}
protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId, DocumentId documentId)
protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId)
{
if (projectId == null)
{
......@@ -225,18 +225,6 @@ protected IVsHierarchy GetHierarchy(Workspace workspace, ProjectId projectId, Do
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);
}
......
......@@ -312,7 +312,7 @@ public override bool TryGetValue(int index, string columnName, out object conten
content = GetProjectName(_factory._workspace, _factory._projectId);
return content != null;
case StandardTableKeyNames.Project:
content = GetHierarchy(_factory._workspace, _factory._projectId, _factory._documentId);
content = GetHierarchy(_factory._workspace, _factory._projectId);
return content != null;
default:
content = null;
......
......@@ -188,7 +188,7 @@ public override bool TryGetValue(int index, string columnName, out object conten
content = GetProjectName(_factory._workspace, _factory._documentId.ProjectId);
return content != null;
case StandardTableKeyNames.Project:
content = GetHierarchy(_factory._workspace, _factory._documentId.ProjectId, _factory._documentId);
content = GetHierarchy(_factory._workspace, _factory._documentId.ProjectId);
return content != null;
case StandardTableKeyNames.TaskCategory:
content = VSTASKCATEGORY.CAT_COMMENTS;
......
......@@ -70,7 +70,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
private readonly ReiteratedVersionSnapshotTracker _snapshotTracker;
private readonly IFormattingRule _vbHelperFormattingRule;
private readonly string _itemMoniker;
private readonly IVsHierarchy _sharedHierarchy;
public AbstractProject Project { get { return _containedLanguage.Project; } }
public bool SupportsRename { get { return _hostType == HostType.Razor; } }
......@@ -80,14 +79,6 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
public TextLoader Loader { get; }
public DocumentKey Key { get; }
public IVsHierarchy SharedHierarchy
{
get
{
return _sharedHierarchy;
}
}
public ContainedDocument(
AbstractContainedLanguage containedLanguage,
SourceCodeKind sourceCodeKind,
......@@ -108,11 +99,12 @@ public IVsHierarchy SharedHierarchy
var rdt = (IVsRunningDocumentTable)componentModel.GetService<SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));
IVsHierarchy sharedHierarchy;
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
? rdt.GetMonikerForHierarchyAndItemId(_sharedHierarchy, itemIdInSharedHierarchy)
? rdt.GetMonikerForHierarchyAndItemId(sharedHierarchy, itemIdInSharedHierarchy)
: rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);
// 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.
先完成此消息的编辑!
想要评论请 注册