Skip to content
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

Source Mapper Improvements: Better Options for Annotated Teal #657

Open
tzaffi opened this issue Feb 1, 2023 · 2 comments
Open

Source Mapper Improvements: Better Options for Annotated Teal #657

tzaffi opened this issue Feb 1, 2023 · 2 comments
Labels
new-feature-request Feature request that needs triage Team Scytale

Comments

@tzaffi
Copy link
Contributor

tzaffi commented Feb 1, 2023

Problem in Upcoming Source Map Feature

When source mapping is enabled and annotated teal generated, there is no mechanism to limit the width of produced lines.

For example, @bbroder-algo generated a source map for code residing in this repo (this is the "Rock Paper Scissors" example from a recent bootcamp), and then ran it through YAPF to wrap very long files, he obtained this snippet:
image

We can see that Compilation(approval_program(),... ...=True) got wrapped because it was too long.

If possible, we'd like to have handling long lines built in to the source mapper, so users don't need to each solve this problem for themselves.

Possible Solutions

  1. Use the YAPF library linked above directly, and just wrap past a certain column width
  2. The source mapper uses the tabulate package and it has a multi-line mode. We could leverage it as well to wrap columns that are too wide
  3. We could simply truncate columns that are too wide
  4. Should we try to use the black library with a very tight column width?
  5. something else?

Dependencies

#650

Urgency

Estimating: Medium. This should be reevaluated based on reception by end users.

@tzaffi tzaffi added Team Scytale new-feature-request Feature request that needs triage labels Feb 1, 2023
@tzaffi tzaffi changed the title Source Mapping: Better options for **Annotated Teal** Source Mapping: Better options for _Annotated Teal_ Feb 1, 2023
@tzaffi tzaffi changed the title Source Mapping: Better options for _Annotated Teal_ Source Mapping: Better options for Annotated Teal Feb 1, 2023
@bbroder-algo
Copy link
Contributor

yes I hacked this with

diff --git a/pyteal/compiler/sourcemap.py b/pyteal/compiler/sourcemap.py
index 4282006..3b31426 100644
--- a/pyteal/compiler/sourcemap.py
+++ b/pyteal/compiler/sourcemap.py
@@ -1,3 +1,4 @@
+import yapf.yapflib.yapf_api as yapf_api
 import ast
 import bisect
 from collections import defaultdict
@@ -514,7 +515,7 @@ class TealMapItem(PyTealFrame):
             _TEAL_LINE_NUMBER: self.teal_lineno,
             _TEAL_LINE: self.teal_line,
             _PROGRAM_COUNTERS: self.pcs_repr(),
-            _PYTEAL_HYBRID_UNPARSED: self.hybrid_unparsed(),
+            _PYTEAL_HYBRID_UNPARSED: yapf_api.FormatCode (self.hybrid_unparsed())[0].replace ('\n','\n//'),
             _PYTEAL_NODE_AST_UNPARSED: self.node_source(),
             _PYTEAL_NODE_AST_QUALNAME: self.code_qualname(),

@bbroder-algo
Copy link
Contributor

my favorite is now
_PYTEAL_HYBRID_UNPARSED: "| " + yapf_api.FormatCode (self.hybrid_unparsed(), style_config="{COLUMN_LIMIT:80}")[0].strip().replace ('\n','\n//'),

@tzaffi tzaffi changed the title Source Mapping: Better options for Annotated Teal Source Mapper Improvements: Better options for Annotated Teal Feb 23, 2023
@tzaffi tzaffi changed the title Source Mapper Improvements: Better options for Annotated Teal Source Mapper Improvements: Better Options for Annotated Teal Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature-request Feature request that needs triage Team Scytale
Projects
None yet
Development

No branches or pull requests

2 participants