MCPcopy Index your code
hub / github.com/python/cpython / get_context

Method get_context

Lib/idlelib/codecontext.py:149–177  ·  view source on GitHub ↗

Return a list of block line tuples and the 'last' indent. The tuple fields are (linenum, indent, text, opener). The list represents header lines from new_topvisible back to stopline with successively shorter indents > stopindent. The list is returned ordered by line

(self, new_topvisible, stopline=1, stopindent=0)

Source from the content-addressed store, hash-verified

147 return "break"
148
149 def get_context(self, new_topvisible, stopline=1, stopindent=0):
150 """Return a list of block line tuples and the 'last' indent.
151
152 The tuple fields are (linenum, indent, text, opener).
153 The list represents header lines from new_topvisible back to
154 stopline with successively shorter indents > stopindent.
155 The list is returned ordered by line number.
156 Last indent returned is the smallest indent observed.
157 """
158 assert stopline > 0
159 lines = []
160 # The indentation level we are currently in.
161 lastindent = INFINITY
162 # For a line to be interesting, it must begin with a block opening
163 # keyword, and have less indentation than lastindent.
164 for linenum in range(new_topvisible, stopline-1, -1):
165 codeline = self.text.get(f'{linenum}.0', f'{linenum}.end')
166 indent, text, opener = get_line_info(codeline)
167 if indent < lastindent:
168 lastindent = indent
169 if opener in ("else", "elif"):
170 # Also show the if statement.
171 lastindent += 1
172 if opener and linenum < new_topvisible and indent >= stopindent:
173 lines.append((linenum, indent, text, opener))
174 if lastindent <= stopindent:
175 break
176 lines.reverse()
177 return lines, lastindent
178
179 def update_code_context(self):
180 """Update context information and lines visible in the context pane.

Callers 2

update_code_contextMethod · 0.95

Calls 4

get_line_infoFunction · 0.85
getMethod · 0.45
appendMethod · 0.45
reverseMethod · 0.45

Tested by 1