MCPcopy Index your code
hub / github.com/bytebase/bytebase / skipHeadingSQLs

Function skipHeadingSQLs

backend/plugin/parser/plsql/completion.go:1269–1303  ·  view source on GitHub ↗
(statement string, caretLine int, caretOffset int)

Source from the content-addressed store, hash-verified

1267}
1268
1269func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string, int, int) {
1270 newCaretLine, newCaretOffset := caretLine, caretOffset
1271 list, err := SplitSQLForCompletion(statement)
1272 if err != nil || notEmptySQLCount(list) <= 1 {
1273 return statement, caretLine, caretOffset
1274 }
1275
1276 caretLine--
1277 start := 0
1278 for i, sql := range list {
1279 sqlEndLine := int(sql.End.GetLine()) - 1
1280 sqlEndColumn := int(sql.End.GetColumn())
1281 if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn >= caretOffset) {
1282 start = i
1283 if i == 0 {
1284 break
1285 }
1286 previousSQLEndLine := int(list[i-1].End.GetLine()) - 1
1287 previousSQLEndColumn := int(list[i-1].End.GetColumn())
1288 newCaretLine = caretLine - previousSQLEndLine + 1
1289 if caretLine == previousSQLEndLine {
1290 newCaretOffset = caretOffset - previousSQLEndColumn + 1
1291 }
1292 break
1293 }
1294 }
1295
1296 var buf strings.Builder
1297 for i := start; i < len(list); i++ {
1298 if _, err := buf.WriteString(list[i].Text); err != nil {
1299 return statement, caretLine, caretOffset
1300 }
1301 }
1302 return buf.String(), newCaretLine, newCaretOffset
1303}
1304
1305func notEmptySQLCount(list []base.Statement) int {
1306 count := 0

Callers 1

computeSQLAndByteOffsetFunction · 0.70

Calls 5

SplitSQLForCompletionFunction · 0.85
notEmptySQLCountFunction · 0.85
StringMethod · 0.65
GetLineMethod · 0.45
GetColumnMethod · 0.45

Tested by

no test coverage detected