Optimize Semantic Token Language Server Request#1865
Conversation
138b0bc to
72fe28c
Compare
anderseknert
left a comment
There was a problem hiding this comment.
Looks great! Some minor things to fix, then good to merge 👍
| # description: Extract function argument declarations | ||
| arg_tokens.declaration contains var if { | ||
| some rule in module.rules | ||
| some var in rule.head.args |
There was a problem hiding this comment.
It's an advanced topic sure, but args aren't necessarily vars! If they aren't they'll be pattern matched for equality in a call. So for example this definition:
f("foo", y) if {
y > 100
}Would be the same as:
f(x, y) if {
x == "foo"
y > 100
}Here's one example of where we use this in Regal to describe an "or switch" pretty much.
So while it's not too common, you'll want to ensure the type is var here:
arg_tokens.declaration contains arg if {
some rule in module.rules
some arg in rule.head.args
arg.type == "var"
}There was a problem hiding this comment.
Ah gotcha, addressed! Went ahead and changed the arg_token naming to var_token as well to be more exact. On second thought, we're still checking for function args only here, just checking that they're used as variables. So I'll leave it as is
| ] | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
It's just complaining about not having a last newline in the file.
| some var in call.args | ||
| # description: Extract variable references in function calls | ||
| arg_tokens.reference contains var if { | ||
| some rule in module.rules |
There was a problem hiding this comment.
Add count(rule.head.args) > 0 below or else you'll be running this on all rules (not just functions)
There was a problem hiding this comment.
Ah good idea, added.
| var.type == "var" | ||
|
|
||
| arg_names := {v.value | some v in ast.found.vars[rule_index].args} | ||
| arg_names := {v.value | some v in rule.head.args} |
There was a problem hiding this comment.
You'll want to do the same check for type == "var" here.
Also, this will be the same for all vars in the rule, so this should be moved up above the walk
There was a problem hiding this comment.
Addressed the location of the function arg name check. I did already have a type check for the arg I was pulling from the array of terms, so just want to verify that's what you meant.
| var.type == "var" | ||
|
|
||
| arg_names := {v.value | some v in ast.found.vars[rule_index].args} | ||
| arg_names := {v.value | some v in rule.head.args} |
There was a problem hiding this comment.
Same as above applies here.
860a23a to
96ce194
Compare
… query from bundle Signed-off-by: Sean Ledford <s_ledford@apple.com>
Signed-off-by: Sean Ledford <s_ledford@apple.com>
96ce194 to
1de6fa1
Compare
These changes are meant to optimize the request for semantic tokens between the client and the language server. Instead of preparing the module required to parse the textDocument prior to every request, the module is now loaded from the regal bundle.