diff --git a/ql/src/semmle/go/PrintAst.qll b/ql/src/semmle/go/PrintAst.qll index 101303ccb7f..b425d475f15 100644 --- a/ql/src/semmle/go/PrintAst.qll +++ b/ql/src/semmle/go/PrintAst.qll @@ -173,6 +173,20 @@ class ExprNode extends BaseAstNode { } } +/** + * A node representing a `File` + */ +class FileNode extends BaseAstNode { + override File ast; + + /** + * Gets the string representation of this File. Note explicitly using a relative path + * like this rather than absolute as per default for the File class is a workaround for + * a bug with codeql run test, which should replace absolute paths but currently does not. + */ + override string toString() { result = qlClass(ast) + ast.getRelativePath() } +} + query predicate nodes(PrintAstNode node, string key, string value) { node.shouldPrint() and value = node.getProperty(key) diff --git a/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected b/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected index 7e3e021c2da..bd1454dbe7f 100644 --- a/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected +++ b/ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected @@ -1,5 +1,5 @@ input.go: -# 0| [File] /home/chris/codeql-home/codeql-go/ql/test/library-tests/semmle/go/PrintAst/input.go +# 0| [File] library-tests/semmle/go/PrintAst/input.go # 3| 0: [ImportDecl] import declaration # 3| 0: [ImportSpec] import specifier # 3| 0: [StringLit] "fmt"