提交 6a537469 编写于 作者: D Dustin Campbell

Merge pull request #8622 from DustinCampbell/fix-code-model-race-for-realz

Fix Code Model race for real this time
......@@ -212,6 +212,13 @@ public TValue Remove(TKey key)
return null;
}
public bool ContainsKey(TKey key)
{
this.AssertIsForeground();
return _table.ContainsKey(key);
}
public bool TryGetValue(TKey key, out TValue value)
{
this.AssertIsForeground();
......
......@@ -199,8 +199,7 @@ internal void OnCodeElementCreated(SyntaxNodeKey nodeKey, EnvDTE.CodeElement ele
// If we're creating an element with the same node key as an element that's already in the table, just remove
// the old element. The old element will continue to function but the new element will replace it in the cache.
EnvDTE.CodeElement oldElement;
if (_codeElementTable.TryGetValue(nodeKey, out oldElement))
if (_codeElementTable.ContainsKey(nodeKey))
{
_codeElementTable.Remove(nodeKey);
}
......
......@@ -3845,22 +3845,7 @@ class C$$
Await TestElement(code,
Sub(state, codeClass)
For i = 1 To 100
Dim initialDocument = state.FileCodeModelObject.GetDocument()
Dim variable As EnvDTE.CodeVariable
Try
variable = codeClass.AddVariable("x", "System.Int32")
Catch ex As InvalidOperationException
Assert.False(True,
$"Failed to add variable in loop iteration {i}!
Exception: {ex.Message}
Document text:
{initialDocument.GetTextAsync(CancellationToken.None).Result}")
Throw ex
End Try
Dim variable = codeClass.AddVariable("x", "System.Int32")
' Now, delete the variable that we just added.
Dim startPoint = variable.StartPoint
......
......@@ -3154,22 +3154,7 @@ End Class
Await TestElement(code,
Sub(state, codeClass)
For i = 1 To 100
Dim initialDocument = state.FileCodeModelObject.GetDocument()
Dim variable As EnvDTE.CodeVariable
Try
variable = codeClass.AddVariable("x", "System.Int32")
Catch ex As InvalidOperationException
Assert.False(True,
$"Failed to add variable in loop iteration {i}!
Exception: {ex.Message}
Document text:
{initialDocument.GetTextAsync(CancellationToken.None).Result}")
Throw ex
End Try
Dim variable = codeClass.AddVariable("x", "System.Int32")
' Now, delete the variable that we just added.
Dim startPoint = variable.StartPoint
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册