Skip to content

Commit 83c72c1

Browse files
d10cCopilot
andcommitted
Add per-file comment markers to the postprocessing InputSig
The `--learn` support that follows needs to render inline-expectation comments in the syntax of the file being edited, and a single CodeQL database can mix source languages (e.g. Java plus XML), so the marker must be chosen per file rather than per database. Extend `TestPostProcessing::InputSig` with `getStartCommentMarker(relativePath)` (no result -> that file is left untouched by `--learn`) and a defaulted `getEndCommentMarker(relativePath)` (`none()` by default: line-comment languages render no closing marker; block-comment languages can override it later). Each language's `InlineExpectationsTestQuery.ql` implements `getStartCommentMarker`, gated to that language's own source extensions so that other file types (XML/YAML/HTML/ERB/Razor) extracted into the same database are not rewritten with the wrong syntax. This commit only wires the marker API through the signature and the per-language inputs; nothing consumes it yet, so behavior is unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1adfa307-c48e-43f5-94e3-8286e4a8c083
1 parent 04e3acb commit 83c72c1

16 files changed

Lines changed: 144 additions & 0 deletions

File tree

‎actions/ql/lib/codeql/actions/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ module Impl implements InlineExpectationsTestSig {
2121
":" + endColumn
2222
)
2323
}
24+
25+
bindingset[relativePath]
26+
string getStartCommentMarker(string relativePath) {
27+
relativePath.regexpMatch(".*\\.ya?ml") and
28+
result = "#"
29+
}
2430
}

‎actions/ql/test/utils/ActionsInlineExpectationsTestQuery.ql‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ private module Impl implements T::InlineExpectationsTestSig {
2020
)
2121
}
2222

23+
bindingset[relativePath]
24+
string getStartCommentMarker(string relativePath) {
25+
relativePath.regexpMatch(".*\\.ya?ml") and
26+
result = "#"
27+
}
28+
2329
class ExpectationComment extends Yaml::YamlComment {
2430
string getContents() { result = this.getText() }
2531
}

‎cpp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ module Impl implements InlineExpectationsTestSig {
3535
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
3636
)
3737
}
38+
39+
bindingset[relativePath]
40+
string getStartCommentMarker(string relativePath) {
41+
// C/C++ databases can also contain XML (e.g. `.xml`, `.props`), whose block-comment
42+
// syntax is not yet supported, so we only render for C/C++ sources.
43+
relativePath
44+
.regexpMatch(".*\\.(c|cc|cpp|cxx|cp|c\\+\\+|h|hh|hpp|hxx|h\\+\\+|inl|tcc|ipp|tpp|cu|cuh)") and
45+
result = "//"
46+
}
3847
}

‎csharp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,12 @@ module Impl implements InlineExpectationsTestSig {
5959
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
6060
)
6161
}
62+
63+
bindingset[relativePath]
64+
string getStartCommentMarker(string relativePath) {
65+
// C# databases can also contain XML (e.g. `.csproj`, `.config`) and Razor markup, whose
66+
// comment syntaxes are not yet supported, so we only render for C# sources.
67+
relativePath.regexpMatch(".*\\.(cs|csx)") and
68+
result = "//"
69+
}
6270
}

‎go/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ module Impl implements InlineExpectationsTestSig {
3030
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
3131
)
3232
}
33+
34+
bindingset[relativePath]
35+
string getStartCommentMarker(string relativePath) {
36+
// Go databases can also contain XML, whose block-comment syntax is not yet supported, so
37+
// we only render for Go sources.
38+
relativePath.matches("%.go") and
39+
result = "//"
40+
}
3341
}

‎java/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ module Impl implements InlineExpectationsTestSig {
4545
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
4646
)
4747
}
48+
49+
bindingset[relativePath]
50+
string getStartCommentMarker(string relativePath) {
51+
// Java databases can also contain XML; those files use a different (block) comment
52+
// syntax that is not yet supported, so we only render for Java and Kotlin sources.
53+
relativePath.matches(["%.java", "%.kt"]) and
54+
result = "//"
55+
}
4856
}

‎java/ql/test-kotlin1/TestUtilities/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ module Impl implements InlineExpectationsTestSig {
4242
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
4343
)
4444
}
45+
46+
bindingset[relativePath]
47+
string getStartCommentMarker(string relativePath) {
48+
relativePath.matches(["%.java", "%.kt"]) and
49+
result = "//"
50+
}
4551
}

‎java/ql/test-kotlin2/TestUtilities/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ module Impl implements InlineExpectationsTestSig {
4242
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
4343
)
4444
}
45+
46+
bindingset[relativePath]
47+
string getStartCommentMarker(string relativePath) {
48+
relativePath.matches(["%.java", "%.kt"]) and
49+
result = "//"
50+
}
4551
}

‎javascript/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ module Impl implements InlineExpectationsTestSig {
1818
)
1919
}
2020

21+
bindingset[relativePath]
22+
string getStartCommentMarker(string relativePath) {
23+
// JavaScript databases can also contain HTML, whose block-comment syntax is not yet
24+
// supported, so we only render for line-comment source files.
25+
relativePath.regexpMatch(".*\\.(js|cjs|mjs|jsx|ts|cts|mts|tsx)") and
26+
result = "//"
27+
}
28+
2129
abstract private class ExpectationCommentImpl extends Locatable {
2230
abstract string getContents();
2331

‎python/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ module Impl implements InlineExpectationsTestSig {
1919
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
2020
)
2121
}
22+
23+
bindingset[relativePath]
24+
string getStartCommentMarker(string relativePath) {
25+
// Python databases can also contain XML, whose block-comment syntax is not yet supported,
26+
// so we only render for Python sources.
27+
relativePath.regexpMatch(".*\\.(py|pyi)") and
28+
result = "#"
29+
}
2230
}

0 commit comments

Comments
 (0)