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

Function tern_runCommand

script/tern.py:147–189  ·  view source on GitHub ↗
(query, pos=None, fragments=True)

Source from the content-addressed store, hash-verified

145 "offsetLines": start}
146
147def tern_runCommand(query, pos=None, fragments=True):
148 if isinstance(query, str): query = {"type": query}
149 if (pos is None):
150 curRow, curCol = vim.current.window.cursor
151 pos = {"line": curRow - 1, "ch": curCol}
152 port, portIsOld = tern_findServer()
153 if port is None: return
154 curSeq = vim.eval("undotree()['seq_cur']")
155
156 doc = {"query": query, "files": []}
157 if curSeq == vim.eval("b:ternBufferSentAt"):
158 fname, sendingFile = (tern_relativeFile(), False)
159 elif len(vim.current.buffer) > 250 and fragments:
160 f = tern_bufferFragment()
161 doc["files"].append(f)
162 pos = {"line": pos["line"] - f["offsetLines"], "ch": pos["ch"]}
163 fname, sendingFile = ("#0", False)
164 else:
165 doc["files"].append(tern_fullBuffer())
166 fname, sendingFile = ("#0", True)
167 query["file"] = fname
168 query["end"] = pos
169 query["lineCharPositions"] = True
170
171 data = None
172 try:
173 data = tern_makeRequest(port, doc)
174 if data is None: return None
175 except:
176 pass
177
178 if data is None and portIsOld:
179 try:
180 port, portIsOld = tern_findServer(port)
181 if port is None: return
182 data = tern_makeRequest(port, doc)
183 if data is None: return None
184 except Exception as e:
185 tern_displayError(e)
186
187 if sendingFile and vim.eval("b:ternInsertActive") == "0":
188 vim.command("let b:ternBufferSentAt = " + str(curSeq))
189 return data
190
191def tern_sendBuffer(files=None):
192 port, _portIsOld = tern_findServer()

Callers 7

tern_lookupDocumentationFunction · 0.85
tern_lookupTypeFunction · 0.85
tern_lookupArgumentHintsFunction · 0.85
tern_lookupDefinitionFunction · 0.85
tern_refsFunction · 0.85
tern_renameFunction · 0.85

Calls 6

tern_findServerFunction · 0.85
tern_relativeFileFunction · 0.85
tern_bufferFragmentFunction · 0.85
tern_fullBufferFunction · 0.85
tern_makeRequestFunction · 0.85
tern_displayErrorFunction · 0.85

Tested by

no test coverage detected