public void OnHelp(string s) { string code = s; int i = code.Length - 1; while (i >= 0 && (char.IsLetterOrDigit(code[i]) || "[]()._".IndexOf(code[i]) > -1)) { i--; } if (i < -1 || i > code.Length - 1) { return; } string var = code.Substring(i + 1, code.Length - (i + 1)); //UnityEngine.Debug.Log("txt so far = " + var); _codeHelper.FindVariables(code); string[] predicitons = _codeHelper.Predict(var); foreach (string option in predicitons) { UnityEngine.Debug.Log("Option: " + option); } }
public static string[] PredictCode(string code, int cursorIndex, CodeHelper codeHelper) { int i = cursorIndex - 1; if (i >= code.Length || i < 0) { return(emptyList); } if ("[]()".IndexOf(code[i]) > -1) { return(emptyList); } int parenthAccum = 0; int bracketAccum = 0; while (i >= 0 && (char.IsLetterOrDigit(code[i]) || "[]()._".IndexOf(code[i]) > -1)) { if (code[i] == '(') { if (parenthAccum < 1) { break; } parenthAccum--; } else if (code[i] == '[') { if (bracketAccum < 1) { break; } bracketAccum--; } else if (code[i] == ')') { parenthAccum++; } else if (code[i] == ']') { if (bracketAccum < 1) { break; } bracketAccum--; } i--; } if (i < -1 || i > code.Length - 1) { return(emptyList); } try { string element = code.Substring(i + 1, cursorIndex - (i + 1)); codeHelper.code = code; return(codeHelper.Predict(element)); } catch (System.Exception e) { return(emptyList); } }