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:/pathC:/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

Class Method Details

.from_path(path) ⇒ Object



30
31
32
# File 'lib/rigor/language_server/uri.rb', line 30

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.

Returns:

  • (String, nil)

    absolute filesystem path for a file:// URI, or nil for unsupported schemes.



19
20
21
22
23
24
25
26
27
28
# File 'lib/rigor/language_server/uri.rb', line 19

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