Skip to content

Commit 6891a70

Browse files
author
刘威
committed
feat: ignore replace picomatch
1 parent 7143548 commit 6891a70

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ vscode extension for generate call graph in [graphviz dot language](https://www.
1212
1. Open your folder and select a entry function
1313
2. Run `CallGraph.showOutgoingCallGraph` command using `Ctrl+Shift+P` or context menu to show outgoing calls
1414
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
1516

1617
## How it works
1718
It depends `vscode.provideOutgoingCalls` and `vscode.provideIncomingCalls` built-in commands.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@
9292
"dot"
9393
],
9494
"dependencies": {
95-
"picomatch": "^2.3.1"
95+
"ignore": "^5.2.4"
9696
}
97-
}
97+
}

src/extension.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { generateDot } from './dot'
88
import { getHtmlContent } from './html'
99
import * as path from 'path'
1010
import * as fs from 'fs'
11-
import * as pm from 'picomatch'
11+
import ignore from 'ignore'
1212

1313
export const output = vscode.window.createOutputChannel('CallGraph')
1414

@@ -53,13 +53,12 @@ const generateGraph = (
5353
if (ignoreFile && !fs.existsSync(ignoreFile)) ignoreFile = null
5454
const graph = await callNodeFunction(entry[0], item => {
5555
if (ignoreFile === null) return false
56-
const patterns = fs
57-
.readFileSync(ignoreFile)
58-
.toString()
59-
.split('\n')
60-
.filter(str => str.length > 0)
61-
.map(str => path.resolve(workspace.fsPath, str))
62-
return pm(patterns)(item.uri.fsPath)
56+
// working in the current workspace
57+
if (!item.uri.fsPath.startsWith(workspace.fsPath)) return true
58+
const ig = ignore().add(fs.readFileSync(ignoreFile).toString())
59+
const itemPath = item.uri.fsPath.replace(`${workspace.fsPath}/`, '')
60+
const ignored = ig.test(itemPath).ignored
61+
return ignored
6362
})
6463

6564
generateDot(graph, dotFile.fsPath)

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ ignore@^5.1.8, ignore@^5.2.0:
762762
resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
763763
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
764764

765+
ignore@^5.2.4:
766+
version "5.2.4"
767+
resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324"
768+
integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==
769+
765770
import-fresh@^3.0.0, import-fresh@^3.2.1:
766771
version "3.3.0"
767772
resolved "https://registry.npmmirror.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"

0 commit comments

Comments
 (0)