mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(wireguard): Improve completions for separator
This commit is contained in:
parent
d9903805c5
commit
3cf43e12b3
@ -302,3 +302,49 @@ DNS=1.1.1.1
|
||||
t.Fatalf("parseFromString: Invalid start and end lines %v", parser.Sections)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPartialKeyWorksCorrectly(
|
||||
t *testing.T,
|
||||
) {
|
||||
sample := dedent(`
|
||||
[Interface]
|
||||
DNS
|
||||
`)
|
||||
parser := createWireguardParser()
|
||||
errors := parser.parseFromString(sample)
|
||||
|
||||
if len(errors) > 0 {
|
||||
t.Fatalf("parseFromString failed with error: %v", errors)
|
||||
}
|
||||
|
||||
if !(parser.Sections[0].Properties[1].Key.Name == "DNS") {
|
||||
t.Fatalf("parseFromString failed to collect properties of section 0: %v", parser.Sections[0].Properties)
|
||||
}
|
||||
|
||||
if !(parser.Sections[0].Properties[1].Separator == nil) {
|
||||
t.Fatalf("parseFromString failed to collect properties of section 0: %v", parser.Sections[0].Properties)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPartialValueWithSeparatorWorksCorrectly(
|
||||
t *testing.T,
|
||||
) {
|
||||
sample := dedent(`
|
||||
[Interface]
|
||||
DNS=
|
||||
`)
|
||||
parser := createWireguardParser()
|
||||
errors := parser.parseFromString(sample)
|
||||
|
||||
if len(errors) > 0 {
|
||||
t.Fatalf("parseFromString failed with error: %v", errors)
|
||||
}
|
||||
|
||||
if !(parser.Sections[0].Properties[1].Value == nil) {
|
||||
t.Fatalf("parseFromString failed to collect properties of section 0: %v", parser.Sections[0].Properties)
|
||||
}
|
||||
|
||||
if !(parser.Sections[0].Properties[1].Separator != nil) {
|
||||
t.Fatalf("parseFromString failed to collect properties of section 0: %v", parser.Sections[0].Properties)
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,19 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return section.getCompletionsForPropertyLine(lineNumber, params.Position.Character)
|
||||
completions, err := section.getCompletionsForPropertyLine(lineNumber, params.Position.Character)
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
// Ignore
|
||||
case propertyNotFullyTypedError:
|
||||
break
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return completions, nil
|
||||
}
|
||||
|
||||
panic("TextDocumentCompletion: unexpected line type")
|
||||
|
@ -48,6 +48,7 @@ func createWireguardProperty(line string) (*wireguardProperty, error) {
|
||||
|
||||
return &wireguardProperty{
|
||||
Key: wireguardPropertyKey{
|
||||
Name: line[indexes[0]:indexes[1]],
|
||||
Location: characterLocation{
|
||||
Start: uint32(indexes[0]),
|
||||
End: uint32(indexes[1]),
|
||||
|
@ -43,13 +43,13 @@ func (s wireguardSection) String() string {
|
||||
}
|
||||
|
||||
func (s *wireguardSection) findProperty(lineNumber uint32) (*wireguardProperty, error) {
|
||||
for _, property := range s.Properties {
|
||||
if property.Key.Location.Start <= lineNumber && property.Key.Location.End >= lineNumber {
|
||||
return &property, nil
|
||||
}
|
||||
property, found := s.Properties[lineNumber]
|
||||
|
||||
if !found {
|
||||
return nil, propertyNotFoundError{}
|
||||
}
|
||||
|
||||
return nil, propertyNotFoundError{}
|
||||
return &property, nil
|
||||
}
|
||||
|
||||
func (s wireguardSection) getCompletionsForEmptyLine() ([]protocol.CompletionItem, error) {
|
||||
@ -112,15 +112,18 @@ func (p wireguardSection) getCompletionsForPropertyLine(
|
||||
var insertText string
|
||||
|
||||
if character == property.Key.Location.End {
|
||||
insertText = " = "
|
||||
insertText = property.Key.Name + " = "
|
||||
} else {
|
||||
insertText = "= "
|
||||
}
|
||||
|
||||
kind := protocol.CompletionItemKindValue
|
||||
|
||||
return []protocol.CompletionItem{
|
||||
{
|
||||
Label: "=",
|
||||
Label: insertText,
|
||||
InsertText: &insertText,
|
||||
Kind: &kind,
|
||||
},
|
||||
}, propertyNotFullyTypedError{}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user