fix(server): Overall improvements

Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
This commit is contained in:
Myzel394 2025-03-15 23:04:40 +01:00 committed by Myzel394
parent 7377d952c8
commit 7feb034a84
No known key found for this signature in database
GPG Key ID: B603E877F73D4ABB
5 changed files with 15 additions and 8 deletions

View File

@ -49,7 +49,7 @@ func checkOption(
if option.Separator == nil || option.Separator.Value.Value == "" {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: option.Key.LocationRange.ToLSPRange(),
Message: fmt.Sprintf("There should be a separator between an option and its value"),
Message: "There should be a separator between an option and its value",
Severity: &common.SeverityError,
})
} else {

View File

@ -46,7 +46,7 @@ func checkOption(
if option.Separator == nil || option.Separator.Value.Value == "" {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: option.Key.LocationRange.ToLSPRange(),
Message: fmt.Sprintf("There should be a separator between an option and its value"),
Message: "There should be a separator between an option and its value",
Severity: &common.SeverityError,
})
} else {

View File

@ -94,6 +94,12 @@ func analyzeSymmetricPropertiesSet(
}
}
type key int
const (
lineKey key = iota
)
// Strategy
// Simply compare the host bits of the IP addresses.
// Use a binary tree to store the host bits.
@ -117,7 +123,7 @@ func analyzeDuplicateAllowedIPs(
}
if ipContext, _ := ipHostSet.ContainsIP(ipAddress); ipContext != nil {
definedLine := (*ipContext).Value("line").(uint32)
definedLine := (*ipContext).Value(lineKey).(uint32)
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Message: fmt.Sprintf("This IP range is already covered on line %d", definedLine+1),
@ -125,7 +131,11 @@ func analyzeDuplicateAllowedIPs(
Range: property.ToLSPRange(),
})
} else {
ipContext := context.WithValue(context.Background(), "line", property.Start.Line)
ipContext := context.WithValue(
context.Background(),
lineKey,
property.Start.Line,
)
ipHostSet.AddIP(
ipAddress,

View File

@ -144,7 +144,7 @@ func (c *WGConfig) Parse(input string) []common.LSPError {
indexes := linePattern.FindStringSubmatchIndex(line)
if indexes == nil || len(indexes) == 0 {
if len(indexes) == 0 {
// Error
errors = append(errors, common.LSPError{
Range: common.LocationRange{

View File

@ -3,14 +3,11 @@ package lsp
import (
"config-lsp/handlers/wireguard"
"config-lsp/handlers/wireguard/handlers"
"regexp"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)
var headerPattern = regexp.MustCompile(`^\s*\[(\w+)?]?`)
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
d := wireguard.DocumentParserMap[params.TextDocument.URI]