Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add relationship between core entities to make it persistable in database #195

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f83fee2
added tree structure with relationship starter skeleton
shivasurya Feb 1, 2025
f9c0073
:ship: added relationship via tree datastructure
shivasurya Feb 2, 2025
c8ef06e
:ship: add processed tree nodes
shivasurya Feb 3, 2025
c3c47dc
refactor: optimize construct.go and move to tree based structure and …
shivasurya Feb 3, 2025
4e43a59
remove method name extraction logic
shivasurya Feb 3, 2025
ff15dac
refactor: move parsing logic to lang parser package - part 1 🚂
shivasurya Feb 5, 2025
0948785
refactor: move parsing logic to lang parser package - part 1 🚂
shivasurya Feb 5, 2025
18765ac
refactor: part 2 move the lang independent parsing
shivasurya Feb 6, 2025
10fb843
refactor: part 3 move object creation expr
shivasurya Feb 6, 2025
71b97a6
refactor: fixed log package
shivasurya Feb 6, 2025
b20acc6
refactor: revamp parsing logic and test
shivasurya Feb 6, 2025
df6dce8
refactor: add relevant model
shivasurya Feb 8, 2025
1dae059
refactor: add modifiable class
shivasurya Feb 9, 2025
26b7f0e
Merge branch 'main' into shiva/graph-relation
shivasurya Feb 12, 2025
00939a3
moved to relational tree approach
shivasurya Feb 15, 2025
b1f39b9
refactor: add db layer table statements
shivasurya Feb 15, 2025
6716504
refactor: datastructure normalization before persist :sad: most tough…
shivasurya Feb 15, 2025
db46405
refactor: datastructure normalization before persist :sad: most tough…
shivasurya Feb 16, 2025
098ffd8
refactor: datastructure normalization before persist :sad: most tough…
shivasurya Feb 17, 2025
9544aa4
refactor: refining relationship nodes
shivasurya Feb 19, 2025
e667178
refactor: removed unwanted code
shivasurya Feb 19, 2025
395fad9
add sqlite db for relational support
shivasurya Feb 19, 2025
d2657ee
fix: added missing semicolon in db schema
shivasurya Feb 21, 2025
dbf8e47
fix: few db column fixes and requires refactor on the goroutine level…
shivasurya Feb 21, 2025
4fc9c3b
removed duplicates while processing ast nodes
shivasurya Feb 23, 2025
e320d74
:rocket: finally db is ready and parsing with relationship is happening
shivasurya Feb 24, 2025
17d989f
fix lint issue
shivasurya Feb 24, 2025
b7ac6f7
persisted important entitiy into database💿
shivasurya Feb 24, 2025
c2097d9
Merge branch 'main' into shiva/graph-relation
shivasurya Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ docs/public/rules/*.json
.DS_Store

node_modules

test-src/android/pathfinder.db
2 changes: 1 addition & 1 deletion sourcecode-parser/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ linters:
- tagliatelle

# Test-related checks. All of them are good.
- tenv
- usetesting
- testableexamples
- thelper
- tparallel
Expand Down
10 changes: 5 additions & 5 deletions sourcecode-parser/cmd/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

"github.com/owenrumney/go-sarif/v2/sarif"

"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph"
utilities "github.com/shivasurya/code-pathfinder/sourcecode-parser/util"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -61,11 +61,11 @@
}
os.Exit(1)
}
codeGraph := initializeProject(projectInput)
treeHolder, db := initializeProject(projectInput)

Check warning on line 64 in sourcecode-parser/cmd/ci.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/ci.go#L64

Added line #L64 was not covered by tests
for _, rule := range ruleset {
queryInput := ParseQuery(rule)
rulesetResult := make(map[string]interface{})
result, err := processQuery(queryInput.Query, codeGraph, output)
result, err := processQuery(queryInput.Query, treeHolder, db, output)

Check warning on line 68 in sourcecode-parser/cmd/ci.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/ci.go#L68

Added line #L68 was not covered by tests

if output == "json" || output == "sarif" {
var resultObject map[string]interface{}
Expand All @@ -85,7 +85,7 @@
// TODO: Add sarif file support
if output == "json" {
if outputFile != "" {
if graph.IsGitHubActions() {
if utilities.IsGitHubActions() {

Check warning on line 88 in sourcecode-parser/cmd/ci.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/ci.go#L88

Added line #L88 was not covered by tests
// append GITHUB_WORKSPACE to output file path
outputFile = os.Getenv("GITHUB_WORKSPACE") + "/" + outputFile
}
Expand Down Expand Up @@ -116,7 +116,7 @@
fmt.Println("Error generating sarif report: ", err)
os.Exit(1)
}
if graph.IsGitHubActions() {
if utilities.IsGitHubActions() {

Check warning on line 119 in sourcecode-parser/cmd/ci.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/ci.go#L119

Added line #L119 was not covered by tests
// append GITHUB_WORKSPACE to output file path
outputFile = os.Getenv("GITHUB_WORKSPACE") + "/" + outputFile
}
Expand Down
47 changes: 26 additions & 21 deletions sourcecode-parser/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"github.com/fatih/color"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/analytics"
parser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/db"
"github.com/shivasurya/code-pathfinder/sourcecode-parser/model"
tree "github.com/shivasurya/code-pathfinder/sourcecode-parser/tree"
utilities "github.com/shivasurya/code-pathfinder/sourcecode-parser/util"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -71,16 +74,17 @@
queryCmd.Flags().String("query-file", "", "File containing query to execute")
}

func initializeProject(project string) *graph.CodeGraph {
codeGraph := graph.NewCodeGraph()
func initializeProject(project string) ([]*model.TreeNode, *db.StorageNode) {
treeHolder := []*model.TreeNode{}
db := db.NewStorageNode(project)

Check warning on line 79 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L77-L79

Added lines #L77 - L79 were not covered by tests
if project != "" {
codeGraph = graph.Initialize(project)
treeHolder = tree.Initialize(project)

Check warning on line 81 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L81

Added line #L81 was not covered by tests
}
return codeGraph
return treeHolder, db

Check warning on line 83 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L83

Added line #L83 was not covered by tests
}

func executeCLIQuery(project, query, output string, stdin bool) (string, error) {
codeGraph := initializeProject(project)
treeHolder, db := initializeProject(project)

Check warning on line 87 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L87

Added line #L87 was not covered by tests

if stdin {
// read from stdin
Expand All @@ -97,7 +101,7 @@
if strings.HasPrefix(input, ":quit") {
return "Okay, Bye!", nil
}
result, err := processQuery(input, codeGraph, output)
result, err := processQuery(input, treeHolder, db, output)

Check warning on line 104 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L104

Added line #L104 was not covered by tests
if err != nil {
analytics.ReportEvent(analytics.ErrorProcessingQuery)
err := fmt.Errorf("PathFinder Query syntax error: %w", err)
Expand All @@ -108,7 +112,7 @@
}
} else {
// read from command line
result, err := processQuery(query, codeGraph, output)
result, err := processQuery(query, treeHolder, db, output)

Check warning on line 115 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L115

Added line #L115 was not covered by tests
if err != nil {
analytics.ReportEvent(analytics.ErrorProcessingQuery)
return "", fmt.Errorf("PathFinder Query syntax error: %w", err)
Expand All @@ -117,7 +121,7 @@
}
}

func processQuery(input string, codeGraph *graph.CodeGraph, output string) (string, error) {
func processQuery(input string, treeHolder []*model.TreeNode, db *db.StorageNode, output string) (string, error) {

Check warning on line 124 in sourcecode-parser/cmd/query.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'treeHolder' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 124 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L124

Added line #L124 was not covered by tests
fmt.Println("Executing query: " + input)
parsedQuery, err := parser.ParseQuery(input)
if err != nil {
Expand All @@ -127,7 +131,7 @@
if len(parts) > 1 {
parsedQuery.Expression = strings.SplitN(parts[1], "SELECT", 2)[0]
}
entities, formattedOutput := graph.QueryEntities(codeGraph, parsedQuery)
entities, formattedOutput := tree.QueryEntities(db, parsedQuery)

Check warning on line 134 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L134

Added line #L134 was not covered by tests
if output == "json" || output == "sarif" {
analytics.ReportEvent(analytics.QueryCommandJSON)
// convert struct to query_results
Expand All @@ -137,9 +141,10 @@
for _, entity := range entities {
for _, entityObject := range entity {
result := make(map[string]interface{})
result["file"] = entityObject.File
result["line"] = entityObject.LineNumber
result["code"] = entityObject.CodeSnippet
fmt.Println(entityObject)
// result["file"] = entityObject.File

Check failure on line 145 in sourcecode-parser/cmd/query.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// result["line"] = entityObject.LineNumber
// result["code"] = entityObject.CodeSnippet

Check warning on line 147 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L144-L147

Added lines #L144 - L147 were not covered by tests

results["result_set"] = append(results["result_set"].([]map[string]interface{}), result) //nolint:all
}
Expand All @@ -152,26 +157,26 @@
}
result := ""
verticalLine := "|"
yellowCode := color.New(color.FgYellow).SprintFunc()
// := color.New(color.FgYellow).SprintFunc()

Check warning on line 160 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L160

Added line #L160 was not covered by tests
greenCode := color.New(color.FgGreen).SprintFunc()
for i, entity := range entities {
for _, entityObject := range entity {
header := fmt.Sprintf("\tFile: %s, Line: %s \n", greenCode(entityObject.File), greenCode(entityObject.LineNumber))
header := fmt.Sprintf("\tFile: %s, Line: %s \n", greenCode(entityObject), greenCode(entityObject))

Check warning on line 164 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L164

Added line #L164 was not covered by tests
// add formatted output to result
output := "\tResult: "
for _, outputObject := range formattedOutput[i] {
output += graph.FormatType(outputObject)
output += utilities.FormatType(outputObject)

Check warning on line 168 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L168

Added line #L168 was not covered by tests
output += " "
output += verticalLine + " "
}
header += output + "\n"
result += header
result += "\n"
codeSnippetArray := strings.Split(entityObject.CodeSnippet, "\n")
for i := 0; i < len(codeSnippetArray); i++ {
lineNumber := color.New(color.FgCyan).SprintfFunc()("%4d", int(entityObject.LineNumber)+i)
result += fmt.Sprintf("%s%s %s %s\n", strings.Repeat("\t", 2), lineNumber, verticalLine, yellowCode(codeSnippetArray[i]))
}
// codeSnippetArray := strings.Split(entityObject, "\n")

Check failure on line 175 in sourcecode-parser/cmd/query.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
// for i := 0; i < len(codeSnippetArray); i++ {
// lineNumber := color.New(color.FgCyan).SprintfFunc()("%4d", int(entityObject.LineNumber)+i)
// result += fmt.Sprintf("%s%s %s %s\n", strings.Repeat("\t", 2), lineNumber, verticalLine, yellowCode(codeSnippetArray[i]))
// }

Check warning on line 179 in sourcecode-parser/cmd/query.go

View check run for this annotation

Codecov / codecov/patch

sourcecode-parser/cmd/query.go#L175-L179

Added lines #L175 - L179 were not covered by tests
result += "\n"
}
}
Expand Down
Loading
Loading