feat: Add support for starlark. #509
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#509
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "amartani/mergiraf:martani/add-starlark"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add support for starlark (bazel's config language).
Welcome, and thanks for the PR! The
LangProfile
looks thought out, and it's nice that you have multiple tests. After a bit of tweaking ofsimple_merge
and an additional signature for list elements, I think this should be good to go!@ -0,0 +1,12 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
I think this conflict could've been resolved even with a default line-based merge algorithm, since the
load
s are only changed by the right side, and thedeps
only by the left side. To actually check that the commutativity works, one would need to try adding something from both sides. Seecdb57b0744/examples/rust/working/use_statements
for an exampleI added a new
load_statement
test case for that, thanks!@ -0,0 +5,4 @@
name = "lib",
srcs = ["src/lib.rs"],
deps = [
"@crates//:log",
One thing you'll probably want is to define a signature for the elements of a list, so that duplicates can be detected. Judging by the examples, it looks like they are all strings, which is a bit unfortunate but not that big of a problem I think. The list gets parsed as follows:
so I think the signature will need to be defined on
string
, and get its value fromstring_content
(I don't thinkstring_{start,end}
can be meaningfully different, maybe become single-quotes at most)Not every list in starlark can be deduplicated, and they may not even be commutative... I added commutative rules for some of the cases where they are in a new
commutative_lists
test case; see if that makes sense.Thanks for the review! PTAL
@ -0,0 +12,4 @@
name = "python_lib",
srcs = ["python_lib.py"],
)
rust_library(
Question: Ideally, this merge would preserve a blank newline between each of the calls. I tried to do that by changing the CommutativeParent separator to be
"\n\n"
, but that then causes a newline to be added betweenload()
calls above as well, and since they are allexpression_statement
in the starlark tree-sitter library, it's not so easy to differentiate between them. Any suggestions on it? I think this is not a big deal, but it does mean that users will likely need to run a formatter after the merge resolution.This sounds like something that could be fixed by #373. Alternatively, as you say, the grammar could be changed to expose different node types at this level, which would make it possible to define children groups with different default separators.
Good to go as far as I am concerned. Thanks for the PR! :)
@ -1102,0 +1129,4 @@
CommutativeParent::from_query(
r#"(call
function: (identifier) @func_name (#any-of? @func_name "exports_files" "glob")
arguments: (argument_list (list) @commutative))"#,
I love that you were able to use this new feature of defining commutative parents via tree-sitter queries! Congrats for that :)