MCPcopy
hub / github.com/ternjs/tern_for_vim / tern_ensureCompletionCached

Function tern_ensureCompletionCached

script/tern.py:220–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218 return "(obj)"
219
220def tern_ensureCompletionCached():
221 cached = vim.eval("b:ternLastCompletionPos")
222 curRow, curCol = vim.current.window.cursor
223 curLine = vim.current.buffer[curRow - 1]
224
225 if (curRow == int(cached["row"]) and curCol >= int(cached["end"]) and
226 curLine[0:int(cached["end"])] == cached["word"] and
227 (not re.match(".*\\W", curLine[int(cached["end"]):curCol]))):
228 return
229
230 data = tern_runCommand({"type": "completions", "types": True, "docs": True},
231 {"line": curRow - 1, "ch": curCol})
232 if data is None: return
233
234 completions = []
235 for rec in data["completions"]:
236 completions.append({"word": rec["name"],
237 "menu": tern_asCompletionIcon(rec.get("type")),
238 "info": tern_typeDoc(rec) })
239 vim.command("let b:ternLastCompletion = " + json.dumps(completions))
240 start, end = (data["start"]["ch"], data["end"]["ch"])
241 vim.command("let b:ternLastCompletionPos = " + json.dumps({
242 "row": curRow,
243 "start": start,
244 "end": end,
245 "word": curLine[0:end]
246 }))
247
248def tern_typeDoc(rec):
249 tp = rec.get("type")

Callers

nothing calls this directly

Calls 3

tern_runCommandFunction · 0.85
tern_asCompletionIconFunction · 0.85
tern_typeDocFunction · 0.85

Tested by

no test coverage detected