Skip to content

Commit 3daf25d

Browse files
committed
Fixes #326, injectable filenames are now set correctly when hovering above an injectable node
1 parent 05019e8 commit 3daf25d

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/commands/generateDependencyInjectionGraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class GenerateDependencyInjectionGraph extends ShowHierarchyBase {
123123
appendNodes([new Node(component.name, this.generatedComponentNode(component), componentFilename, component.filename, false, NodeType.component, componentPosition)]);
124124
component.dependencyInjections.forEach(injectable => {
125125
const injectablePosition = this.graphState.nodePositions[injectable.name];
126-
appendNodes([new Node(injectable.name, injectable.name, injectable.filename.replace(this.workspaceDirectory, ''), component.filename, false, NodeType.injectable, injectablePosition)]);
126+
appendNodes([new Node(injectable.name, injectable.name, injectable.filename.replace(this.workspaceDirectory, ''), injectable.filename, false, NodeType.injectable, injectablePosition)]);
127127
appendEdges([new Edge((this.edges.length + 1).toString(), injectable.name, component.name, ArrowType.injectable)]);
128128
});
129129
});

src/moduleManager.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@ export class ModuleManager {
1919
project.components.set(file.name, file);
2020
}
2121
else if (file instanceof Pipe) {
22-
project.pipes.set(file.name, new NamedEntity(file.name, filename));
22+
project.pipes.set(file.name, file);
2323
}
2424
else if (file instanceof Directive) {
25-
project.directives.set(file.name, new NamedEntity(file.name, filename));
25+
project.directives.set(file.name, file);
2626
}
2727
else if (file instanceof Injectable) {
28-
project.directives.set(file.name, new NamedEntity(file.name, filename));
28+
project.injectables.set(file.name, file);
2929
}
3030
});
31+
project.components.forEach(component => {
32+
component.dependencyInjections.forEach(injectable => {
33+
const filename = project.injectables.get(injectable.name)?.filename;
34+
if (filename !== undefined) {
35+
injectable.filename = filename;
36+
}
37+
});
38+
});
3139
return project;
3240
}
3341

@@ -59,39 +67,38 @@ export class ModuleManager {
5967
regex = /@Component\s*\(\s*(\{.+?\})\s*\)\s*export\s+class\s+(\w+)\s+(.*)/ims;
6068
match = regex.exec(fileContents.toString());
6169
if (match !== null) {
62-
const componentBody = match[1];
6370
const className = match[2];
6471
const component = new Component(className, filename);
6572
const classBody = match[3];
66-
this.enrichComponent(component, classBody, componentBody);
73+
this.enrichComponent(component, classBody);
6774
return component;
6875
}
69-
regex = /@Directive\s*\(\s*(\{.+?\})\s*\)\s*export\s+class\s+(\w+)\s+/ims;
76+
regex = /@Directive\s*\(.*?\)\s*export\s+class\s+(\w+)\s+/ims;
7077
match = regex.exec(fileContents.toString());
7178
if (match !== null) {
72-
return new Directive(match[2], filename);
79+
return new Directive(match[1], filename);
7380
}
74-
regex = /@Pipe\s*\(\s*(\{.+?\})\s*\)\s*export\s+class\s+(\w+)\s+/ims;
81+
regex = /@Pipe\s*\(.*?\)\s*export\s+class\s+(\w+)\s+/ims;
7582
match = regex.exec(fileContents.toString());
7683
if (match !== null) {
77-
return new Pipe(match[2], filename);
84+
return new Pipe(match[1], filename);
7885
}
79-
regex = /@Injectable\s*\(\s*(\{.+?\})\s*\)\s*export\s+class\s+(\w+)\s+/ims;
86+
regex = /@Injectable\s*\(.*?\)\s*export\s+class\s+(\w+)\s+/ims;
8087
match = regex.exec(fileContents.toString());
8188
if (match !== null) {
82-
return new Injectable(match[2], filename);
89+
return new Injectable(match[1], filename);
8390
}
8491
}
8592

86-
private static enrichComponent(component: Component, classBody: string, componentBody: string): void {
93+
private static enrichComponent(component: Component, classBody: string): void {
8794
let regex = /constructor\s*\((.*?)\)/ims;
8895
let match = regex.exec(classBody);
8996
if (match !== null) {
9097
const constructorParameters = match[1];
9198
regex = /\s*\w+\s+\w+\s*:\s*(\w+)[,]*/gims;
9299
match = regex.exec(constructorParameters);
93100
while (match) {
94-
component.dependencyInjections.push(new NamedEntity(match[1], component.filename));
101+
component.dependencyInjections.push(new NamedEntity(match[1], ''));
95102
match = regex.exec(constructorParameters);
96103
}
97104
}

0 commit comments

Comments
 (0)