Documentation
¶
Overview ¶
Package trace は対応関係の追跡(対応表・影響範囲分析・欠落検出・ グラフ出力)と、文書を読む経路(索引・本文取り出し・検索)を提供する。
Index ¶
- Constants
- func StatusGlyph(status string) string
- func StatusLegend() string
- func StatusMeaning(status string) string
- type Entry
- type GapsReport
- type Hit
- type Impact
- type Index
- type Location
- type Match
- type Matrix
- type MatrixRow
- type SearchOptions
- type SearchResult
- type Trace
- func (t *Trace) CheckIDs(ids []string) error
- func (t *Trace) Gaps(docType string) (*GapsReport, error)
- func (t *Trace) GraphOutput(filter []string) string
- func (t *Trace) Impact(id string, depth int) (*Impact, error)
- func (t *Trace) Index(docType string) (*Index, error)
- func (t *Trace) Matrix(from string, filter []string) (*Matrix, error)
- func (t *Trace) Search(opts SearchOptions) (*SearchResult, error)
- func (t *Trace) Section(id string) (string, error)
- func (t *Trace) TypeAt(i int) string
Constants ¶
const ( StatusComplete = "complete" // すべての経路が連鎖の最終段まで届いている StatusPartial = "partial" // 一部の経路が途中で途切れている StatusMissing = "missing" // 下流へ辿る経路が 1 本も無い )
行の状態。機械可読な出力にはこの語がそのまま載る。 表示の記号にしないのは、絵文字を線上の契約にすると 消費側が表示の都合の変更で壊れるため。
const ( // DefaultSearchLimit は返す節の上限。 DefaultSearchLimit = 20 // DefaultSearchMaxHits は 1 節あたりに表示する一致行の上限。 DefaultSearchMaxHits = 3 )
検索の既定値。出力が文脈を圧迫しない大きさに収める。
Variables ¶
This section is empty.
Functions ¶
func StatusLegend ¶ added in v0.2.0
func StatusLegend() string
StatusLegend は欠落として報告されうる状態の凡例を作る。 状態を足したらここに現れるよう、記号と意味は状態の定義から引く。 出力とヘルプの両方が使うので、写しを持たせない。
func StatusMeaning ¶ added in v0.2.0
StatusMeaning は状態の意味を人の言葉で返す。凡例の出所をここ 1 か所にする。 記号の側に説明を書き写すと、状態を足したときに片方だけが取り残される。
Types ¶
type Entry ¶
type Entry struct {
ID string `json:"id"`
Type string `json:"type"`
Title string `json:"title,omitempty"`
File string `json:"file"`
Line int `json:"line"`
EndLine int `json:"end_line"`
Refs []string `json:"refs"` // このセクションが本文で参照している識別子(上流)
Downstream []string `json:"downstream"` // このセクションから影響が及ぶ識別子(参照元と、入れ子の子)
}
Entry は索引の 1 件。識別子が「どの文書のどこにあるか」を示す。
type GapsReport ¶
type GapsReport struct {
Type string `json:"type"`
Chain []string `json:"chain"`
Items []MatrixRow `json:"items"`
Summary struct {
Total int `json:"total"`
Complete int `json:"complete"`
RatePct int `json:"coverage_percent"`
Incomplete int `json:"incomplete"`
} `json:"summary"`
}
GapsReport は最終段まで辿り切れなかった起点の一覧。
判定は対応表と同じものを使う。別に数えると、対応表が ✅ と言う行を こちらが未達と数える、という食い違いが起きる。
type Impact ¶
type Impact struct {
Target string `json:"target"`
Direct []Location `json:"direct_impact"`
Indirect []Location `json:"indirect_impact"`
Summary struct {
DirectCount int `json:"direct_count"`
IndirectCount int `json:"indirect_count"`
} `json:"summary"`
}
Impact は影響範囲分析の結果。
type Location ¶
type Location struct {
ID string `json:"id"`
File string `json:"file"`
Line int `json:"line"`
Title string `json:"title,omitempty"`
}
Location は ID の定義位置。
type Match ¶
type Match struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
File string `json:"file"`
Line int `json:"line"`
Hits []Hit `json:"hits"`
// HitCount は絞り込む前の一致行数。Hits より大きければ表示を打ち切っている。
HitCount int `json:"hit_count"`
}
Match は一致した節 1 件。ID が空なら、どの節にも属さない本文(前文など)。
type Matrix ¶
type Matrix struct {
Rows []MatrixRow `json:"rows"`
// Chain は連鎖の各段。段数が可変なので、JSON の消費側が列の意味を知るために出す。
Chain []string `json:"chain"`
Summary struct {
Total int `json:"total"`
Complete int `json:"complete"`
Partial int `json:"partial"`
Missing int `json:"missing"`
RatePct int `json:"coverage_percent"`
} `json:"summary"`
}
Matrix は対応表。列は連鎖の段数だけあり、3 段に限らない。
type MatrixRow ¶
type MatrixRow struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
// Paths は起点から下流へ辿った経路。各要素が 1 経路で、起点自身は含まない。
// 途中で下流が途切れた経路は連鎖の段数より短くなる。
Paths [][]string `json:"paths"`
Status string `json:"status"`
}
MatrixRow は連鎖の起点 1 件分の行。
type SearchOptions ¶
type SearchOptions struct {
Pattern string // 正規表現。Fixed が真なら文字列そのまま
Fixed bool
Type string // 文書タイプで絞る。空なら全部
Limit int // 返す節の上限。0 で既定
MaxHits int // 1 節あたりの一致行の上限。0 で既定
}
SearchOptions は検索の指示。
type SearchResult ¶
type SearchResult struct {
Matches []Match `json:"matches"`
// Total は Limit で絞る前の一致節数。絞り足りないかを呼び出し側が判断できる。
Total int `json:"total"`
Truncated bool `json:"truncated"`
}
SearchResult は検索結果。
type Trace ¶
type Trace struct {
Cfg *config.Config
Docs []*parser.Document
Graph *graph.Graph
Chain []string // 文書タイプの並び(上流から下流へ)
// contains filtered or unexported fields
}
Trace は解析済みの文書群と ID 依存グラフ。
func Build ¶
Build は文書を解析して ID 依存グラフを構築する。 エッジは「参照された ID → 参照しているセクションの ID」(上流 → 下流)。
paths は呼び出し側で解決済みであることを前提とする(既定解決や 非通常ファイルの除去は行わない)。CLI は internal/cli.ExpandTargets を経由する。
func (*Trace) CheckIDs ¶
CheckIDs は識別子の一覧がすべて定義済みかを検査する。 空要素(末尾カンマなど)は指定なしとして無視する。 graph のように、下位の出力が未知の識別子を黙って空の結果にする 経路の手前で使う。
func (*Trace) Gaps ¶
func (t *Trace) Gaps(docType string) (*GapsReport, error)
Gaps は連鎖の最終段まで辿り切れない ID を列挙する。 docType が空なら連鎖の先頭を対象にする。
func (*Trace) GraphOutput ¶
GraphOutput は依存グラフを Mermaid(flowchart LR)で出力する。 filter が非空ならその ID だけの部分グラフにする。
形式は Mermaid だけ。Markdown へそのまま貼れば図になるので、 出力を絵にするための外部コマンドが要らない。
func (*Trace) Index ¶
Index は全識別子の索引を作る。docType を指定するとその文書タイプだけに絞る。
文書が複数ファイルへ分かれると「どの識別子がどこにあるか」を人も道具も 見失いやすい。本文を開かずに所在を引けるようにするための出力。
func (*Trace) Matrix ¶
Matrix は連鎖に沿った対応表を構築する。
from が非空ならその文書タイプを起点の段にする(空なら連鎖の先頭)。 filter が非空の場合、その ID(起点)だけを対象にする。
段数は連鎖の宣言に従う。段飛ばしは経路として認めない。起点が最終段を直接 参照していても途中の段が空なら、そこで途切れた経路として扱う(途中が欠けて いること自体が知りたい情報のため)。
func (*Trace) Search ¶
func (t *Trace) Search(opts SearchOptions) (*SearchResult, error)
Search は本文と見出しの表題から語を探し、一致を節へ帰属させて返す。
探すのは本文の行だけで、コードブロックの中は見ない。参照や用語の判定と 同じ本文の行(解析結果の Prose)を使うので、使用例として書いたコマンドが 検索にだけ引っかかることはない。
帰属は参照の紐付けと同じ規則で、一致行を含む直近の識別子付き見出しに属する。 見出しより前の本文はどの節にも属さないので、識別子を空にして位置だけ返す。