Skip to content

Commit

Permalink
[20231027]Feat/support tips feature (#4)
Browse files Browse the repository at this point in the history
* support login with AKSK input

* add aksk input

* login with AKSK: 1.store aksk in process. 2.add refresh feature. 3.add icon pkg.

* add aksk input

* support: set aksk and terraform init/plan/apply/destroy cmd

* update tiat-resource.config

* 1.add res doc redirect function. 2.adjust tips logic.

* 1.scrape tool. 2.adjust package.json for npm compile.
  • Loading branch information
lyu571 authored Nov 1, 2023
1 parent 5080aec commit 88f8e38
Show file tree
Hide file tree
Showing 19 changed files with 35,702 additions and 19,288 deletions.
Empty file removed config/snippets/resources.json
Empty file.
8 changes: 0 additions & 8 deletions config/snippets/tiat-urls.json

This file was deleted.

53,731 changes: 34,697 additions & 19,034 deletions config/snippets/tiat-resources.json → config/tips/tiat-resources.json

Large diffs are not rendered by default.

557 changes: 541 additions & 16 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,23 @@
"mocha": "^10.1.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.9.4",
"vscode": "^1.1.34"
"vscode": "^1.1.34",
"@types/cheerio": "^0.22.33",
"cheerio": "^1.0.0-rc.12"
},
"dependencies": {
"@types/jsdom": "^21.1.4",
"@types/strip-ansi": "^5.2.1",
"all": "^0.0.0",
"asynckit": "^0.4.0",
"axios": "^1.3.5",
"chalk": "^4.1.2",
"fs-extra": "^11.1.0",
"inversify": "^6.0.1",
"jsdom": "^22.1.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"marked": "^0.3.6",
"opn": "^6.0.0",
"reflect-metadata": "^0.1.13",
"shared": "^0.2.0",
Expand All @@ -278,4 +283,4 @@
"vscode-extension-telemetry-wrapper": "^0.13.3",
"vscode-nls-i18n": "^0.2.4"
}
}
}
24 changes: 0 additions & 24 deletions src/autocomplete/TerraformDefinitionProvider.ts

This file was deleted.

21 changes: 21 additions & 0 deletions src/autocomplete/TerraformExampleProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CompletionItemProvider, TextDocument, Position, CancellationToken, CompletionItem } from "vscode";
import resources from '../../config/tips/tiat-resources.json';
import * as _ from "lodash";

var topLevelTypes = ["output", "provider", "resource", "variable", "data"];
var topLevelRegexes = topLevelTypes.map(o => {
return {
type: o,
regex: new RegExp(o + ' "[A-Za-z0-9\-_]+" "[A-Za-z0-9\-_]*" \{')
};
});

export class TerraformExampleProvider implements CompletionItemProvider {
document: TextDocument;
position: Position;
token: CancellationToken;

public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): CompletionItem[] {
return [];
}
}
18 changes: 18 additions & 0 deletions src/autocomplete/TerraformHoverProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HoverProvider, TextDocument, Position, CancellationToken, CompletionItem, CompletionItemKind, Hover, ProviderResult } from "vscode";
import resources from '../../config/tips/tiat-resources.json';
import * as _ from "lodash";

var topLevelTypes = ["output", "provider", "resource", "variable", "data"];
var topLevelRegexes = topLevelTypes.map(o => {
return {
type: o,
regex: new RegExp(o + ' "[A-Za-z0-9\-_]+" "[A-Za-z0-9\-_]*" \{')
};
});

export class TerraformHoverProvider implements HoverProvider {
provideHover(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Hover> {
throw new Error("Method not implemented.");
}

}
28 changes: 28 additions & 0 deletions src/autocomplete/TerraformResDocProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
DefinitionProvider,
TextDocument,
Position,
CancellationToken,
Definition
} from "vscode";
import * as _ from "lodash";
// import * as opn from "opn";
import opn from "opn";
import resources from '../../config/tips/tiat-resources.json';

const urlPrefix = "https://www.terraform.io";

export class TerraformResDocProvider implements DefinitionProvider {
public provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Definition {
const words = document.getWordRangeAtPosition(position);
const resName = document.getText(words);

const found = _.get(resources, resName);
const urlSuffix = found.url?.toString() || "";
var target = <string>(urlPrefix + urlSuffix);
if (urlSuffix && target) {
opn(target);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CompletionItemProvider, TextDocument, Position, CancellationToken, CompletionItem, CompletionItemKind } from "vscode";
// var resources = require('../../config/snippets/tiat-resources.json');
import resources from '../../config/snippets/tiat-resources.json';
import resources from '../../config/tips/tiat-resources.json';
import * as _ from "lodash";

var topLevelTypes = ["output", "provider", "resource", "variable", "data"];
Expand All @@ -11,7 +10,7 @@ var topLevelRegexes = topLevelTypes.map(o => {
};
});

export class TerraformCompletionProvider implements CompletionItemProvider {
export class TerraformTipsProvider implements CompletionItemProvider {
document: TextDocument;
position: Position;
token: CancellationToken;
Expand All @@ -31,7 +30,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
}

// Are we trying to type a variable?
if (this.isTypingVariable(lineTillCurrentPosition)) {
if (this.isTypingTfCode(lineTillCurrentPosition)) {
// These variables should always just have 3 parts, resource type, resource name, exported field
var varString = this.getVariableString(lineTillCurrentPosition);
var parts = varString.split(".");
Expand Down Expand Up @@ -74,7 +73,6 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
}

// Are we trying to type a parameter to a resource?

let possibleResources = this.checkTopLevelResource(lineTillCurrentPosition);
if (possibleResources.length > 0) {
return this.getHintsForStrings(possibleResources);
Expand All @@ -87,8 +85,8 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
if (parentType && parentType.type === "resource") {
let resourceType = this.getResourceTypeFromLine(line);
let ret = this.getItemsForArgs(resources[resourceType].args, resourceType);
return ret;
}
return ret;
}
else if (parentType && parentType.type !== "resource") {
// We don't want to accidentally include some other containers stuff
return [];
Expand All @@ -99,7 +97,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
}

getNamesForResourceType(document: TextDocument, resourceType: string): string[] {
var r = new RegExp('resource "' + resourceType +'" "([a-zA-Z0-9\-_]+)"');
var r = new RegExp('resource "' + resourceType + '" "([a-zA-Z0-9\-_]+)"');
var found = [];
for (var i = 0; i < document.lineCount; i++) {
var line = document.lineAt(i).text;
Expand Down Expand Up @@ -128,7 +126,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
}

isTopLevelType(line: string): boolean {
for (var i=0; i<topLevelTypes.length; i++) {
for (var i = 0; i < topLevelTypes.length; i++) {
var resourceType = topLevelTypes[i];
if (resourceType.indexOf(line) === 0) {
return true;
Expand All @@ -138,7 +136,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
}

getTopLevelType(line: string): CompletionItem[] {
for (var i=0; i<topLevelTypes.length; i++) {
for (var i = 0; i < topLevelTypes.length; i++) {
var resourceType = topLevelTypes[i];
if (resourceType.indexOf(line) === 0) {
return [new CompletionItem(resourceType, CompletionItemKind.Enum)];
Expand All @@ -147,7 +145,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
return [];
}

isTypingVariable(line: string): boolean {
isTypingTfCode(line: string): boolean {
var r = /\$\{[0-9a-zA-Z_\.\-]*$/;
return r.test(line);
}
Expand Down Expand Up @@ -183,7 +181,7 @@ export class TerraformCompletionProvider implements CompletionItemProvider {
});
}

getParentType(line: string): boolean|any {
getParentType(line: string): boolean | any {
for (var i = 0; i < topLevelRegexes.length; i++) {
let tl = topLevelRegexes[i];
if (tl.regex.test(line)) {
Expand Down
15 changes: 8 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { init } from "vscode-nls-i18n";
import { TerraformCommand, TerraformerCommand } from "./commons/customCmdRegister";
import { terraformShellManager } from "./client/terminal/terraformShellManager";
import { DialogOption } from "./utils/uiUtils";
import { TerraformCompletionProvider } from './autocomplete/TerraformCompletionProvider';
import { TerraformDefinitionProvider } from './autocomplete/TerraformDefinitionProvider';
import { registerExternelCommands } from './commons';
import { TerraformTipsProvider } from './autocomplete/TerraformTipsProvider';
import { TerraformResDocProvider } from './autocomplete/TerraformResDocProvider';
import { registerExternelCommands, bindExtensionContext } from './commons';
import { registerView } from './views';
import { TerraformRunner } from './client/runner/terraformRunner';
import { TerraformerRunner } from './client/runner/terraformerRunner';
import { GitUtils } from './utils/gitUtils';
import { bindExtensionContext } from "./commons";
import _ from 'lodash';

const TF_MODE: vscode.DocumentFilter = { language: 'terraform', scheme: 'file' };
Expand Down Expand Up @@ -96,8 +95,8 @@ export async function activate(context: vscode.ExtensionContext) {

// auto-complete
console.log('activate the auto complete(snippets and lint) feature');
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(TF_MODE, new TerraformCompletionProvider(), '.'));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(TF_MODE, new TerraformDefinitionProvider()));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(TF_MODE, new TerraformTipsProvider(), '.'));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(TF_MODE, new TerraformResDocProvider()));

// import-resource
console.log('activate the import feature');
Expand All @@ -107,4 +106,6 @@ export async function activate(context: vscode.ExtensionContext) {
}

// This method is called when your extension is deactivated
export function deactivate() { }
export function deactivate() {
/* TODO document why this function 'deactivate' is empty */
}
Loading

0 comments on commit 88f8e38

Please sign in to comment.