diff --git a/pkg/server/completion.go b/pkg/server/completion.go index 573ea98..aad90d2 100644 --- a/pkg/server/completion.go +++ b/pkg/server/completion.go @@ -197,7 +197,7 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind } detail := prefix + concat + insertText - item := protocol.CompletionItem{ + return protocol.CompletionItem{ Label: label, Detail: detail, Kind: kind, @@ -205,10 +205,7 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind Description: typeToString(body), }, InsertText: insertText, - } - - if strings.HasPrefix(insertText, "[") { - item.TextEdit = &protocol.TextEdit{ + TextEdit: &protocol.TextEdit{ Range: protocol.Range{ Start: protocol.Position{ Line: position.Line, @@ -220,10 +217,8 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind }, }, NewText: insertText, - } + }, } - - return item } func typeToString(t ast.Node) string { diff --git a/pkg/server/completion_test.go b/pkg/server/completion_test.go index fa85eb9..44d581e 100644 --- a/pkg/server/completion_test.go +++ b/pkg/server/completion_test.go @@ -162,6 +162,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FunctionCompletion, Detail: "self.greet(name)", InsertText: "greet(name)", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 16, + }, + End: protocol.Position{ + Line: 4, + Character: 16, + }, + }, + NewText: "greet(name)", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "function", }, @@ -190,6 +203,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FunctionCompletion, Detail: "self.greet(name)", InsertText: "greet(name)", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 17, + }, + End: protocol.Position{ + Line: 4, + Character: 17, + }, + }, + NewText: "greet(name)", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "function", }, @@ -208,6 +234,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "self.foo", InsertText: "foo", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 5, + Character: 12, + }, + End: protocol.Position{ + Line: 5, + Character: 12, + }, + }, + NewText: "foo", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -226,6 +265,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.VariableCompletion, Detail: "somevar", InsertText: "somevar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 5, + Character: 7, + }, + End: protocol.Position{ + Line: 5, + Character: 7, + }, + }, + NewText: "somevar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -244,6 +296,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.VariableCompletion, Detail: "somevar", InsertText: "somevar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 5, + Character: 11, + }, + End: protocol.Position{ + Line: 5, + Character: 11, + }, + }, + NewText: "somevar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -273,6 +338,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "otherfile.bar", InsertText: "bar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 15, + }, + End: protocol.Position{ + Line: 4, + Character: 15, + }, + }, + NewText: "bar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -282,6 +360,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "otherfile.foo", InsertText: "foo", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 15, + }, + End: protocol.Position{ + Line: 4, + Character: 15, + }, + }, + NewText: "foo", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -302,6 +393,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "otherfile.bar", InsertText: "bar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 16, + }, + End: protocol.Position{ + Line: 4, + Character: 16, + }, + }, + NewText: "bar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -322,6 +426,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "$.attribute", InsertText: "attribute", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 7, + Character: 12, + }, + End: protocol.Position{ + Line: 7, + Character: 12, + }, + }, + NewText: "attribute", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -331,6 +448,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "$.attribute2", InsertText: "attribute2", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 7, + Character: 12, + }, + End: protocol.Position{ + Line: 7, + Character: 12, + }, + }, + NewText: "attribute2", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -351,6 +481,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "$.attribute", InsertText: "attribute", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 7, + Character: 13, + }, + End: protocol.Position{ + Line: 7, + Character: 13, + }, + }, + NewText: "attribute", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -360,6 +503,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "$.attribute2", InsertText: "attribute2", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 7, + Character: 13, + }, + End: protocol.Position{ + Line: 7, + Character: 13, + }, + }, + NewText: "attribute2", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -380,6 +536,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "file.bar", InsertText: "bar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 12, + }, + End: protocol.Position{ + Line: 2, + Character: 12, + }, + }, + NewText: "bar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -389,6 +558,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "file.foo", InsertText: "foo", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 12, + }, + End: protocol.Position{ + Line: 2, + Character: 12, + }, + }, + NewText: "foo", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -409,6 +591,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "obj.bar", InsertText: "bar", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 8, + Character: 12, + }, + End: protocol.Position{ + Line: 8, + Character: 12, + }, + }, + NewText: "bar", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -418,6 +613,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "obj.foo", InsertText: "foo", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 8, + Character: 12, + }, + End: protocol.Position{ + Line: 8, + Character: 12, + }, + }, + NewText: "foo", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -438,6 +646,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello.hel", InsertText: "hel", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 14, + Character: 9, + }, + End: protocol.Position{ + Line: 14, + Character: 9, + }, + }, + NewText: "hel", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -447,6 +668,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello.hello", InsertText: "hello", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 14, + Character: 9, + }, + End: protocol.Position{ + Line: 14, + Character: 9, + }, + }, + NewText: "hello", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -468,6 +702,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello.hel.wel", InsertText: "wel", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 14, + Character: 10, + }, + End: protocol.Position{ + Line: 14, + Character: 10, + }, + }, + NewText: "wel", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -499,6 +746,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello.to", InsertText: "to", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 6, + }, + End: protocol.Position{ + Line: 2, + Character: 6, + }, + }, + NewText: "to", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -519,6 +779,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello.to.the", InsertText: "the", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 9, + }, + End: protocol.Position{ + Line: 2, + Character: 9, + }, + }, + NewText: "the", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -539,6 +812,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello2.the", InsertText: "the", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 7, + }, + End: protocol.Position{ + Line: 2, + Character: 7, + }, + }, + NewText: "the", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", }, @@ -559,6 +845,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "hello3.world", InsertText: "world", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 2, + Character: 7, + }, + End: protocol.Position{ + Line: 2, + Character: 7, + }, + }, + NewText: "world", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "string", }, @@ -579,6 +878,19 @@ func TestCompletion(t *testing.T) { Kind: protocol.FieldCompletion, Detail: "g.hello.to", InsertText: "to", + TextEdit: &protocol.TextEdit{ + Range: protocol.Range{ + Start: protocol.Position{ + Line: 3, + Character: 13, + }, + End: protocol.Position{ + Line: 3, + Character: 13, + }, + }, + NewText: "to", + }, LabelDetails: protocol.CompletionItemLabelDetails{ Description: "object", },