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
e6f3c05682
commit
2e17ce8ca1
28
doc-values/value-documentation.go
Normal file
28
doc-values/value-documentation.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package docvalues
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DocumentationValue struct {
|
||||||
|
Documentation string
|
||||||
|
Value Value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v DocumentationValue) GetTypeDescription() []string {
|
||||||
|
return v.Value.GetTypeDescription()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v DocumentationValue) CheckIsValid(value string) []*InvalidValue {
|
||||||
|
return v.Value.CheckIsValid(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v DocumentationValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem {
|
||||||
|
return v.Value.FetchCompletions(line, cursor)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v DocumentationValue) FetchHoverInfo(line string, cursor uint32) []string {
|
||||||
|
return strings.Split(v.Documentation, "\n")
|
||||||
|
}
|
@ -25,10 +25,9 @@ var maxPortValue = 65535
|
|||||||
var minMTUValue = 68
|
var minMTUValue = 68
|
||||||
var maxMTUValue = 1500
|
var maxMTUValue = 1500
|
||||||
|
|
||||||
var interfaceOptions map[docvalues.EnumString]docvalues.Value = map[docvalues.EnumString]docvalues.Value{
|
var interfaceOptions = map[string]docvalues.DocumentationValue{
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"Address": {
|
||||||
"Address",
|
Documentation: `Defines what address range the local node should route traffic for. Depending on whether the node is a simple client joining the VPN subnet, or a bounce server that's relaying traffic between multiple clients, this can be set to a single IP of the node itself (specified with CIDR notation), e.g. 192.0.2.3/32), or a range of IPv4/IPv6 subnets that the node can route traffic for.
|
||||||
`Defines what address range the local node should route traffic for. Depending on whether the node is a simple client joining the VPN subnet, or a bounce server that's relaying traffic between multiple clients, this can be set to a single IP of the node itself (specified with CIDR notation), e.g. 192.0.2.3/32), or a range of IPv4/IPv6 subnets that the node can route traffic for.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
Node is a client that only routes traffic for itself
|
Node is a client that only routes traffic for itself
|
||||||
@ -44,13 +43,13 @@ You can also specify multiple subnets or IPv6 subnets like so:
|
|||||||
|
|
||||||
Address = 192.0.2.1/24,2001:DB8::/64
|
Address = 192.0.2.1/24,2001:DB8::/64
|
||||||
`,
|
`,
|
||||||
): docvalues.IPAddressValue{
|
Value: docvalues.IPAddressValue{
|
||||||
AllowIPv4: true,
|
AllowIPv4: true,
|
||||||
AllowIPv6: true,
|
AllowIPv6: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"ListenPort": {
|
||||||
"ListenPort",
|
Documentation: `When the node is acting as a public bounce server, it should hardcode a port to listen for incoming VPN connections from the public internet. Clients not acting as relays should not set this value.
|
||||||
`When the node is acting as a public bounce server, it should hardcode a port to listen for incoming VPN connections from the public internet. Clients not acting as relays should not set this value.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
Using default WireGuard port
|
Using default WireGuard port
|
||||||
@ -60,20 +59,21 @@ Using default WireGuard port
|
|||||||
Using custom WireGuard port
|
Using custom WireGuard port
|
||||||
|
|
||||||
ListenPort = 7000
|
ListenPort = 7000
|
||||||
`): docvalues.NumberValue{
|
`,
|
||||||
Min: &minPortValue,
|
Value: docvalues.NumberValue{
|
||||||
Max: &maxPortValue,
|
Min: &minPortValue,
|
||||||
|
Max: &maxPortValue,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"PrivateKey": {
|
||||||
"PrivateKey",
|
Documentation: `This is the private key for the local node, never shared with other servers. All nodes must have a private key set, regardless of whether they are public bounce servers relaying traffic, or simple clients joining the VPN.
|
||||||
`This is the private key for the local node, never shared with other servers. All nodes must have a private key set, regardless of whether they are public bounce servers relaying traffic, or simple clients joining the VPN.
|
|
||||||
|
|
||||||
This key can be generated with [wg genkey > example.key]
|
This key can be generated with [wg genkey > example.key]
|
||||||
`,
|
`,
|
||||||
): docvalues.StringValue{},
|
Value: docvalues.StringValue{},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
},
|
||||||
"DNS",
|
"DNS": {
|
||||||
`The DNS server(s) to announce to VPN clients via DHCP, most clients will use this server for DNS requests over the VPN, but clients can also override this value locally on their nodes
|
Documentation: `The DNS server(s) to announce to VPN clients via DHCP, most clients will use this server for DNS requests over the VPN, but clients can also override this value locally on their nodes
|
||||||
|
|
||||||
The value can be left unconfigured to use the system's default DNS servers
|
The value can be left unconfigured to use the system's default DNS servers
|
||||||
|
|
||||||
@ -86,18 +86,18 @@ or multiple DNS servers can be provided
|
|||||||
|
|
||||||
DNS = 9.9.9.9,1.1.1.1,8.8.8.8
|
DNS = 9.9.9.9,1.1.1.1,8.8.8.8
|
||||||
`,
|
`,
|
||||||
): docvalues.ArrayValue{
|
Value: docvalues.ArrayValue{
|
||||||
Separator: ",",
|
Separator: ",",
|
||||||
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
|
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
|
||||||
SubValue: docvalues.IPAddressValue{
|
SubValue: docvalues.IPAddressValue{
|
||||||
AllowIPv4: true,
|
AllowIPv4: true,
|
||||||
AllowIPv6: true,
|
AllowIPv6: true,
|
||||||
AllowRange: false,
|
AllowRange: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"Table": {
|
||||||
"Table",
|
Documentation: `Optionally defines which routing table to use for the WireGuard routes, not necessary to configure for most setups.
|
||||||
`Optionally defines which routing table to use for the WireGuard routes, not necessary to configure for most setups.
|
|
||||||
|
|
||||||
There are two special values: ‘off’ disables the creation of routes altogether, and ‘auto’ (the default) adds routes to the default table and enables special handling of default routes.
|
There are two special values: ‘off’ disables the creation of routes altogether, and ‘auto’ (the default) adds routes to the default table and enables special handling of default routes.
|
||||||
|
|
||||||
@ -106,27 +106,28 @@ https://git.zx2c4.com/WireGuard/about/src/tools/man/wg-quick.8
|
|||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Table = 1234
|
Table = 1234
|
||||||
`): docvalues.OrValue{
|
`,
|
||||||
Values: []docvalues.Value{
|
Value: docvalues.OrValue{
|
||||||
docvalues.EnumValue{
|
Values: []docvalues.Value{
|
||||||
EnforceValues: false,
|
docvalues.EnumValue{
|
||||||
Values: []docvalues.EnumString{
|
EnforceValues: false,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Values: []docvalues.EnumString{
|
||||||
"off",
|
docvalues.CreateEnumStringWithDoc(
|
||||||
"Disable the creation of routes altogether",
|
"off",
|
||||||
),
|
"Disable the creation of routes altogether",
|
||||||
docvalues.CreateEnumStringWithDoc(
|
),
|
||||||
"auto",
|
docvalues.CreateEnumStringWithDoc(
|
||||||
"Adds routes to the default table and enables special handling of default routes",
|
"auto",
|
||||||
),
|
"Adds routes to the default table and enables special handling of default routes",
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
docvalues.StringValue{},
|
||||||
},
|
},
|
||||||
docvalues.StringValue{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"MTU": {
|
||||||
"MTU",
|
Documentation: `Optionally defines the maximum transmission unit (MTU, aka packet/frame size) to use when connecting to the peer, not necessary to configure for most setups.
|
||||||
`Optionally defines the maximum transmission unit (MTU, aka packet/frame size) to use when connecting to the peer, not necessary to configure for most setups.
|
|
||||||
|
|
||||||
The MTU is automatically determined from the endpoint addresses or the system default route, which is usually a sane choice.
|
The MTU is automatically determined from the endpoint addresses or the system default route, which is usually a sane choice.
|
||||||
|
|
||||||
@ -135,23 +136,23 @@ https://git.zx2c4.com/WireGuard/about/src/tools/man/wg-quick.8
|
|||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
MTU = 1500
|
MTU = 1500
|
||||||
`): docvalues.NumberValue{
|
`, Value: docvalues.NumberValue{
|
||||||
Min: &minMTUValue,
|
Min: &minMTUValue,
|
||||||
Max: &maxMTUValue,
|
Max: &maxMTUValue,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"PreUp": {
|
||||||
"PreUp",
|
Documentation: `Optionally run a command before the interface is brought up. This option can be specified multiple times, with commands executed in the order they appear in the file.
|
||||||
`Optionally run a command before the interface is brought up. This option can be specified multiple times, with commands executed in the order they appear in the file.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Add an IP route
|
Add an IP route
|
||||||
|
|
||||||
PreUp = ip rule add ipproto tcp dport 22 table 1234
|
PreUp = ip rule add ipproto tcp dport 22 table 1234
|
||||||
`): docvalues.StringValue{},
|
`, Value: docvalues.StringValue{},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
},
|
||||||
"PostUp",
|
"PostUp": {
|
||||||
`Optionally run a command after the interface is brought up. This option can appear multiple times, as with PreUp
|
Documentation: `Optionally run a command after the interface is brought up. This option can appear multiple times, as with PreUp
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
Read in a config value from a file or some command's output
|
Read in a config value from a file or some command's output
|
||||||
@ -177,10 +178,11 @@ Add an iptables rule to enable packet forwarding on the WireGuard interface
|
|||||||
Force WireGuard to re-resolve IP address for peer domain
|
Force WireGuard to re-resolve IP address for peer domain
|
||||||
|
|
||||||
PostUp = resolvectl domain %i "~."; resolvectl dns %i 192.0.2.1; resolvectl dnssec %i yes
|
PostUp = resolvectl domain %i "~."; resolvectl dns %i 192.0.2.1; resolvectl dnssec %i yes
|
||||||
`): docvalues.StringValue{},
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.StringValue{},
|
||||||
"PreDown",
|
},
|
||||||
`Optionally run a command before the interface is brought down. This option can appear multiple times, as with PreUp
|
"PreDown": {
|
||||||
|
Documentation: `Optionally run a command before the interface is brought down. This option can appear multiple times, as with PreUp
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
Log a line to a file
|
Log a line to a file
|
||||||
@ -190,10 +192,11 @@ Log a line to a file
|
|||||||
Hit a webhook on another server
|
Hit a webhook on another server
|
||||||
|
|
||||||
PostDown = curl https://events.example.dev/wireguard/stopping/?key=abcdefg
|
PostDown = curl https://events.example.dev/wireguard/stopping/?key=abcdefg
|
||||||
`): docvalues.StringValue{},
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.StringValue{},
|
||||||
"PostDown",
|
},
|
||||||
`Optionally run a command after the interface is brought down. This option can appear multiple times, as with PreUp
|
"PostDown": {
|
||||||
|
Documentation: `Optionally run a command after the interface is brought down. This option can appear multiple times, as with PreUp
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@ -208,11 +211,13 @@ Hit a webhook on another server
|
|||||||
Remove the iptables rule that forwards packets on the WireGuard interface
|
Remove the iptables rule that forwards packets on the WireGuard interface
|
||||||
|
|
||||||
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
|
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
|
||||||
`): docvalues.StringValue{},
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.StringValue{},
|
||||||
"PreSharedKey",
|
},
|
||||||
"Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
"PreSharedKey": {
|
||||||
): docvalues.StringValue{},
|
Documentation: "Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
||||||
|
Value: docvalues.StringValue{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var interfaceAllowedDuplicateFields = map[string]struct{}{
|
var interfaceAllowedDuplicateFields = map[string]struct{}{
|
||||||
@ -222,10 +227,9 @@ var interfaceAllowedDuplicateFields = map[string]struct{}{
|
|||||||
"PostDown": {},
|
"PostDown": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
var peerOptions map[docvalues.EnumString]docvalues.Value = map[docvalues.EnumString]docvalues.Value{
|
var peerOptions = map[string]docvalues.DocumentationValue{
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"Endpoint": {
|
||||||
"Endpoint",
|
Documentation: `Defines the publicly accessible address for a remote peer. This should be left out for peers behind a NAT or peers that don't have a stable publicly accessible IP:PORT pair. Typically, this only needs to be defined on the main bounce server, but it can also be defined on other public nodes with stable IPs like public-server2 in the example config below.
|
||||||
`Defines the publicly accessible address for a remote peer. This should be left out for peers behind a NAT or peers that don't have a stable publicly accessible IP:PORT pair. Typically, this only needs to be defined on the main bounce server, but it can also be defined on other public nodes with stable IPs like public-server2 in the example config below.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
Endpoint is an IP address
|
Endpoint is an IP address
|
||||||
@ -235,10 +239,11 @@ Endpoint is an IP address
|
|||||||
Endpoint is a hostname/FQDN
|
Endpoint is a hostname/FQDN
|
||||||
|
|
||||||
Endpoint = public-server1.example-vpn.tld:51820
|
Endpoint = public-server1.example-vpn.tld:51820
|
||||||
`): docvalues.StringValue{},
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.StringValue{},
|
||||||
"AllowedIPs",
|
},
|
||||||
`This defines the IP ranges for which a peer will route traffic. On simple clients, this is usually a single address (the VPN address of the simple client itself). For bounce servers this will be a range of the IPs or subnets that the relay server is capable of routing traffic for. Multiple IPs and subnets may be specified using comma-separated IPv4 or IPv6 CIDR notation (from a single /32 or /128 address, all the way up to 0.0.0.0/0 and ::/0 to indicate a default route to send all internet and VPN traffic through that peer). This option may be specified multiple times.
|
"AllowedIPs": {
|
||||||
|
Documentation: `This defines the IP ranges for which a peer will route traffic. On simple clients, this is usually a single address (the VPN address of the simple client itself). For bounce servers this will be a range of the IPs or subnets that the relay server is capable of routing traffic for. Multiple IPs and subnets may be specified using comma-separated IPv4 or IPv6 CIDR notation (from a single /32 or /128 address, all the way up to 0.0.0.0/0 and ::/0 to indicate a default route to send all internet and VPN traffic through that peer). This option may be specified multiple times.
|
||||||
|
|
||||||
When deciding how to route a packet, the system chooses the most specific route first, and falls back to broader routes. So for a packet destined to 192.0.2.3, the system would first look for a peer advertising 192.0.2.3/32 specifically, and would fall back to a peer advertising 192.0.2.1/24 or a larger range like 0.0.0.0/0 as a last resort.
|
When deciding how to route a packet, the system chooses the most specific route first, and falls back to broader routes. So for a packet destined to 192.0.2.3, the system would first look for a peer advertising 192.0.2.3/32 specifically, and would fall back to a peer advertising 192.0.2.1/24 or a larger range like 0.0.0.0/0 as a last resort.
|
||||||
|
|
||||||
@ -264,28 +269,29 @@ Peer is a relay server that routes to itself and all nodes on its local LAN
|
|||||||
|
|
||||||
AllowedIPs = 192.0.2.3/32,192.168.1.1/24
|
AllowedIPs = 192.0.2.3/32,192.168.1.1/24
|
||||||
`,
|
`,
|
||||||
): docvalues.ArrayValue{
|
Value: docvalues.ArrayValue{
|
||||||
Separator: ",",
|
Separator: ",",
|
||||||
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
|
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
|
||||||
SubValue: docvalues.IPAddressValue{
|
SubValue: docvalues.IPAddressValue{
|
||||||
AllowIPv4: true,
|
AllowIPv4: true,
|
||||||
AllowIPv6: true,
|
AllowIPv6: true,
|
||||||
AllowRange: true,
|
AllowRange: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
docvalues.CreateEnumStringWithDoc(
|
"PublicKey": {
|
||||||
"PublicKey",
|
Documentation: `This is the public key for the remote node, shareable with all peers. All nodes must have a public key set, regardless of whether they are public bounce servers relaying traffic, or simple clients joining the VPN.
|
||||||
`This is the public key for the remote node, shareable with all peers. All nodes must have a public key set, regardless of whether they are public bounce servers relaying traffic, or simple clients joining the VPN.
|
|
||||||
|
|
||||||
This key can be generated with wg pubkey < example.key > example.key.pub. (see above for how to generate the private key example.key)
|
This key can be generated with wg pubkey < example.key > example.key.pub. (see above for how to generate the private key example.key)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
PublicKey = somePublicKeyAbcdAbcdAbcdAbcd=
|
PublicKey = somePublicKeyAbcdAbcdAbcdAbcd=
|
||||||
`): docvalues.StringValue{},
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.StringValue{},
|
||||||
"PersistentKeepalive",
|
},
|
||||||
`If the connection is going from a NAT-ed peer to a public peer, the node behind the NAT must regularly send an outgoing ping in order to keep the bidirectional connection alive in the NAT router's connection table.
|
"PersistentKeepalive": {
|
||||||
|
Documentation: `If the connection is going from a NAT-ed peer to a public peer, the node behind the NAT must regularly send an outgoing ping in order to keep the bidirectional connection alive in the NAT router's connection table.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@ -300,11 +306,13 @@ Local public node to remote NAT-ed node
|
|||||||
Oocal NAT-ed node to remote public node
|
Oocal NAT-ed node to remote public node
|
||||||
|
|
||||||
PersistentKeepalive = 25 this will send a ping to every 25 seconds keeping the connection open in the local NAT router's connection table.
|
PersistentKeepalive = 25 this will send a ping to every 25 seconds keeping the connection open in the local NAT router's connection table.
|
||||||
`): docvalues.PositiveNumberValue(),
|
`,
|
||||||
docvalues.CreateEnumStringWithDoc(
|
Value: docvalues.PositiveNumberValue(),
|
||||||
"PreSharedKey",
|
},
|
||||||
"Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
"PreSharedKey": {
|
||||||
): docvalues.StringValue{},
|
Documentation: "Optionally defines a pre-shared key for the peer, used to authenticate the connection. This is not necessary, but strongly recommended for security.",
|
||||||
|
Value: docvalues.StringValue{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var peerAllowedDuplicateFields = map[string]struct{}{}
|
var peerAllowedDuplicateFields = map[string]struct{}{}
|
||||||
|
@ -117,8 +117,8 @@ DNS
|
|||||||
t.Fatalf("getCompletionsForPropertyLine: Expected 1 completion, but got %v", len(completions))
|
t.Fatalf("getCompletionsForPropertyLine: Expected 1 completion, but got %v", len(completions))
|
||||||
}
|
}
|
||||||
|
|
||||||
if *completions[0].InsertText != " = " {
|
if *completions[0].InsertText != "DNS = " {
|
||||||
t.Fatalf("getCompletionsForPropertyLine: Expected completion to be ' = ', but got '%v'", completions[0].Label)
|
t.Fatalf("getCompletionsForPropertyLine: Expected completion to be 'DNS = ', but got '%v'", completions[0].Label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func (s wireguardSection) getCompletionsForEmptyLine() ([]protocol.CompletionIte
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
options := make(map[docvalues.EnumString]docvalues.Value)
|
options := make(map[string]docvalues.DocumentationValue)
|
||||||
|
|
||||||
switch *s.Name {
|
switch *s.Name {
|
||||||
case "Interface":
|
case "Interface":
|
||||||
@ -69,13 +69,7 @@ func (s wireguardSection) getCompletionsForEmptyLine() ([]protocol.CompletionIte
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the option from the available options
|
delete(options, property.Key.Name)
|
||||||
maps.DeleteFunc(
|
|
||||||
options,
|
|
||||||
func(key docvalues.EnumString, value docvalues.Value) bool {
|
|
||||||
return key.DescriptionText == property.Key.Name
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case "Peer":
|
case "Peer":
|
||||||
maps.Copy(options, peerOptions)
|
maps.Copy(options, peerOptions)
|
||||||
@ -86,13 +80,7 @@ func (s wireguardSection) getCompletionsForEmptyLine() ([]protocol.CompletionIte
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the option from the available options
|
delete(options, property.Key.Name)
|
||||||
maps.DeleteFunc(
|
|
||||||
options,
|
|
||||||
func(key docvalues.EnumString, value docvalues.Value) bool {
|
|
||||||
return key.DescriptionText == property.Key.Name
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,14 +88,14 @@ func (s wireguardSection) getCompletionsForEmptyLine() ([]protocol.CompletionIte
|
|||||||
|
|
||||||
return utils.MapMapToSlice(
|
return utils.MapMapToSlice(
|
||||||
options,
|
options,
|
||||||
func(key docvalues.EnumString, value docvalues.Value) protocol.CompletionItem {
|
func(optionName string, value docvalues.DocumentationValue) protocol.CompletionItem {
|
||||||
insertText := key.InsertText + " = "
|
insertText := optionName + " = "
|
||||||
|
|
||||||
return protocol.CompletionItem{
|
return protocol.CompletionItem{
|
||||||
Label: key.InsertText,
|
|
||||||
InsertText: &insertText,
|
|
||||||
Documentation: key.Documentation,
|
|
||||||
Kind: &kind,
|
Kind: &kind,
|
||||||
|
Documentation: value.Documentation,
|
||||||
|
Label: optionName,
|
||||||
|
InsertText: &insertText,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
), nil
|
), nil
|
||||||
@ -151,19 +139,9 @@ func (p wireguardSection) getCompletionsForPropertyLine(
|
|||||||
|
|
||||||
switch *p.Name {
|
switch *p.Name {
|
||||||
case "Interface":
|
case "Interface":
|
||||||
for enum, opt := range interfaceOptions {
|
option = interfaceOptions[property.Key.Name]
|
||||||
if enum.InsertText == property.Key.Name {
|
|
||||||
option = opt
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "Peer":
|
case "Peer":
|
||||||
for enum, opt := range peerOptions {
|
option = peerOptions[property.Key.Name]
|
||||||
if enum.InsertText == property.Key.Name {
|
|
||||||
option = opt
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if option == nil {
|
if option == nil {
|
||||||
|
@ -128,6 +128,16 @@ func KeysOfMap[T comparable, O any](values map[T]O) []T {
|
|||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValuesOfMap[T comparable, O any](values map[T]O) []O {
|
||||||
|
keys := make([]O, 0)
|
||||||
|
|
||||||
|
for _, value := range values {
|
||||||
|
keys = append(keys, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
func DoesPathExist(path string) bool {
|
func DoesPathExist(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user