vscode-openscad
vscode-openscad copied to clipboard
[Enhancement] Inline variable value hints
This is a dedicated thread to discuss the enhancement proposed by @Dorro101 in #32.
Proposal
It would be convenient to have a toggleable feature that displays the evaluated value of variables inline. For example,
// Variables and arrays
width = 32; // width = 32
height = 8; // height = 8
clearance = 0.2; // clearance = 0.2
size = [width, height + clearance]; // size = [32, 8.2]
name = "foo"; // name = "foo"
Note that what are displayed as "comments" are visual only and do not reflect the actual content of the file.
There are two parts to this:
- The overlays themselves should be relatively straight forward to implement. The VSCode Decorator API can be used for this. See: vscode.rocks/decorations and microsoft/vscode-extension-samples@main/decorator-sample/USAGE.md
- Evaluating the actual variables. This is the hard part because it requires a parser/interpreter. It is possible this will be easier with the implementation of a language server in https://github.com/Antyos/vscode-openscad/pull/31, but I am not too familiar with all of that.
Other questions that still need to be answers:
- How should
for
loops be treated?for (i = [0:5]) { // i = [0, 1, 2, 3, 4] // Stuff }
- Or
let()
statements? - Nesting is probably going to be an issue.
for (i = [0:10]) { for (j = [0:i]) { for (k = [i:j]) { // Stuff } } }
- What about named parameters in function calls?
cylinder(h = height, r1 = 10, r2 = r+10, center = true); // h = 10, r1 = 10, r2 = 20, center = true
- How should long arrays or lots of parameters be handled?
Plans
As of right now, I have no immediate plans to implement this feature. However, I think it would be a cool feature to have in the extension. If anyone wants to take a go at this and submit a PR, please be my guest.
And an important question, does the nesting issue make this completely infeasible?