11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- "use strict" ;
5-
64import vscode = require( "vscode" ) ;
75import { NotificationType , RequestType } from "vscode-languageclient" ;
86import { LanguageClient } from "vscode-languageclient/node" ;
@@ -50,19 +48,17 @@ interface IShowChoicePromptRequestArgs {
5048}
5149
5250interface IShowChoicePromptResponseBody {
53- responseText : string ;
51+ responseText : string | undefined ;
5452 promptCancelled : boolean ;
5553}
5654
5755interface IShowInputPromptResponseBody {
58- responseText : string ;
56+ responseText : string | undefined ;
5957 promptCancelled : boolean ;
6058}
6159
6260
63- function showChoicePrompt (
64- promptDetails : IShowChoicePromptRequestArgs ,
65- client : LanguageClient ) : Thenable < IShowChoicePromptResponseBody > {
61+ function showChoicePrompt ( promptDetails : IShowChoicePromptRequestArgs ) : Thenable < IShowChoicePromptResponseBody > {
6662
6763 let resultThenable : Thenable < IShowChoicePromptResponseBody > ;
6864
@@ -121,11 +117,12 @@ function showChoicePrompt(
121117 return resultThenable ;
122118}
123119
124- function showInputPrompt ( promptDetails : IShowInputPromptRequestArgs ) : Thenable < IShowInputPromptResponseBody > {
125- return vscode . window . showInputBox ( { placeHolder : promptDetails . name + ": " } ) . then ( onInputEntered ) ;
120+ async function showInputPrompt ( promptDetails : IShowInputPromptRequestArgs ) : Promise < IShowInputPromptResponseBody > {
121+ const responseText = await vscode . window . showInputBox ( { placeHolder : promptDetails . name + ": " } ) ;
122+ return onInputEntered ( responseText ) ;
126123}
127124
128- function onItemsSelected ( chosenItems : ICheckboxQuickPickItem [ ] ) : IShowChoicePromptResponseBody {
125+ function onItemsSelected ( chosenItems : ICheckboxQuickPickItem [ ] | undefined ) : IShowChoicePromptResponseBody {
129126 if ( chosenItems !== undefined ) {
130127 return {
131128 promptCancelled : false ,
@@ -140,7 +137,7 @@ function onItemsSelected(chosenItems: ICheckboxQuickPickItem[]): IShowChoiceProm
140137 }
141138}
142139
143- function onItemSelected ( chosenItem : vscode . QuickPickItem ) : IShowChoicePromptResponseBody {
140+ function onItemSelected ( chosenItem : vscode . QuickPickItem | undefined ) : IShowChoicePromptResponseBody {
144141 if ( chosenItem !== undefined ) {
145142 return {
146143 promptCancelled : false ,
@@ -155,7 +152,7 @@ function onItemSelected(chosenItem: vscode.QuickPickItem): IShowChoicePromptResp
155152 }
156153}
157154
158- function onInputEntered ( responseText : string ) : IShowInputPromptResponseBody {
155+ function onInputEntered ( responseText : string | undefined ) : IShowInputPromptResponseBody {
159156 if ( responseText !== undefined ) {
160157 return {
161158 promptCancelled : false ,
@@ -171,7 +168,7 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {
171168
172169export class ConsoleFeature extends LanguageClientConsumer {
173170 private commands : vscode . Disposable [ ] ;
174- private handlers : vscode . Disposable [ ] ;
171+ private handlers : vscode . Disposable [ ] = [ ] ;
175172
176173 constructor ( private log : Logger ) {
177174 super ( ) ;
@@ -192,6 +189,10 @@ export class ConsoleFeature extends LanguageClientConsumer {
192189 }
193190
194191 const editor = vscode . window . activeTextEditor ;
192+ if ( editor === undefined ) {
193+ return ;
194+ }
195+
195196 let selectionRange : vscode . Range ;
196197
197198 if ( ! editor . selection . isEmpty ) {
@@ -200,7 +201,7 @@ export class ConsoleFeature extends LanguageClientConsumer {
200201 selectionRange = editor . document . lineAt ( editor . selection . start . line ) . range ;
201202 }
202203
203- await this . languageClient . sendRequest ( EvaluateRequestType , {
204+ await this . languageClient ? .sendRequest ( EvaluateRequestType , {
204205 expression : editor . document . getText ( selectionRange ) ,
205206 } ) ;
206207
@@ -221,12 +222,12 @@ export class ConsoleFeature extends LanguageClientConsumer {
221222 }
222223 }
223224
224- public setLanguageClient ( languageClient : LanguageClient ) {
225+ public override setLanguageClient ( languageClient : LanguageClient ) {
225226 this . languageClient = languageClient ;
226227 this . handlers = [
227228 this . languageClient . onRequest (
228229 ShowChoicePromptRequestType ,
229- ( promptDetails ) => showChoicePrompt ( promptDetails , this . languageClient ) ) ,
230+ ( promptDetails ) => showChoicePrompt ( promptDetails ) ) ,
230231
231232 this . languageClient . onRequest (
232233 ShowInputPromptRequestType ,
0 commit comments