-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(completion): quote labels when necessary #136
Conversation
68e3e1c
to
779ab8d
Compare
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a copy from upstream code as the formatter that has this logic is in an internal/
package. We should probably ask to make the formatter a public package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring the tokens because that would be too much to copy and maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
When labels contain non-alpha characters or start with a number, they need to be quoted. This PR implements that for autocompletion.