fix(wireguard): Improvements

This commit is contained in:
Myzel394 2024-08-14 18:28:06 +02:00
parent d456f4a569
commit d3aa99b5f5
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
3 changed files with 16 additions and 21 deletions

View File

@ -1,12 +0,0 @@
package wireguard
type malformedLineError struct{}
func (e *malformedLineError) Error() string {
return "Malformed line"
}
type lineError struct {
Line uint32
Err error
}

View File

@ -1,6 +1,7 @@
package wireguard
import (
"config-lsp/common"
"regexp"
"slices"
"strings"
@ -21,11 +22,16 @@ type wireguardParser struct {
CommentLines map[uint32]struct{}
}
func (p *wireguardParser) clear() {
p.Sections = []wireguardSection{}
p.CommentLines = map[uint32]struct{}{}
}
func createWireguardParser() wireguardParser {
return wireguardParser{
Sections: []wireguardSection{},
CommentLines: map[uint32]struct{}{},
}
parser := wireguardParser{}
parser.clear()
return parser
}
type lineType string
@ -53,8 +59,8 @@ func getLineType(line string) lineType {
return LineTypeProperty
}
func (p *wireguardParser) parseFromString(input string) []lineError {
errors := []lineError{}
func (p *wireguardParser) parseFromString(input string) []common.ParseError {
errors := []common.ParseError{}
lines := strings.Split(
input,
"\n",
@ -81,7 +87,7 @@ func (p *wireguardParser) parseFromString(input string) []lineError {
err := collectedProperties.AddLine(currentLineNumber, line)
if err != nil {
errors = append(errors, lineError{
errors = append(errors, common.ParseError{
Line: currentLineNumber,
Err: err,
})

View File

@ -1,6 +1,7 @@
package wireguard
import (
docvalues "config-lsp/doc-values"
"config-lsp/utils"
"regexp"
"strings"
@ -42,7 +43,7 @@ func createWireguardProperty(line string) (*wireguardProperty, error) {
if indexes == nil {
// weird, should not happen
return nil, &malformedLineError{}
return nil, &docvalues.MalformedLineError{}
}
return &wireguardProperty{
@ -58,7 +59,7 @@ func createWireguardProperty(line string) (*wireguardProperty, error) {
indexes := linePattern.FindStringSubmatchIndex(line)
if indexes == nil || len(indexes) == 0 {
return nil, &malformedLineError{}
return nil, &docvalues.MalformedLineError{}
}
keyStart := uint32(indexes[2])