Allow retrieval of the "relative file path" from the source link map#699
Open
chuckries wants to merge 1 commit intodotnet:mainfrom
Open
Allow retrieval of the "relative file path" from the source link map#699chuckries wants to merge 1 commit intodotnet:mainfrom
chuckries wants to merge 1 commit intodotnet:mainfrom
Conversation
It can be helpful for consumers of the Source Link to know what portion of the file path provided to the query is substituted into the URL. One example is for building a heuristic file path on disk to store the downloaded source link file to. This relative path can give end users more context on where the file is located in the original repository. This change add a new TryGetUri overload that provides the "relative file path" as another out param. It also updates the tests to add coverage for this.
Contributor
Author
|
cc @tmat |
chuckries
commented
Feb 1, 2021
| else if (string.Equals(path, file.Path, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| Debug.Assert(mappedUri.Suffix.Length == 0); | ||
| relativeFilePath = Path.GetFileName(file.Path); |
Contributor
Author
There was a problem hiding this comment.
@tmat Mac tests don't like this because the test input is windows style paths and I'm assuming Path.GetFileName(...) looks for forward slashes on that OS.
should this just be something like
int lastSeparatorIndex = file.Path.LastIndexOfAny(new[] { '\\', '/' });
relativeFilePath = lastSeparatorIndex > 0 ? file.Path.Substring(lastSeparatorIndex + 1) : file.Path;
Member
There was a problem hiding this comment.
Can we set relativeFilePath = null here? Since there is no relative path... the caller can use the file name, if they want to.
tmat
reviewed
Jul 27, 2021
| /// Maps specified <paramref name="path"/> to the corresponding URL. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception> | ||
| public bool TryGetUri( |
Member
There was a problem hiding this comment.
Add doc comment for relativeFilePath
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It can be helpful for consumers of the Source Link to know what portion
of the file path provided to the query is substituted into the URL. One
example is for building a heuristic file path on disk to store the
downloaded source link file to. This relative path can give end users
more context on where the file is located in the original repository.
This change add a new TryGetUri overload that provides the "relative
file path" as another out param. It also updates the tests to add
coverage for this.