forked from princjef/gomarkdoc
/
value.go
62 lines (52 loc) · 1.43 KB
/
value.go
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
package lang
import (
"go/doc"
)
// Value holds documentation for a var or const declaration within a package.
type Value struct {
cfg *Config
doc *doc.Value
}
// NewValue creates a new Value from the raw const or var documentation and the
// token.FileSet of files for the containing package.
func NewValue(cfg *Config, doc *doc.Value) *Value {
return &Value{cfg, doc}
}
// Level provides the default level that headers for the value should be
// rendered.
func (v *Value) Level() int {
return v.cfg.Level
}
// Location returns a representation of the node's location in a file within a
// repository.
func (v *Value) Location() Location {
return NewLocation(v.cfg, v.doc.Decl)
}
// Summary provides the one-sentence summary of the value's documentation
// comment.
func (v *Value) Summary() string {
return extractSummary(v.doc.Doc)
}
// Doc provides the structured contents of the documentation comment for the
// example.
func (v *Value) Doc() *Doc {
return NewDoc(v.cfg.Inc(1), v.doc.Doc)
}
// Decl provides the raw text representation of the code for declaring the const
// or var.
func (v *Value) Decl() (string, error) {
return printNode(v.doc.Decl, v.cfg.FileSet)
}
// Anchor produces anchor text for the value.
func (v *Value) Anchor() string {
var kind SymbolKind
if v.doc.Decl.Tok.String() == "const" {
kind = ConstSymbolKind
} else {
kind = VarSymbolKind
}
return Symbol{
Kind: kind,
Name: v.doc.Names[0],
}.Anchor()
}