Skip to content

Commit

Permalink
fixed dynamic auto-completions
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev committed May 6, 2019
1 parent 6ea0e82 commit 219d62b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
23 changes: 9 additions & 14 deletions src/renderer/scripts/autoCompletions/Dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from "fs";

let PARENT_CONTEXT = {};
let NODE_CONTEXT = {};
let PREV_CONTEXT = undefined;
let PREV_CONTEXT = [];

export function walkSync(dir, filelist = []) {
fs.readdirSync(dir).forEach(file => {
Expand All @@ -25,15 +25,14 @@ export function SET_CONTEXT(node, parent) {
NODE_CONTEXT = node;
}
export function CONTEXT_UP() {
PREV_CONTEXT = NODE_CONTEXT;
PREV_CONTEXT.push(NODE_CONTEXT);
if(NODE_CONTEXT !== undefined) NODE_CONTEXT = NODE_CONTEXT.parent;
if(PARENT_CONTEXT !== undefined) PARENT_CONTEXT = PARENT_CONTEXT.parent;
}
export function CONTEXT_DOWN() {
if(PREV_CONTEXT !== undefined) {
if(PREV_CONTEXT.length > 0) {
PARENT_CONTEXT = NODE_CONTEXT;
NODE_CONTEXT = PREV_CONTEXT;
PREV_CONTEXT = undefined;
NODE_CONTEXT = PREV_CONTEXT.pop();
} else if(NODE_CONTEXT !== undefined) {
throw new Error("Called CONTEXT_DOWN without PREV_CONTEXT.");
}
Expand All @@ -42,9 +41,10 @@ export function CONTEXT_DOWN() {
export const DYNAMIC = {
list: {
next_index() {
let arr = NODE_CONTEXT.toJSON();
if(Array.isArray(arr)) {
if(NODE_CONTEXT.is_array) {
let res = [];
let arr = NODE_CONTEXT.toJSON();

for(let i = arr.length; i >= 0; i--) {
res.push(i + "");
}
Expand All @@ -53,15 +53,10 @@ export const DYNAMIC = {
return [ "0" ];
},
index_pair() {
let arr = NODE_CONTEXT.toJSON();
if(Array.isArray(arr)) return [ "0", "1" ];
return [ "0" ];
return [ "0", "1" ];
},
index_triple() {
let arr = NODE_CONTEXT.toJSON();
if(Array.isArray(arr) && arr.length >= 2) return [ "1", "2" ];
if(Array.isArray(arr)) return [ "0", "1" ];
return [ "0" ];
return [ "0", "1", "2" ];
}
},
setting: {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/scripts/autoCompletions/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Provider {
}
static removeFromLib(path, current=LIB) {
let { key, created } = path.shift();
console.log(key, created);
// console.log(key, created);
if(path.length > 0) this.removeFromLib(path, current[key]);
if(created) delete current[key];
}
Expand Down Expand Up @@ -191,16 +191,16 @@ class Provider {

let key = path_arr.shift();
if(current[key] === undefined) {
//TODO: ONE COMPONENT PER CONDITION WHICH USES CURRENT & KEY TO EVALUATE
let res = ComponentProvider.process(this, key, path_arr, current);
if(res !== undefined) {
return res;
} else if(current !== LIB) {
for(let k of Object.keys(current)) {
if(k[0] === "$") {
CONTEXT_UP();
for(let i = 0; i < path_arr.length + 1; i++) CONTEXT_UP();
let { object, value } = this.omegaExpression(k);
CONTEXT_DOWN();
for(let i = 0; i < path_arr.length + 1; i++) CONTEXT_DOWN();

if(value.includes(key) || object[key] !== undefined)
return this.walk(path_arr, current[k]);
}
Expand Down

0 comments on commit 219d62b

Please sign in to comment.