import { Position , SourceLocation } from "estree" ; import { Position as LSPosition , Range as LSRange } from "vscode-languageserver" ; export function newPosition ( line , column ) { return { line , column } ; } export function comparePositions ( a , b ) { if ( a . line < b . line ) return - 1 ; if ( a . line > b . line ) return 1 ; if ( a . column < b . column ) return - 1 ; if ( a . column > b . column ) return 1 ; return 0 ; } export function toPosition ( lsp ) { return newPosition ( lsp . line + 1 , lsp . character ) ; } export function toLSPosition ( pos ) { return LSPosition . create ( pos . line - 1 , pos . column ) ; } export function toLSRange ( loc ) { return LSRange . create ( toLSPosition ( loc . start ) , toLSPosition ( loc . end ) ) ; } export function newLocation ( startLine , startColumn , endLine , endColumn ) { let start = { line : startLine , column : startColumn } ; let end = { line : endLine , column : endColumn } ; return { start , end } ; } export function containsPosition ( loc , position ) { return comparePositions ( position , loc . start ) >= 0 && comparePositions ( position , loc . end ) <= 0 ; }