-
Notifications
You must be signed in to change notification settings - Fork 919
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
Variable autocompletion in expressions #2692
Conversation
995aef5
to
204a97c
Compare
Indeed, for undefined variables which require a more complex analysis (compared to "just" calling enumerateVariables), we might think about a cache/memoization of the results, with the challenge being (like all caches) to:
I think we could have this "cache" created at the initialization of a GenericExpressionField, and passed down to the autocompletions so that autocompletions of variables can be stored there. This way we would compute variables "only" once per scene/project/object per field. But all of this is if we want to support "undefined variables". Maybe we don't want to even do this in expressions? When you write an expression, it might be acceptable to handle in autocompletions only the properly declared variables. It would encourage to declare them. And you always have the variables editor that will help you find undefined variables - and at this moment we can afford the "CPU power" to do it (because we only do it once per dialog, which is fair). So for now I would say not to worry about this, and create another issue to tackle this later? :) |
204a97c
to
52d3f10
Compare
const filteredVariablesList = filterStringList(definedVariableNames, prefix); | ||
|
||
return filteredVariablesList.map(variableName => ({ | ||
kind: 'Text', |
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.
nitpicking: a variable name is technically not a "Text" (which means, in this context, a "string literal", i.e: a sequence of characters enclosed in double quotation marks), but an "Identifier" (which means, in this context, a sequence of characters, excepted for special separator characters (like spaces, comma, dots...) and that does not start with a number).
So the autocompletion here if really providing you with an "Identifier", so we should set the kind to it (not that it will change anything, but something in the future might rely on this information).
Also add it to the export type ExpressionAutocompletion
type (like Text) and this should be good to 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.
Looks great! 🚀 Added a nitpicking comment, then we're good!
|
Yep, this is also a bit similar to the fact that the autocompletion in the variables editor was restricted to "root variables". Support for structure/arrays could be added for expressions and for variable dialogs, so that:
This improvement could be done to the VariableField, the expressions and the Variable editor dialogs (i.e: everything that relies on |
This is committed over: #2702
I didn't find an easy way to use undefined variables without having them calculated at every input so I revert it. I'll create an issue for it.