diff --git a/server/src/languageService/services/autoCompleter.ts b/server/src/languageService/services/autoCompleter.ts index aec3ca4b..00b47962 100644 --- a/server/src/languageService/services/autoCompleter.ts +++ b/server/src/languageService/services/autoCompleter.ts @@ -1,7 +1,8 @@ import {SchemaToMappingTransformer} from "../schemaToMappingTransformer" -import {TextDocument} from 'vscode-languageserver-types'; +import {TextDocument, CompletionList} from 'vscode-languageserver-types'; import {JSONSchema} from "../jsonSchema"; import {YAMLDocument, YAMLNode} from 'yaml-ast-parser'; + let AutoComplete = require('triesearch'); export class AutoCompleter { @@ -17,11 +18,15 @@ export class AutoCompleter { } public search(searchItem: String): Array{ - return this.autoCompleter.search(searchItem).map(x => x.value); + return this.autoCompleter.search(searchItem).map(x => ({ + label: x.value.toString() + })); } - public searchAll(): Array{ - return Object.keys(this.kuberSchema); + public searchAll() { + return Object.keys(this.kuberSchema).map(x => ({ + label: x.toString() + })); } public initData(data:Array): void { @@ -42,7 +47,7 @@ export class AutoCompleter { let results = this.kuberSchema[getParentNodeValue].map(x => x.children).reduce((a, b) => a.concat(b)).filter((value, index, self) => self.indexOf(value) === index); this.initData(results); }else{ - this.initData(this.searchAll()); + this.initData(Object.keys(this.kuberSchema)); } } @@ -65,8 +70,9 @@ export class AutoCompleter { public generateScalarAutocompletion(nodeValue: String){ let results = this.kuberSchema[nodeValue.toString()].map(x => x.default).filter((value, index, self) => self.indexOf(value) === index && value !== undefined); - return results; + return results.map(x => ({ + label: x.toString() + })); } - } \ No newline at end of file diff --git a/server/src/languageService/services/yamlCompletion.ts b/server/src/languageService/services/yamlCompletion.ts index 8f9effbc..900fcd4f 100644 --- a/server/src/languageService/services/yamlCompletion.ts +++ b/server/src/languageService/services/yamlCompletion.ts @@ -26,36 +26,23 @@ export class YamlCompletion { let node = findNode(doc, offset); if(node !== undefined && node.kind === Kind.SCALAR){ - autoComplete.generateScalarAutocompletion(node.parent.key.value).map(x => result.items.push({ - label: x.toString() - })); - return result; + return autoComplete.generateScalarAutocompletion(node.parent.key.value); } - if(node != undefined && node.value !== null && node.value.kind === Kind.SCALAR){ - autoComplete.generateScalarAutocompletion(node.key.value).map(x => result.items.push({ - label: x.toString() - })); - return result; + if(node != undefined && node.value !== null && node.value !== undefined && node.value.kind === Kind.SCALAR){ + return autoComplete.generateScalarAutocompletion(node.key.value); } if(node === undefined || node.parent === null){ //Its a root node - autoComplete.searchAll().map(x => result.items.push({ - label: x.toString() - })); + return autoComplete.searchAll(); }else{ autoComplete.generateResults(node); - autoComplete.search(node.key.value).map(x => result.items.push({ - label: x.toString() - })); + return autoComplete.search(node.key.value); } - - - return result; + }); - } - + } }