MCPcopy Index your code
hub / github.com/dbcli/pgcli / _split_multiple_statements

Function _split_multiple_statements

pgcli/packages/sqlcompletion.py:185–217  ·  view source on GitHub ↗
(full_text, text_before_cursor, parsed)

Source from the content-addressed store, hash-verified

183
184
185def _split_multiple_statements(full_text, text_before_cursor, parsed):
186 if len(parsed) > 1:
187 # Multiple statements being edited -- isolate the current one by
188 # cumulatively summing statement lengths to find the one that bounds
189 # the current position
190 current_pos = len(text_before_cursor)
191 stmt_start, stmt_end = 0, 0
192
193 for statement in parsed:
194 stmt_len = len(str(statement))
195 stmt_start, stmt_end = stmt_end, stmt_end + stmt_len
196
197 if stmt_end >= current_pos:
198 text_before_cursor = full_text[stmt_start:current_pos]
199 full_text = full_text[stmt_start:]
200 break
201
202 elif parsed:
203 # A single statement
204 statement = parsed[0]
205 else:
206 # The empty string
207 return full_text, text_before_cursor, None
208
209 token2 = None
210 if statement.get_type() in ("CREATE", "CREATE OR REPLACE"):
211 token1 = statement.token_first()
212 if token1:
213 token1_idx = statement.token_index(token1)
214 token2 = statement.token_next(token1_idx)[1]
215 if token2 and token2.value.upper() == "FUNCTION":
216 full_text, text_before_cursor, statement = _statement_from_function(full_text, text_before_cursor, statement)
217 return full_text, text_before_cursor, statement
218
219
220SPECIALS_SUGGESTION = {

Callers 2

__init__Method · 0.85
_statement_from_functionFunction · 0.85

Calls 1

_statement_from_functionFunction · 0.85

Tested by

no test coverage detected