提交 1bd00171 编写于 作者: B Balaji Krishnan

Merge pull request #4797 from balajikris/RDT-3645

Get document moniker from IVsProject instead of RDT
// 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.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Utilities
{
internal static class VsHierarchyExtensions
{
public static string GetMonikerForHierarchyAndItemId(this IVsRunningDocumentTable runningDocTable, IVsHierarchy hierarchy, uint itemid)
{
if (runningDocTable == null)
{
throw new ArgumentNullException(nameof(runningDocTable));
}
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
}
// First, get the doc cookie for this
IEnumRunningDocuments runningDocsEnum;
Marshal.ThrowExceptionForHR(runningDocTable.GetRunningDocumentsEnum(out runningDocsEnum));
var cookies = new uint[1];
uint cookiesFetched;
while (runningDocsEnum.Next(1, cookies, out cookiesFetched) == VSConstants.S_OK && cookiesFetched == 1)
{
uint documentFlags;
uint documentReadLocks;
uint documentEditLocks;
string documentId;
IVsHierarchy documentHierarchy;
uint documentItemID;
IntPtr pDocData;
Marshal.ThrowExceptionForHR(runningDocTable.GetDocumentInfo(cookies[0], out documentFlags, out documentReadLocks, out documentEditLocks, out documentId, out documentHierarchy, out documentItemID, out pDocData));
try
{
if (documentHierarchy == hierarchy && documentItemID == itemid)
{
return documentId;
}
}
finally
{
Marshal.Release(pDocData);
}
}
// Uh, OK, that's probably not good that we're supposedly an open file but not in the RDT.
return null;
}
// Gets the IVsHierarchy's name property for this item.
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,22 +98,16 @@ internal sealed class ContainedDocument : ForegroundThreadAffinitizedObject, IVi
_optionService = _workspace.Services.GetService<IOptionService>();
_hostType = GetHostType();
var rdt = (IVsRunningDocumentTable)componentModel.GetService<SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));
IVsHierarchy sharedHierarchy;
uint itemIdInSharedHierarchy;
var isSharedHierarchy = LinkedFileUtilities.TryGetSharedHierarchyAndItemId(hierarchy, itemId, out sharedHierarchy, out itemIdInSharedHierarchy);
var filePath = isSharedHierarchy
? rdt.GetMonikerForHierarchyAndItemId(sharedHierarchy, itemIdInSharedHierarchy)
: rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);
// we couldn't look up the document moniker in RDT for a hierarchy/item pair
// Since we only use this moniker as a key, we could fall back to something else, like the document name.
if (filePath == null)
string filePath;
if (!ErrorHandler.Succeeded(((IVsProject)hierarchy).GetMkDocument(itemId, out filePath)))
{
Debug.Assert(false, "Could not get the document moniker for an item in its hierarchy.");
filePath = hierarchy.GetDocumentNameForHierarchyAndItemId(itemId);
// we couldn't look up the document moniker from an hierarchy for an itemid.
// Since we only use this moniker as a key, we could fall back to something else, like the document name.
Debug.Assert(false, "Could not get the document moniker for an item from its hierarchy.");
if (!hierarchy.TryGetItemName(itemId, out filePath))
{
Environment.FailFast("Failed to get document moniker for a contained document");
}
}
if (Project.Hierarchy != null)
......
......@@ -649,7 +649,6 @@
<Compile Include="Implementation\Utilities\VsDebugName.cs" />
<Compile Include="Implementation\Utilities\VsEnumBSTR.cs" />
<Compile Include="Implementation\Utilities\VsEnumDebugName.cs" />
<Compile Include="Implementation\Utilities\VsHierarchyExtensions.cs" />
<Compile Include="Implementation\Venus\AbstractContainedLanguage.cs" />
<Compile Include="Implementation\Venus\CodeBlockEnumerator.cs" />
<Compile Include="Implementation\Venus\ContainedDocument.cs" />
......@@ -752,4 +751,4 @@
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册