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
|
package wireguard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@ -21,11 +22,16 @@ type wireguardParser struct {
|
|||||||
CommentLines map[uint32]struct{}
|
CommentLines map[uint32]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *wireguardParser) clear() {
|
||||||
|
p.Sections = []wireguardSection{}
|
||||||
|
p.CommentLines = map[uint32]struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func createWireguardParser() wireguardParser {
|
func createWireguardParser() wireguardParser {
|
||||||
return wireguardParser{
|
parser := wireguardParser{}
|
||||||
Sections: []wireguardSection{},
|
parser.clear()
|
||||||
CommentLines: map[uint32]struct{}{},
|
|
||||||
}
|
return parser
|
||||||
}
|
}
|
||||||
|
|
||||||
type lineType string
|
type lineType string
|
||||||
@ -53,8 +59,8 @@ func getLineType(line string) lineType {
|
|||||||
return LineTypeProperty
|
return LineTypeProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *wireguardParser) parseFromString(input string) []lineError {
|
func (p *wireguardParser) parseFromString(input string) []common.ParseError {
|
||||||
errors := []lineError{}
|
errors := []common.ParseError{}
|
||||||
lines := strings.Split(
|
lines := strings.Split(
|
||||||
input,
|
input,
|
||||||
"\n",
|
"\n",
|
||||||
@ -81,7 +87,7 @@ func (p *wireguardParser) parseFromString(input string) []lineError {
|
|||||||
err := collectedProperties.AddLine(currentLineNumber, line)
|
err := collectedProperties.AddLine(currentLineNumber, line)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, lineError{
|
errors = append(errors, common.ParseError{
|
||||||
Line: currentLineNumber,
|
Line: currentLineNumber,
|
||||||
Err: err,
|
Err: err,
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package wireguard
|
package wireguard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
docvalues "config-lsp/doc-values"
|
||||||
"config-lsp/utils"
|
"config-lsp/utils"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -42,7 +43,7 @@ func createWireguardProperty(line string) (*wireguardProperty, error) {
|
|||||||
|
|
||||||
if indexes == nil {
|
if indexes == nil {
|
||||||
// weird, should not happen
|
// weird, should not happen
|
||||||
return nil, &malformedLineError{}
|
return nil, &docvalues.MalformedLineError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &wireguardProperty{
|
return &wireguardProperty{
|
||||||
@ -58,7 +59,7 @@ func createWireguardProperty(line string) (*wireguardProperty, error) {
|
|||||||
indexes := linePattern.FindStringSubmatchIndex(line)
|
indexes := linePattern.FindStringSubmatchIndex(line)
|
||||||
|
|
||||||
if indexes == nil || len(indexes) == 0 {
|
if indexes == nil || len(indexes) == 0 {
|
||||||
return nil, &malformedLineError{}
|
return nil, &docvalues.MalformedLineError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyStart := uint32(indexes[2])
|
keyStart := uint32(indexes[2])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user