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

web uiの追加 #37

Merged
merged 5 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
dist
/isucrud
22 changes: 5 additions & 17 deletions dbdoc/dbdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dbdoc
import (
"fmt"
"go/token"
"os"

"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
Expand All @@ -19,25 +18,25 @@ type Config struct {
DestinationFilePath string
}

func Run(conf Config) error {
func Run(conf Config) ([]*Node, error) {
ctx := &Context{
FileSet: token.NewFileSet(),
WorkDir: conf.WorkDir,
}

ssaProgram, pkgs, err := BuildSSA(ctx, conf.BuildArgs)
if err != nil {
return fmt.Errorf("failed to build ssa: %w", err)
return nil, fmt.Errorf("failed to build ssa: %w", err)
}

loopRangeMap, err := BuildLoopRangeMap(ctx)
if err != nil {
return fmt.Errorf("failed to build loop range map: %w", err)
return nil, fmt.Errorf("failed to build loop range map: %w", err)
}

funcs, err := BuildFuncs(ctx, pkgs, ssaProgram, loopRangeMap)
if err != nil {
return fmt.Errorf("failed to build funcs: %w", err)
return nil, fmt.Errorf("failed to build funcs: %w", err)
}

nodes := BuildGraph(
Expand All @@ -46,18 +45,7 @@ func Run(conf Config) error {
conf.IgnoreMain, conf.IgnoreInitialize,
)

f, err := os.Create(conf.DestinationFilePath)
if err != nil {
return fmt.Errorf("failed to make directory: %w", err)
}
defer f.Close()

err = WriteMermaid(f, nodes)
if err != nil {
return fmt.Errorf("failed to write mermaid: %w", err)
}

return nil
return nodes, nil
}

func BuildSSA(ctx *Context, args []string) (*ssa.Program, []*packages.Package, error) {
Expand Down
165 changes: 0 additions & 165 deletions dbdoc/mermaid.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mazrean/isucrud

go 1.22.0
go 1.23

toolchain go1.22.9

Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/list/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ func (q Queue[T]) Peek() (T, bool) {
return e.Value()
}

func (q *Queue[T]) Iter(yield func(T) bool) {
for e := q.l.Front(); e.e != nil; e = q.l.Front() {
q.l.Remove(e)

v, ok := e.Value()
if !ok {
break
}

yield(v)
}
}

func (q Queue[T]) Clear() {
q.l.Init()
}
41 changes: 41 additions & 0 deletions internal/ui/asset/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="ja">

<head>
<meta charset="UTF-8">
<title>Mermaid</title>
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"
integrity="sha512-3PBlo2Duz3n8ZReWwpL22r4w1JZH8ZRv2cdYkXZ4K+O50hB9KdKfJ5Tevi5M1fCqfH7GQt2AcDDMRrneJ/dfYw=="
crossorigin="anonymous"></script>
<script>
mermaid.initialize({
startOnLoad: true,
theme: 'defalt',
// clockを有効にするためにセキュリティレベルを下げる
securityLevel: 'loose',
});
</script>
</head>

<body>
{{if .IsFiltered}}<button onclick="location.href = '/'">全ノードを表示する</button>{{end}}
<div>
nodes:
{{range .NodeTypes}}<span>
<span style="color: #{{.Color}};">■</span>
{{.Label}}
</span>{{end}}
</div><div>
edges:
{{range .EdgeTypes}}<span>
<span style="color: #{{.Color}};">■</span>
{{.Label}}
</span>{{end}}
</div>
<div
class="mermaid"
id="mermaid-data"
>{{.MermaidData}}</div>
</body>

</html>
7 changes: 7 additions & 0 deletions internal/ui/asset/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DB Graph
node: {{range .NodeTypes}}![](https://via.placeholder.com/16/{{.Color}}/FFFFFF/?text=%20) `{{.Label}}` {{end}}

edge: {{range .EdgeTypes}}![](https://via.placeholder.com/16/{{.Color}}/FFFFFF/?text=%20) `{{.Label}}` {{end}}
```mermaid
{{.MermaidData}}
```
Loading
Loading