Skip to content

Commit 4c4efc0

Browse files
authored
Only add column offsets when they are non-zero for GitHub. (#68)
1 parent a41fef1 commit 4c4efc0

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 3.3.0 - 2025-11-05
11+
12+
### Changed
13+
14+
- Only add column offsets when they are non-zero for GitHub. (#68)
15+
1016
## 3.2.2 - 2025-07-02
1117

1218
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "githubinator",
33
"displayName": "Githubinator",
44
"description": "Quickly open files on Github and other providers. View blame information, copy permalinks and more. See the \"commands\" section of the README for more details.",
5-
"version": "3.2.2",
5+
"version": "3.3.0",
66
"publisher": "chdsbd",
77
"license": "SEE LICENSE IN LICENSE",
88
"icon": "images/logo256.png",

src/providers.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ export function pathJoin(...args: string[]): string {
111111
export class Github extends BaseProvider {
112112
DEFAULT_HOSTNAMES = ["github.com"]
113113
PROVIDER_NAME = "github"
114+
115+
buildLines({ start, end }: ISelection): string {
116+
let line = `L${start.line + 1}`
117+
if (start.character !== 0) {
118+
line += `C${start.character + 1}`
119+
}
120+
line += `-L${end.line + 1}`
121+
if (end.character !== 0) {
122+
line += `C${end.character + 1}`
123+
}
124+
return line
125+
}
114126
async getUrls({
115127
selection,
116128
head,
@@ -121,11 +133,7 @@ export class Github extends BaseProvider {
121133
return null
122134
}
123135
const rootUrl = `https://${repoInfo.hostname}/`
124-
const { start, end } = selection
125-
// Github uses 1-based indexing
126-
const lines = `L${start.line + 1}C${start.character + 1}-L${
127-
end.line + 1
128-
}C${end.character + 1}`
136+
const lines = this.buildLines(selection)
129137
const repoUrl = new url.URL(
130138
path.join(repoInfo.org, repoInfo.repo),
131139
rootUrl,

src/test/suite/providers.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ suite("Github", async () => {
5454
})
5555
const expected = {
5656
blobUrl:
57-
"https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18C1-L25C1",
57+
"https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
5858
blameUrl:
59-
"https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18C1-L25C1",
59+
"https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25",
6060
compareUrl:
6161
"https://github.com/recipeyak/recipeyak/compare/db99a912f5c4bffe11d91e163cd78ed96589611b",
6262
historyUrl:
@@ -87,17 +87,17 @@ suite("Github", async () => {
8787
)
8888
const result = await gh.getUrls({
8989
selection: {
90-
start: { line: 17, character: 0 },
91-
end: { line: 24, character: 0 },
90+
start: { line: 17, character: 4 },
91+
end: { line: 24, character: 5 },
9292
},
9393
head: createBranch("master"),
9494
relativeFilePath: "frontend/src/components/App.tsx",
9595
})
9696
const expected = {
9797
blobUrl:
98-
"https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18C1-L25C1",
98+
"https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18C5-L25C6",
9999
blameUrl:
100-
"https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18C1-L25C1",
100+
"https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18C5-L25C6",
101101
compareUrl:
102102
"https://github.mycompany.com/recipeyak/recipeyak/compare/master",
103103
historyUrl:

0 commit comments

Comments
 (0)