module Solargraph::LanguageServer::UriHelpers

Methods to handle conversions between file URIs and paths.

Public Instance Methods

decode(text) click to toggle source

Decode text from a URI path component in LSP.

@param text [String] @return [String]

# File lib/solargraph/language_server/uri_helpers.rb, line 44
def decode text
  CGI.unescape(text)
end
encode(text) click to toggle source

Encode text to be used as a URI path component in LSP.

@param text [String] @return [String]

# File lib/solargraph/language_server/uri_helpers.rb, line 32
def encode text
  CGI.escape(text)
     .gsub('%3A', ':')
     .gsub('%5C', '\\')
     .gsub('%2F', '/')
     .gsub('+', '%20')
end
file_to_uri(file) click to toggle source

Convert a file path to a URI.

@param file [String] @return [String]

# File lib/solargraph/language_server/uri_helpers.rb, line 24
def file_to_uri file
  "file://#{encode(file.gsub(/^([a-z]\:)/i, '/\1'))}"
end
uri_to_file(uri) click to toggle source

Convert a file URI to a path.

@param uri [String] @return [String]

# File lib/solargraph/language_server/uri_helpers.rb, line 16
def uri_to_file uri
  decode(uri).sub(/^file\:(?:\/\/)?/, '').sub(/^\/([a-z]\:)/i, '\1')
end