YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.3k stars 201 forks source link

C# command registration uses argument as literal rather than resolved value #379

Closed TheMartianLife closed 7 months ago

TheMartianLife commented 9 months ago

What is the current behavior?

If a command is registered with a variable as the name, the variable name becomes the suggested value in command completions rather than the variable value. This would likewise affect any computed value, such as if the command name argument were set to a concatenated or interpolated string.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

var STRING_VARIABLE = “command_name”;
//…
[YarnCommand(STRING_VARIABLE)]

Upon typing <<command_ in Yarn, there will be no completion suggestion as instead it has registered “STRING_VARIABLE” as the command name.

Where I think the issue comes from:

/YarnSpinnerTool/YarnSpinner/YarnSpinner.LanguageServer/src/Server/Workspace/CSharpFileData.cs

desplesda commented 7 months ago

I think the way we fix this is to keep track of all const string variables encountered while doing the check, and then use that information to resolve these to string literals when building the list of Yarn action methods. Doing it this way means we don't need to invoke the entire compilation and can stay entirely within the domain of walking the syntax trees.

desplesda commented 7 months ago

At the moment we're not sure whether this will need to be limited to a per-file check, or if we will be able to do it across the entire project.

McJones commented 7 months ago

Fixed in https://github.com/YarnSpinnerTool/YarnSpinner-Unity/commit/8b11441217f52ddc2f9cceaa89e2846efe99af50