Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow retrieval of the "relative file path" from the source link map #699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chuckries
Copy link
Contributor

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.

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.
@chuckries
Copy link
Contributor Author

cc @tmat

return true;
}
}
else if (string.Equals(path, file.Path, StringComparison.OrdinalIgnoreCase))
{
Debug.Assert(mappedUri.Suffix.Length == 0);
relativeFilePath = Path.GetFileName(file.Path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, can't use GetFileName.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set relativeFilePath = null here? Since there is no relative path... the caller can use the file name, if they want to.

Base automatically changed from master to main March 17, 2021 22:33
/// Maps specified <paramref name="path"/> to the corresponding URL.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
public bool TryGetUri(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc comment for relativeFilePath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants