diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index d164a96..4ffc1ed 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -24,6 +24,7 @@ "AppVeyor", "AzurePipelines", "Bamboo", + "Bitbucket", "Bitrise", "GitHubActions", "GitLab", diff --git a/Directory.Build.props b/Directory.Build.props index a7dbdec..0c01950 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 2022.2.0 + 2022.2.3 diff --git a/src/Resharper.ConfigurationSense/Extensions/JPropertyExtensions.cs b/src/Resharper.ConfigurationSense/Extensions/JPropertyExtensions.cs new file mode 100644 index 0000000..5b98503 --- /dev/null +++ b/src/Resharper.ConfigurationSense/Extensions/JPropertyExtensions.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; + +using Newtonsoft.Json.Linq; + +namespace Resharper.ConfigurationSense.Extensions +{ + public static class JPropertyExtensions + { + public static string GetSettingsPath(this JProperty property) + { + if (property.Parent == null) + { + return string.Empty; + } + + var positions = new List(); + JToken previous = null; + for (JToken current = property; current != null; current = current.Parent) + { + switch (current.Type) + { + case JTokenType.Property: + var prop = (JProperty)current; + positions.Add(prop.Name); + break; + case JTokenType.Array: + case JTokenType.Constructor: + if (previous != null) + { + int index = ((IList)current).IndexOf(previous); + + positions.Add(index.ToString()); + } + break; + } + + previous = current; + } + + positions.Reverse(); + + return string.Join(":", positions); + } + } +} diff --git a/src/Resharper.ConfigurationSense/Extensions/ProjectExtensions.cs b/src/Resharper.ConfigurationSense/Extensions/ProjectExtensions.cs index be040b8..d3b0a5e 100644 --- a/src/Resharper.ConfigurationSense/Extensions/ProjectExtensions.cs +++ b/src/Resharper.ConfigurationSense/Extensions/ProjectExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -62,7 +62,7 @@ public static IEnumerable GetJsonProjectSettings( if ((property.Value.Type != JTokenType.Object && property.Value.Type != JTokenType.Array && settingType == JsonSettingType.Value) || settingType == JsonSettingType.All) { - formattedPath = FormatJsonPath(property); + formattedPath = property.GetSettingsPath(); } if (string.IsNullOrEmpty(formattedPath)) @@ -147,12 +147,6 @@ public static IEnumerable GetXmlProjectSettings( return result.Select(x => new KeyValueSetting(x.Key, string.Join(", ", x.Value))); } - private static string FormatJsonPath(JToken property) - { - var formattedPath = property.Path.Replace(".", ":"); - return formattedPath; - } - private static IEnumerable GetSettingTags(string settingsTagName, IProjectFile configFile) { var xmlFile = configFile.GetPrimaryPsiFile() as XmlFile;