Skip to content

Commit e50d91d

Browse files
author
Luo Zhihao
authored
Merge pull request #17 from liuwei1025:master
feat: ignore replace picomatch
2 parents 7143548 + 5121429 commit e50d91d

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@types/glob": "^7.2.0",
6767
"@types/mocha": "^9.1.0",
6868
"@types/node": "14.x",
69-
"@types/picomatch": "^2.3.0",
7069
"@types/vscode": "^1.65.0",
7170
"@typescript-eslint/eslint-plugin": "^5.16.0",
7271
"@typescript-eslint/parser": "^5.16.0",
@@ -92,6 +91,6 @@
9291
"dot"
9392
],
9493
"dependencies": {
95-
"picomatch": "^2.3.1"
94+
"ignore": "^5.2.4"
9695
}
97-
}
96+
}

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@
9090
resolved "https://registry.npmmirror.com/@types/node/-/node-14.18.12.tgz#0d4557fd3b94497d793efd4e7d92df2f83b4ef24"
9191
integrity sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==
9292

93-
"@types/picomatch@^2.3.0":
94-
version "2.3.0"
95-
resolved "https://registry.npmmirror.com/@types/picomatch/-/picomatch-2.3.0.tgz#75db5e75a713c5a83d5b76780c3da84a82806003"
96-
integrity sha512-O397rnSS9iQI4OirieAtsDqvCj4+3eY1J+EPdNTKuHuRWIfUoGyzX294o8C4KJYaLqgSrd2o60c5EqCU8Zv02g==
97-
9893
"@types/vscode@^1.65.0":
9994
version "1.65.0"
10095
resolved "https://registry.npmmirror.com/@types/vscode/-/vscode-1.65.0.tgz#042dd8d93c32ac62cb826cd0fa12376069d1f448"
@@ -762,6 +757,11 @@ ignore@^5.1.8, ignore@^5.2.0:
762757
resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
763758
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
764759

760+
ignore@^5.2.4:
761+
version "5.2.4"
762+
resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324"
763+
integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==
764+
765765
import-fresh@^3.0.0, import-fresh@^3.2.1:
766766
version "3.3.0"
767767
resolved "https://registry.npmmirror.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"

0 commit comments

Comments
 (0)