Skip to content

Commit

Permalink
Started reworking yamlCompletion and autoCompleter
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Jun 12, 2017
1 parent 5707c3c commit d0e10d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
20 changes: 13 additions & 7 deletions server/src/languageService/services/autoCompleter.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,11 +18,15 @@ export class AutoCompleter {
}

public search(searchItem: String): Array<String>{
return this.autoCompleter.search(searchItem).map(x => x.value);
return this.autoCompleter.search(searchItem).map(x => ({
label: x.value.toString()
}));
}

public searchAll(): Array<String>{
return Object.keys(this.kuberSchema);
public searchAll() {
return Object.keys(this.kuberSchema).map(x => ({
label: x.toString()
}));
}

public initData(data:Array<String>): void {
Expand All @@ -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));
}
}

Expand All @@ -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()
}));
}


}
27 changes: 7 additions & 20 deletions server/src/languageService/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,23 @@ export class YamlCompletion {
let node = findNode(<YAMLNode>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;

});
}

}


}
Expand Down

0 comments on commit d0e10d2

Please sign in to comment.