Skip to content

GitHub permalinks: Deduplicate the line number if the range is one line.#2980

Merged
alexr00 merged 2 commits intomicrosoft:mainfrom
lgarron:deduplicate-single-line-range
Sep 23, 2021
Merged

GitHub permalinks: Deduplicate the line number if the range is one line.#2980
alexr00 merged 2 commits intomicrosoft:mainfrom
lgarron:deduplicate-single-line-range

Conversation

@lgarron
Copy link
Contributor

@lgarron lgarron commented Sep 1, 2021

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

Copy link
Contributor Author

@lgarron lgarron Sep 1, 2021

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.

Copy link
Contributor Author

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}`}` : '';

Copy link
Contributor Author

@lgarron lgarron Sep 1, 2021

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}`;
  }
}

Copy link
Member

@alexr00 alexr00 left a 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.

@alexr00 alexr00 added this to the September 2021 milestone Sep 23, 2021
Copy link
Member

@alexr00 alexr00 left a 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!

@alexr00 alexr00 merged commit 408d9f4 into microsoft:main Sep 23, 2021
@lgarron lgarron deleted the deduplicate-single-line-range branch October 2, 2021 02:05
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.

2 participants