mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Add basic code navigation queries
This commit is contained in:
19
ql/src/codeql/IDE.qll
Normal file
19
ql/src/codeql/IDE.qll
Normal file
@@ -0,0 +1,19 @@
|
||||
private import codeql.files.FileSystem
|
||||
|
||||
/**
|
||||
* Returns an appropriately encoded version of a filename `name`
|
||||
* passed by the VS Code extension in order to coincide with the
|
||||
* output of `.getFile()` on locatable entities.
|
||||
*/
|
||||
cached
|
||||
File getFileBySourceArchiveName(string name) {
|
||||
// The name provided for a file in the source archive by the VS Code extension
|
||||
// has some differences from the absolute path in the database:
|
||||
// 1. colons are replaced by underscores
|
||||
// 2. there's a leading slash, even for Windows paths: "C:/foo/bar" ->
|
||||
// "/C_/foo/bar"
|
||||
// 3. double slashes in UNC prefixes are replaced with a single slash
|
||||
// We can handle 2 and 3 together by unconditionally adding a leading slash
|
||||
// before replacing double slashes.
|
||||
name = ("/" + result.getAbsolutePath().replaceAll(":", "_")).replaceAll("//", "/")
|
||||
}
|
||||
20
ql/src/localDefinitions.ql
Normal file
20
ql/src/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.IDE
|
||||
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/localReferences.ql
Normal file
21
ql/src/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.IDE
|
||||
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
|
||||
@@ -8,31 +8,13 @@
|
||||
*/
|
||||
|
||||
import codeql_ruby.printAst
|
||||
import codeql.files.FileSystem
|
||||
import codeql.IDE
|
||||
|
||||
/**
|
||||
* The source file to generate an AST from.
|
||||
*/
|
||||
external string selectedSourceFile();
|
||||
|
||||
/**
|
||||
* Returns an appropriately encoded version of a filename `name`
|
||||
* passed by the VS Code extension in order to coincide with the
|
||||
* output of `.getFile()` on locatable entities.
|
||||
*/
|
||||
cached
|
||||
File getFileBySourceArchiveName(string name) {
|
||||
// The name provided for a file in the source archive by the VS Code extension
|
||||
// has some differences from the absolute path in the database:
|
||||
// 1. colons are replaced by underscores
|
||||
// 2. there's a leading slash, even for Windows paths: "C:/foo/bar" ->
|
||||
// "/C_/foo/bar"
|
||||
// 3. double slashes in UNC prefixes are replaced with a single slash
|
||||
// We can handle 2 and 3 together by unconditionally adding a leading slash
|
||||
// before replacing double slashes.
|
||||
name = ("/" + result.getAbsolutePath().replaceAll(":", "_")).replaceAll("//", "/")
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the configuration to print only nodes in the selected source file.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user