Skip to content

Commit 997a622

Browse files
committed
Rust: also implement localReferences.ql
1 parent 45e9c2f commit 997a622

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Provides classes and predicates related to jump-to-definition links
3+
* in the code viewer.
4+
*/
5+
6+
private import codeql.rust.elements.Variable
7+
private import codeql.rust.elements.Locatable
8+
9+
private predicate localVariable(Locatable e, Variable def) { e = def.getAnAccess() }
10+
11+
/**
12+
* Gets an element, of kind `kind`, that element `use` uses, if any.
13+
*/
14+
cached
15+
Variable definitionOf(Locatable use, string kind) {
16+
localVariable(use, result) and kind = "local variable"
17+
}

rust/ql/lib/ide-contextual-queries/localDefinitions.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
* @description Generates use-definition pairs that provide the data
44
* for jump-to-definition in the code viewer.
55
* @kind definitions
6-
* @id rus/ide-jump-to-definition
6+
* @id rust/ide-jump-to-definition
77
* @tags ide-contextual-queries/local-definitions
88
*/
99

1010
import codeql.IDEContextual
1111
import codeql.rust.elements.Variable
1212
import codeql.rust.elements.Locatable
13+
import Definitions
1314

1415
external string selectedSourceFile();
1516

16-
predicate localVariable(Locatable e, Variable def) { e = def.getAnAccess() }
17-
1817
from Locatable e, Variable def, string kind
1918
where
20-
e.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) and
21-
localVariable(e, def) and
22-
kind = "local variable"
19+
def = definitionOf(e, kind) and
20+
e.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile())
2321
select e, def, kind
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @name Find-references links
3+
* @description Generates use-definition pairs that provide the data
4+
* for find-references in the code viewer.
5+
* @kind definitions
6+
* @id rust/ide-find-references
7+
* @tags ide-contextual-queries/local-references
8+
*/
9+
10+
import codeql.IDEContextual
11+
import codeql.rust.elements.Locatable
12+
import codeql.rust.elements.Variable
13+
import Definitions
14+
15+
external string selectedSourceFile();
16+
17+
from Locatable e, Variable def, string kind
18+
where
19+
def = definitionOf(e, kind) and
20+
def.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile())
21+
select e, def, kind

0 commit comments

Comments
 (0)