From c000fa6e024da7014910c3496990f3606e5523d1 Mon Sep 17 00:00:00 2001 From: Duologic Date: Mon, 11 Mar 2024 22:10:33 +0100 Subject: [PATCH] fix: remove copied code --- pkg/server/completion.go | 49 ++++------------------------------------ 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/pkg/server/completion.go b/pkg/server/completion.go index ed8f593..573ea98 100644 --- a/pkg/server/completion.go +++ b/pkg/server/completion.go @@ -174,8 +174,6 @@ func formatLabel(str string) string { } func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind, body ast.Node, position protocol.Position) protocol.CompletionItem { - mustNotQuoteLabel := IsValidIdentifier(label) - paramsString := "" if asFunc, ok := body.(*ast.Function); ok { kind = protocol.FunctionCompletion @@ -190,6 +188,9 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind concat := "" characterStartPosition := position.Character - 1 + if prefix == "" { + characterStartPosition = position.Character + } if prefix != "" && !strings.HasPrefix(insertText, "[") { concat = "." characterStartPosition = position.Character @@ -206,9 +207,7 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind InsertText: insertText, } - // Remove leading `.` character when quoting label - if !mustNotQuoteLabel { - log.Print(len(prefix)) + if strings.HasPrefix(insertText, "[") { item.TextEdit = &protocol.TextEdit{ Range: protocol.Range{ Start: protocol.Position{ @@ -227,46 +226,6 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind return item } -// Start - Copied from go-jsonnet/internal/parser/lexer.go - -func isUpper(r rune) bool { - return r >= 'A' && r <= 'Z' -} -func isLower(r rune) bool { - return r >= 'a' && r <= 'z' -} -func isNumber(r rune) bool { - return r >= '0' && r <= '9' -} -func isIdentifierFirst(r rune) bool { - return isUpper(r) || isLower(r) || r == '_' -} -func isIdentifier(r rune) bool { - return isIdentifierFirst(r) || isNumber(r) -} -func IsValidIdentifier(str string) bool { - if len(str) == 0 { - return false - } - for i, r := range str { - if i == 0 { - if !isIdentifierFirst(r) { - return false - } - } else { - if !isIdentifier(r) { - return false - } - } - } - // Ignore tokens for now, we should ask upstream to make the formatter a public package - // so we can use go-jsonnet/internal/formatter/pretty_field_names.go directly. - // return getTokenKindFromID(str) == tokenIdentifier - return true -} - -// End - Copied from go-jsonnet/internal/parser/lexer.go - func typeToString(t ast.Node) string { switch t.(type) { case *ast.Array: