-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathReferencesProcessor.ts
More file actions
59 lines (52 loc) · 1.98 KB
/
Copy pathReferencesProcessor.ts
File metadata and controls
59 lines (52 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { isBrsFile, isXmlFile } from '../../astUtils/reflection';
import { createVisitor, WalkMode } from '../../astUtils/visitors';
import type { BrsFile } from '../../files/BrsFile';
import type { ProvideReferencesEvent, Reference } from '../../interfaces';
export class ReferencesProcessor {
public constructor(
private event: ProvideReferencesEvent
) {
}
public process() {
if (isBrsFile(this.event.file)) {
this.event.references.push(
...this.findVariableReferences(this.event.file)
);
}
}
private findVariableReferences(file: BrsFile) {
const callSiteToken = file.getTokenAt(this.event.position);
let locations = [] as Reference[];
const searchFor = callSiteToken.text.toLowerCase();
for (const scope of this.event.scopes) {
const processedFiles = new Set<BrsFile>();
for (const file of scope.getAllFiles()) {
if (isXmlFile(file) || processedFiles.has(file)) {
continue;
}
processedFiles.add(file);
file.ast.walk(createVisitor({
VariableExpression: (e) => {
if (e.name.text.toLowerCase() === searchFor) {
locations.push({
srcPath: file.srcPath,
range: e.range
});
}
},
AssignmentStatement: (e) => {
if (e.name.text.toLowerCase() === searchFor) {
locations.push({
srcPath: file.srcPath,
range: e.name.range
});
}
}
}), {
walkMode: WalkMode.visitAllRecursive
});
}
}
return locations;
}
}