Skip to content

Commit 3d6f857

Browse files
authored
Fix recursive caller nodes (#569)
Avoid recursions in caller tree and remove any previous reference count labels before appending one.
1 parent b488530 commit 3d6f857

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

plugins/cpp/webgui/js/cppInfoTree.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ function (model, viewHandler, util) {
3131
}
3232

3333
function createReferenceCountLabel(label, count) {
34-
return label + '<span class="reference-count">(' + count + ')</span>';
34+
var parsedLabel = $('<div>').append($.parseHTML(label));
35+
parsedLabel.children('span.reference-count').remove();
36+
parsedLabel.append('<span class="reference-count">(' + count + ')</span>');
37+
38+
return parsedLabel.html();
3539
}
3640

3741
function createLabel(astNodeInfo) {
@@ -119,10 +123,12 @@ function (model, viewHandler, util) {
119123
return res;
120124
}
121125

122-
function loadReferenceNodes(parentNode, nodeInfo, refTypes) {
126+
function loadReferenceNodes(parentNode, nodeInfo, refTypes, scratch) {
123127
var res = [];
124128
var fileGroupsId = [];
125129

130+
scratch = scratch || {};
131+
126132
var references = model.cppservice.getReferences(
127133
nodeInfo.id,
128134
parentNode.refType);
@@ -148,6 +154,12 @@ function (model, viewHandler, util) {
148154
});
149155

150156
var fileInfo = model.project.getFileInfo(fileId);
157+
158+
if (parentNode.refType === refTypes['Caller']) {
159+
scratch.visitedNodeIDs =
160+
(scratch.visitedNodeIDs || []).concat(nodeInfo.id);
161+
}
162+
151163
res.push({
152164
id : fileGroupsId[fileId],
153165
name : createReferenceCountLabel(
@@ -161,14 +173,17 @@ function (model, viewHandler, util) {
161173

162174
referenceInFile.forEach(function (reference) {
163175
if (parentNode.refType === refTypes['Caller']) {
176+
var showChildren =
177+
scratch.visitedNodeIDs.indexOf(reference.id) == -1;
164178
res.push({
165179
id : reference.id,
166180
name : createLabel(reference),
167181
nodeInfo : reference,
168182
refType : parentNode.refType,
169183
cssClass : 'icon icon-Method',
170-
hasChildren : true,
171-
getChildren : function () {
184+
hasChildren : showChildren,
185+
getChildren : showChildren
186+
? function () {
172187
var res = [];
173188

174189
//--- Recursive Node ---//
@@ -185,7 +200,9 @@ function (model, viewHandler, util) {
185200
refType : parentNode.refType,
186201
cssClass : parentNode.cssClass,
187202
hasChildren : true,
188-
getChildren : parentNode.getChildren
203+
getChildren : function () {
204+
return loadReferenceNodes(this, reference, refTypes, scratch);
205+
}
189206
});
190207

191208
//--- Call ---//
@@ -206,6 +223,7 @@ function (model, viewHandler, util) {
206223
});
207224
return res;
208225
}
226+
: undefined
209227
});
210228
} else if (parentNode.refType === refTypes['Usage']) {
211229
res.push({

0 commit comments

Comments
 (0)