Skip to content

Commit 93cd2e2

Browse files
committed
fix: remove copied code
1 parent eeb1fdb commit 93cd2e2

File tree

1 file changed

+4
-45
lines changed

1 file changed

+4
-45
lines changed

pkg/server/completion.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ func formatLabel(str string) string {
174174
}
175175

176176
func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind, body ast.Node, position protocol.Position) protocol.CompletionItem {
177-
mustNotQuoteLabel := IsValidIdentifier(label)
178-
179177
paramsString := ""
180178
if asFunc, ok := body.(*ast.Function); ok {
181179
kind = protocol.FunctionCompletion
@@ -190,6 +188,9 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
190188

191189
concat := ""
192190
characterStartPosition := position.Character - 1
191+
if prefix == "" {
192+
characterStartPosition = position.Character
193+
}
193194
if prefix != "" && !strings.HasPrefix(insertText, "[") {
194195
concat = "."
195196
characterStartPosition = position.Character
@@ -206,9 +207,7 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
206207
InsertText: insertText,
207208
}
208209

209-
// Remove leading `.` character when quoting label
210-
if !mustNotQuoteLabel {
211-
log.Print(len(prefix))
210+
if strings.HasPrefix(insertText, "[") {
212211
item.TextEdit = &protocol.TextEdit{
213212
Range: protocol.Range{
214213
Start: protocol.Position{
@@ -227,46 +226,6 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
227226
return item
228227
}
229228

230-
// Start - Copied from go-jsonnet/internal/parser/lexer.go
231-
232-
func isUpper(r rune) bool {
233-
return r >= 'A' && r <= 'Z'
234-
}
235-
func isLower(r rune) bool {
236-
return r >= 'a' && r <= 'z'
237-
}
238-
func isNumber(r rune) bool {
239-
return r >= '0' && r <= '9'
240-
}
241-
func isIdentifierFirst(r rune) bool {
242-
return isUpper(r) || isLower(r) || r == '_'
243-
}
244-
func isIdentifier(r rune) bool {
245-
return isIdentifierFirst(r) || isNumber(r)
246-
}
247-
func IsValidIdentifier(str string) bool {
248-
if len(str) == 0 {
249-
return false
250-
}
251-
for i, r := range str {
252-
if i == 0 {
253-
if !isIdentifierFirst(r) {
254-
return false
255-
}
256-
} else {
257-
if !isIdentifier(r) {
258-
return false
259-
}
260-
}
261-
}
262-
// Ignore tokens for now, we should ask upstream to make the formatter a public package
263-
// so we can use go-jsonnet/internal/formatter/pretty_field_names.go directly.
264-
// return getTokenKindFromID(str) == tokenIdentifier
265-
return true
266-
}
267-
268-
// End - Copied from go-jsonnet/internal/parser/lexer.go
269-
270229
func typeToString(t ast.Node) string {
271230
switch t.(type) {
272231
case *ast.Array:

0 commit comments

Comments
 (0)