@@ -174,8 +174,6 @@ func formatLabel(str string) string {
174
174
}
175
175
176
176
func createCompletionItem (label , prefix string , kind protocol.CompletionItemKind , body ast.Node , position protocol.Position ) protocol.CompletionItem {
177
- mustNotQuoteLabel := IsValidIdentifier (label )
178
-
179
177
paramsString := ""
180
178
if asFunc , ok := body .(* ast.Function ); ok {
181
179
kind = protocol .FunctionCompletion
@@ -190,6 +188,9 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
190
188
191
189
concat := ""
192
190
characterStartPosition := position .Character - 1
191
+ if prefix == "" {
192
+ characterStartPosition = position .Character
193
+ }
193
194
if prefix != "" && ! strings .HasPrefix (insertText , "[" ) {
194
195
concat = "."
195
196
characterStartPosition = position .Character
@@ -206,9 +207,7 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
206
207
InsertText : insertText ,
207
208
}
208
209
209
- // Remove leading `.` character when quoting label
210
- if ! mustNotQuoteLabel {
211
- log .Print (len (prefix ))
210
+ if strings .HasPrefix (insertText , "[" ) {
212
211
item .TextEdit = & protocol.TextEdit {
213
212
Range : protocol.Range {
214
213
Start : protocol.Position {
@@ -227,46 +226,6 @@ func createCompletionItem(label, prefix string, kind protocol.CompletionItemKind
227
226
return item
228
227
}
229
228
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
-
270
229
func typeToString (t ast.Node ) string {
271
230
switch t .(type ) {
272
231
case * ast.Array :
0 commit comments