OpenC3 / cosmos

OpenC3 COSMOS
https://openc3.com
Other
108 stars 30 forks source link

When commenting out a line with '#', also comment following ERB code '<%#=...%>' #776

Closed jurgensymynck closed 1 year ago

jurgensymynck commented 1 year ago

Is your feature request related to a problem? Please describe.

Commenting out command , telemetry or screen definitions by just placing a # symbol in front of a line containing Ruby ERB <% ... %>has caused me some headaches , trying to decipher unrelated error messages like "Warning TLM_XXX redefined and "Error: packet_id undefined" this example doesn't work:

TELEMETRY <%= tisco_target_name %> TLM_PING LITTLE_ENDIAN
  <%= render "_tlm_common_header.txt", locals: {packet_id: 0x81} %>

# As of now, it's too soon to experiment with BLOCK data type...
# TELEMETRY <%= tisco_target_name %> TLM_ECHO_BLOCK LITTLE_ENDIAN
#   <%= render "_tlm_common_header.txt", locals: {packet_id: 0x9E} %>
#   APPEND_ITEM DATA_0 8 BLOCK "Data 0"

TELEMETRY <%= tisco_target_name %> TLM_ECHO_UINT32 LITTLE_ENDIAN
  <%= render "_tlm_common_header.txt", locals: {packet_id: 0x8E} %>
  APPEND_ITEM DATA_0 8 UINT "Data_0"
    FORMAT_STRING "0x%0X"

... but this works:

TELEMETRY <%= tisco_target_name %> TLM_PING LITTLE_ENDIAN
  <%= render "_tlm_common_header.txt", locals: {packet_id: 0x81} %>

# As of now, it's too soon to experiment with BLOCK data type...
# TELEMETRY <%#= tisco_target_name %> TLM_ECHO_BLOCK LITTLE_ENDIAN
#   <%#= render "_tlm_common_header.txt", locals: {packet_id: 0x9E} %>
#   APPEND_ITEM DATA_0 8 BLOCK "Data 0"

TELEMETRY <%= tisco_target_name %> TLM_ECHO_UINT32 LITTLE_ENDIAN
  <%= render "_tlm_common_header.txt", locals: {packet_id: 0x8E} %>
  APPEND_ITEM DATA_0 8 UINT "Data_0"
    FORMAT_STRING "0x%0X"

Describe the solution you'd like

gr. Jurgen

timothyscherer commented 1 year ago

I have run into this issue before. The ERB ignores comments, and at the time there was no interest in changing the behavior. See #60 for reference. I believe this behavior is unintuitive and should be addressed, since it won't affect backwards compatibility, and will save many headaches as you mentioned.

jmthomas commented 1 year ago

Unfortunately this is just how ERB works when it processes a file. As @jurgensymynck figured out, you can comment out ERB statements with <%# but that's both unintuitive and annoying when your editor simply comments out the entire line. I think the only way for us to handle this in COSMOS would be to pre-process the file and strip out any comment lines before running ERB. I'll look into that as a possible solution.

jurgensymynck commented 1 year ago

Hi guys,

I would argue against this workaround, because we need the comments not only in our own editor but also when reading/sharing our files in the COSMOS integrated editor...

If my original proposition of amending the <%= in a commented line is not possible to implement, than I would already be very happy with some kind of warning message during parsing like Line XXX: Warning: active ERB code in commented line and have a paragraph on the documentation website what this means and what the side effects could be when ignoring this warning.

Greetings, Jurgen