mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package docvalues
|
|
|
|
import (
|
|
"strings"
|
|
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
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...,
|
|
)
|
|
}
|
|
func (v OrValue) CheckIsValid(value string) error {
|
|
var firstError error = nil
|
|
|
|
for _, subValue := range v.Values {
|
|
err := subValue.CheckIsValid(value)
|
|
|
|
if err == nil {
|
|
return nil
|
|
} else if firstError == nil {
|
|
firstError = err
|
|
}
|
|
}
|
|
|
|
return firstError
|
|
}
|
|
func (v OrValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem {
|
|
completions := make([]protocol.CompletionItem, 0)
|
|
|
|
for _, subValue := range v.Values {
|
|
completions = append(completions, subValue.FetchCompletions(line, cursor)...)
|
|
}
|
|
|
|
return completions
|
|
}
|