-
Notifications
You must be signed in to change notification settings - Fork 511
🧹 Refactor classes that do not need a language client to not inherit from IFeature #2685
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
🧹 Refactor classes that do not need a language client to not inherit from IFeature #2685
Conversation
extensionFeatures = [ | ||
new ConsoleFeature(logger), | ||
// Register commands that do not require Language client | ||
commandRegistrations = [ |
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'm not super crazy about having two different types of commands. What if rather than implementing IFeature
, you create a base class called Feature (or another name if you can come up with something better). Then each subclass would use extends
instead of implements
. The base class would implement vscode.Disposable and would provide a protected languageClient
property getter. Then we can treat each command/feature the same with respect to storing them in a single collection in main and a single loop to dispose of them.
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 disagree.
Having a separate list, means less work to do for the SessionManager
, which only needs to manage classes, which require management therefore due to it depending on the languageClient
. The value of this PR is to decouple standalone and self-contained command registrations, whilst also removing boilerplate code in those classes.
IFeature
could be called something like ILanguageClientConsumer
to better reflect what it does.
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'm not sure how I feel about this but I do like the idea of having a base class for LanguageClientConsumer
that sets a property languageClient
.
export class LanguageClientConsumer {
private _languageClient: LanguageClient;
public get languageClient(): LanguageClient {
if (!_languageClient) {
// Show warning that extension isn't done starting up
}
return _languageClient;
}
public set languageClient(value: LanguageClient){
this._languageClient = value;
}
}
This will stop so many issues that just have the unhelpful Unable to instantiate; language client undefined.
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 think I'm cool with some "features" just implementing Dispose and other "features" extending this LanguageClientConsumer
.
Did you want to make that change @bergmeister?
the if statement can just run:
window.showInformationMessage("PowerShell extension has not finished starting up. Please try again in a few moments.");
or something.
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've just added a LanguageClientConsumer
base class in 57b714b
I couldn't remove the usage of IFeature
yet because the dispose()
and setLanguageClient
methods are still being used. Trying to get rid of that would be a bit more complicated and I wouldn't like to convolute this PR too much.
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.
@bergmeister any reason: LanguageClientConsumer
can't inherit from IFeature
instead of everything inheriting from IFeature
?
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.
LanguageClientConsumer
could be abstract so each thing can implement their own dispose... but then you can remove all of the:
public setLanguageClient(languageClient: LanguageClient) {
this.languageClient = languageClient;
}
and have just one of those in LanguageClientConsumer
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.
Yes, good idea. I made it an abstract class and dispose()
an abstract method so that every implementation has to implement that one. I've also noticed that ExpandAlias
and ShowHelpFeature
have the logger
passed into the constructor but actually never use the loggers, should we remove those unnecessary references as well or do that in another follow up PR?
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.
Ah let's leave those in for now. Really we should add logging ;)
…code in some implementations
@bergmeister was this ready for review again? Unfortunately I added #2799 and #2789 which added 2 more |
Yes, ready for review, adapted for upstream changes. |
PR Summary
IFeature
is a really bad name for declaring usage of the language client, we should maybe rename that in another PR.Also cleanup some unused imports in those classes.
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets.Please mark anything not applicable to this PR
NA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready