-
Notifications
You must be signed in to change notification settings - Fork 566
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
GitHub permalinks: Deduplicate the line number if the range is one line. #2980
GitHub permalinks: Deduplicate the line number if the range is one line. #2980
Conversation
@@ -492,10 +492,19 @@ export async function createGithubPermalink( | |||
} | |||
} | |||
const pathSegment = uri.path.substring(repository.rootUri.path.length); | |||
const rangeString = range ? `#L${range.start.line + 1}-L${range.end.line + 1}` : ''; | |||
const rangeString = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could theoretically be kept one one line, or shortened by conditionally updating a variable in the main block for createGithubPermalink()
. However, I thought this would be the easiest to read, since it contains the calculation entirely inside a separate block without side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line would look something like this:
const rangeString = range ? `#L${range.start.line + 1}${range.start.line === range.end.line ? '' : `-L${range.end.line + 1}`}` : '';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting it in the same in the main block for createGithubPermalink()
could look like this:
let rangeString = '';
if (range) {
rangeString = `#L${range.start.line + 1}`;
if (range.start.line !== range.end.line) {
rangeString += `-L${range.end.line + 1}`;
}
}
This will generate URLs like: https://github.com/microsoft/vscode-pull-request-github/blob/39d333d9931d685d01078e27c4e6583eda55fc27/src/issues/util.ts#L495 ... instead of: https://github.com/microsoft/vscode-pull-request-github/blob/39d333d9931d685d01078e27c4e6583eda55fc27/src/issues/util.ts#L495-L495
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Just one comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
This will generate URLs like:
https://github.com/microsoft/vscode-pull-request-github/blob/39d333d9931d685d01078e27c4e6583eda55fc27/src/issues/util.ts#L495
... instead of:
https://github.com/microsoft/vscode-pull-request-github/blob/39d333d9931d685d01078e27c4e6583eda55fc27/src/issues/util.ts#L495-L495