(ScriptEngine engine, String boxName, String allText, int line, int ch, boolean explicitlyRequested)
| 96 | } |
| 97 | |
| 98 | public List<Completion> completion(ScriptEngine engine, String boxName, String allText, int line, int ch, |
| 99 | boolean explicitlyRequested) { |
| 100 | |
| 101 | List<Completion> r = new ArrayList<>(); |
| 102 | |
| 103 | |
| 104 | try { |
| 105 | engine.put("__someFile", allText); |
| 106 | engine.eval("var __completions = new java.util.ArrayList()"); |
| 107 | try { |
| 108 | engine.eval("__fieldglobal.self.ternServer.request({query:{type:\"completions\", " + |
| 109 | "types:true, docs:true, file:\"#0\", end:{line:" + line + ",ch:" + ch + "}}, " + |
| 110 | "\n" + |
| 111 | "files:[{type:\"full\",name:\"" + boxName + ".js\",text:__someFile}]},\n" + |
| 112 | " function (e,r){\n" + |
| 113 | " for(var i=0;i<r.completions.length;i++)" + |
| 114 | " if (r && r.end)" + |
| 115 | " __completions.add(new __fieldglobal.fieldbox.execution" + |
| 116 | ".Completion(r.start, r.end, r.completions[i].name, '<span class=type>'+r" + |
| 117 | ".completions[i].type+' — </span><span class=doc>'+(r" + |
| 118 | ".completions[i].doc==null ? '' : r.completions[i].doc)+'</span>'))" + |
| 119 | " })"); |
| 120 | ArrayList<Completion> aa = (ArrayList<Completion>) engine.getContext().getAttribute("__completions"); |
| 121 | if (aa!=null) |
| 122 | r.addAll(aa); |
| 123 | } catch (ScriptException e) { |
| 124 | e.printStackTrace(); |
| 125 | } |
| 126 | |
| 127 | Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); |
| 128 | Log.log("completion.debug", () -> { |
| 129 | Log.log("completion.debug", () -> "bindings are..."); |
| 130 | for (Object k : bindings.keySet()) { |
| 131 | Object t = bindings.get(k); |
| 132 | if (t == null) continue; |
| 133 | if (t instanceof String) if (((String) t).split("\n").length > 0) |
| 134 | t = ((String) t).split("\n")[0] + " ..."; |
| 135 | final Object finalT = t; |
| 136 | Log.log("completion.debug", () -> " " + k + " " + finalT); |
| 137 | } |
| 138 | return null; |
| 139 | }); |
| 140 | |
| 141 | if (allText.trim() |
| 142 | .length() == 0) return r; |
| 143 | |
| 144 | String[] lines = allText.split("\n"); |
| 145 | int c = 0; |
| 146 | for (int i = 0; i < line; i++) { |
| 147 | c += lines[i].length() + 1; |
| 148 | } |
| 149 | |
| 150 | c += ch; |
| 151 | |
| 152 | |
| 153 | final int finalC = c; |
| 154 | Log.log("completion.debug", () -> " line :" + line + " -> " + ch + " -> " + finalC + " alltext" + |
| 155 | " is <" + allText + ">"); |
nothing calls this directly
no test coverage detected