Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ void ISourceMap.Add(object item, SourceRange range)

lock (_gate)
{
// Map works on a last one wins basis. When we refresh the item for a range,
// just keep the last range

// Remove old item instance for this range.
// Find the entry for the current range
var rangeItemEntry = _sourceByItem.FirstOrDefault(kv => kv.Value.Equals(range) && kv.Key.GetType().Equals(item.GetType()));

if (rangeItemEntry.Key != null)
{
// If found, remove the outdated item from the map
_sourceByItem.Remove(rangeItemEntry.Key);
}

_sourceByItem[item] = range;
_dirty = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InterfaceConverter<T> : JsonConverter, IObservableConverter, IObser
private readonly ResourceExplorer resourceExplorer;
private readonly List<IJsonLoadObserver> observers = new List<IJsonLoadObserver>();
private readonly SourceContext sourceContext;
private readonly ConcurrentDictionary<string, T> cachedRefDialogs = new ConcurrentDictionary<string, T>();
private readonly Dictionary<string, T> cachedRefDialogs = new Dictionary<string, T>();

/// <summary>
/// Initializes a new instance of the <see cref="InterfaceConverter{T}"/> class.
Expand Down Expand Up @@ -203,25 +203,20 @@ public void RegisterObserver(IJsonLoadObserver observer)

private static JToken TryAssignId(JToken jToken, SourceContext sourceContext)
{
// This is the jToken we'll use to build the concrete type.
var tokenToBuild = jToken;

// If our JToken does not have an id, try to get an id from the resource explorer
// in a best-effort manner.
if (jToken is JObject jObj && !jObj.ContainsKey("id"))
{
// Check if we have an id registered for this token
if (sourceContext is ResourceSourceContext rsc && rsc.DefaultIdMap.ContainsKey(jToken))
{
// Clone the token since we'll alter it from the file version.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed elsewhere so we don't need the cloning anymore.

// If we don't clone, future ranges will be calculated based on the altered token.
// which will end in a wrong source range.
tokenToBuild = jToken.DeepClone();
tokenToBuild["id"] = rsc.DefaultIdMap[jToken];
// Just assign. Avoid cloning JTokens since Json.NET does not clone line info
// Tracking item on Json.NET: https://github.com/JamesNK/Newtonsoft.Json/issues/2410
jToken["id"] = rsc.DefaultIdMap[jToken];
}
}

return tokenToBuild;
return jToken;
}
}
}