Open Nhyland28 opened 1 year ago
I actually think I figured out a way to make description
the first key value pair in the dimension block and it's pretty simple! You can just switch the order of the concatenation that creates new_block
.
Old version:
new_block = old_block + (new_node,)
Fixed (so description is first):
new_block = (new_node,) + old_block
Still trying to figure out a way to dynamically map the suffix for that node.
Hey @Nhyland28! Thanks for the detailed writeup. Not many people have used advanced parsing mode (to my knowledge) so totally possible you're encountering some rough edges of the library. I'm open to suggestions for improving it.
You figured out the correct way to make the description node the first item in the list by changing the order. That looks correct.
The way lkml assigns whitespace to each SyntaxToken
probably could be improved, sometimes it feels a bit arbitrary. In this case, the whitespace you're looking for is actually in old_block.left_brace.suffix
(the suffix of the {
token rather than the prefix of the first PairNode
). Does that give you what you need to fix the code?
Out of curiosity, how are you adding descriptions dynamically? Are you using ChatGPT or something to populate them?
Hi!
First off thanks for all the work that went into this library, it has exactly what I was looking for!
I'm creating a class which adds descriptions to dimensions when they do not exist. I'm using the advanced parsing method as I want to make sure all comments and formatting are kept. Here is the current iteration of my class (and the initial creation of the DocumentNode):
For the new
description
PairNode
I'm trying to dynamically assign thetype
'sSyntaxToken
'sprefix
value so that it aligns with the other objects. My idea was that it could just copy theprefix
value from the firstPairNode
in the sameBlockNode
. When I try to grab that value it returns an empty string (see theprint(len(old_prefix))
. My expectation is that it should return a string with 2 whitespaces`. I could hardcode it (like I have it in the above class definition) but I would rather use that
old_prefix` value in case other LookML files are formatted differently.Additionally, I would love to have the
description
become the first parameter in the dimension. Currently the above class places it last. I was thinking this is where I could useSyntaxToken
'sline_number
value; however, I haven't been able to get it to work. My fear is that this would actually be a pretty complex change because I would potentially have to change theline_number
for everySyntaxToken
in theBlockNode
(e.g. move them down one). Any thoughts or ideas on how I could make the description the first element?Current:
Goal: