z_mirror/luapls
git clone https://git.raiguard.me/z_mirror/luapls
d0e4705
main
1package util 2 3import ( 4"errors" 5"fmt" 6"net/url" 7"os" 8"path/filepath" 9 10 protocol"github.com/tliron/glsp/protocol_3_16" 11) 12 13// Ptr returns a pointer to the given value. 14func Ptr [T any ](value T )* T { 15return & value 16} 17 18// FileExists returns whether the given file exists on the filesystem. 19func FileExists (path string )bool { 20_ ,err := os .Stat (path ) 21return err == nil 22} 23 24// URIToPath returns a path from the given URI. 25func URIToPath (uri protocol.URI ) (string ,error ) { 26u ,err := url .ParseRequestURI (uri ) 27if err != nil { 28return "" ,errors .New (fmt .Sprintf ("Failed to parse file URI: %s" ,err )) 29 } 30return u .Path ,nil 31} 32 33// PathToURI returns an absolute URI from a file path. 34func PathToURI (path string ) (protocol.URI ,error ) { 35abs ,err := filepath .Abs (path ) 36if err != nil { 37return "" ,errors .New (fmt .Sprintf ("Failed to convert filepath to URI: %s" ,err )) 38 } 39return "file://" + abs ,nil 40}