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

Function tern_bufferFragment

script/tern.py:126–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124 "text": tern_bufferSlice(vim.current.buffer, 0, len(vim.current.buffer))}
125
126def tern_bufferFragment():
127 curRow, curCol = vim.current.window.cursor
128 line = curRow - 1
129 buf = vim.current.buffer
130 minIndent = None
131 start = None
132
133 for i in range(max(0, line - 50), line):
134 if not re.match(".*\\bfunction\\b", buf[i]): continue
135 indent = len(re.match("^\\s*", buf[i]).group(0))
136 if minIndent is None or indent <= minIndent:
137 minIndent = indent
138 start = i
139
140 if start is None: start = max(0, line - 50)
141 end = min(len(buf) - 1, line + 20)
142 return {"type": "part",
143 "name": tern_relativeFile(),
144 "text": tern_bufferSlice(buf, start, end),
145 "offsetLines": start}
146
147def tern_runCommand(query, pos=None, fragments=True):
148 if isinstance(query, str): query = {"type": query}

Callers 1

tern_runCommandFunction · 0.85

Calls 2

tern_relativeFileFunction · 0.85
tern_bufferSliceFunction · 0.85

Tested by

no test coverage detected