Skip to content

Commit

Permalink
fix: remove copied code
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Mar 14, 2024
1 parent be8e887 commit c000fa6
Showing 1 changed file with 4 additions and 45 deletions.
49 changes: 4 additions & 45 deletions pkg/server/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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:
Expand Down

0 comments on commit c000fa6

Please sign in to comment.