caretLine is 1-based and caretOffset is 0-based.
(statement string, caretLine int, caretOffset int)
| 1405 | |
| 1406 | // caretLine is 1-based and caretOffset is 0-based. |
| 1407 | func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string, int, int) { |
| 1408 | newCaretLine, newCaretOffset := caretLine, caretOffset |
| 1409 | list, err := SplitSQL(statement) |
| 1410 | if err != nil || len(base.FilterEmptyStatements(list)) <= 1 { |
| 1411 | return statement, caretLine, caretOffset |
| 1412 | } |
| 1413 | |
| 1414 | start := 0 |
| 1415 | for i, sql := range list { |
| 1416 | // Both caretLine and End.Line are 1-based |
| 1417 | // End.Column is 1-based exclusive (points after the last character) |
| 1418 | // caretOffset is 0-based |
| 1419 | sqlEndLine := int(sql.End.GetLine()) |
| 1420 | sqlEndColumn := int(sql.End.GetColumn()) |
| 1421 | // Use > for End.Column comparison because it's exclusive (points after last char) |
| 1422 | if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn > caretOffset) { |
| 1423 | start = i |
| 1424 | if i == 0 { |
| 1425 | // The caret is in the first SQL statement, so we don't need to skip any SQL statements. |
| 1426 | break |
| 1427 | } |
| 1428 | previousSQLEndLine := int(list[i-1].End.GetLine()) |
| 1429 | previousSQLEndColumn := int(list[i-1].End.GetColumn()) |
| 1430 | newCaretLine = caretLine - previousSQLEndLine + 1 |
| 1431 | if caretLine == previousSQLEndLine { |
| 1432 | // The caret is in the same line as the last line of the previous SQL statement. |
| 1433 | // We need to adjust the caret offset. |
| 1434 | // previousSQLEndColumn is 1-based exclusive, caretOffset is 0-based |
| 1435 | newCaretOffset = caretOffset - previousSQLEndColumn + 1 |
| 1436 | } |
| 1437 | break |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | var buf strings.Builder |
| 1442 | for i := start; i < len(list); i++ { |
| 1443 | if _, err := buf.WriteString(list[i].Text); err != nil { |
| 1444 | return statement, caretLine, caretOffset |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | return buf.String(), newCaretLine, newCaretOffset |
| 1449 | } |
| 1450 | |
| 1451 | // caretLine is 1-based and caretOffset is 0-based. |
| 1452 | func skipHeadingSQLWithoutSemicolon(statement string, caretLine int, caretOffset int) (string, int, int) { |
no test coverage detected