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); } }
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); } }
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); }
/// <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); } }
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))); }
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)); }
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) }); }
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)); }
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)); }
public override object?GetOption(OptionKey optionKey) => _backingOptionSet.GetOption(optionKey);
public bool TryMapEditorConfigKeyToOption(string key, string?language, [NotNullWhen(true)] out IEditorConfigStorageLocation2?storageLocation, out OptionKey optionKey) => _globalOptionService.TryMapEditorConfigKeyToOption(key, language, out storageLocation, out optionKey);
public object?GetOption(OptionKey optionKey) => _globalOptionService.GetOption(optionKey);
/// <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; }
/// <summary> /// Creates a new <see cref="OptionSet" /> that contains the changed value. /// </summary> public abstract OptionSet WithChangedOption(OptionKey optionAndLanguage, object value);
private bool ShouldSerialize(OptionKey optionKey) => _serializableOptions.Contains(optionKey.Option) && (!optionKey.Option.IsPerLanguage || _languages.Contains(optionKey.Language !));
public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object?value) { return(new DocumentSpecificOptionSet(_documentOptions, _underlyingOptions, _values.SetItem(optionAndLanguage, value))); }
private bool ShouldSerialize(OptionKey optionKey) => _serializableOptionValues.ContainsKey(optionKey) && (!optionKey.Option.IsPerLanguage || RemoteSupportedLanguages.IsSupported(optionKey.Language));
public new object? GetOption(OptionKey optionKey) => base.GetOption(optionKey);
internal OptionChangedEventArgs(OptionKey optionKey, object value) { this.optionKey = optionKey; this.value = value; }
/// <summary> /// Gets the value of the option. /// </summary> public abstract object GetOption(OptionKey optionKey);
internal OptionChangedEventArgs(OptionKey optionKey, object value) { _optionKey = optionKey; _value = value; }
private static bool SupportedSerializer(OptionKey optionKey, OptionSerializerMetadata metadata) { return(optionKey.Language == null || optionKey.Language == metadata.Language); }
private protected abstract object?GetOptionCore(OptionKey optionKey);
public override object GetOption(OptionKey optionKey) { return(_backingOptionSet.GetOption(optionKey)); }
/// <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);
/// <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))); }