MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / getLineStartPositionForPosition

Function getLineStartPositionForPosition

internal/fixables/disable.go:93–105  ·  view source on GitHub ↗

getLineStartPositionForPosition finds the start of the line containing the given position.

(pos int, sourceFile *ast.SourceFile)

Source from the content-addressed store, hash-verified

91
92// getLineStartPositionForPosition finds the start of the line containing the given position.
93func getLineStartPositionForPosition(pos int, sourceFile *ast.SourceFile) int {
94 text := sourceFile.Text()
95 if pos <= 0 || pos > len(text) {
96 return 0
97 }
98 // Walk backwards to find the newline
99 for i := pos - 1; i >= 0; i-- {
100 if text[i] == '\n' {
101 return i + 1
102 }
103 }
104 return 0
105}
106
107// getIndentationAtPosition returns the whitespace characters from line start to the first non-whitespace.
108func getIndentationAtPosition(sourceFile *ast.SourceFile, lineStartPos int) string {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected