Пример #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);
            }
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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)));
        }
Пример #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));
        }
Пример #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)
            });
        }
Пример #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));
                }
Пример #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));
        }
Пример #10
0
 public override object?GetOption(OptionKey optionKey)
 => _backingOptionSet.GetOption(optionKey);
Пример #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);
Пример #12
0
 public object?GetOption(OptionKey optionKey) => _globalOptionService.GetOption(optionKey);
Пример #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;
 }
Пример #15
0
 private protected override object?GetOptionCore(OptionKey optionKey)
 => _backingOptionSet.GetOption(optionKey);
 internal OptionChangedEventArgs(OptionKey optionKey, object?value)
 {
     Option   = optionKey.Option;
     Language = optionKey.Language;
     Value    = value;
 }
Пример #17
0
 /// <summary>
 /// Creates a new <see cref="OptionSet" /> that contains the changed value.
 /// </summary>
 public abstract OptionSet WithChangedOption(OptionKey optionAndLanguage, object value);
Пример #18
0
 private bool ShouldSerialize(OptionKey optionKey)
 => _serializableOptions.Contains(optionKey.Option) &&
 (!optionKey.Option.IsPerLanguage || _languages.Contains(optionKey.Language !));
Пример #19
0
 public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object?value)
 {
     return(new DocumentSpecificOptionSet(_documentOptions, _underlyingOptions, _values.SetItem(optionAndLanguage, value)));
 }
Пример #20
0
 private bool ShouldSerialize(OptionKey optionKey)
 => _serializableOptionValues.ContainsKey(optionKey) &&
 (!optionKey.Option.IsPerLanguage || RemoteSupportedLanguages.IsSupported(optionKey.Language));
Пример #21
0
 public new object? GetOption(OptionKey optionKey)
     => base.GetOption(optionKey);
Пример #22
0
 internal OptionChangedEventArgs(OptionKey optionKey, object value)
 {
     this.optionKey = optionKey;
     this.value     = value;
 }
Пример #23
0
 /// <summary>
 /// Gets the value of the option.
 /// </summary>
 public abstract object GetOption(OptionKey optionKey);
Пример #24
0
 internal OptionChangedEventArgs(OptionKey optionKey, object value)
 {
     _optionKey = optionKey;
     _value     = value;
 }
Пример #25
0
 private static bool SupportedSerializer(OptionKey optionKey, OptionSerializerMetadata metadata)
 {
     return(optionKey.Language == null || optionKey.Language == metadata.Language);
 }
Пример #26
0
 private protected abstract object?GetOptionCore(OptionKey optionKey);
Пример #27
0
 public override object GetOption(OptionKey optionKey)
 {
     return(_backingOptionSet.GetOption(optionKey));
 }
Пример #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);
Пример #29
0
 public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object?value)
 => new DocumentOptionSet(_backingOptionSet.WithChangedOption(optionAndLanguage, value), _language);
Пример #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)));
 }