Skip to content
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

Set Roslyn's global line formatting options #6338

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<Tooling_MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.21103.2</Tooling_MicrosoftCodeAnalysisTestingVersion>
<MicrosoftVisualStudioShellPackagesVersion>17.2.32330.158</MicrosoftVisualStudioShellPackagesVersion>
<MicrosoftVisualStudioPackagesVersion>17.3.37-preview</MicrosoftVisualStudioPackagesVersion>
<RoslynPackageVersion>4.3.0-1.22222.8</RoslynPackageVersion>
<RoslynPackageVersion>4.3.0-2.22259.8</RoslynPackageVersion>
<VisualStudioLanguageServerProtocolVersion>17.3.15</VisualStudioLanguageServerProtocolVersion>
<MicrosoftNetCompilersToolsetVersion>4.2.0-1.final</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Razor.Editor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;

namespace Microsoft.VisualStudio.Editor.Razor
{
Expand All @@ -17,17 +18,29 @@ internal class DefaultEditorSettingsManager : EditorSettingsManager
public override event EventHandler<EditorSettingsChangedEventArgs> Changed;

private readonly object _settingsAccessorLock = new object();
private readonly RazorGlobalOptions _globalOptions;
private EditorSettings _settings;

[ImportingConstructor]
public DefaultEditorSettingsManager([ImportMany] IEnumerable<EditorSettingsChangedTrigger> editorSettingsChangeTriggers)
public DefaultEditorSettingsManager(
[ImportMany] IEnumerable<EditorSettingsChangedTrigger> editorSettingsChangeTriggers,
RazorGlobalOptions globalOptions = null)
{
_settings = EditorSettings.Default;

// update Roslyn's global options (null in tests):
if (globalOptions != null)
{
globalOptions.TabSize = _settings.IndentSize;
globalOptions.UseTabs = _settings.IndentWithTabs;
}

foreach (var changeTrigger in editorSettingsChangeTriggers)
{
changeTrigger.Initialize(this);
}

_globalOptions = globalOptions;
}

public override EditorSettings Current
Expand All @@ -48,6 +61,13 @@ public override void Update(EditorSettings updatedSettings)
throw new ArgumentNullException(nameof(updatedSettings));
}

// update Roslyn's global options (null in tests):
if (_globalOptions != null)
{
_globalOptions.TabSize = updatedSettings.IndentSize;
_globalOptions.UseTabs = updatedSettings.IndentWithTabs;
}

lock (_settingsAccessorLock)
{
if (!_settings.Equals(updatedSettings))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Razor.Editor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Xunit;

namespace Microsoft.VisualStudio.Editor.Razor
Expand Down