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

Fix AbstractLanguageService constructor #61513

Merged
merged 3 commits into from
May 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ internal abstract partial class AbstractLanguageService<TPackage, TLanguageServi
where TPackage : AbstractPackage<TPackage, TLanguageService>
where TLanguageService : AbstractLanguageService<TPackage, TLanguageService>
{
private readonly IGlobalOptionService _globalOptions;

public AbstractLanguageService(IGlobalOptionService globalOptions)
{
_globalOptions = globalOptions;
}

public int Format(IVsTextLayer textLayer, TextSpan[] selections)
{
var result = VSConstants.S_OK;
Expand Down Expand Up @@ -62,7 +55,7 @@ private int FormatWorker(IVsTextLayer textLayer, TextSpan[] selections, Cancella

var root = document.GetSyntaxRootSynchronously(cancellationToken);
var text = root.SyntaxTree.GetText(cancellationToken);
var formattingOptions = document.GetSyntaxFormattingOptionsAsync(_globalOptions, cancellationToken).AsTask().WaitAndGetResult(cancellationToken);
var formattingOptions = document.GetSyntaxFormattingOptionsAsync(GlobalOptions, cancellationToken).AsTask().WaitAndGetResult(cancellationToken);

var ts = selections.Single();
var start = text.Lines[ts.iStartLine].Start + ts.iStartIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ internal abstract partial class AbstractLanguageService<TPackage, TLanguageServi
// Note: The lifetime for state in this class is carefully managed. For every bit of state
// we set up, there is a corresponding tear down phase which deconstructs the state in the
// reverse order it was created in.
internal IGlobalOptionService GlobalOptions { get; private set; }
internal VisualStudioWorkspaceImpl Workspace { get; private set; }
internal IVsEditorAdaptersFactoryService EditorAdaptersFactoryService { get; private set; }
internal HostDiagnosticUpdateSource HostDiagnosticUpdateSource { get; private set; }
Expand All @@ -70,19 +71,13 @@ internal abstract partial class AbstractLanguageService<TPackage, TLanguageServi
/// </remarks>
private bool _isSetUp;

protected AbstractLanguageService(
TPackage package)
protected AbstractLanguageService(TPackage package)
{
this.Package = package;
Package = package;
}

public override IServiceProvider SystemServiceProvider
{
get
{
return this.Package;
}
}
=> Package;

/// <summary>
/// Setup and TearDown go in reverse order.
Expand Down Expand Up @@ -140,6 +135,7 @@ protected virtual void GetServices()
// This method should only contain calls to acquire services off of the component model
// or service providers. Anything else which is more complicated should go in Initialize
// instead.
this.GlobalOptions = this.Package.ComponentModel.GetService<IGlobalOptionService>();
this.Workspace = this.Package.ComponentModel.GetService<VisualStudioWorkspaceImpl>();
this.EditorAdaptersFactoryService = this.Package.ComponentModel.GetService<IVsEditorAdaptersFactoryService>();
this.HostDiagnosticUpdateSource = this.Package.ComponentModel.GetService<HostDiagnosticUpdateSource>();
Expand Down