Skip to content

Fix reading indent style and indent size from VS settings - #65382

Merged
arunchndr merged 1 commit into
dotnet:release/dev17.4from
tmat:IndentFix
Nov 16, 2022
Merged

arunchndr merged 1 commit into
dotnet:release/dev17.4from
tmat:IndentFix

Conversation

@tmat

@tmat tmat commented Nov 11, 2022 •

Copy link
Copy Markdown
Member

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

@tmat
tmat requested a review from a team as a code owner November 11, 2022 23:32
@ghost ghost added the Area-IDE label Nov 11, 2022
@tmat

tmat commented Nov 11, 2022

Copy link
Copy Markdown
Member Author

@CyrusNajmabadi @jasonmalinowski @arkalyanms

@tmat
tmat changed the base branch from main to release/dev17.4 November 11, 2022 23:36

@jasonmalinowski jasonmalinowski left a comment

Copy link
Copy Markdown
Member

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!

Comment on lines +81 to +83
public static PerLanguageOption2<IndentStyle> SmartIndent { get; } =
new(FeatureName, FormattingOptionGroups.IndentationAndSpacing, nameof(SmartIndent), defaultValue: IndentationOptions.DefaultIndentStyle,
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Indent Style"));

@Youssef1313 Youssef1313 Nov 12, 2022 •

Copy link
Copy Markdown
Member

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.

@tmat tmat Nov 12, 2022 •

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Copy Markdown
Member

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.

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this PR fix #65360 ? If so, can you modify the description to include "Fixes #65360" so the issue gets auto closed?

Comment on lines +119 to +123
if (optionKey.Option.Type == typeof(int) &&
_settingManager.TryGetValue(storageKey, out int intValue) == GetValueResult.Success)
{
return intValue;
}

@Youssef1313 Youssef1313 Nov 12, 2022 •

Copy link
Copy Markdown
Member

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?

EditorConfigStorageLocation.ForInt32Option("indent_size"),

Edit: This change might not be necessary with the suggestion in #65382 (review)

@tmat tmat Nov 12, 2022 •

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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

@Youssef1313 Youssef1313 left a comment •

Copy link
Copy Markdown
Member

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:

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.

Comment on lines +81 to +83
public static PerLanguageOption2<IndentStyle> SmartIndent { get; } =
new(FeatureName, FormattingOptionGroups.IndentationAndSpacing, nameof(SmartIndent), defaultValue: IndentationOptions.DefaultIndentStyle,
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Indent Style"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@arunchndr

Copy link
Copy Markdown

@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

@arunchndr

arunchndr commented Nov 16, 2022 •

Copy link
Copy Markdown

Merging based on QB response over email. This should be taken when 17.4.2 opens up.

cc: @jasonmalinowski

@arunchndr
arunchndr merged commit 5309168 into dotnet:release/dev17.4 Nov 16, 2022
@arunchndr

Copy link
Copy Markdown

@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.

@sharwell

Copy link
Copy Markdown
Contributor

@tmat do we know how this worked prior to 17.4?

@Youssef1313

Copy link
Copy Markdown
Member

@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.

@tmat

tmat commented Nov 16, 2022

Copy link
Copy Markdown
Member Author

Yup, we used a legacy VS interface to read the options.

@tmat
tmat deleted the IndentFix branch November 16, 2022 17:22
@Youssef1313

Youssef1313 commented Nov 16, 2022 •

Copy link
Copy Markdown
Member

@tmat What about TS, F#, and Xaml? How do they work now? Asking specifically about these line which don't exist now:

InitializeSettingsForLanguage(InternalLanguageNames.TypeScript, new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77"));
InitializeSettingsForLanguage("F#", new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"));
InitializeSettingsForLanguage("Xaml", new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41"));

@tmat

tmat commented Nov 16, 2022

Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quick actions use wrong indent

6 participants