提交 146092ce 编写于 作者: D Dustin Campbell

Code Model: When setting the name of a CodeElement, ensure that its members are updated

Code Model tracks nodes with a "node key" concept, which is effectively
the full name of an element coupled with an ordinal. When the name of a
CodeElement is updated, its node key must also be updated since the name
of the underlying node has changed. However, we had failed to update the
node keys of any members of that CodeElement, which means that they can
no longer be located after their parent container's name changes. This
is now fixed.
上级 6f0a9a0a
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel
......
......@@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.LanguageServices.Implementation.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
using Roslyn.Utilities;
......@@ -106,7 +107,14 @@ protected override string GetName()
protected override void SetName(string value)
{
UpdateNodeAndReaquireNodeKey(FileCodeModel.UpdateName, value);
var nodeKeyValidation = new NodeKeyValidation();
nodeKeyValidation.AddFileCodeModel(this.FileCodeModel);
var node = LookupNode();
FileCodeModel.UpdateName(node, value);
nodeKeyValidation.RestoreKeys();
}
}
}
......@@ -28,6 +28,14 @@ public void AddProject(AbstractProject project)
}
}
public void AddFileCodeModel(FileCodeModel fileCodeModel)
{
var handle = new ComHandle<EnvDTE80.FileCodeModel2, FileCodeModel>(fileCodeModel);
var globalNodeKeys = fileCodeModel.GetCurrentNodeKeys();
_nodeKeysMap.Add(handle, globalNodeKeys);
}
public void RestoreKeys()
{
foreach (var e in _nodeKeysMap)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册