mirror of
https://github.com/github/codeql.git
synced 2026-02-20 00:43:44 +01:00
Merge pull request #61 from github/aibaars/code-nav
Add basic code navigation queries
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
20
ql/src/ide-contextual-queries/localDefinitions.ql
Normal file
20
ql/src/ide-contextual-queries/localDefinitions.ql
Normal 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
|
||||
21
ql/src/ide-contextual-queries/localReferences.ql
Normal file
21
ql/src/ide-contextual-queries/localReferences.ql
Normal 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
|
||||
25
ql/src/ide-contextual-queries/printAst.ql
Normal file
25
ql/src/ide-contextual-queries/printAst.ql
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user