@@ -7,13 +7,14 @@ package regal.lsp.template
77render_for_builtin (builtin) := content if {
88 category := _category (builtin)
99 builtin_safe := _to_safe_builtin (builtin)
10+ args := concat (" , " , [arg.name | some arg in builtin_safe.decl.args])
1011
1112 content := replace (
1213 strings.render_template (_builtin_template, {
1314 " builtin" : builtin_safe,
1415 " category" : category,
1516 " link" : _docs_link (builtin_safe, category),
16- " snippet" : _example_snippet ( builtin_safe) ,
17+ " snippet" : $ " ```rego \n { builtin_safe.decl.result.name } := { builtin_safe.name } ( { args } ) \n ``` " ,
1718 }),
1819 " <bt>" , " `" ,
1920 )
@@ -22,7 +23,7 @@ render_for_builtin(builtin) := content if {
2223_docs_link (builtin, category) := link if {
2324 builtin.categories != []
2425
25- link := [substring (bc, 4 , - 1 ) |
26+ link := [trim_prefix (bc, " url= " ) |
2627 some bc in builtin.categories
2728 startswith (bc, " url=" )
2829 ][0 ]
@@ -56,15 +57,6 @@ _category(builtin) := builtin.categories[0] if {
5657 i != - 1
5758} else := builtin.name
5859
59- _example_snippet (builtin) := snippet if {
60- args := [arg.name | some arg in builtin.decl.args]
61- snippet := sprintf (" ```rego\n %s := %s(%s)\n ```" , [
62- builtin.decl.result.name,
63- builtin.name,
64- concat (" , " , args),
65- ])
66- }
67-
6860# here to work around the **extremely** annoying behavior of strings.render_template
6961# where missing keys are treated as fatal errors instead of giving template authors a
7062# chance to handle this: https://github.com/open-policy-agent/opa/issues/7931
@@ -83,11 +75,9 @@ _to_safe_builtin(builtin) := safe if {
8375 }
8476
8577 merged := object.union (safe_attributes, builtin)
86- safe := object.union (merged, {" decl" : {" args" : _safe_args ( merged.decl.args) }})
78+ safe := object.union (merged, {" decl" : {" args" : [ _to_safe_arg (i, arg) | some i, arg in merged.decl.args] }})
8779}
8880
89- _safe_args (args) := [_to_safe_arg (i, arg) | some i, arg in args]
90-
9181_to_safe_arg (i, arg) := arg if {
9282 _safe_arg (arg)
9383} else := object.union (
0 commit comments