Skip to content

Commit f2c7c41

Browse files
Merge pull request #2406 from Marcono1234/location-url-column
Include column numbers in location URLs
2 parents add3296 + 152e194 commit f2c7c41

File tree

13 files changed

+100
-79
lines changed

13 files changed

+100
-79
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [UNRELEASED]
44

5+
- Links to code on GitHub now include column numbers as well as line numbers. [#2406](https://github.com/github/vscode-codeql/pull/2406)
56
- No longer highlight trailing commas for jump to definition. [#2615](https://github.com/github/vscode-codeql/pull/2615)
67

78
## 1.8.8 - 17 July 2023

extensions/ql-vscode/src/common/bqrs-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,7 @@ export function tryGetRemoteLocation(
142142
fileLink,
143143
resolvableLocation.startLine,
144144
resolvableLocation.endLine,
145+
resolvableLocation.startColumn,
146+
resolvableLocation.endColumn,
145147
);
146148
}

extensions/ql-vscode/src/common/location-link-utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ export function createRemoteFileRef(
44
fileLink: FileLink,
55
startLine?: number,
66
endLine?: number,
7+
startColumn?: number,
8+
endColumn?: number,
79
): string {
8-
if (startLine && endLine && startLine !== endLine) {
10+
if (
11+
startColumn &&
12+
endColumn &&
13+
startLine &&
14+
endLine &&
15+
// Verify that location information is valid; otherwise highlighting might be broken
16+
((startLine === endLine && startColumn < endColumn) || startLine < endLine)
17+
) {
18+
// This relies on column highlighting of new code view on GitHub
19+
return `${fileLink.fileLinkPrefix}/${fileLink.filePath}#L${startLine}C${startColumn}-L${endLine}C${endColumn}`;
20+
} else if (startLine && endLine && startLine < endLine) {
921
return `${fileLink.fileLinkPrefix}/${fileLink.filePath}#L${startLine}-L${endLine}`;
1022
} else if (startLine) {
1123
return `${fileLink.fileLinkPrefix}/${fileLink.filePath}#L${startLine}`;

extensions/ql-vscode/src/variant-analysis/markdown-generation.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ function generateMarkdownForInterpretedResult(
148148
lines.push(
149149
createMarkdownRemoteFileRef(
150150
interpretedResult.fileLink,
151-
interpretedResult.highlightedRegion?.startLine,
152-
interpretedResult.highlightedRegion?.endLine,
151+
interpretedResult.highlightedRegion,
153152
),
154153
);
155154
lines.push("");
@@ -250,8 +249,7 @@ function generateMarkdownForAlertMessage(
250249
} else if (token.t === "location") {
251250
alertMessage += createMarkdownRemoteFileRef(
252251
token.location.fileLink,
253-
token.location.highlightedRegion?.startLine,
254-
token.location.highlightedRegion?.endLine,
252+
token.location.highlightedRegion,
255253
token.text,
256254
);
257255
}
@@ -275,8 +273,7 @@ function generateMarkdownForPathResults(
275273
const threadFlow = codeFlow.threadFlows[i];
276274
const link = createMarkdownRemoteFileRef(
277275
threadFlow.fileLink,
278-
threadFlow.highlightedRegion?.startLine,
279-
threadFlow.highlightedRegion?.endLine,
276+
threadFlow.highlightedRegion,
280277
);
281278
pathLines.push(`${listNumber}. ${link}`);
282279

@@ -361,13 +358,18 @@ function generateMarkdownForRawTableCell(
361358
*/
362359
export function createMarkdownRemoteFileRef(
363360
fileLink: FileLink,
364-
startLine?: number,
365-
endLine?: number,
361+
region?: HighlightedRegion,
366362
linkText?: string,
367363
): string {
368364
const markdownLink = `[${
369365
linkText || fileLink.filePath
370-
}](${createRemoteFileRef(fileLink, startLine, endLine)})`;
366+
}](${createRemoteFileRef(
367+
fileLink,
368+
region?.startLine,
369+
region?.endLine,
370+
region?.startColumn,
371+
region?.endColumn,
372+
)})`;
371373
return markdownLink;
372374
}
373375

extensions/ql-vscode/src/view/common/FileCodeSnippet/CodeSnippetMessage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export const CodeSnippetMessage = ({
7373
token.location.fileLink,
7474
token.location.highlightedRegion?.startLine,
7575
token.location.highlightedRegion?.endLine,
76+
token.location.highlightedRegion?.startColumn,
77+
token.location.highlightedRegion?.endColumn,
7678
)}
7779
>
7880
{token.text}

extensions/ql-vscode/src/view/common/FileCodeSnippet/FileCodeSnippet.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const FileCodeSnippet = ({
6565
fileLink,
6666
highlightedRegion?.startLine || startingLine,
6767
highlightedRegion?.endLine || endingLine,
68+
highlightedRegion?.startColumn,
69+
highlightedRegion?.endColumn,
6870
);
6971

7072
if (!codeSnippet) {

extensions/ql-vscode/test/unit-tests/common/location.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("getting links to remote (GitHub) locations", () => {
8787
);
8888

8989
expect(link).toEqual(
90-
"https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194-L237",
90+
"https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194C18-L237C1",
9191
);
9292
});
9393

@@ -129,7 +129,7 @@ describe("getting links to remote (GitHub) locations", () => {
129129
);
130130

131131
expect(link).toEqual(
132-
"https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194-L237",
132+
"https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194C18-L237C1",
133133
);
134134
});
135135
});

extensions/ql-vscode/test/unit-tests/data/markdown-generation/interpreted-results/path-problem/expected/result-1-github-codeql.md

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

extensions/ql-vscode/test/unit-tests/data/markdown-generation/interpreted-results/path-problem/expected/result-2-meteor-meteor.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### meteor/meteor
22

3-
[npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
3+
[npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C28-L259C62)
44

55
<pre><code class="javascript"> if (isWindows()) {
66
//set for the current session and beyond
@@ -9,46 +9,46 @@
99
}
1010
</code></pre>
1111

12-
*This shell command depends on an uncontrolled [absolute path](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39).*
12+
*This shell command depends on an uncontrolled [absolute path](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39C20-L39C61).*
1313

1414
#### Paths
1515

1616
<details>
1717
<summary>Path with 11 steps</summary>
1818

19-
1. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39)
19+
1. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39C20-L39C61)
2020
<pre><code class="javascript">
2121
const meteorLocalFolder = '.meteor';
2222
const meteorPath = <strong>path.resolve(rootPath, meteorLocalFolder)</strong>;
2323

2424
module.exports = {
2525
</code></pre>
2626

27-
2. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39)
27+
2. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39C7-L39C61)
2828
<pre><code class="javascript">
2929
const meteorLocalFolder = '.meteor';
3030
const <strong>meteorPath = path.resolve(rootPath, meteorLocalFolder)</strong>;
3131

3232
module.exports = {
3333
</code></pre>
3434

35-
3. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L44)
35+
3. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L44C3-L44C13)
3636
<pre><code class="javascript"> METEOR_LATEST_VERSION,
3737
extractPath: rootPath,
3838
<strong>meteorPath</strong>,
3939
release: process.env.INSTALL_METEOR_VERSION || METEOR_LATEST_VERSION,
4040
rootPath,
4141
</code></pre>
4242

43-
4. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L12)
43+
4. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L12C3-L12C13)
4444
<pre><code class="javascript">const os = require('os');
4545
const {
4646
<strong>meteorPath</strong>,
4747
release,
4848
startedPath,
4949
</code></pre>
5050

51-
5. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L11-L23)
51+
5. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L11C7-L23C27)
5252
<pre><code class="javascript">const tmp = require('tmp');
5353
const os = require('os');
5454
const <strong>{</strong>
@@ -68,47 +68,47 @@
6868
const {
6969
</code></pre>
7070

71-
6. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
71+
6. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C42-L259C52)
7272
<pre><code class="javascript"> if (isWindows()) {
7373
//set for the current session and beyond
7474
child_process.execSync(`setx path "${<strong>meteorPath</strong>}/;%path%`);
7575
return;
7676
}
7777
</code></pre>
7878

79-
7. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
79+
7. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C42-L259C52)
8080
<pre><code class="javascript"> if (isWindows()) {
8181
//set for the current session and beyond
8282
child_process.execSync(`setx path "${<strong>meteorPath</strong>}/;%path%`);
8383
return;
8484
}
8585
</code></pre>
8686

87-
8. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
87+
8. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C42-L259C52)
8888
<pre><code class="javascript"> if (isWindows()) {
8989
//set for the current session and beyond
9090
child_process.execSync(`setx path "${<strong>meteorPath</strong>}/;%path%`);
9191
return;
9292
}
9393
</code></pre>
9494

95-
9. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
95+
9. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C42-L259C52)
9696
<pre><code class="javascript"> if (isWindows()) {
9797
//set for the current session and beyond
9898
child_process.execSync(`setx path "${<strong>meteorPath</strong>}/;%path%`);
9999
return;
100100
}
101101
</code></pre>
102102

103-
10. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
103+
10. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C42-L259C52)
104104
<pre><code class="javascript"> if (isWindows()) {
105105
//set for the current session and beyond
106106
child_process.execSync(`setx path "${<strong>meteorPath</strong>}/;%path%`);
107107
return;
108108
}
109109
</code></pre>
110110

111-
11. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
111+
11. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C28-L259C62)
112112
<pre><code class="javascript"> if (isWindows()) {
113113
//set for the current session and beyond
114114
child_process.execSync(<strong>`setx path "${meteorPath}/;%path%`</strong>);
@@ -121,15 +121,15 @@
121121
<details>
122122
<summary>Path with 2 steps</summary>
123123

124-
1. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39)
124+
1. [npm-packages/meteor-installer/config.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/config.js#L39C20-L39C61)
125125
<pre><code class="javascript">
126126
const meteorLocalFolder = '.meteor';
127127
const meteorPath = <strong>path.resolve(rootPath, meteorLocalFolder)</strong>;
128128

129129
module.exports = {
130130
</code></pre>
131131

132-
2. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259)
132+
2. [npm-packages/meteor-installer/install.js](https://github.com/meteor/meteor/blob/73b538fe201cbfe89dd0c709689023f9b3eab1ec/npm-packages/meteor-installer/install.js#L259C28-L259C62)
133133
<pre><code class="javascript"> if (isWindows()) {
134134
//set for the current session and beyond
135135
child_process.execSync(<strong>`setx path "${meteorPath}/;%path%`</strong>);

extensions/ql-vscode/test/unit-tests/data/markdown-generation/interpreted-results/problem/expected/result-1-github-codeql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### github/codeql
22

3-
[javascript/extractor/tests/regexp/input/multipart.js](https://github.com/github/codeql/blob/d094bbc06d063d0da8d0303676943c345e61de53/javascript/extractor/tests/regexp/input/multipart.js#L17-L20)
3+
[javascript/extractor/tests/regexp/input/multipart.js](https://github.com/github/codeql/blob/d094bbc06d063d0da8d0303676943c345e61de53/javascript/extractor/tests/regexp/input/multipart.js#L17C6-L20C6)
44

55
<pre><code class="javascript">
66
var bad95 = new RegExp(

extensions/ql-vscode/test/unit-tests/data/markdown-generation/interpreted-results/problem/expected/result-2-meteor-meteor.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### meteor/meteor
22

3-
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L415)
3+
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L415C41-L415C48)
44

55
<pre><code class="javascript"> /g,hashElement);
66
*/
@@ -13,7 +13,7 @@
1313

1414
----------------------------------------
1515

16-
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L523)
16+
[packages/deprecated/markdown/showdown.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/packages/deprecated/markdown/showdown.js#L523C58-L523C61)
1717

1818
<pre><code class="javascript"> // Build a regex to find HTML tags and comments. See Friedl's
1919
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
@@ -26,7 +26,7 @@
2626

2727
----------------------------------------
2828

29-
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9)
29+
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9C24-L9C38)
3030

3131
<pre><code class="javascript">// ## Parser utilities
3232

@@ -39,15 +39,15 @@ pp.strictDirective = function(start) {
3939

4040
----------------------------------------
4141

42-
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9)
42+
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9C43-L9C57)
4343

4444
<pre><code class="javascript">const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/</code></pre>
4545

4646
*This part of the regular expression may cause exponential backtracking on strings starting with '"' and containing many repetitions of '\!'.*
4747

4848
----------------------------------------
4949

50-
[app/src/main/AndroidManifest.xml](https://github.com/AlexRogalskiy/android-nrf-toolbox/blob/034cf3aa7d2a3a4145177de32546ca518a462a66/app/src/main/AndroidManifest.xml#L239-L249)
50+
[app/src/main/AndroidManifest.xml](https://github.com/AlexRogalskiy/android-nrf-toolbox/blob/034cf3aa7d2a3a4145177de32546ca518a462a66/app/src/main/AndroidManifest.xml#L239C3-L249C15)
5151

5252
<pre><code class="javascript"> &lt;/service&gt;
5353

0 commit comments

Comments
 (0)