Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 96a0466

Browse files
committed
- Fix: Retrieving effective formatting options from parent containers didn't work properly.
- Fix: CSharpFormattingOptionsPersistence didn't load global options from settings.
1 parent 8a1c65b commit 96a0466

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsContainer.cs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ internal CSharpFormattingOptionsContainer(CSharpFormattingOptionsContainer paren
4444
this.parent = parent;
4545
this.activeOptions = new HashSet<string>();
4646
Reset();
47+
cachedOptions = CreateOptions();
4748
}
4849

4950
public CSharpFormattingOptionsContainer Parent
@@ -81,7 +82,7 @@ private void OnPropertyChanged(string propertyName)
8182
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
8283
}
8384
}
84-
85+
8586
#endregion
8687

8788
private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -120,33 +121,6 @@ public object GetOption(string option)
120121
return null;
121122
}
122123

123-
/// <summary>
124-
/// Retrieves the value of a formatting option where desired type and option name are defined by a
125-
/// property getter on <see cref="ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions"/>.
126-
/// Searches in current and (if nothing set here) parent containers.
127-
/// </summary>
128-
/// <param name="propertyGetter">
129-
/// Property getter lambda expression
130-
/// (example: o =&gt; o.IndentStructBody)
131-
/// </param>
132-
/// <returns>True, if option with given type could be found in hierarchy. False otherwise.</returns>
133-
public T GetEffectiveOption<T>(Expression<Func<CSharpFormattingOptions, T>> propertyGetter)
134-
where T : struct
135-
{
136-
// Get name of property (to look for in dictionary)
137-
string optionName = null;
138-
MemberExpression memberExpression = propertyGetter.Body as MemberExpression;
139-
if (memberExpression != null) {
140-
optionName = memberExpression.Member.Name;
141-
var val = GetEffectiveOption(optionName);
142-
if (val is T) {
143-
return (T) val;
144-
}
145-
}
146-
147-
return default(T);
148-
}
149-
150124
/// <summary>
151125
/// Retrieves the value of a formatting option by looking at current and (if nothing set here) parent
152126
/// containers.
@@ -160,9 +134,11 @@ public object GetEffectiveOption(string option)
160134
do
161135
{
162136
object val = null;
163-
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
164-
if (propertyInfo != null) {
165-
val = propertyInfo.GetValue(container.cachedOptions);
137+
if (container.activeOptions.Contains(option)) {
138+
PropertyInfo propertyInfo = typeof(CSharpFormattingOptions).GetProperty(option);
139+
if (propertyInfo != null) {
140+
val = propertyInfo.GetValue(container.cachedOptions);
141+
}
166142
}
167143
if (val != null) {
168144
return val;
@@ -241,7 +217,7 @@ private CSharpFormattingOptions CreateOptions()
241217
propertyInfo.SetValue(outputOptions, val);
242218
}
243219
}
244-
220+
245221
return outputOptions;
246222
}
247223

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static CSharpFormattingOptionsPersistence()
3939
// Load global settings
4040
GlobalOptions = new CSharpFormattingOptionsPersistence(
4141
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer());
42+
GlobalOptions.Load();
4243

4344
// Handlers for solution loading/unloading
4445
SD.ProjectService.SolutionOpened += SolutionOpened;
@@ -66,7 +67,7 @@ public static CSharpFormattingOptionsPersistence GetProjectOptions(IProject proj
6667
// Lazily create options container
6768
projectOptions[key] = new CSharpFormattingOptionsPersistence(
6869
csproject.ExtensionProperties,
69-
new CSharpFormattingOptionsContainer(SolutionOptions.OptionsContainer));
70+
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)); // HACK!
7071
}
7172

7273
return projectOptions[key];

0 commit comments

Comments
 (0)