mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
104 lines
2.0 KiB
Go
104 lines
2.0 KiB
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
type Value interface {
|
|
getTypeDescription() []string
|
|
}
|
|
|
|
type EnumValue struct {
|
|
Values []string
|
|
}
|
|
func (v EnumValue) getTypeDescription() []string {
|
|
lines := make([]string, len(v.Values) + 1)
|
|
lines[0] = "Enum of:"
|
|
|
|
for index, value := range v.Values {
|
|
lines[index + 1] += "\t* " + value
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
type PositiveNumberValue struct {}
|
|
func (v PositiveNumberValue) getTypeDescription() []string {
|
|
return []string{ "Positive number" }
|
|
}
|
|
|
|
type ArrayValue struct {
|
|
SubValue Value
|
|
Separator string
|
|
AllowDuplicates bool
|
|
}
|
|
func (v ArrayValue) getTypeDescription() []string {
|
|
subValue := v.SubValue.(Value)
|
|
|
|
return append(
|
|
[]string{ "An Array separated by " + v.Separator + " of:" },
|
|
subValue.getTypeDescription()...
|
|
)
|
|
}
|
|
|
|
type OrValue struct {
|
|
Values []Value
|
|
}
|
|
func (v OrValue) getTypeDescription() []string {
|
|
lines := make([]string, 0)
|
|
|
|
for _, subValueRaw := range v.Values {
|
|
subValue := subValueRaw.(Value)
|
|
subLines := subValue.getTypeDescription()
|
|
|
|
for index, line := range subLines {
|
|
if strings.HasPrefix(line, "\t*") {
|
|
subLines[index] = "\t" + line
|
|
} else {
|
|
subLines[index] = "\t* " + line
|
|
}
|
|
}
|
|
|
|
lines = append(lines, subLines...)
|
|
}
|
|
|
|
return append(
|
|
[]string{ "One of:" },
|
|
lines...
|
|
)
|
|
}
|
|
|
|
type StringValue struct {}
|
|
func (v StringValue) getTypeDescription() []string {
|
|
return []string{ "String" }
|
|
}
|
|
|
|
type CustomValue struct {
|
|
FetchValue func() Value
|
|
}
|
|
func (v CustomValue) getTypeDescription() []string {
|
|
return []string{ "Custom" }
|
|
}
|
|
|
|
|
|
type Option struct {
|
|
Documentation string
|
|
Value Value
|
|
}
|
|
|
|
func GetDocumentation(o *Option) protocol.MarkupContent {
|
|
typeDescription := strings.Join(o.Value.getTypeDescription(), "\n")
|
|
|
|
return protocol.MarkupContent{
|
|
Kind: protocol.MarkupKindPlainText,
|
|
Value: "### Type\n" + typeDescription + "\n\n---\n\n### Documentation\n" + o.Documentation,
|
|
}
|
|
}
|
|
|
|
func NewOption(documentation string, value Value) Option {
|
|
return Option{documentation, value}
|
|
}
|
|
|