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 {
2525 const includeBrace = lineTillCurrentPosition . indexOf ( EXAMPLE_TRIGGER_CHARACTER ) ;
2626
2727 if ( endwithBrace ) {
28- const resourceType = this . getDefinedResourceTypes ( document ) ;
28+ const resourceType = this . getDefinedResourceTypes ( lineTillCurrentPosition ) ;
2929 const res = examples [ resourceType ] ;
3030 const text = res . example ;
3131 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.` ;
3333 c . command = {
3434 title : 'Insert Example' ,
3535 command : EXAMPLE_CMD ,
3636 arguments : [ text ] ,
3737 } ;
38- exampleItems . push ( c ) ;
38+ exampleItems . push ( c )
3939 }
4040
4141 return exampleItems ;
4242 }
4343
44-
45-
46- getDefinedResourceTypes ( document : TextDocument ) : string {
44+ getDefinedResourceTypes ( lineText : string ) : string {
4745 let r = / r e s o u r c e " ( [ a - z A - Z 0 - 9 \- _ ] + ) " / ;
4846 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 ;
5651 }
52+
5753 return found ;
5854 }
5955}
You can’t perform that action at this time.
0 commit comments