Module: PlatformosCheck::LanguageServer::URIHelper
- Included in:
- CorrectionExecuteCommandProvider, Diagnostic, DiagnosticsEngine, DocumentChangeCorrector, DocumentLinkProvider, Handler, RunChecksExecuteCommandProvider
- Defined in:
- lib/platformos_check/language_server/uri_helper.rb
Instance Method Summary collapse
- #file_path(uri_string) ⇒ Object
-
#file_uri(absolute_path) ⇒ Object
Will URI.encode a string the same way VS Code would.
Instance Method Details
#file_path(uri_string) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/platformos_check/language_server/uri_helper.rb', line 28 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.sub(%r{^/([a-z]:/)}i, '\1') end |
#file_uri(absolute_path) ⇒ Object
Will URI.encode a string the same way VS Code would. There are two things to watch out for:
-
VS Code still uses the outdated ‘%20’ for spaces
-
VS Code prefixes Windows paths with / (so /C:/Users/… is expected)
Exists because of github.com/Platform-OS/platformos-lsp/issues/360
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/platformos_check/language_server/uri_helper.rb', line 17 def file_uri(absolute_path) return if absolute_path.nil? "file://" + absolute_path .to_s .split('/') .map { |x| CGI.escape(x).gsub('+', '%20') } .join('/') .sub(%r{^/?}, '/') # Windows paths should be prefixed by /c: end |