提交 606f0397 编写于 作者: J Jason Malinowski

Make AbstractProjectCodeModel.GetCodeModelCache private

This was being used directly in a lot of places, but I think it's a bit
eaiser to follow object relationships if all creation methods go
through AbstractProjectCodeModel, and from there might get forwarded.

A fair number of checks were being made of whether the CodeModelCache
was null; I don't believe these make sense. Once the underlying
_codeModelCache type is made non-null, it is never set to null, and the
only way it could fail to create in the first place is if the project
was never in the ProjectTracker. Given we only produce these once we
already have a live AbstractProject, that's not possible.
上级 9d284f1d
......@@ -36,36 +36,18 @@ protected override void OnDocumentRemoved(string filePath)
base.OnDocumentRemoved(filePath);
// We may have a code model floating around for it
var codeModelCache = ProjectCodeModel.GetCodeModelCache();
if (codeModelCache != null)
{
codeModelCache.OnSourceFileRemoved(filePath);
}
ProjectCodeModel.OnSourceFileRemoved(filePath);
}
public override int CreateCodeModel(object parent, out EnvDTE.CodeModel codeModel)
{
var codeModelCache = ProjectCodeModel.GetCodeModelCache();
if (codeModelCache == null)
{
codeModel = null;
return VSConstants.E_FAIL;
}
codeModel = codeModelCache.GetOrCreateRootCodeModel((EnvDTE.Project)parent);
codeModel = ProjectCodeModel.GetOrCreateRootCodeModel((EnvDTE.Project)parent);
return VSConstants.S_OK;
}
public override int CreateFileCodeModel(string fileName, object parent, out EnvDTE.FileCodeModel ppFileCodeModel)
{
var codeModelCache = ProjectCodeModel.GetCodeModelCache();
if (codeModelCache == null)
{
ppFileCodeModel = null;
return VSConstants.E_FAIL;
}
ppFileCodeModel = codeModelCache.GetOrCreateFileCodeModel(fileName, parent).Handle;
ppFileCodeModel = ProjectCodeModel.GetOrCreateFileCodeModel(fileName, parent).Handle;
return VSConstants.S_OK;
}
}
......
......@@ -30,7 +30,7 @@ internal void OnProjectClosed()
_codeModelCache?.OnProjectClosed();
}
internal CodeModelProjectCache GetCodeModelCache()
private CodeModelProjectCache GetCodeModelCache()
{
Contract.ThrowIfNull(VSProject);
Contract.ThrowIfNull(VisualStudioWorkspace);
......@@ -84,7 +84,28 @@ public bool TryGetCachedFileCodeModel(string fileName, out ComHandle<EnvDTE80.Fi
return GetCodeModelCache().GetOrCreateFileCodeModel(filePath);
}
public ComHandle<EnvDTE80.FileCodeModel2, FileCodeModel> GetOrCreateFileCodeModel(string filePath, object parent)
{
return GetCodeModelCache().GetOrCreateFileCodeModel(filePath, parent);
}
public EnvDTE.CodeModel GetOrCreateRootCodeModel(EnvDTE.Project parent)
{
return GetCodeModelCache().GetOrCreateRootCodeModel(parent);
}
public void OnSourceFileRemoved(string fileName)
{
GetCodeModelCache().OnSourceFileRemoved(fileName);
}
public void OnSourceFileRenaming(string filePath, string newFilePath)
{
GetCodeModelCache().OnSourceFileRenaming(filePath, newFilePath);
}
internal abstract bool CanCreateFileCodeModelThroughProject(string filePath);
internal abstract object CreateFileCodeModelThroughProject(string filePath);
}
}
......@@ -26,18 +26,11 @@ internal override object CreateFileCodeModelThroughProject(string filePath)
return null;
}
var codeModelCache = GetCodeModelCache();
return codeModelCache.GetOrCreateFileCodeModel(filePath, projectItem).Handle;
return this.GetOrCreateFileCodeModel(filePath, projectItem).Handle;
}
private EnvDTE.ProjectItem GetProjectItem(string filePath)
{
var codeModelCache = GetCodeModelCache();
if (codeModelCache == null)
{
return null;
}
var dteProject = VisualStudioWorkspace.TryGetDTEProject(VSProject.Id);
if (dteProject == null)
{
......@@ -49,29 +42,17 @@ private EnvDTE.ProjectItem GetProjectItem(string filePath)
public EnvDTE.CodeModel GetCodeModel(EnvDTE.Project parent)
{
var codeModelCache = GetCodeModelCache();
if (codeModelCache == null)
{
return null;
}
return codeModelCache.GetOrCreateRootCodeModel(parent);
return this.GetOrCreateRootCodeModel(parent);
}
public EnvDTE.FileCodeModel GetFileCodeModel(EnvDTE.ProjectItem item)
{
var codeModelCache = GetCodeModelCache();
if (codeModelCache == null)
{
return null;
}
if (!item.TryGetFullPath(out var filePath))
{
return null;
}
return codeModelCache.GetOrCreateFileCodeModel(filePath, item).Handle;
return this.GetOrCreateFileCodeModel(filePath, item).Handle;
}
}
}
......@@ -27,11 +27,7 @@ protected override void OnDocumentRemoved(string filePath)
base.OnDocumentRemoved(filePath);
// We may have a code model floating around for it
var codeModelCache = _projectCodeModel?.GetCodeModelCache();
if (codeModelCache != null)
{
codeModelCache.OnSourceFileRemoved(filePath);
}
_projectCodeModel?.OnSourceFileRemoved(filePath);
}
public EnvDTE.CodeModel GetCodeModel(EnvDTE.Project parent)
......
......@@ -104,13 +104,7 @@ internal override bool RenameFileCodeModelInstance(DocumentId documentId, string
return false;
}
var codeModelCache = codeModelProvider.ProjectCodeModel.GetCodeModelCache();
if (codeModelCache == null)
{
return false;
}
codeModelCache.OnSourceFileRenaming(document.FilePath, newFilePath);
codeModelProvider.ProjectCodeModel.OnSourceFileRenaming(document.FilePath, newFilePath);
return true;
}
......
......@@ -17,14 +17,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
End Property
Public Overrides Function CreateCodeModel(pProject As EnvDTE.Project, pProjectItem As EnvDTE.ProjectItem, ByRef ppCodeModel As EnvDTE.CodeModel) As Integer
ppCodeModel = Nothing
Dim codeModelCache = ProjectCodeModel.GetCodeModelCache()
If codeModelCache Is Nothing Then
Return VSConstants.E_FAIL
End If
ppCodeModel = codeModelCache.GetOrCreateRootCodeModel(pProject)
ppCodeModel = ProjectCodeModel.GetOrCreateRootCodeModel(pProject)
Return VSConstants.S_OK
End Function
......@@ -36,12 +29,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
Dim fileName = pProjectItem.FileNames(1)
If Not String.IsNullOrWhiteSpace(fileName) Then
Dim codeModelCache = ProjectCodeModel.GetCodeModelCache()
If codeModelCache Is Nothing Then
Return VSConstants.E_FAIL
End If
ppFileCodeModel = codeModelCache.GetOrCreateFileCodeModel(fileName, pProjectItem).Handle
ppFileCodeModel = ProjectCodeModel.GetOrCreateFileCodeModel(fileName, pProjectItem).Handle
Return VSConstants.S_OK
End If
End If
......@@ -53,10 +41,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
MyBase.OnDocumentRemoved(filePath)
' We may have a code model floating around for it
Dim codeModelCache = ProjectCodeModel.GetCodeModelCache()
If codeModelCache IsNot Nothing Then
codeModelCache.OnSourceFileRemoved(filePath)
End If
ProjectCodeModel.OnSourceFileRemoved(filePath)
End Sub
Public Overrides Sub Disconnect()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册