Skip to content

Commit

Permalink
Null check changeEvent.contentChanges[0] and log bad messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Mar 22, 2018
1 parent 5db096d commit c0d0386
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/features/HelpCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Disposable, EndOfLine, Position, Range, SnippetString,
TextDocument, TextDocumentChangeEvent, window, workspace } from "vscode";
import { LanguageClient, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { Logger } from "../logging";

export const CommentHelpRequestType =
new RequestType<any, any, void, void>("powerShell/getCommentHelp");
Expand All @@ -27,7 +28,7 @@ export class HelpCompletionFeature implements IFeature {
private languageClient: LanguageClient;
private disposable: Disposable;

constructor() {
constructor(private log: Logger) {
this.helpCompletionProvider = new HelpCompletionProvider();
const subscriptions = [];
workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions);
Expand All @@ -44,7 +45,8 @@ export class HelpCompletionFeature implements IFeature {
}

public onEvent(changeEvent: TextDocumentChangeEvent): void {
if (!changeEvent) {
if (!(changeEvent && changeEvent.contentChanges && changeEvent.contentChanges[0])) {
this.log.write(`Bad change event message: ${JSON.stringify(changeEvent)}`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function activate(context: vscode.ExtensionContext): void {
new DebugSessionFeature(context, sessionManager),
new PickPSHostProcessFeature(),
new SpecifyScriptArgsFeature(context),
new HelpCompletionFeature(),
new HelpCompletionFeature(logger),
new CustomViewsFeature(),
];

Expand Down

0 comments on commit c0d0386

Please sign in to comment.