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

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

Merged
merged 2 commits into from
Sep 23, 2021
Merged

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

merged 2 commits into from
Sep 23, 2021

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

@@ -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 = () => {
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.

src/issues/util.ts Outdated Show resolved Hide resolved
@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.

None yet

2 participants