Merge pull request #61 from github/aibaars/code-nav

Add basic code navigation queries
This commit is contained in:
Arthur Baars
2020-12-07 14:47:43 +01:00
committed by GitHub
4 changed files with 67 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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