mirror of
https://github.com/github/codeql.git
synced 2026-01-30 06:42:57 +01:00
Add the printAst contextual query
This is similar to the cpp query for printing the AST in the context of VS Code. This PR also includes a small refactoring to extract the `getEncodedFile` predicate to a new `qll` file.
This commit is contained in:
9
ql/src/ideContextual.qll
Normal file
9
ql/src/ideContextual.qll
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Provides classes and predicates related to contextual queries
|
||||
* in the code viewer.
|
||||
*/
|
||||
|
||||
import go
|
||||
|
||||
cached
|
||||
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }
|
||||
@@ -8,12 +8,10 @@
|
||||
*/
|
||||
|
||||
import go
|
||||
import ideContextual
|
||||
|
||||
external string selectedSourceFile();
|
||||
|
||||
cached
|
||||
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }
|
||||
|
||||
from Ident def, Ident use, Entity e
|
||||
where use.uses(e) and def.declares(e) and use.getFile() = getEncodedFile(selectedSourceFile())
|
||||
select use, def, "V"
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
*/
|
||||
|
||||
import go
|
||||
import ideContextual
|
||||
|
||||
external string selectedSourceFile();
|
||||
|
||||
cached
|
||||
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }
|
||||
|
||||
from Ident def, Ident use, Entity e
|
||||
where use.uses(e) and def.declares(e) and def.getFile() = getEncodedFile(selectedSourceFile())
|
||||
select use, def, "V"
|
||||
|
||||
26
ql/src/printAst.ql
Normal file
26
ql/src/printAst.ql
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @name Print AST
|
||||
* @description Outputs a representation of a file's Abstract Syntax Tree. This
|
||||
* query is used by the VS Code extension.
|
||||
* @id go/print-ast
|
||||
* @kind graph
|
||||
* @tags ide-contextual-queries/print-ast
|
||||
*/
|
||||
|
||||
import go
|
||||
import semmle.go.PrintAst
|
||||
import ideContextual
|
||||
|
||||
/**
|
||||
* The source file to generate an AST from.
|
||||
*/
|
||||
external string selectedSourceFile();
|
||||
|
||||
/**
|
||||
* Hook to customize the functions printed by this query.
|
||||
*/
|
||||
class Cfg extends PrintAstConfiguration {
|
||||
override predicate shouldPrintFunction(FuncDef func) {
|
||||
func.getFile() = getEncodedFile(selectedSourceFile())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user