Sha256: 6abe666563f19c2bf948032a5710199f36c03ca309ab2d227a2e2361c730b725
Contents?: true
Size: 1.08 KB
Versions: 10
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require "benchmark" require "uri" require "cgi" module ThemeCheck module LanguageServer module URIHelper # Will URI.encode a string the same way VS Code would. There are two things # to watch out for: # # 1. VS Code still uses the outdated '%20' for spaces # 2. VS Code prefixes Windows paths with / (so /C:/Users/... is expected) # # Exists because of https://github.com/Shopify/theme-check/issues/360 def file_uri(absolute_path) "file://" + absolute_path .to_s .split('/') .map { |x| CGI.escape(x).gsub('+', '%20') } .join('/') .sub(%r{^/?}, '/') # Windows paths should be prefixed by /c: end def file_path(uri_string) return if uri_string.nil? uri = URI(uri_string) path = CGI.unescape(uri.path) # On Windows, VS Code sends the URLs as file:///C:/... # /C:/1234 is not a valid path in ruby. So we strip the slash. path = path.sub(%r{^/([a-z]:/)}i, '\1') path end end end end
Version data entries
10 entries across 10 versions & 1 rubygems