MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / _split_multiple_statements

Function _split_multiple_statements

mssqlcli/packages/sqlcompletion.py:199–233  ·  view source on GitHub ↗
(full_text, text_before_cursor, parsed)

Source from the content-addressed store, hash-verified

197
198
199def _split_multiple_statements(full_text, text_before_cursor, parsed):
200 if len(parsed) > 1:
201 # Multiple statements being edited -- isolate the current one by
202 # cumulatively summing statement lengths to find the one that bounds
203 # the current position
204 current_pos = len(text_before_cursor)
205 stmt_start, stmt_end = 0, 0
206
207 for statement in parsed:
208 stmt_len = len(str(statement))
209 stmt_start, stmt_end = stmt_end, stmt_end + stmt_len
210
211 if stmt_end >= current_pos:
212 text_before_cursor = full_text[stmt_start:current_pos]
213 full_text = full_text[stmt_start:]
214 break
215
216 elif parsed:
217 # A single statement
218 statement = parsed[0]
219 else:
220 # The empty string
221 return full_text, text_before_cursor, None
222
223 token2 = None
224 if statement.get_type() in ('CREATE', 'CREATE OR REPLACE'):
225 token1 = statement.token_first()
226 if token1:
227 token1_idx = statement.token_index(token1)
228 token2 = statement.token_next(token1_idx)[1]
229 if token2 and token2.value.upper() == 'FUNCTION':
230 full_text, text_before_cursor, statement = _statement_from_function(
231 full_text, text_before_cursor, statement
232 )
233 return full_text, text_before_cursor, statement
234
235
236SPECIALS_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