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

Method open_completions

Lib/idlelib/autocomplete.py:101–159  ·  view source on GitHub ↗

Find the completions and create the AutoCompleteWindow. Return True if successful (no syntax error or so found). If complete is True, then if there's nothing to complete and no start of completion, won't open completions and return False. If mode is given, will open a

(self, args)

Source from the content-addressed store, hash-verified

99 self.open_completions(args)
100
101 def open_completions(self, args):
102 """Find the completions and create the AutoCompleteWindow.
103 Return True if successful (no syntax error or so found).
104 If complete is True, then if there's nothing to complete and no
105 start of completion, won't open completions and return False.
106 If mode is given, will open a completion list only in this mode.
107 """
108 evalfuncs, complete, wantwin, mode = args
109 # Cancel another delayed call, if it exists.
110 if self._delayed_completion_id is not None:
111 self.text.after_cancel(self._delayed_completion_id)
112 self._delayed_completion_id = None
113
114 hp = HyperParser(self.editwin, "insert")
115 curline = self.text.get("insert linestart", "insert")
116 i = j = len(curline)
117 if hp.is_in_string() and (not mode or mode==FILES):
118 # Find the beginning of the string.
119 # fetch_completions will look at the file system to determine
120 # whether the string value constitutes an actual file name
121 # XXX could consider raw strings here and unescape the string
122 # value if it's not raw.
123 self._remove_autocomplete_window()
124 mode = FILES
125 # Find last separator or string start
126 while i and curline[i-1] not in "'\"" + SEPS:
127 i -= 1
128 comp_start = curline[i:j]
129 j = i
130 # Find string start
131 while i and curline[i-1] not in "'\"":
132 i -= 1
133 comp_what = curline[i:j]
134 elif hp.is_in_code() and (not mode or mode==ATTRS):
135 self._remove_autocomplete_window()
136 mode = ATTRS
137 while i and (curline[i-1] in ID_CHARS or ord(curline[i-1]) > 127):
138 i -= 1
139 comp_start = curline[i:j]
140 if i and curline[i-1] == '.': # Need object with attributes.
141 hp.set_index("insert-%dc" % (len(curline)-(i-1)))
142 comp_what = hp.get_expression()
143 if (not comp_what or
144 (not evalfuncs and comp_what.find('(') != -1)):
145 return None
146 else:
147 comp_what = ""
148 else:
149 return None
150
151 if complete and not comp_what and not comp_start:
152 return None
153 comp_lists = self.fetch_completions(comp_what, mode)
154 if not comp_lists[0]:
155 return None
156 self.autocompletewindow = self._make_autocomplete_window()
157 return not self.autocompletewindow.show_window(
158 comp_lists, "insert-%dc" % len(comp_start),

Callers 7

autocomplete_eventMethod · 0.95
test_oc_no_listMethod · 0.80
test_open_completionsMethod · 0.80

Calls 12

is_in_stringMethod · 0.95
is_in_codeMethod · 0.95
set_indexMethod · 0.95
get_expressionMethod · 0.95
fetch_completionsMethod · 0.95
HyperParserClass · 0.90
after_cancelMethod · 0.80
show_windowMethod · 0.80
getMethod · 0.45
findMethod · 0.45

Tested by 4

test_oc_no_listMethod · 0.64
test_open_completionsMethod · 0.64