-
Notifications
You must be signed in to change notification settings - Fork 37
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
More stringent ast.ref_to_string #1106
Conversation
While I started looking into #1104 I encountered some cases where `ast.ref_to_string`, and it's `static` counterpart would return wrong representations. We already had a bit of a homegrown format, which was convenient for some things, but would also leak out in places where it shouldn't be. Now use the same format as OPA for representing refs as strings. Also added the query in error messages where we fail to prepare or eval in a couple of places, as the lack of those made debugging this issue much harder than it had to be. Signed-off-by: Anders Eknert <anders@styra.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -575,7 +575,7 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) { // nolint:mai | |||
|
|||
responseParams := map[string]any{ | |||
"type": "opa-debug", | |||
"name": "Debug " + path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
rs := ref_to_string(ref) | ||
ss := substring(rs, 0, indexof(rs, ".$")) | ||
str := _trim_from_var(rs, regex.find_n(`\[[^"]`, rs, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the ref is foo.bar[7]
? Or this isn't expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for our purposes now, I think we'll want to eval only up to the first non-stringy path. But we can change that later.
While I started looking into StyraInc#1104 I encountered some cases where `ast.ref_to_string`, and it's `static` counterpart would return wrong representations. We already had a bit of a homegrown format, which was convenient for some things, but would also leak out in places where it shouldn't be. Now use the same format as OPA for representing refs as strings. Also added the query in error messages where we fail to prepare or eval in a couple of places, as the lack of those made debugging this issue much harder than it had to be. Signed-off-by: Anders Eknert <anders@styra.com>
While I started looking into #1104 I encountered some cases where
ast.ref_to_string
, and it'sstatic
counterpart would return wrong representations. We already had a bit of a homegrown format, which was convenient for some things, but would also leak out in places where it shouldn't be. Now use the same format as OPA for representing refs as strings.Also added the query in error messages where we fail to prepare or eval in a couple of places, as the lack of those made debugging this issue much harder than it had to be.