Skip to content

🧹 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

Merged
merged 8 commits into from
Jul 23, 2020
12 changes: 0 additions & 12 deletions src/feature.ts

This file was deleted.

9 changes: 1 addition & 8 deletions src/features/CodeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
*--------------------------------------------------------*/

import vscode = require("vscode");
import { LanguageClient } from "vscode-languageclient";
import Window = vscode.window;
import { IFeature } from "../feature";
import { ILogger } from "../logging";

export class CodeActionsFeature implements IFeature {
export class CodeActionsFeature implements vscode.Disposable {
private applyEditsCommand: vscode.Disposable;
private showDocumentationCommand: vscode.Disposable;
private languageClient: LanguageClient;

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

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

public showRuleDocumentation(ruleId: string) {
const pssaDocBaseURL = "https://github.com/PowerShell/PSScriptAnalyzer/blob/master/RuleDocumentation";

Expand Down
12 changes: 3 additions & 9 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import vscode = require("vscode");
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
import { IFeature } from "../feature";
import { Logger } from "../logging";
import Settings = require("../settings");
import { LanguageClientConsumer } from "../languageClientConsumer";

export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void, void>("evaluate");
export const OutputNotificationType = new NotificationType<IOutputNotificationBody, void>("output");
Expand Down Expand Up @@ -197,19 +197,14 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {
}
}

export class ConsoleFeature implements IFeature {
export class ConsoleFeature extends LanguageClientConsumer {
private commands: vscode.Disposable[];
private languageClient: LanguageClient;
private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void;

constructor(private log: Logger) {
super();
this.commands = [
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
if (this.languageClient === undefined) {
this.log.writeAndShowError(`<${ConsoleFeature.name}>: ` +
"Unable to instantiate; language client undefined.");
return;
}

if (vscode.window.activeTerminal &&
vscode.window.activeTerminal.name !== "PowerShell Integrated Console") {
Expand Down Expand Up @@ -257,7 +252,6 @@ export class ConsoleFeature implements IFeature {

public setLanguageClient(languageClient: LanguageClient) {
this.languageClient = languageClient;

this.languageClient.onRequest(
ShowChoicePromptRequestType,
(promptDetails) => showChoicePrompt(promptDetails, this.languageClient));
Expand Down
8 changes: 3 additions & 5 deletions src/features/CustomViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import * as path from "path";
import * as vscode from "vscode";
import { LanguageClient, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { LanguageClientConsumer } from "../languageClientConsumer";

export class CustomViewsFeature implements IFeature {
export class CustomViewsFeature extends LanguageClientConsumer {

private commands: vscode.Disposable[] = [];
private languageClient: LanguageClient;
private contentProvider: PowerShellContentProvider;

constructor() {
super();
this.contentProvider = new PowerShellContentProvider();
this.commands.push(
vscode.workspace.registerTextDocumentContentProvider(
Expand Down Expand Up @@ -65,8 +65,6 @@ export class CustomViewsFeature implements IFeature {
args.id,
args.appendedHtmlBodyContent);
});

this.languageClient = languageClient;
}
}

Expand Down
21 changes: 9 additions & 12 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import vscode = require("vscode");
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider,
ExtensionContext, WorkspaceFolder } from "vscode";
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { getPlatformDetails, OperatingSystem } from "../platform";
import { PowerShellProcess} from "../process";
import { SessionManager, SessionStatus } from "../session";
import Settings = require("../settings");
import utils = require("../utils");
import { NamedPipeDebugAdapter } from "../debugAdapter";
import { Logger } from "../logging";
import { LanguageClientConsumer } from "../languageClientConsumer";

export const StartDebuggerNotificationType =
new NotificationType<void, void>("powerShell/startDebugger");

export class DebugSessionFeature implements IFeature, DebugConfigurationProvider, vscode.DebugAdapterDescriptorFactory {
export class DebugSessionFeature extends LanguageClientConsumer
implements DebugConfigurationProvider, vscode.DebugAdapterDescriptorFactory {

private sessionCount: number = 1;
private command: vscode.Disposable;
private tempDebugProcess: PowerShellProcess;
private tempSessionDetails: utils.IEditorServicesSessionDetails;

constructor(context: ExtensionContext, private sessionManager: SessionManager, private logger: Logger) {
super();
// Register a debug configuration provider
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("PowerShell", this));
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory("PowerShell", this))
Expand Down Expand Up @@ -325,10 +327,9 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
}
}

export class SpecifyScriptArgsFeature implements IFeature {
export class SpecifyScriptArgsFeature implements vscode.Disposable {

private command: vscode.Disposable;
private languageClient: LanguageClient;
private context: vscode.ExtensionContext;

constructor(context: vscode.ExtensionContext) {
Expand All @@ -340,10 +341,6 @@ export class SpecifyScriptArgsFeature implements IFeature {
});
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

public dispose() {
this.command.dispose();
}
Expand Down Expand Up @@ -391,14 +388,14 @@ interface IGetPSHostProcessesResponseBody {
hostProcesses: IPSHostProcessInfo[];
}

export class PickPSHostProcessFeature implements IFeature {
export class PickPSHostProcessFeature extends LanguageClientConsumer {

private command: vscode.Disposable;
private languageClient: LanguageClient;
private waitingForClientToken: vscode.CancellationTokenSource;
private getLanguageClientResolve: (value?: LanguageClient | Thenable<LanguageClient>) => void;

constructor() {
super();

this.command =
vscode.commands.registerCommand("PowerShell.PickPSHostProcess", () => {
Expand Down Expand Up @@ -522,14 +519,14 @@ interface IRunspace {
export const GetRunspaceRequestType =
new RequestType<any, IRunspace[], string, void>("powerShell/getRunspace");

export class PickRunspaceFeature implements IFeature {
export class PickRunspaceFeature extends LanguageClientConsumer {

private command: vscode.Disposable;
private languageClient: LanguageClient;
private waitingForClientToken: vscode.CancellationTokenSource;
private getLanguageClientResolve: (value?: LanguageClient | Thenable<LanguageClient>) => void;

constructor() {
super();
this.command =
vscode.commands.registerCommand("PowerShell.PickRunspace", (processId) => {
return this.getLanguageClient()
Expand Down
8 changes: 1 addition & 7 deletions src/features/Examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import path = require("path");
import vscode = require("vscode");
import { LanguageClient } from "vscode-languageclient";
import { IFeature } from "../feature";

export class ExamplesFeature implements IFeature {
export class ExamplesFeature implements vscode.Disposable {
private command: vscode.Disposable;
private examplesPath: string;

Expand All @@ -21,10 +19,6 @@ export class ExamplesFeature implements IFeature {
});
}

public setLanguageClient(languageclient: LanguageClient) {
// Eliminate tslint warning
}

public dispose() {
this.command.dispose();
}
Expand Down
17 changes: 4 additions & 13 deletions src/features/ExpandAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@

import vscode = require("vscode");
import Window = vscode.window;
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { RequestType } from "vscode-languageclient";
import { Logger } from "../logging";
import { LanguageClientConsumer } from "../languageClientConsumer";

export const ExpandAliasRequestType = new RequestType<any, any, void, void>("powerShell/expandAlias");

export class ExpandAliasFeature implements IFeature {
export class ExpandAliasFeature extends LanguageClientConsumer {
private command: vscode.Disposable;
private languageClient: LanguageClient;

constructor(private log: Logger) {
super();
this.command = vscode.commands.registerCommand("PowerShell.ExpandAlias", () => {
if (this.languageClient === undefined) {
this.log.writeAndShowError(`<${ExpandAliasFeature.name}>: ` +
"Unable to instantiate; language client undefined.");
return;
}

const editor = Window.activeTextEditor;
const document = editor.document;
Expand Down Expand Up @@ -50,8 +45,4 @@ export class ExpandAliasFeature implements IFeature {
public dispose() {
this.command.dispose();
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}
}
11 changes: 3 additions & 8 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as path from "path";
import * as vscode from "vscode";
import { LanguageClient, NotificationType, NotificationType0,
Position, Range, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { Logger } from "../logging";
import Settings = require("../settings");
import { LanguageClientConsumer } from "../languageClientConsumer";

export interface IExtensionCommand {
name: string;
Expand Down Expand Up @@ -173,20 +173,15 @@ interface IInvokeRegisteredEditorCommandParameter {
commandName: string;
}

export class ExtensionCommandsFeature implements IFeature {
export class ExtensionCommandsFeature extends LanguageClientConsumer {

private command: vscode.Disposable;
private command2: vscode.Disposable;
private languageClient: LanguageClient;
private extensionCommands: IExtensionCommand[] = [];

constructor(private log: Logger) {
super();
this.command = vscode.commands.registerCommand("PowerShell.ShowAdditionalCommands", () => {
if (this.languageClient === undefined) {
this.log.writeAndShowError(`<${ExtensionCommandsFeature.name}>: ` +
"Unable to instantiate; language client undefined.");
return;
}

const editor = vscode.window.activeTextEditor;
let start = editor.selection.start;
Expand Down
10 changes: 3 additions & 7 deletions src/features/ExternalApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as vscode from "vscode";
import { v4 as uuidv4 } from 'uuid';
import { LanguageClient } from "vscode-languageclient";
import { IFeature } from "../feature";
import { LanguageClientConsumer } from "../languageClientConsumer";
import { Logger } from "../logging";
import { SessionManager } from "../session";

Expand All @@ -15,12 +15,12 @@ export interface IExternalPowerShellDetails {
architecture: string;
}

export class ExternalApiFeature implements IFeature {
export class ExternalApiFeature extends LanguageClientConsumer {
private commands: vscode.Disposable[];
private languageClient: LanguageClient;
private static readonly registeredExternalExtension: Map<string, IExternalExtension> = new Map<string, IExternalExtension>();

constructor(private sessionManager: SessionManager, private log: Logger) {
super();
this.commands = [
/*
DESCRIPTION:
Expand Down Expand Up @@ -141,10 +141,6 @@ export class ExternalApiFeature implements IFeature {
command.dispose();
}
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}
}

interface IExternalExtension {
Expand Down
13 changes: 4 additions & 9 deletions src/features/FindModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
*--------------------------------------------------------*/

import vscode = require("vscode");
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import Window = vscode.window;
import { IFeature } from "../feature";
import { RequestType } from "vscode-languageclient";
import QuickPickItem = vscode.QuickPickItem;
import { LanguageClientConsumer } from "../languageClientConsumer";

export const FindModuleRequestType =
new RequestType<any, any, void, void>("powerShell/findModule");

export const InstallModuleRequestType =
new RequestType<string, void, void, void>("powerShell/installModule");

export class FindModuleFeature implements IFeature {
export class FindModuleFeature extends LanguageClientConsumer {

private command: vscode.Disposable;
private languageClient: LanguageClient;
private cancelFindToken: vscode.CancellationTokenSource;

constructor() {
super();
this.command = vscode.commands.registerCommand("PowerShell.PowerShellFindModule", () => {
// It takes a while to get the list of PowerShell modules, display some UI to let user know
this.cancelFindToken = new vscode.CancellationTokenSource();
Expand Down Expand Up @@ -53,10 +52,6 @@ export class FindModuleFeature implements IFeature {
});
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

public dispose() {
this.command.dispose();
}
Expand Down
7 changes: 1 addition & 6 deletions src/features/GenerateBugReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os = require("os");
import vscode = require("vscode");
import { IFeature, LanguageClient } from "../feature";
import { SessionManager } from "../session";
import Settings = require("../settings");

Expand All @@ -26,7 +25,7 @@ const extensions =
return 0;
});

export class GenerateBugReportFeature implements IFeature {
export class GenerateBugReportFeature implements vscode.Disposable {

private command: vscode.Disposable;

Expand Down Expand Up @@ -81,10 +80,6 @@ ${this.generateExtensionTable(extensions)}
this.command.dispose();
}

public setLanguageClient(languageclient: LanguageClient) {
// Eliminate tslint warning.
}

private generateExtensionTable(installedExtensions): string {
if (!installedExtensions.length) {
return "none";
Expand Down
Loading