Repository navigation
Expand file tree
/
Copy pathdocument_node.go
More file actions
79 lines (70 loc) · 2.47 KB
/
Copy pathdocument_node.go
File metadata and controls
79 lines (70 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package codegraph
import (
"github.com/compforge/codegraph/internal/analysis"
"github.com/compforge/codegraph/internal/language"
)
// DocumentKind describes material, independently of its parsing grammar.
// A Manifest is not evidence of an independent engineering Component.
type DocumentKind string
const (
SourceDocument DocumentKind = "source"
ManifestDocument DocumentKind = "manifest"
GitlinkDocument DocumentKind = "gitlink"
UnknownDocument DocumentKind = "unknown"
)
// ManifestMetadata preserves explicit project declarations. Name is a Go module
// path or a packaging project name; Python/JS names are not import namespaces.
// Absent metadata does not imply that a project lacks a dynamically supplied value.
type ManifestMetadata struct {
Format string `json:"format"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Project bool `json:"project"`
BuildSystem bool `json:"buildSystem"`
Workspace bool `json:"workspace"`
NameLocation *Location `json:"nameLocation,omitempty"`
VersionLocation *Location `json:"versionLocation,omitempty"`
}
// DocumentNode is a typed view of the same Node stored in Graph. Declaration
// membership and outlines come from relations, never a second object hierarchy.
type DocumentNode struct{ Node }
// Document returns a detached Document node by snapshot-relative path.
func (g *Graph) Document(path string) (DocumentNode, bool) {
n, ok := g.Node(DocumentID(path))
if !ok || n.Kind != DocumentNodeKind {
return DocumentNode{}, false
}
return DocumentNode{Node: n}, true
}
func projectManifest(f analysis.Facts) *ManifestMetadata {
if f.Manifest == nil {
return nil
}
m := f.Manifest
out := &ManifestMetadata{Format: m.Format, Name: m.Name, Version: m.Version, Project: m.Project, BuildSystem: m.BuildSystem, Workspace: m.Workspace}
if m.NameSpan.End > m.NameSpan.Start {
out.NameLocation = locationPtr(f, m.NameSpan)
}
if m.VersionSpan.End > m.VersionSpan.Start {
out.VersionLocation = locationPtr(f, m.VersionSpan)
}
return out
}
func cloneManifest(m *ManifestMetadata) *ManifestMetadata {
if m == nil {
return nil
}
out := *m
if m.NameLocation != nil {
loc := *m.NameLocation
out.NameLocation = &loc
}
if m.VersionLocation != nil {
loc := *m.VersionLocation
out.VersionLocation = &loc
}
return &out
}
func materialKind(path, gitlink string) DocumentKind {
return DocumentKind(language.MaterialKind(path, gitlink))
}