Example #1
0
        public LinkedList <KeyValueSettingLookupItem> GetJsonSettingsLookupItems(
            ISpecificCodeCompletionContext context,
            JsonSettingType settingType,
            string jsonPath = null)
        {
            var lookupItems = new LinkedList <KeyValueSettingLookupItem>();

            var project = context.BasicContext.File.GetProject();

            if (project == null)
            {
                return(lookupItems);
            }

            var rangeMarker = CreateRangeMarker(context);
            var settings    = project.GetJsonProjectSettings(settingType, jsonPath);

            return(CreateLookupItems(context, settings, project, rangeMarker, lookupItems));
        }
Example #2
0
        public static IEnumerable <KeyValueSetting> GetJsonProjectSettings(
            this IProject project,
            JsonSettingType settingType,
            string searchPath = null)
        {
            var configFiles = GetNetCoreJsonConfigFiles(project);

            var settings = new HashSet <KeyValueSetting>(KeyValueSetting.KeyComparer);

            foreach (var projectFile in configFiles)
            {
                var json = ParseJsonProjectFile(projectFile);

                var properties = new Queue <JProperty>();
                properties.EnqueueRange(json.Properties());

                var secretsJson = ReadSecretsSafe(project);
                if (secretsJson != null)
                {
                    properties.EnqueueRange(secretsJson.Properties());
                }

                while (properties.Count > 0)
                {
                    var property = properties.Dequeue();
                    if (!property.HasValues || string.IsNullOrEmpty(property.Path))
                    {
                        continue;
                    }

                    string formattedPath = null;

                    if (property.Value.Type == JTokenType.Object)
                    {
                        foreach (var nestedProperty in ((JObject)property.Value).Properties())
                        {
                            properties.Enqueue(nestedProperty);
                        }
                    }

                    if ((property.Value.Type != JTokenType.Object && property.Value.Type != JTokenType.Array &&
                         settingType == JsonSettingType.Value) || settingType == JsonSettingType.All)
                    {
                        formattedPath = FormatJsonPath(property);
                    }

                    if (string.IsNullOrEmpty(formattedPath))
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(searchPath))
                    {
                        if (formattedPath.StartsWith(searchPath, StringComparison.OrdinalIgnoreCase))
                        {
                            formattedPath = formattedPath.Replace(searchPath, string.Empty);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    settings.Add(new KeyValueSetting(formattedPath, property.Value.ToString()));
                }
            }

            return(settings);
        }