diff --git a/src/features/HelpCompletion.ts b/src/features/HelpCompletion.ts index 997bf00593..f056e10fe0 100644 --- a/src/features/HelpCompletion.ts +++ b/src/features/HelpCompletion.ts @@ -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("powerShell/getCommentHelp"); @@ -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); @@ -44,14 +45,21 @@ export class HelpCompletionFeature implements IFeature { } public onEvent(changeEvent: TextDocumentChangeEvent): void { - this.helpCompletionProvider.updateState( - changeEvent.document, - changeEvent.contentChanges[0].text, - changeEvent.contentChanges[0].range); - - // todo raise an event when trigger is found, and attach complete() to the event. - if (this.helpCompletionProvider.triggerFound) { - this.helpCompletionProvider.complete().then(() => this.helpCompletionProvider.reset()); + if (!(changeEvent && changeEvent.contentChanges)) { + this.log.write(`Bad TextDocumentChangeEvent message: ${JSON.stringify(changeEvent)}`); + return; + } + + if (changeEvent.contentChanges.length > 0) { + this.helpCompletionProvider.updateState( + changeEvent.document, + changeEvent.contentChanges[0].text, + changeEvent.contentChanges[0].range); + + // todo raise an event when trigger is found, and attach complete() to the event. + if (this.helpCompletionProvider.triggerFound) { + this.helpCompletionProvider.complete().then(() => this.helpCompletionProvider.reset()); + } } } } diff --git a/src/main.ts b/src/main.ts index eb27fd56cf..169235db8b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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(), ];