mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(wireguard): Improvements
This commit is contained in:
parent
d456f4a569
commit
d3aa99b5f5
@ -1,12 +0,0 @@
|
||||
package wireguard
|
||||
|
||||
type malformedLineError struct{}
|
||||
|
||||
func (e *malformedLineError) Error() string {
|
||||
return "Malformed line"
|
||||
}
|
||||
|
||||
type lineError struct {
|
||||
Line uint32
|
||||
Err error
|
||||
}
|
@ -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 createWireguardParser() wireguardParser {
|
||||
return wireguardParser{
|
||||
Sections: []wireguardSection{},
|
||||
CommentLines: map[uint32]struct{}{},
|
||||
func (p *wireguardParser) clear() {
|
||||
p.Sections = []wireguardSection{}
|
||||
p.CommentLines = map[uint32]struct{}{}
|
||||
}
|
||||
|
||||
func createWireguardParser() wireguardParser {
|
||||
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,
|
||||
})
|
||||
|
@ -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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user