Skip to content

Commit 0f7cb45

Browse files
author
beicause
committed
extension: use showSaveDialog to replace saveDir config
allows users to select a path to save the dot or svg file
1 parent 5d2abea commit 0f7cb45

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ vscode extension for generate call graph in [graphviz dot language](https://www.
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

1818
## Configuration
19-
You can configure `ignoreFile`(.callgraphignore by default), `maxDepth` and `saveDir` for svg or dot in settings. See the descriptions in setting.
19+
You can configure `ignoreFile`(.callgraphignore by default), `maxDepth`. See the descriptions in setting.
2020

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

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141
"configuration": {
4242
"title": "CallGraph",
4343
"properties": {
44-
"call-graph.saveDir": {
45-
"type": "string",
46-
"default": "${workspace}",
47-
"description": "the dir where svg and dot file will be saved"
48-
},
4944
"call-graph.ignoreFile": {
5045
"type": "string",
5146
"default": "${workspace}/.callgraphignore",

src/extension.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,34 +113,18 @@ export function activate(context: vscode.ExtensionContext) {
113113
const savedName =
114114
type === 'Incoming' ? 'call_graph_incoming' : 'call_graph_outgoing'
115115
const dotFile = type === 'Incoming' ? dotFileIncoming : dotFileOutgoing
116-
const existed = (p: string) =>
117-
vscode.window.showErrorMessage(`Already exists, please delete it manually.\n${p} `)
118116

119117
if (msg.command === 'download') {
120-
const dir = vscode.workspace
121-
.getConfiguration()
122-
.get<string>('call-graph.saveDir')
123-
?.replace('${workspace}', workspace.fsPath)
124-
let f = dir ? vscode.Uri.file(dir) : workspace
125-
if (!fs.existsSync(f.fsPath))
126-
fs.mkdirSync(f.fsPath, { recursive: true })
127-
128-
switch (msg.type) {
129-
case 'dot':
130-
f = vscode.Uri.joinPath(f, `${savedName}.dot`)
131-
if (!fs.existsSync(f.fsPath)) {
132-
fs.copyFileSync(dotFile.fsPath, f.fsPath)
133-
vscode.window.showInformationMessage(f.fsPath)
134-
} else existed(f.fsPath)
135-
break
136-
case 'svg':
137-
f = vscode.Uri.joinPath(f, `${savedName}.svg`)
138-
if (!fs.existsSync(f.fsPath)) {
139-
fs.writeFileSync(f.fsPath, msg.data)
140-
vscode.window.showInformationMessage(f.fsPath)
141-
} else existed(f.fsPath)
142-
break
118+
const saveFunc = async (fileType: "dot" | "svg") => {
119+
const f = await vscode.window.showSaveDialog({
120+
filters: fileType === "svg" ? { "Image": ["svg"] } : { "Graphviz": ["dot", "gv"] },
121+
defaultUri: vscode.Uri.joinPath(workspace, `${savedName}.${fileType}`)
122+
})
123+
if (!f) return
124+
fs.copyFileSync(dotFile.fsPath, f.fsPath)
125+
vscode.window.showInformationMessage("Call Graph file saved: " + f.fsPath)
143126
}
127+
saveFunc(msg.type)
144128
}
145129
}
146130
const incomingDisposable = vscode.commands.registerCommand(

0 commit comments

Comments
 (0)