microsoft / advanced-formula-environment

Create, edit, and reuse formulas in Excel
https://aka.ms/get-afe
MIT License
113 stars 11 forks source link

Comments in the Grid tab #49

Open dlealv opened 1 year ago

dlealv commented 1 year ago

What is the purpose of allowing comments in the Grid tab? They are allowed (in some cases), but Excel doesn't render them properly, and when you put a comment the function doesn't get invoked. For example:

image

It treats the function invocation as a text. I would suggest to use comments both block and inline comments, in a similar way a compiler will treat them in any other language, something that doesn't produce any output. It can serve the following purposes:

  1. Comment something in the grid, for clarification purposes
  2. Debug your code, you can add comments to remove a specific portion of your code during the invocation

For example:

image

We have a function, but we would like to know the intermediate calculation of a specific variable. In this case, it produces an error.

We want to test or debug different possible calculations, in a single cell:

image

The above code doesn't produce any error, but it doesn't generate any output

Thanks in advance,

David

jack-williams commented 1 year ago

In the examples where 'comments' are allowed, these are not really code comments. Any content that does not immediately start with = is treated as text rather than a formula.

In that regard we are consistent: comments are now allowed in formulas in the grid page. The 'bug' here is that we syntax highlight "text" cells that look like formulas, misleading the user.

dlealv commented 1 year ago

@jack-williams Thanks for your response, back to my first question, what is the purpose, based on the comment's current functionality? What is the use case AFE is trying to respond to and what it is used for?

Why comments in Grid would have a different interpretation than in other tabs? Allowing comments is really a nice feature, but now in Grid it is not a comment anymore instead it is just a text.

I don't see the point of allowing comments in the Grid tab, since they are not treated as comments. I am confused with the current functionality of comments treated as text.

Per my understanding from your response, comment syntax in the Grid tab has no special meaning since they don't start with the equal sign (which is the single rule to follow), then are treated as text. From my previous comment, I would suggest leveraging comment functionality for the Grid tab to, it is consistent and also there are some use cases as I showed where it is useful. In case you want to consider it as a possible improvement.

Thanks,

David

jack-williams commented 1 year ago

Why comments in Grid would have a different interpretation than in other tabs?

Comments are not supported in the Excel formula language; to support comments in AFE we have to perform some tricks. For modules this is easy as we store the original text in the file parts and assume the module content is the truth. For cells this would not work for various reasons, including cells moving due to row insertion. We would need to align the comments with the new cell position.

I'd like to support comments in Grid, it is just more work.

I am confused with the current functionality of comments treated as text.

The entire cell content is treated as text because it is not a formula. The code editing component we use is not aware of this and uses its default syntax highlighting that triggers based on regular expressions.

The technical answer to why this is hard to support, is that we would need to change the monaco language mode based on the content in the editor, which is not a typical thing to do (but is possible).

dlealv commented 1 year ago

I understand @jack-williams just that it is nice to have, but you need to weigh the effort versus the benefit. Before sending the output to Excel, the comments would need to be removed like in any other compiler.