mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 15:35:28 +02:00
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package docvalues
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
type NotANumberError struct{}
|
|
|
|
func (e NotANumberError) Error() string {
|
|
return "This must be number"
|
|
}
|
|
|
|
type NumberNotInRangeError struct {
|
|
Min *int
|
|
Max *int
|
|
}
|
|
|
|
func (e NumberNotInRangeError) Error() string {
|
|
if e.Min == nil {
|
|
return fmt.Sprintf("This must be at most or less than %d", *e.Max)
|
|
}
|
|
|
|
if e.Max == nil {
|
|
return fmt.Sprintf("This must be equal or more than %d", *e.Min)
|
|
}
|
|
|
|
return fmt.Sprintf("This must be between %d and %d (inclusive)", *e.Min, *e.Max)
|
|
}
|
|
|
|
type NumberValue struct {
|
|
Min *int
|
|
Max *int
|
|
}
|
|
|
|
func (v NumberValue) GetTypeDescription() []string {
|
|
if v.Min != nil {
|
|
if v.Max != nil {
|
|
return []string{fmt.Sprintf("A number between %d and %d (inclusive)", *v.Min, *v.Max)}
|
|
} else {
|
|
return []string{fmt.Sprintf("A number of at least %d", *v.Min)}
|
|
}
|
|
} else if v.Max != nil {
|
|
return []string{fmt.Sprintf("A number of at most %d", *v.Max)}
|
|
}
|
|
|
|
return []string{"A number"}
|
|
}
|
|
func (v NumberValue) CheckIsValid(value string) error {
|
|
println("Da number is checking if it is valid", value)
|
|
number, err := strconv.Atoi(value)
|
|
|
|
if err != nil {
|
|
return NotANumberError{}
|
|
}
|
|
|
|
if (v.Min != nil && number < *v.Min) || (v.Max != nil && number > *v.Max) {
|
|
return NumberNotInRangeError{v.Min, v.Max}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (v NumberValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem {
|
|
return []protocol.CompletionItem{}
|
|
}
|