MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / offsetToLineColumn

Function offsetToLineColumn

pkg/lsp/handler.go:560–582  ·  view source on GitHub ↗

offsetToLineColumn converts an absolute offset to line and column

(content string, offset int)

Source from the content-addressed store, hash-verified

558
559// offsetToLineColumn converts an absolute offset to line and column
560func offsetToLineColumn(content string, offset int) (line, col int) {
561 if offset < 0 {
562 return 0, 0
563 }
564 if offset >= len(content) {
565 offset = len(content) - 1
566 if offset < 0 {
567 return 0, 0
568 }
569 }
570
571 line = 0
572 col = 0
573 for i := 0; i < offset && i < len(content); i++ {
574 if content[i] == '\n' {
575 line++
576 col = 0
577 } else {
578 col++
579 }
580 }
581 return
582}
583
584// isWhitespace returns true if c is a whitespace character
585func isWhitespace(c byte) bool {

Callers 3

TestOffsetToLineColumnFunction · 0.85
extractPositionFromErrorFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestOffsetToLineColumnFunction · 0.68