Module: Rigor::LanguageServer::Uri
- Defined in:
- lib/rigor/language_server/uri.rb
Overview
LSP DocumentUri ↔ filesystem path conversions. v1 supports only ‘file://` URIs; other schemes (e.g. `untitled:`) return nil from `#to_path` so the caller can short-circuit.
Windows drive-letter handling: ‘file:///C:/path` → `C:/path`. The leading slash after the scheme is dropped on Windows; on POSIX it stays. v1 ships POSIX behaviour; Windows specifics land when Windows CI is wired (see design doc § “Open questions”).
Class Method Summary collapse
- .from_path(path) ⇒ Object
-
.to_path(uri) ⇒ String?
Absolute filesystem path for a ‘file://` URI, or nil for unsupported schemes.
Class Method Details
.from_path(path) ⇒ Object
35 36 37 |
# File 'lib/rigor/language_server/uri.rb', line 35 def from_path(path) "#{FILE_SCHEME}#{path}" end |
.to_path(uri) ⇒ String?
Returns absolute filesystem path for a ‘file://` URI, or nil for unsupported schemes.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rigor/language_server/uri.rb', line 22 def to_path(uri) return nil unless uri.is_a?(String) && uri.start_with?(FILE_SCHEME) # Percent-decode at the BYTE level so multi-byte UTF-8 # escapes (`%E6%97%A5` → `日`) reassemble correctly. Each # `%xx` decodes to one raw byte; the result is a byte string # we re-interpret as UTF-8. `delete_prefix` always returns # a String (vs `byteslice` whose RBS return is `String?`). uri.delete_prefix(FILE_SCHEME).b .gsub(/%([0-9A-Fa-f]{2})/) { ::Regexp.last_match(1).hex.chr } .force_encoding(Encoding::UTF_8) end |