Skip to content

Commit 55e8ca3

Browse files
corbobrjmholt
authored andcommitted
Log when languageClient not loaded during initialization (#1555)
* Log when languageClient not loaded. Copy the pattern from ExtensionsCommandsFeature to the other instances of the check without a log of the error.
1 parent b955202 commit 55e8ca3

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/features/Console.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import vscode = require("vscode");
66
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
77
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
88
import { IFeature } from "../feature";
9+
import { Logger } from "../logging";
910

1011
export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void, void>("evaluate");
1112
export const OutputNotificationType = new NotificationType<IOutputNotificationBody, void>("output");
@@ -200,11 +201,12 @@ export class ConsoleFeature implements IFeature {
200201
private languageClient: LanguageClient;
201202
private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void;
202203

203-
constructor() {
204+
constructor(private log: Logger) {
204205
this.commands = [
205206
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
206207
if (this.languageClient === undefined) {
207-
// TODO: Log error message
208+
this.log.writeAndShowError(`<${ConsoleFeature.name}>: ` +
209+
"Unable to instantiate; language client undefined.");
208210
return;
209211
}
210212

src/features/ExpandAlias.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import vscode = require("vscode");
66
import Window = vscode.window;
77
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
88
import { IFeature } from "../feature";
9+
import { Logger } from "../logging";
910

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

1213
export class ExpandAliasFeature implements IFeature {
1314
private command: vscode.Disposable;
1415
private languageClient: LanguageClient;
1516

16-
constructor() {
17+
constructor(private log: Logger) {
1718
this.command = vscode.commands.registerCommand("PowerShell.ExpandAlias", () => {
1819
if (this.languageClient === undefined) {
19-
// TODO: Log error message
20+
this.log.writeAndShowError(`<${ExpandAliasFeature.name}>: ` +
21+
"Unable to instantiate; language client undefined.");
2022
return;
2123
}
2224

src/features/SelectPSSARules.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import vscode = require("vscode");
66
import { LanguageClient, RequestType } from "vscode-languageclient";
77
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
88
import { IFeature } from "../feature";
9+
import { Logger } from "../logging";
910

1011
export const GetPSSARulesRequestType = new RequestType<any, any, void, void>("powerShell/getPSSARules");
1112
export const SetPSSARulesRequestType = new RequestType<any, any, void, void>("powerShell/setPSSARules");
@@ -20,9 +21,11 @@ export class SelectPSSARulesFeature implements IFeature {
2021
private command: vscode.Disposable;
2122
private languageClient: LanguageClient;
2223

23-
constructor() {
24+
constructor(private log: Logger) {
2425
this.command = vscode.commands.registerCommand("PowerShell.SelectPSSARules", () => {
2526
if (this.languageClient === undefined) {
27+
this.log.writeAndShowError(`<${SelectPSSARulesFeature.name}>: ` +
28+
"Unable to instantiate; language client undefined.");
2629
return;
2730
}
2831

src/features/ShowHelp.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import vscode = require("vscode");
66
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
77
import { IFeature } from "../feature";
8+
import { Logger } from "../logging";
89

910
export const ShowHelpRequestType =
1011
new RequestType<string, void, void, void>("powerShell/showHelp");
@@ -14,10 +15,11 @@ export class ShowHelpFeature implements IFeature {
1415
private deprecatedCommand: vscode.Disposable;
1516
private languageClient: LanguageClient;
1617

17-
constructor() {
18+
constructor(private log: Logger) {
1819
this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", () => {
1920
if (this.languageClient === undefined) {
20-
// TODO: Log error message
21+
this.log.writeAndShowError(`<${ShowHelpFeature.name}>: ` +
22+
"Unable to instantiate; language client undefined.");
2123
return;
2224
}
2325

src/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ export function activate(context: vscode.ExtensionContext): void {
118118

119119
// Create features
120120
extensionFeatures = [
121-
new ConsoleFeature(),
121+
new ConsoleFeature(logger),
122122
new ExamplesFeature(),
123123
new OpenInISEFeature(),
124124
new GenerateBugReportFeature(sessionManager),
125-
new ExpandAliasFeature(),
126-
new ShowHelpFeature(),
125+
new ExpandAliasFeature(logger),
126+
new ShowHelpFeature(logger),
127127
new FindModuleFeature(),
128128
new PesterTestsFeature(sessionManager),
129129
new ExtensionCommandsFeature(logger),
130-
new SelectPSSARulesFeature(),
130+
new SelectPSSARulesFeature(logger),
131131
new CodeActionsFeature(),
132132
new NewFileOrProjectFeature(),
133133
new DocumentFormatterFeature(logger, documentSelector),

0 commit comments

Comments
 (0)