Module: Solargraph::LanguageServer::UriHelpers
- Included in:
- Host, Host::Sources, Message::TextDocument::Base, Message::TextDocument::DocumentSymbol, Message::Workspace::DidChangeWatchedFiles, Message::Workspace::WorkspaceSymbol
- Defined in:
- lib/solargraph/language_server/uri_helpers.rb
Overview
Methods to handle conversions between file URIs and paths.
Class Method Summary collapse
-
.decode(text) ⇒ String
Decode text from a URI path component in LSP.
-
.encode(text) ⇒ String
Encode text to be used as a URI path component in LSP.
-
.file_to_uri(file) ⇒ String
Convert a file path to a URI.
-
.uri_to_file(uri) ⇒ String
Convert a file URI to a path.
Class Method Details
.decode(text) ⇒ String
Decode text from a URI path component in LSP.
44 45 46 |
# File 'lib/solargraph/language_server/uri_helpers.rb', line 44 def decode text CGI.unescape(text) end |
.encode(text) ⇒ String
Encode text to be used as a URI path component in LSP.
32 33 34 35 36 37 38 |
# 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) ⇒ String
Convert a file path to a URI.
24 25 26 |
# 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) ⇒ String
Convert a file URI to a path.
16 17 18 |
# 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 |