diff --git a/ql/src/printAst.ql b/ql/src/codeql/IDEContextual.qll similarity index 54% rename from ql/src/printAst.ql rename to ql/src/codeql/IDEContextual.qll index 92898a25228..0e58b1d878b 100644 --- a/ql/src/printAst.ql +++ b/ql/src/codeql/IDEContextual.qll @@ -1,19 +1,4 @@ -/** - * @name Print AST - * @description Produces a representation of a file's Abstract Syntax Tree. - * This query is used by the VS Code extension. - * @id ruby/print-ast - * @kind graph - * @tags ide-contextual-queries/print-ast - */ - -import codeql_ruby.printAst -import codeql.files.FileSystem - -/** - * The source file to generate an AST from. - */ -external string selectedSourceFile(); +private import codeql.files.FileSystem /** * Returns an appropriately encoded version of a filename `name` @@ -32,12 +17,3 @@ File getFileBySourceArchiveName(string name) { // before replacing double slashes. name = ("/" + result.getAbsolutePath().replaceAll(":", "_")).replaceAll("//", "/") } - -/** - * Overrides the configuration to print only nodes in the selected source file. - */ -class Cfg extends PrintAstConfiguration { - override predicate shouldPrintNode(Generated::AstNode n) { - n.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) - } -} diff --git a/ql/src/ide-contextual-queries/localDefinitions.ql b/ql/src/ide-contextual-queries/localDefinitions.ql new file mode 100644 index 00000000000..de4ec0ec29b --- /dev/null +++ b/ql/src/ide-contextual-queries/localDefinitions.ql @@ -0,0 +1,20 @@ +/** + * @name Jump-to-definition links + * @description Generates use-definition pairs that provide the data + * for jump-to-definition in the code viewer. + * @kind definitions + * @id ruby/ide-jump-to-definition + * @tags ide-contextual-queries/local-definitions + */ + +import codeql.IDEContextual +import codeql_ruby.AST + +external string selectedSourceFile(); + +from AstNode e, Variable def, string kind +where + e = def.getAnAccess() and + kind = "local variable" and + e.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) +select e, def, kind diff --git a/ql/src/ide-contextual-queries/localReferences.ql b/ql/src/ide-contextual-queries/localReferences.ql new file mode 100644 index 00000000000..a5820983e26 --- /dev/null +++ b/ql/src/ide-contextual-queries/localReferences.ql @@ -0,0 +1,21 @@ +/** + * @name Find-references links + * @description Generates use-definition pairs that provide the data + * for find-references in the code viewer. + * @kind definitions + * @id ruby/ide-find-references + * @tags ide-contextual-queries/local-references + */ + +import codeql.IDEContextual +import codeql_ruby.AST +import codeql_ruby.ast.Variable + +external string selectedSourceFile(); + +from AstNode e, Variable def, string kind +where + e = def.getAnAccess() and + kind = "local variable" and + def.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) +select e, def, kind diff --git a/ql/src/ide-contextual-queries/printAst.ql b/ql/src/ide-contextual-queries/printAst.ql new file mode 100644 index 00000000000..2e9acbc43d4 --- /dev/null +++ b/ql/src/ide-contextual-queries/printAst.ql @@ -0,0 +1,25 @@ +/** + * @name Print AST + * @description Produces a representation of a file's Abstract Syntax Tree. + * This query is used by the VS Code extension. + * @id ruby/print-ast + * @kind graph + * @tags ide-contextual-queries/print-ast + */ + +import codeql_ruby.printAst +import codeql.IDEContextual + +/** + * The source file to generate an AST from. + */ +external string selectedSourceFile(); + +/** + * Overrides the configuration to print only nodes in the selected source file. + */ +class Cfg extends PrintAstConfiguration { + override predicate shouldPrintNode(Generated::AstNode n) { + n.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) + } +}