Merge pull request #262 from aeisenberg/aeisenberg/print-ast

Add the printAst contextual query
This commit is contained in:
Andrew Eisenberg
2020-07-20 11:11:42 -07:00
committed by GitHub
4 changed files with 37 additions and 6 deletions

9
ql/src/ideContextual.qll Normal file
View 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 }

View File

@@ -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"

View File

@@ -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
View 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())
}
}