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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal abstract partial class AbstractLanguageService<TPackage, TLanguageServi
where TPackage : AbstractPackage<TPackage, TLanguageService>
where TLanguageService : AbstractLanguageService<TPackage, TLanguageService>
{
private readonly IGlobalOptionService _globalOptions;

internal TPackage Package { get; }
internal VsLanguageDebugInfo LanguageDebugInfo { get; private set; }

Expand Down Expand Up @@ -70,19 +72,14 @@ internal abstract partial class AbstractLanguageService<TPackage, TLanguageServi
/// </remarks>
private bool _isSetUp;

protected AbstractLanguageService(
TPackage package)
protected AbstractLanguageService(TPackage package)
{
this.Package = package;
_globalOptions = package.ComponentModel.GetService<IGlobalOptionService>();
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in GetServices()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess.

Not sure why we have Setup instead of doing that work in the constructor.

_languageService = CreateLanguageService();
_languageService.Setup();

Copy link
Member

@davidwengier davidwengier May 25, 2022

Choose a reason for hiding this comment

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

I found this issue when working in SetupNewTextView, because in that scenario GetServices() has not been called yet. This was painful to discover, but does mean there is at least one code path that doesn't do the extra initialization.

Package = package;
}

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

/// <summary>
/// Setup and TearDown go in reverse order.
Expand Down