@@ -54,7 +54,7 @@ export class HelpCompletionFeature implements IFeature {
54
54
}
55
55
}
56
56
57
- public onEvent ( changeEvent : TextDocumentChangeEvent ) : void {
57
+ public async onEvent ( changeEvent : TextDocumentChangeEvent ) : Promise < void > {
58
58
if ( ! ( changeEvent && changeEvent . contentChanges ) ) {
59
59
this . log . writeWarning ( `<${ HelpCompletionFeature . name } >: ` +
60
60
`Bad TextDocumentChangeEvent message: ${ JSON . stringify ( changeEvent ) } ` ) ;
@@ -69,7 +69,8 @@ export class HelpCompletionFeature implements IFeature {
69
69
70
70
// todo raise an event when trigger is found, and attach complete() to the event.
71
71
if ( this . helpCompletionProvider . triggerFound ) {
72
- this . helpCompletionProvider . complete ( ) . then ( ( ) => this . helpCompletionProvider . reset ( ) ) ;
72
+ await this . helpCompletionProvider . complete ( ) ;
73
+ await this . helpCompletionProvider . reset ( ) ;
73
74
}
74
75
}
75
76
}
@@ -156,36 +157,37 @@ class HelpCompletionProvider {
156
157
this . triggerFinderHelpComment . reset ( ) ;
157
158
}
158
159
159
- public complete ( ) : Thenable < void > {
160
+ public async complete ( ) : Promise < void > {
160
161
if ( this . langClient === undefined ) {
161
162
return ;
162
163
}
163
164
164
- const change = this . lastChangeText ;
165
165
const triggerStartPos = this . lastChangeRange . start ;
166
- const triggerEndPos = this . lastChangeRange . end ;
167
166
const doc = this . lastDocument ;
168
167
169
- return this . langClient . sendRequest (
170
- CommentHelpRequestType ,
171
- {
172
- documentUri : doc . uri . toString ( ) ,
173
- triggerPosition : triggerStartPos ,
174
- blockComment : this . settings . helpCompletion === Settings . HelpCompletion . BlockComment ,
175
- } ) . then ( ( result ) => {
176
- if ( result == null || result . content == null ) {
177
- return ;
178
- }
168
+ const result = await this . langClient . sendRequest ( CommentHelpRequestType , {
169
+ documentUri : doc . uri . toString ( ) ,
170
+ triggerPosition : triggerStartPos ,
171
+ blockComment : this . settings . helpCompletion === Settings . HelpCompletion . BlockComment ,
172
+ } ) ;
173
+
174
+ if ( ! ( result && result . content ) ) {
175
+ return ;
176
+ }
177
+
178
+ const replaceRange = new Range ( triggerStartPos . translate ( 0 , - 1 ) , triggerStartPos . translate ( 0 , 1 ) ) ;
179
+
180
+ // TODO add indentation level to the help content
181
+ // Trim leading whitespace (used by the rule for indentation) as VSCode takes care of the indentation.
182
+ // Trim the last empty line and join the strings.
183
+ const lines : string [ ] = result . content ;
184
+ const text = lines
185
+ . map ( ( x ) => ( x as any ) . trimLeft ( ) )
186
+ . join ( this . getEOL ( doc . eol ) ) ;
179
187
180
- // todo add indentation level to the help content
181
- const editor = window . activeTextEditor ;
182
- const replaceRange = new Range ( triggerStartPos . translate ( 0 , - 1 ) , triggerStartPos . translate ( 0 , 1 ) ) ;
188
+ const snippetString = new SnippetString ( text ) ;
183
189
184
- // Trim leading whitespace (used by the rule for indentation) as VSCode takes care of the indentation.
185
- // Trim the last empty line and join the strings.
186
- const text = result . content . map ( ( x ) => x . trimLeft ( ) ) . slice ( 0 , - 1 ) . join ( this . getEOL ( doc . eol ) ) ;
187
- editor . insertSnippet ( new SnippetString ( text ) , replaceRange ) ;
188
- } ) ;
190
+ window . activeTextEditor . insertSnippet ( snippetString , replaceRange ) ;
189
191
}
190
192
191
193
private getEOL ( eol : EndOfLine ) : string {
0 commit comments