提交 598228e1 编写于 作者: B Balaji Krishnan

For a shared item that is a contained document, use the correct itemId and...

For a shared item that is a contained document, use the correct itemId and hierarchy to get a document moniker from running document table.
上级 8975096f
......@@ -152,5 +152,23 @@ private string GetActiveIntellisenseProjectContextInternal(IVsHierarchy hierarch
? intellisenseProjectName as string
: null;
}
public static bool TryGetItemIdInSharedHierarchy(IVsHierarchy hierarchy, uint itemId, IVsHierarchy sharedHierarchy, out uint itemIdInSharedHierarchy)
{
string fullPath;
int found;
VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1];
if (ErrorHandler.Succeeded(((IVsProject)hierarchy).GetMkDocument(itemId, out fullPath))
&& ErrorHandler.Succeeded(((IVsProject)sharedHierarchy).IsDocumentInProject(fullPath, out found, priority, out itemIdInSharedHierarchy))
&& found != 0
&& itemIdInSharedHierarchy != (uint)VSConstants.VSITEMID.Nil)
{
return true;
}
itemIdInSharedHierarchy = (uint)VSConstants.VSITEMID.Nil;
return false;
}
}
}
......@@ -2,7 +2,6 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Utilities
......@@ -53,6 +52,11 @@ public static string GetMonikerForHierarchyAndItemId(this IVsRunningDocumentTabl
// Uh, OK, that's probably not good that we're supposedly an open file but not in the RDT. We'll fall back
// to the IVsHierarchy's name property for this item.
return GetDocumentNameForHierarchyAndItemId(hierarchy, itemid);
}
public static string GetDocumentNameForHierarchyAndItemId(this IVsHierarchy hierarchy, uint itemid)
{
object property;
Marshal.ThrowExceptionForHR(hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out property));
return (string)property;
......
......@@ -98,10 +98,38 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
_optionService = _workspace.Services.GetService<IOptionService>();
_hostType = GetHostType();
this.SharedHierarchy = hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(hierarchy, itemId);
var rdt = (IVsRunningDocumentTable)componentModel.GetService<SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));
var filePath = rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);
this.SharedHierarchy = hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(hierarchy, itemId);
string filePath = null;
if (this.SharedHierarchy == null)
{
// this is not a shared item, look up the hierarchy/itemid pair in the RDT
filePath = rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);
}
else
{
// this *is* a shared item, map from itemId to shared itemId and look up the
// sharedHierarchy/sharedItemId pair in the RDT.
uint itemIdInSharedHierarchy;
if (LinkedFileUtilities.TryGetItemIdInSharedHierarchy(hierarchy, itemId, this.SharedHierarchy, out itemIdInSharedHierarchy))
{
filePath = rdt.GetMonikerForHierarchyAndItemId(this.SharedHierarchy, itemIdInSharedHierarchy);
}
// This is a shared item. But we either couldn't to map an itemId in its shared hierarchy or
// we couldn't look up the document moniker in RDT for a shared hierarchy/item pair
// Since we only use this moniker as a key, we could fall back to something else, like the document name,
// which is the same fall back we have for a non-shared item. we use the headHierarchy/itemId pair for that.
if (filePath == null)
{
Debug.Assert(false,"Could not get itemId in SharedHierarchy or could not find the document moniker for a shared item in its SharedHierarchy.");
filePath = hierarchy.GetDocumentNameForHierarchyAndItemId(itemId);
}
}
if (Project.Hierarchy != null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册