Esempio n. 1
0
        public override object GetOption(OptionKey optionKey)
        {
            lock (_gate)
            {
                object value;

                if (!_values.TryGetValue(optionKey, out value))
                {
                    value = _service != null?_service.GetOption(optionKey) : optionKey.Option.DefaultValue;

                    _values = _values.Add(optionKey, value);
                }

                return(value);
            }
        }
Esempio n. 2
0
        public object GetOption(OptionKey optionKey)
        {
            lock (_gate)
            {
                if (_currentValues.TryGetValue(optionKey, out var value))
                {
                    return(value);
                }

                value = LoadOptionFromSerializerOrGetDefault(optionKey);

                _currentValues = _currentValues.Add(optionKey, value);

                return(value);
            }
        }
Esempio n. 3
0
        private object LoadOptionFromSerializerOrGetDefault(OptionKey optionKey)
        {
            foreach (var serializer in _optionSerializers)
            {
                // We have a deserializer, so deserialize and use that value.
                object deserializedValue;
                if (serializer.Value.TryFetch(optionKey, out deserializedValue))
                {
                    return(deserializedValue);
                }
            }

            // Just use the default. We will still cache this so we aren't trying to deserialize
            // over and over.
            return(optionKey.Option.DefaultValue);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the value of the option.
        /// </summary>
        public object GetOption(OptionKey optionKey)
        {
            lock (gate)
            {
                object value;

                if (!values.TryGetValue(optionKey, out value))
                {
                    value = this.service != null?this.service.GetOption(optionKey) : optionKey.Option.DefaultValue;

                    values = values.Add(optionKey, value);
                }

                return(value);
            }
        }
Esempio n. 5
0
        public override OptionSet WithChangedOption(OptionKey optionKey, object?value)
        {
            // Make sure we first load this in current optionset
            var currentValue = GetOption(optionKey);

            // Check if the new value is the same as the current value.
            if (Equals(value, currentValue))
            {
                // Return a cloned option set as the public API 'WithChangedOption' guarantees a new option set is returned.
                return(new SolutionOptionSet(_globalOptions, _values, _changedOptionKeys));
            }

            return(new SolutionOptionSet(
                       _globalOptions,
                       _values.SetItem(optionKey, value),
                       _changedOptionKeys.Add(optionKey)));
        }
Esempio n. 6
0
        private protected override object?GetOptionCore(OptionKey optionKey)
        {
            // If we already know the document specific value, we're done
            if (_values.TryGetValue(optionKey, out var value))
            {
                return(value);
            }

            if (TryGetAnalyzerConfigOption(optionKey, out value))
            {
                // Cache and return
                return(ImmutableInterlocked.GetOrAdd(ref _values, optionKey, value));
            }

            // We don't have a document specific value, so forward
            return(_underlyingOptions.GetOption(optionKey));
        }
Esempio n. 7
0
        public void RefreshOption(OptionKey optionKey, object newValue)
        {
            lock (_gate)
            {
                if (_currentValues.TryGetValue(optionKey, out var oldValue))
                {
                    if (object.Equals(oldValue, newValue))
                    {
                        // Value is still the same, no reason to raise events
                        return;
                    }
                }

                _currentValues = _currentValues.SetItem(optionKey, newValue);
            }

            RaiseEvents(new List <OptionChangedEventArgs> {
                new OptionChangedEventArgs(optionKey, newValue)
            });
        }
Esempio n. 8
0
                public override object?GetOption(OptionKey optionKey)
                {
                    // If we already know the document specific value, we're done
                    if (_values.TryGetValue(optionKey, out var value))
                    {
                        return(value);
                    }

                    foreach (var documentOptionSource in _documentOptions)
                    {
                        if (documentOptionSource.TryGetDocumentOption(optionKey, out value))
                        {
                            // Cache and return
                            return(ImmutableInterlocked.GetOrAdd(ref _values, optionKey, value));
                        }
                    }

                    // We don't have a document specific value, so forward
                    return(_underlyingOptions.GetOption(optionKey));
                }
Esempio n. 9
0
        public override OptionSet WithChangedOption(OptionKey optionKey, object?value)
        {
            // Make sure we first load this in current optionset
            var currentValue = this.GetOption(optionKey);

            // Check if the new value is the same as the current value.
            if (Equals(value, currentValue))
            {
                // Return a cloned option set as the public API 'WithChangedOption' guarantees a new option set is returned.
                return(new SerializableOptionSet(
                           _workspaceOptionSet, _serializableOptionValues, _changedOptionKeysSerializable, _changedOptionKeysNonSerializable));
            }

            WorkspaceOptionSet workspaceOptionSet;
            ImmutableDictionary <OptionKey, object?> serializableOptionValues;
            ImmutableHashSet <OptionKey>             changedOptionKeysSerializable;
            ImmutableHashSet <OptionKey>             changedOptionKeysNonSerializable;

            if (ShouldSerialize(optionKey))
            {
                workspaceOptionSet               = _workspaceOptionSet;
                serializableOptionValues         = _serializableOptionValues.SetItem(optionKey, value);
                changedOptionKeysSerializable    = _changedOptionKeysSerializable.Add(optionKey);
                changedOptionKeysNonSerializable = _changedOptionKeysNonSerializable;
            }
            else
            {
                workspaceOptionSet               = (WorkspaceOptionSet)_workspaceOptionSet.WithChangedOption(optionKey, value);
                serializableOptionValues         = _serializableOptionValues;
                changedOptionKeysSerializable    = _changedOptionKeysSerializable;
                changedOptionKeysNonSerializable = _changedOptionKeysNonSerializable.Add(optionKey);
            }

            return(new SerializableOptionSet(
                       workspaceOptionSet, serializableOptionValues, changedOptionKeysSerializable, changedOptionKeysNonSerializable));
        }
Esempio n. 10
0
 public override object?GetOption(OptionKey optionKey)
 => _backingOptionSet.GetOption(optionKey);
Esempio n. 11
0
 public bool TryMapEditorConfigKeyToOption(string key, string?language, [NotNullWhen(true)] out IEditorConfigStorageLocation2?storageLocation, out OptionKey optionKey) => _globalOptionService.TryMapEditorConfigKeyToOption(key, language, out storageLocation, out optionKey);
Esempio n. 12
0
 public object?GetOption(OptionKey optionKey) => _globalOptionService.GetOption(optionKey);
Esempio n. 13
0
 /// <summary>
 /// Gets the value of the option cast to type <typeparamref name="T"/>, or the default value if not otherwise set.
 /// </summary>
 public T GetOption <T>(OptionKey optionKey)
 => OptionsHelpers.GetOption <T>(optionKey, _getOptionCore);
 internal OptionChangedEventArgs(OptionKey optionKey, object?value)
 {
     OptionKey = optionKey;
     Value     = value;
 }
 private protected override object?GetOptionCore(OptionKey optionKey)
 => _backingOptionSet.GetOption(optionKey);
 internal OptionChangedEventArgs(OptionKey optionKey, object?value)
 {
     Option   = optionKey.Option;
     Language = optionKey.Language;
     Value    = value;
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new <see cref="OptionSet" /> that contains the changed value.
 /// </summary>
 public abstract OptionSet WithChangedOption(OptionKey optionAndLanguage, object value);
Esempio n. 18
0
 private bool ShouldSerialize(OptionKey optionKey)
 => _serializableOptions.Contains(optionKey.Option) &&
 (!optionKey.Option.IsPerLanguage || _languages.Contains(optionKey.Language !));
Esempio n. 19
0
 public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object?value)
 {
     return(new DocumentSpecificOptionSet(_documentOptions, _underlyingOptions, _values.SetItem(optionAndLanguage, value)));
 }
Esempio n. 20
0
 private bool ShouldSerialize(OptionKey optionKey)
 => _serializableOptionValues.ContainsKey(optionKey) &&
 (!optionKey.Option.IsPerLanguage || RemoteSupportedLanguages.IsSupported(optionKey.Language));
Esempio n. 21
0
 public new object? GetOption(OptionKey optionKey)
     => base.GetOption(optionKey);
Esempio n. 22
0
 internal OptionChangedEventArgs(OptionKey optionKey, object value)
 {
     this.optionKey = optionKey;
     this.value     = value;
 }
Esempio n. 23
0
 /// <summary>
 /// Gets the value of the option.
 /// </summary>
 public abstract object GetOption(OptionKey optionKey);
 internal OptionChangedEventArgs(OptionKey optionKey, object value)
 {
     _optionKey = optionKey;
     _value     = value;
 }
Esempio n. 25
0
 private static bool SupportedSerializer(OptionKey optionKey, OptionSerializerMetadata metadata)
 {
     return(optionKey.Language == null || optionKey.Language == metadata.Language);
 }
Esempio n. 26
0
 private protected abstract object?GetOptionCore(OptionKey optionKey);
Esempio n. 27
0
 public override object GetOption(OptionKey optionKey)
 {
     return(_backingOptionSet.GetOption(optionKey));
 }
Esempio n. 28
0
 /// <summary>
 /// Gets the value of the option, or the default value if not otherwise set.
 /// </summary>
 public object?GetOption(OptionKey optionKey)
 => OptionsHelpers.GetPublicOption(optionKey, _getOptionCore);
 public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object?value)
 => new DocumentOptionSet(_backingOptionSet.WithChangedOption(optionAndLanguage, value), _language);
Esempio n. 30
0
 /// <summary>
 /// Creates a new <see cref="OptionSet" /> that contains the changed value.
 /// </summary>
 public OptionSet WithChangedOption(OptionKey optionAndLanguage, object value)
 {
     return(new OptionSet(this.service, this.values.SetItem(optionAndLanguage, value)));
 }