Skip to content

Commit 79d7038

Browse files
author
beicause
committed
Merge remote-tracking branch 'origin/master' into pr/sulfurandcu/19-3
2 parents 6662c02 + 7cda40e commit 79d7038

File tree

10 files changed

+2373
-1405
lines changed

10 files changed

+2373
-1405
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## [1.1.3] 2024-03-18
4+
5+
- fix the file path label in graph, now it's the corresponding file system path instead of encoded Uri.
6+
- now the saved svg fits its original size, not moved or scaled.
7+
38
## [1.1.3] 2023-10-26
49

510
- use [node-ignore](https://www.npmjs.com/package/ignore) for .callgraphignore to fix relative issues([#17](https://github.com/beicause/call-graph/pull/17))

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# call-graph
22

3-
![call-graph](https://raw.githubusercontent.com/beicause/call-graph/master/images/call-graph.png)
3+
![call-graph](./images/call_graph_outgoing.png)
44
vscode extension for generate call graph in [graphviz dot language](https://www.graphviz.org/doc/info/lang.html), based on vscode call hierarchy language feature.
55

66
## Features
77

8-
* generate call graph in dot language and preview.
8+
* generate call graph in graphviz dot language and preview.
99
* save graph as dot or svg file
1010

1111
## Quick start
1212
1. Open your folder and select a entry function
13-
2. Run `CallGraph.showOutgoingCallGraph` command using `Ctrl+Shift+P` or context menu to show outgoing calls
14-
3. Or Run `CallGraph.showIncomingCallGraph` command using `Ctrl+Shift+P` or context menu to show incoming calls
15-
4. Add `.callgraphignore` file in your project root directory to ignore some files or folders
13+
2. Run `CallGraph.showOutgoingCallGraph` command using context menu or `Ctrl+Shift+P` to show outgoing calls
14+
3. Or Run `CallGraph.showIncomingCallGraph` command using context menu or `Ctrl+Shift+P` to show incoming calls
15+
4. Click `save dot file` or `save as svg` in the bottom left corner to save the graph
16+
5. Add `.callgraphignore` file in your project root directory to ignore some files or folders in workspace (the syntax is the same as `.gitignore`)
1617

1718
## How it works
1819
It depends `vscode.provideOutgoingCalls` and `vscode.provideIncomingCalls` built-in commands( the same with `Show Call Hierarchy` command, not available for some language server ).

images/call-graph.png

-777 KB
Binary file not shown.

images/call_graph_outgoing.png

160 KB
Loading

package-lock.json

Lines changed: 2350 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "call-graph",
33
"displayName": "Call Graph",
44
"description": "call graph for vscode",
5-
"version": "1.1.3",
5+
"version": "1.1.4",
66
"publisher": "LuoZhihao",
77
"engines": {
88
"vscode": "^1.65.0"
@@ -55,10 +55,10 @@
5555
}
5656
},
5757
"scripts": {
58-
"vscode:prepublish": "yarn run compile",
58+
"vscode:prepublish": "npm run compile",
5959
"compile": "tsc -p ./",
6060
"watch": "tsc -watch -p ./",
61-
"pretest": "yarn run compile && yarn run lint",
61+
"pretest": "npm run compile && npm run lint",
6262
"lint": "eslint src --ext ts",
6363
"test": "node ./out/test/runTest.js"
6464
},
@@ -80,7 +80,7 @@
8080
"url": "https://github.com/beicause/call-graph.git"
8181
},
8282
"license": "Apache",
83-
"icon": "images/call-graph.png",
83+
"icon": "images/call_graph_outgoing.png",
8484
"bugs": {
8585
"url": "https://github.com/beicause/call-graph/issues"
8686
},

src/dot.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import { CallHierarchyNode } from "./call"
22
import * as fs from 'fs'
33
import * as vscode from 'vscode'
44
import { isDeepStrictEqual } from "util"
5-
import * as path from "path"
65
import { output } from "./extension"
76

87
export function generateDot(graph: CallHierarchyNode,path:string) {
98
const dot = new Graph()
10-
const root = vscode.workspace.workspaceFolders?.[0].uri.toString()??''
9+
const root = vscode.workspace.workspaceFolders?.[0].uri.fsPath??''
1110
dot.addAttr({ rankdir: "LR" })
1211
const getNode = (n: CallHierarchyNode) => {
1312
return {
14-
name: `"${n.item.uri}#${n.item.name}@${n.item.range.start.line}:${n.item.range.start.character}"`,
13+
name: `"${n.item.uri.fsPath}#${n.item.name}@${n.item.range.start.line}:${n.item.range.start.character}"`,
1514
attr: { label: n.item.name },
16-
subgraph: { name: n.item.uri.toString(), attr: { label: n.item.uri.toString().replace(root,'${workspace}') } },
15+
subgraph: { name: n.item.uri.fsPath, attr: { label: n.item.uri.fsPath.replace(root,'${workspace}') } },
1716
next: []
1817
} as Node
1918
}

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function activate(context: vscode.ExtensionContext) {
114114
type === 'Incoming' ? 'call_graph_incoming' : 'call_graph_outgoing'
115115
const dotFile = type === 'Incoming' ? dotFileIncoming : dotFileOutgoing
116116
const existed = (p: string) =>
117-
vscode.window.showErrorMessage(`Already exists.\n${p} `)
117+
vscode.window.showErrorMessage(`Already exists, please delete it manually.\n${p} `)
118118

119119
if (msg.command === 'download') {
120120
const dir = vscode.workspace

src/html.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function getHtmlContent(dot?:string){
1717
<button id="downloadDot">save dot file</button>
1818
<button id="downloadSvg">save as svg</button>
1919
</div>
20+
<div id="hide" style="display: none;"><div/>
2021
</body>
2122
<script>
2223
(async function () {
@@ -25,12 +26,12 @@ export function getHtmlContent(dot?:string){
2526
vscode.setState(dot)
2627
const res =await (await fetch(dot)).text()
2728
d3.select('#app').graphviz().renderDot(res)
28-
29-
29+
d3.select('#hide').graphviz({zoom:false}).renderDot(res)
3030
3131
d3.select('#downloadSvg').on('click',()=>{
3232
const serializer = new XMLSerializer()
33-
const svg = serializer.serializeToString(d3.select('svg').node())
33+
// The svg in #app may have been scaled or moved, use #hide
34+
const svg = serializer.serializeToString(d3.select('#hide>svg').node())
3435
3536
vscode.postMessage({
3637
command: 'download',

0 commit comments

Comments
 (0)