Repository navigation
Expand file tree
/
Copy pathmodel.go
More file actions
263 lines (208 loc) · 6.15 KB
/
Copy pathmodel.go
File metadata and controls
263 lines (208 loc) · 6.15 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package codegraph
import (
"crypto/sha256"
"encoding/json"
"fmt"
"sort"
"github.com/compforge/codegraph/internal/analysis"
"github.com/compforge/codegraph/pkg"
)
type NodeKind = pkg.NodeKind
const (
DocumentNodeKind = pkg.DocumentNodeKind
DirectoryNodeKind = pkg.DirectoryNodeKind
Reference = pkg.Reference
Import = pkg.Import
Export = pkg.Export
Struct = pkg.Struct
Interface = pkg.Interface
Field = pkg.Field
Method = pkg.Method
Function = pkg.Function
Type = pkg.Type
TypeAlias = pkg.TypeAlias
Class = pkg.Class
Constructor = pkg.Constructor
Variable = pkg.Variable
Constant = pkg.Constant
Module = pkg.Module
Package = pkg.Package
Enum = pkg.Enum
Record = pkg.Record
Namespace = pkg.Namespace
Property = pkg.Property
Trait = pkg.Trait
Macro = pkg.Macro
Union = pkg.Union
)
type Location = pkg.Location
type Node = pkg.Node
func cloneNode(n Node) Node {
n.Tags = append([]Tag(nil), n.Tags...)
n.Manifest = cloneManifest(n.Manifest)
if n.Resource != nil {
r := *n.Resource
n.Resource = &r
}
if n.Binding != nil {
b := *n.Binding
n.Binding = &b
}
if n.Location != nil {
loc := *n.Location
n.Location = &loc
}
if n.NameLocation != nil {
loc := *n.NameLocation
n.NameLocation = &loc
}
if n.SignatureLocation != nil {
loc := *n.SignatureLocation
n.SignatureLocation = &loc
}
n.Markers = append([]Marker(nil), n.Markers...)
n.Documentation = append([]Documentation(nil), n.Documentation...)
return n
}
func declarationKind(kind string) (NodeKind, error) {
if concrete := analysis.ConcreteKind(kind); concrete != "" {
return NodeKind(concrete), nil
}
return "", fmt.Errorf("unsupported declaration kind %q", kind)
}
type ResourceReference = pkg.ResourceReference
type ReferenceKind = pkg.ReferenceKind
const (
CallReference = pkg.CallReference
SymbolReference = pkg.SymbolReference
BaseReference = pkg.BaseReference
InterfaceReference = pkg.InterfaceReference
DecoratorReference = pkg.DecoratorReference
)
type ModuleBinding = pkg.ModuleBinding
type RelationKind = pkg.RelationKind
const (
InDirectory = pkg.InDirectory
InNamespace = pkg.InNamespace
Encloses = pkg.Encloses
Contains = pkg.Contains
Declares = pkg.Declares
Imports = pkg.Imports
Calls = pkg.Calls
References = pkg.References
Extends = pkg.Extends
Implements = pkg.Implements
OccursIn = pkg.OccursIn
Aliases = pkg.Aliases
Exports = pkg.Exports
Decorates = pkg.Decorates
)
type Confidence = pkg.Confidence
const (
Exact = pkg.Exact
Scoped = pkg.Scoped
NameOnly = pkg.NameOnly
Heuristic = pkg.Heuristic
)
type Evidence = pkg.Evidence
type Relation = pkg.Relation
type Path = pkg.Path
type Subgraph = pkg.Subgraph
// cloneRelation detaches both the proof list and optional supporting locations.
func cloneRelation(r Relation) Relation {
r.Evidence = append([]Evidence(nil), r.Evidence...)
for i := range r.Evidence {
if r.Evidence[i].Location != nil {
loc := *r.Evidence[i].Location
r.Evidence[i].Location = &loc
}
}
return r
}
type DiagnosticSubject = pkg.DiagnosticSubject
const (
DocumentSubject = pkg.DocumentSubject
DeclarationsSubject = pkg.DeclarationsSubject
RelationsSubject = pkg.RelationsSubject
ContextSubject = pkg.ContextSubject
ResourcesSubject = pkg.ResourcesSubject
)
type Diagnostic = pkg.Diagnostic
type OutlineCoverage = pkg.OutlineCoverage
func extractionDiagnostic(f analysis.Facts, issue analysis.Issue) Diagnostic {
d := Diagnostic{Code: issue.Code, Message: issue.Message, Subject: DiagnosticSubject(issue.Subject),
Relation: RelationKind(issue.Relation), Location: location(f, issue.Span)}
if issue.Outline != nil {
outline := OutlineCoverage(*issue.Outline)
d.Outline = &outline
}
return d
}
func cloneDiagnostics(in []Diagnostic) []Diagnostic {
out := append([]Diagnostic(nil), in...)
for i := range out {
if out[i].Outline != nil {
outline := *out[i].Outline
out[i].Outline = &outline
}
}
return out
}
type Documentation = pkg.Documentation
type MarkerKind = pkg.MarkerKind
const (
Spec = pkg.Spec
Case = pkg.Case
Rule = pkg.Rule
Link = pkg.Link
Doc = pkg.Doc
)
type Marker = pkg.Marker
type BuildReport = pkg.BuildReport
type MaterialReport = pkg.MaterialReport
type AnalysisReport = pkg.AnalysisReport
type SelectionReport = pkg.SelectionReport
type PublicationReport = pkg.PublicationReport
func cloneReport(r BuildReport) BuildReport {
r.Documents = append([]string(nil), r.Documents...)
r.Diagnostics = cloneDiagnostics(r.Diagnostics)
return r
}
// DocumentID identifies a document node by its snapshot-relative logical path.
func DocumentID(name string) string { return "document:" + name }
// declarationID is shared by early detached results and published nodes.
func declarationID(path string, kind NodeKind, qualifiedName string, start int) string {
return "node:" + identity(path, kind, qualifiedName, start)
}
func identity(parts ...any) string {
b, _ := json.Marshal(parts)
h := sha256.Sum256(b)
return fmt.Sprintf("%x", h[:])
}
func location(f analysis.Facts, span analysis.Span) Location {
line := sort.Search(len(f.LineStarts), func(i int) bool { return f.LineStarts[i] > span.Start })
endLine := sort.Search(len(f.LineStarts), func(i int) bool { return f.LineStarts[i] > span.End })
if endLine == 0 {
endLine = 1
}
return Location{Path: f.Path, StartByte: span.Start, EndByte: span.End, Line: line, Column: span.Start - f.LineStarts[line-1] + 1, EndLine: endLine, EndColumn: span.End - f.LineStarts[endLine-1] + 1}
}
func locationPtr(f analysis.Facts, span analysis.Span) *Location {
loc := location(f, span)
return &loc
}
const (
Reads = pkg.Reads
Writes = pkg.Writes
UsesType = pkg.UsesType
Captures = pkg.Captures
UsesResource = pkg.UsesResource
CallSite = pkg.CallSite
ReadSite = pkg.ReadSite
WriteSite = pkg.WriteSite
TypeUse = pkg.TypeUse
CaptureSite = pkg.CaptureSite
ResourceUse = pkg.ResourceUse
DecoratorUse = pkg.DecoratorUse
BindsTo = pkg.BindsTo
)