                 return index
             }
         }
-        return 0
+        return -1
+    }
+    
+    // Zero-based line number for the given a character offset
+    func line(offset: Int, startFrom: Int = 0) -> Int {
+        for index in startFrom..<lines.count {
+            let line = lines[index]
+            
+            if line.range.location + line.range.length > offset {
+                return index
+            }
+        }
+        return -1
     }
 }

              let length = statement.length else {
            return nil
        }
        let startLine = file.line(for: offset, startFrom: 0)
        let endLine = file.line(for: offset + length, startFrom: startLine)

        return (startLine, endLine)
    }


        for token in syntaxMap.tokens where token.type == SyntaxKind.comment.rawValue ||
                                            token.type == SyntaxKind.docComment.rawValue {
            let startLine = file.line(byteOffset: token.offset, startFrom: 0)
            let endLine = file.line(byteOffset: token.offset + token.length, startFrom: startLine)

            if startLine <= endLine {
                result.formUnion(Set(startLine...endLine))
