-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix reading indent style and indent size from VS settings #65382
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation in the PR description!
public static PerLanguageOption2<IndentStyle> SmartIndent { get; } = | ||
new(FeatureName, FormattingOptionGroups.IndentationAndSpacing, nameof(SmartIndent), defaultValue: IndentationOptions.DefaultIndentStyle, | ||
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Indent Style")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how roaming storage location is useful here?
This doesn't seem to be exposed in Tools → Options, and it's not in AutomationObject.
So its value will always remain DefaultIndentStyle
and it is never fetched/persisted through import/export.
Anything I'm missing? I'm curious to know the user-visible effect of this change if you noticed any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option is read from global options here: https://sourceroslyn.io/#Microsoft.CodeAnalysis.LanguageServer.Protocol/Features/Options/IndentationOptionsStorage.cs,21
Global options end up calling VisualStudioSettingsOptionPersister
to read the option from VS settings, but that only happens if it has the storage.
The option is owned by the VS platform, not Roslyn. Roslyn does not set it nor has any UI that exposes it. It just needs to read it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tmat @arkalyanms for clarifying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (optionKey.Option.Type == typeof(int) && | ||
_settingManager.TryGetValue(storageKey, out int intValue) == GetValueResult.Success) | ||
{ | ||
return intValue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead update the following line to match the type stored in _settingsManager
?
roslyn/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingOptions2.cs
Line 55 in f814f00
EditorConfigStorageLocation.ForInt32Option("indent_size"), |
Edit: This change might not be necessary with the suggestion in #65382 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. The fact that the option is stored as Int64 in VS setting is a VS-specific quirk. Quite odd, since there is no reason for it to be 64 bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmat Then what about the more generalized approach suggested in #65382 (review)?
This will ensure that no such issues exist whatever the type of option is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow up on that later on: #65394
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think we could adjust the following:
roslyn/src/VisualStudio/Core/Def/Options/VisualStudioSettingsOptionPersister.cs
Lines 205 to 210 in f814f00
else if (value != null && optionKey.Option.Type != value.GetType()) | |
{ | |
// We got something back different than we expected, so fail to deserialize | |
value = null; | |
return false; | |
} |
We can do it like this:
try
{
value = Convert.ChangeType(value, optionKey.Option.Type);
}
catch
{
value = null;
return false;
}
This basically says if we got different types, try to convert it. Can we convert? Then everything is good. Failed to convert? Nothing we can do to read the option.
public static PerLanguageOption2<IndentStyle> SmartIndent { get; } = | ||
new(FeatureName, FormattingOptionGroups.IndentationAndSpacing, nameof(SmartIndent), defaultValue: IndentationOptions.DefaultIndentStyle, | ||
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Indent Style")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmat Lets park it here until we get soft approval from QB. Please fill in the ask mode template at https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1675408 |
Merging based on QB response over email. This should be taken when 17.4.2 opens up. cc: @jasonmalinowski |
@Cosifne should we consider backporting the integration test fixes to 17.5 and enabling the check since we are taking servicing fixes? Might be worthwhile discussing in team meeting. |
@tmat do we know how this worked prior to 17.4? |
@sharwell Maybe because of the deletion of https://github.com/dotnet/roslyn/blob/da6f98ea75b91293a16ed2f75ac0d7bae767c4fd/src/VisualStudio/Core/Def/Options/LanguageSettingsPersister.cs in 51cc7c9 I'm not sure though how Visual Studio is interacting with these options, so @tmat can say for sure. In the deleted class, I also see we were initializing settings for TS, F#, and Xaml. I don't know how these are supposed to work today with the current implementation. |
Yup, we used a legacy VS interface to read the options. |
@tmat What about TS, F#, and Xaml? How do they work now? Asking specifically about these line which don't exist now: roslyn/src/VisualStudio/Core/Def/Options/LanguageSettingsPersister.cs Lines 64 to 66 in da6f98e
|
When they call Roslyn to perform an operation that needs these options the operation reads them from global options, which works the same way as C#/VB. |
Turns out ISettingsManager stores indent size as Int64 which wasn't converted to Int32.
We were also missing storage location for Indent Style.
Fixes #65375 (https://developercommunity.visualstudio.com/t/Quick-actions-use-wrong-indent/10197217)
Fixes AB#1674009
Fixes AB#1675408
Fixes #65360
Fixes regression introduced by #62684