File tree Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -25,35 +25,31 @@ export class TerraformExampleProvider implements CompletionItemProvider {
25
25
const includeBrace = lineTillCurrentPosition . indexOf ( EXAMPLE_TRIGGER_CHARACTER ) ;
26
26
27
27
if ( endwithBrace ) {
28
- const resourceType = this . getDefinedResourceTypes ( document ) ;
28
+ const resourceType = this . getDefinedResourceTypes ( lineTillCurrentPosition ) ;
29
29
const res = examples [ resourceType ] ;
30
30
const text = res . example ;
31
31
let c = new CompletionItem ( `Auto complete example: {${ resourceType } }` , vscode . CompletionItemKind . Snippet ) ;
32
- c . detail = " Press `ENTER` to insert example." ;
32
+ c . detail = ` Press \ `ENTER\ ` to insert example code.\nPress \`ESC\` to continue.` ;
33
33
c . command = {
34
34
title : 'Insert Example' ,
35
35
command : EXAMPLE_CMD ,
36
36
arguments : [ text ] ,
37
37
} ;
38
- exampleItems . push ( c ) ;
38
+ exampleItems . push ( c )
39
39
}
40
40
41
41
return exampleItems ;
42
42
}
43
43
44
-
45
-
46
- getDefinedResourceTypes ( document : TextDocument ) : string {
44
+ getDefinedResourceTypes ( lineText : string ) : string {
47
45
let r = / r e s o u r c e " ( [ a - z A - Z 0 - 9 \- _ ] + ) " / ;
48
46
let found = "" ;
49
- for ( let i = 0 ; i < document . lineCount ; i ++ ) {
50
- let line = document . lineAt ( i ) . text ;
51
- let result = RegExp ( r ) . exec ( line ) ;
52
- if ( result && result . length > 1 ) {
53
- found = result [ 1 ] ;
54
- return found ;
55
- }
47
+ let result = RegExp ( r ) . exec ( lineText ) ;
48
+ if ( result && result . length > 1 ) {
49
+ found = result [ 1 ] ;
50
+ return found ;
56
51
}
52
+
57
53
return found ;
58
54
}
59
55
}
You can’t perform that action at this time.
0 commit comments