mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix(server): Overall improvements
Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
This commit is contained in:
parent
7377d952c8
commit
7feb034a84
@ -49,7 +49,7 @@ func checkOption(
|
|||||||
if option.Separator == nil || option.Separator.Value.Value == "" {
|
if option.Separator == nil || option.Separator.Value.Value == "" {
|
||||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||||
Range: option.Key.LocationRange.ToLSPRange(),
|
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,
|
Severity: &common.SeverityError,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,7 @@ func checkOption(
|
|||||||
if option.Separator == nil || option.Separator.Value.Value == "" {
|
if option.Separator == nil || option.Separator.Value.Value == "" {
|
||||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||||
Range: option.Key.LocationRange.ToLSPRange(),
|
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,
|
Severity: &common.SeverityError,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,6 +94,12 @@ func analyzeSymmetricPropertiesSet(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type key int
|
||||||
|
|
||||||
|
const (
|
||||||
|
lineKey key = iota
|
||||||
|
)
|
||||||
|
|
||||||
// Strategy
|
// Strategy
|
||||||
// Simply compare the host bits of the IP addresses.
|
// Simply compare the host bits of the IP addresses.
|
||||||
// Use a binary tree to store the host bits.
|
// Use a binary tree to store the host bits.
|
||||||
@ -117,7 +123,7 @@ func analyzeDuplicateAllowedIPs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ipContext, _ := ipHostSet.ContainsIP(ipAddress); ipContext != nil {
|
if ipContext, _ := ipHostSet.ContainsIP(ipAddress); ipContext != nil {
|
||||||
definedLine := (*ipContext).Value("line").(uint32)
|
definedLine := (*ipContext).Value(lineKey).(uint32)
|
||||||
|
|
||||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||||
Message: fmt.Sprintf("This IP range is already covered on line %d", definedLine+1),
|
Message: fmt.Sprintf("This IP range is already covered on line %d", definedLine+1),
|
||||||
@ -125,7 +131,11 @@ func analyzeDuplicateAllowedIPs(
|
|||||||
Range: property.ToLSPRange(),
|
Range: property.ToLSPRange(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ipContext := context.WithValue(context.Background(), "line", property.Start.Line)
|
ipContext := context.WithValue(
|
||||||
|
context.Background(),
|
||||||
|
lineKey,
|
||||||
|
property.Start.Line,
|
||||||
|
)
|
||||||
|
|
||||||
ipHostSet.AddIP(
|
ipHostSet.AddIP(
|
||||||
ipAddress,
|
ipAddress,
|
||||||
|
@ -144,7 +144,7 @@ func (c *WGConfig) Parse(input string) []common.LSPError {
|
|||||||
|
|
||||||
indexes := linePattern.FindStringSubmatchIndex(line)
|
indexes := linePattern.FindStringSubmatchIndex(line)
|
||||||
|
|
||||||
if indexes == nil || len(indexes) == 0 {
|
if len(indexes) == 0 {
|
||||||
// Error
|
// Error
|
||||||
errors = append(errors, common.LSPError{
|
errors = append(errors, common.LSPError{
|
||||||
Range: common.LocationRange{
|
Range: common.LocationRange{
|
||||||
|
@ -3,14 +3,11 @@ package lsp
|
|||||||
import (
|
import (
|
||||||
"config-lsp/handlers/wireguard"
|
"config-lsp/handlers/wireguard"
|
||||||
"config-lsp/handlers/wireguard/handlers"
|
"config-lsp/handlers/wireguard/handlers"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/tliron/glsp"
|
"github.com/tliron/glsp"
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
)
|
)
|
||||||
|
|
||||||
var headerPattern = regexp.MustCompile(`^\s*\[(\w+)?]?`)
|
|
||||||
|
|
||||||
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
|
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
|
||||||
d := wireguard.DocumentParserMap[params.TextDocument.URI]
|
d := wireguard.DocumentParserMap[params.TextDocument.URI]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user