提交 cb6729b0 编写于 作者: C Cyrus Najmabadi

Clear the cache as the solution changes.

上级 8d9db83e
......@@ -15,6 +15,10 @@ internal partial class SemanticModelReuseWorkspaceServiceFactory : IWorkspaceSer
{
private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWorkspaceService
{
public SemanticModelReuseWorkspaceService(Workspace _)
{
}
public Task<SemanticModel> ReuseExistingSpeculativeModelAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
// TODO: port the GetSemanticModelForNodeAsync implementation from Workspaces layer,
......
......@@ -52,6 +52,8 @@ internal partial class SemanticModelReuseWorkspaceServiceFactory : IWorkspaceSer
{
private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWorkspaceService
{
private readonly Workspace _workspace;
/// <summary>
/// A mapping from a document id to the last semantic model we produced for it, along with the top level
/// semantic version that that semantic model corresponds to. We can continue reusing the semantic model as
......@@ -67,6 +69,29 @@ private sealed class SemanticModelReuseWorkspaceService : ISemanticModelReuseWor
/// </summary>
private ImmutableDictionary<DocumentId, SemanticModelReuseInfo?> _semanticModelMap = ImmutableDictionary<DocumentId, SemanticModelReuseInfo?>.Empty;
public SemanticModelReuseWorkspaceService(Workspace workspace)
{
_workspace = workspace;
_workspace.WorkspaceChanged += (_, e) =>
{
// if our map points at documents not in the current solution, then we want to clear things out.
// this way we don't hold onto semantic models past, say, the c#/vb solutions closing.
var map = _semanticModelMap;
if (map.IsEmpty)
return;
var solution = e.NewSolution;
foreach (var (docId, _) in map)
{
if (!solution.ContainsDocument(docId))
{
_semanticModelMap = ImmutableDictionary<DocumentId, SemanticModelReuseInfo?>.Empty;
return;
}
}
};
}
public async Task<SemanticModel> ReuseExistingSpeculativeModelAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
var reuseService = document.GetRequiredLanguageService<ISemanticModelReuseLanguageService>();
......
......@@ -21,6 +21,6 @@ public SemanticModelReuseWorkspaceServiceFactory()
}
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
=> new SemanticModelReuseWorkspaceService();
=> new SemanticModelReuseWorkspaceService(workspaceServices.Workspace);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册