-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(GH-24) Allow parsing in tasks mode
- Loading branch information
Showing
21 changed files
with
449 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
require 'uri' | ||
require 'puppet' | ||
|
||
module PuppetLanguageServer | ||
module UriHelper | ||
def self.build_file_uri(path) | ||
path.start_with?('/') ? 'file://' + path : 'file:///' + path | ||
'file://' + Puppet::Util.uri_encode(path.start_with?('/') ? path : '/' + path) | ||
end | ||
|
||
# Compares two URIs and returns the relative path | ||
# | ||
# @param root_uri [String] The root URI to compare to | ||
# @param uri [String] The URI to compare to the root | ||
# @param case_sensitive [Boolean] Whether the path comparison is case senstive or not. Default is true | ||
# @return [String] Returns the relative path string if the URI is indeed a child of the root, otherwise returns nil | ||
def self.relative_uri_path(root_uri, uri, case_sensitive = true) | ||
actual_root = URI(root_uri) | ||
actual_uri = URI(uri) | ||
return nil unless actual_root.scheme == actual_uri.scheme | ||
|
||
# CGI.unescape doesn't handle space rules properly in uri paths | ||
# URI.unescape does, but returns strings in their original encoding | ||
# Mostly safe here as we're only worried about file based URIs | ||
root_path = URI.unescape(actual_root.path) # rubocop:disable Lint/UriEscapeUnescape | ||
uri_path = URI.unescape(actual_uri.path) # rubocop:disable Lint/UriEscapeUnescape | ||
if case_sensitive | ||
return nil unless uri_path.slice(0, root_path.length) == root_path | ||
else | ||
return nil unless uri_path.slice(0, root_path.length).casecmp(root_path).zero? | ||
end | ||
|
||
uri_path.slice(root_path.length..-1) | ||
end | ||
end | ||
end |
Oops, something went wrong.