getLineStartPositionForPosition finds the start of the line containing the given position.
(pos int, sourceFile *ast.SourceFile)
| 91 | |
| 92 | // getLineStartPositionForPosition finds the start of the line containing the given position. |
| 93 | func 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. |
| 108 | func getIndentationAtPosition(sourceFile *ast.SourceFile, lineStartPos int) string { |
no outgoing calls
no test coverage detected