Skip to content

Commit

Permalink
fix: example line
Browse files Browse the repository at this point in the history
  • Loading branch information
lyu571 committed Nov 21, 2023
1 parent 27a451e commit f9ba221
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/autocomplete/TerraformExampleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,31 @@ export class TerraformExampleProvider implements CompletionItemProvider {
const includeBrace = lineTillCurrentPosition.indexOf(EXAMPLE_TRIGGER_CHARACTER);

if (endwithBrace) {
const resourceType = this.getDefinedResourceTypes(document);
const resourceType = this.getDefinedResourceTypes(lineTillCurrentPosition);
const res = examples[resourceType];
const text = res.example;
let c = new CompletionItem(`Auto complete example: {${resourceType}}`, vscode.CompletionItemKind.Snippet);
c.detail = "Press `ENTER` to insert example.";
c.detail = `Press \`ENTER\` to insert example code.\nPress \`ESC\` to continue.`;
c.command = {
title: 'Insert Example',
command: EXAMPLE_CMD,
arguments: [text],
};
exampleItems.push(c);
exampleItems.push(c)

Check warning on line 38 in src/autocomplete/TerraformExampleProvider.ts

View workflow job for this annotation

GitHub Actions / pr-check

Missing semicolon
}

return exampleItems;
}



getDefinedResourceTypes(document: TextDocument): string {
getDefinedResourceTypes(lineText: string): string {
let r = /resource "([a-zA-Z0-9\-_]+)"/;
let found = "";
for (let i = 0; i < document.lineCount; i++) {
let line = document.lineAt(i).text;
let result = RegExp(r).exec(line);
if (result && result.length > 1) {
found = result[1];
return found;
}
let result = RegExp(r).exec(lineText);
if (result && result.length > 1) {
found = result[1];
return found;
}

return found;
}
}
Expand Down

0 comments on commit f9ba221

Please sign in to comment.