Skip to content

Commit 3bb631e

Browse files
author
João Monte
authored
Add max depth configuration (#23)
1 parent f184e2e commit 3bb631e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ vscode extension for generate call graph in [graphviz dot language](https://www.
1515
4. Click `save dot file` or `save as svg` in the bottom left corner to save the graph
1616
5. Add `.callgraphignore` file in your project root directory to ignore some files or folders in workspace (the syntax is the same as `.gitignore`)
1717

18+
## Extra configuration
19+
- **Max depth**: You can set the max depth at the `Call-graph: Max Depth` setting in the editor settings session. Note that it applies for both incoming and outgoing call graphs.
20+
1821
## How it works
1922
It depends `vscode.provideOutgoingCalls` and `vscode.provideIncomingCalls` built-in commands( the same with `Show Call Hierarchy` command, not available for some language server ).
2023

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"type": "string",
5151
"default": "${workspace}/.callgraphignore",
5252
"description": "the file that specific paths should ignore"
53+
},
54+
"call-graph.maxDepth": {
55+
"type": "number",
56+
"default": 0,
57+
"description": "the graph max depth. Set to 0 for unlimited depth"
5358
}
5459
}
5560
}

src/call.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ async function getCallNode(
1212
ignore: (item: vscode.CallHierarchyItem) => boolean,
1313
outgoing: Boolean = true
1414
) {
15+
const maxDepth = vscode.workspace
16+
.getConfiguration()
17+
.get<number>('call-graph.maxDepth') || 0
1518
const command = outgoing
1619
? 'vscode.provideOutgoingCalls'
1720
: 'vscode.provideIncomingCalls'
1821
const nodes = new Set<CallHierarchyNode>()
19-
const insertNode = async (node: CallHierarchyNode) => {
22+
const insertNode = async (node: CallHierarchyNode, depth=0) => {
23+
if (maxDepth > 0 && depth >= maxDepth) return
2024
output.appendLine('resolve: ' + node.item.name)
2125
nodes.add(node)
2226
const calls:
@@ -45,7 +49,7 @@ async function getCallNode(
4549
if (isSkip) continue
4650
const child = { item: next, children: [] }
4751
node.children.push(child)
48-
await insertNode(child)
52+
await insertNode(child, depth + 1)
4953
}
5054
}
5155
const graph = { item: entryItem, children: [] as CallHierarchyNode[] }

0 commit comments

Comments
 (0)