Skip to content

Commit 4afcb90

Browse files
author
Christoph Bergmeister
committed
Refactor classes that do not need a language client to not inherit from IFeature
1 parent b335bcf commit 4afcb90

10 files changed

+26
-66
lines changed

src/features/CodeActions.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
*--------------------------------------------------------*/
44

55
import vscode = require("vscode");
6-
import { LanguageClient } from "vscode-languageclient";
76
import Window = vscode.window;
8-
import { IFeature } from "../feature";
97
import { ILogger } from "../logging";
108

11-
export class CodeActionsFeature implements IFeature {
9+
export class CodeActionsFeature implements vscode.Disposable {
1210
private applyEditsCommand: vscode.Disposable;
1311
private showDocumentationCommand: vscode.Disposable;
14-
private languageClient: LanguageClient;
1512

1613
constructor(private log: ILogger) {
1714
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
@@ -37,10 +34,6 @@ export class CodeActionsFeature implements IFeature {
3734
this.showDocumentationCommand.dispose();
3835
}
3936

40-
public setLanguageClient(languageclient: LanguageClient) {
41-
this.languageClient = languageclient;
42-
}
43-
4437
public showRuleDocumentation(ruleId: string) {
4538
const pssaDocBaseURL = "https://github.com/PowerShell/PSScriptAnalyzer/blob/master/RuleDocumentation";
4639

src/features/CustomViews.ts

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { IFeature } from "../feature";
1010
export class CustomViewsFeature implements IFeature {
1111

1212
private commands: vscode.Disposable[] = [];
13-
private languageClient: LanguageClient;
1413
private contentProvider: PowerShellContentProvider;
1514

1615
constructor() {
@@ -65,8 +64,6 @@ export class CustomViewsFeature implements IFeature {
6564
args.id,
6665
args.appendedHtmlBodyContent);
6766
});
68-
69-
this.languageClient = languageClient;
7067
}
7168
}
7269

src/features/DebugSession.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,9 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
325325
}
326326
}
327327

328-
export class SpecifyScriptArgsFeature implements IFeature {
328+
export class SpecifyScriptArgsFeature implements vscode.Disposable {
329329

330330
private command: vscode.Disposable;
331-
private languageClient: LanguageClient;
332331
private context: vscode.ExtensionContext;
333332

334333
constructor(context: vscode.ExtensionContext) {
@@ -340,10 +339,6 @@ export class SpecifyScriptArgsFeature implements IFeature {
340339
});
341340
}
342341

343-
public setLanguageClient(languageclient: LanguageClient) {
344-
this.languageClient = languageclient;
345-
}
346-
347342
public dispose() {
348343
this.command.dispose();
349344
}

src/features/Examples.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import path = require("path");
66
import vscode = require("vscode");
7-
import { LanguageClient } from "vscode-languageclient";
8-
import { IFeature } from "../feature";
97

10-
export class ExamplesFeature implements IFeature {
8+
export class ExamplesFeature implements vscode.Disposable {
119
private command: vscode.Disposable;
1210
private examplesPath: string;
1311

@@ -21,10 +19,6 @@ export class ExamplesFeature implements IFeature {
2119
});
2220
}
2321

24-
public setLanguageClient(languageclient: LanguageClient) {
25-
// Eliminate tslint warning
26-
}
27-
2822
public dispose() {
2923
this.command.dispose();
3024
}

src/features/GenerateBugReport.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import cp = require("child_process");
66
import os = require("os");
77
import vscode = require("vscode");
8-
import { IFeature, LanguageClient } from "../feature";
98
import { SessionManager } from "../session";
109
import Settings = require("../settings");
1110

@@ -27,7 +26,7 @@ const extensions =
2726
return 0;
2827
});
2928

30-
export class GenerateBugReportFeature implements IFeature {
29+
export class GenerateBugReportFeature implements vscode.Disposable {
3130

3231
private command: vscode.Disposable;
3332
private powerShellProcess: cp.ChildProcess;
@@ -83,10 +82,6 @@ ${this.generateExtensionTable(extensions)}
8382
this.command.dispose();
8483
}
8584

86-
public setLanguageClient(languageclient: LanguageClient) {
87-
// Eliminate tslint warning.
88-
}
89-
9085
private generateExtensionTable(installedExtensions): string {
9186
if (!installedExtensions.length) {
9287
return "none";

src/features/ISECompatibility.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44
import * as vscode from "vscode";
5-
import { LanguageClient } from "vscode-languageclient";
6-
import { IFeature } from "../feature";
75
import * as Settings from "../settings";
86

97
interface ISetting {
@@ -15,7 +13,7 @@ interface ISetting {
1513
/**
1614
* A feature to implement commands to make code like the ISE and reset the settings.
1715
*/
18-
export class ISECompatibilityFeature implements IFeature {
16+
export class ISECompatibilityFeature implements vscode.Disposable {
1917
// Marking settings as public so we can use it within the tests without needing to duplicate the list of settings.
2018
public static settings: ISetting[] = [
2119
{ path: "workbench.activityBar", name: "visible", value: false },
@@ -27,7 +25,6 @@ export class ISECompatibilityFeature implements IFeature {
2725
];
2826
private iseCommandRegistration: vscode.Disposable;
2927
private defaultCommandRegistration: vscode.Disposable;
30-
private languageClient: LanguageClient;
3128

3229
constructor() {
3330
this.iseCommandRegistration = vscode.commands.registerCommand(
@@ -41,10 +38,6 @@ export class ISECompatibilityFeature implements IFeature {
4138
this.defaultCommandRegistration.dispose();
4239
}
4340

44-
public setLanguageClient(languageclient: LanguageClient) {
45-
this.languageClient = languageclient;
46-
}
47-
4841
private async EnableISEMode() {
4942
for (const iseSetting of ISECompatibilityFeature.settings) {
5043
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true);

src/features/OpenInISE.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import ChildProcess = require("child_process");
66
import vscode = require("vscode");
7-
import { IFeature, LanguageClient } from "../feature";
87

9-
export class OpenInISEFeature implements IFeature {
8+
export class OpenInISEFeature implements vscode.Disposable {
109
private command: vscode.Disposable;
1110

1211
constructor() {
@@ -33,8 +32,4 @@ export class OpenInISEFeature implements IFeature {
3332
public dispose() {
3433
this.command.dispose();
3534
}
36-
37-
public setLanguageClient(languageClient: LanguageClient) {
38-
// Not needed for this feature.
39-
}
4035
}

src/features/PesterTests.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as path from "path";
66
import vscode = require("vscode");
7-
import { IFeature, LanguageClient } from "../feature";
87
import { SessionManager } from "../session";
98
import Settings = require("../settings");
109
import utils = require("../utils");
@@ -14,10 +13,9 @@ enum LaunchType {
1413
Run,
1514
}
1615

17-
export class PesterTestsFeature implements IFeature {
16+
export class PesterTestsFeature implements vscode.Disposable {
1817

1918
private command: vscode.Disposable;
20-
private languageClient: LanguageClient;
2119
private invokePesterStubScriptPath: string;
2220

2321
constructor(private sessionManager: SessionManager) {
@@ -47,10 +45,6 @@ export class PesterTestsFeature implements IFeature {
4745
this.command.dispose();
4846
}
4947

50-
public setLanguageClient(languageClient: LanguageClient) {
51-
this.languageClient = languageClient;
52-
}
53-
5448
private launchAllTestsInActiveEditor(launchType: LaunchType, fileUri: vscode.Uri) {
5549
const uriString = fileUri.toString();
5650
const launchConfig = this.createLaunchConfig(uriString, launchType);

src/features/RunCode.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ enum LaunchType {
1414
Run,
1515
}
1616

17-
export class RunCodeFeature implements IFeature {
17+
export class RunCodeFeature implements vscode.Disposable {
1818

1919
private command: vscode.Disposable;
20-
private languageClient: LanguageClient;
2120

2221
constructor(private sessionManager: SessionManager) {
2322
this.command = vscode.commands.registerCommand(
@@ -31,10 +30,6 @@ export class RunCodeFeature implements IFeature {
3130
this.command.dispose();
3231
}
3332

34-
public setLanguageClient(languageClient: LanguageClient) {
35-
this.languageClient = languageClient;
36-
}
37-
3833
private async launchTask(
3934
runInDebugger: boolean,
4035
scriptToRun: string,

src/main.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const AI_KEY: string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217";
5050
let logger: Logger;
5151
let sessionManager: SessionManager;
5252
let extensionFeatures: IFeature[] = [];
53+
let commandRegistrations: vscode.Disposable[] = [];
5354
let telemetryReporter: TelemetryReporter;
5455

5556
const documentSelector: DocumentSelector = [
@@ -139,26 +140,30 @@ export function activate(context: vscode.ExtensionContext): void {
139140
PackageJSON.version,
140141
telemetryReporter);
141142

142-
// Create features
143-
extensionFeatures = [
144-
new ConsoleFeature(logger),
143+
// Register commands that do not require Language client
144+
commandRegistrations = [
145145
new ExamplesFeature(),
146-
new OpenInISEFeature(),
147146
new GenerateBugReportFeature(sessionManager),
147+
new ISECompatibilityFeature(),
148+
new OpenInISEFeature(),
149+
new PesterTestsFeature(sessionManager),
150+
new RunCodeFeature(sessionManager),
151+
new CodeActionsFeature(logger),
152+
new SpecifyScriptArgsFeature(context),
153+
]
154+
155+
// Create features that require language client
156+
extensionFeatures = [
157+
new ConsoleFeature(logger),
148158
new ExpandAliasFeature(logger),
149159
new GetCommandsFeature(logger),
150-
new ISECompatibilityFeature(),
151160
new ShowHelpFeature(logger),
152161
new FindModuleFeature(),
153-
new PesterTestsFeature(sessionManager),
154-
new RunCodeFeature(sessionManager),
155162
new ExtensionCommandsFeature(logger),
156-
new CodeActionsFeature(logger),
157163
new NewFileOrProjectFeature(),
158164
new RemoteFilesFeature(),
159165
new DebugSessionFeature(context, sessionManager, logger),
160166
new PickPSHostProcessFeature(),
161-
new SpecifyScriptArgsFeature(context),
162167
new HelpCompletionFeature(logger),
163168
new CustomViewsFeature(),
164169
new PickRunspaceFeature(),
@@ -206,6 +211,10 @@ export function deactivate(): void {
206211
feature.dispose();
207212
});
208213

214+
commandRegistrations.forEach((commandRegistration) => {
215+
commandRegistration.dispose();
216+
});
217+
209218
// Dispose of the current session
210219
sessionManager.dispose();
211220

0 commit comments

Comments
 (0)