Skip to content

Disallow side-by-side arguments in calls #153

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

Merged
merged 6 commits into from
Nov 19, 2024

Conversation

DavisVaughan
Copy link
Member

@DavisVaughan DavisVaughan commented Nov 19, 2024

Closes #140

Inspired by "array hole" support in tree-sitter-javascript, i.e. [1, , , 2]
https://github.com/tree-sitter/tree-sitter-javascript/blob/108b2d4d17a04356a340aea809e4dd5b801eb40d/grammar.js#L570-L577

The usage of delimSep1(optional(field("argument", $.argument)), $.comma) fully expands into what you see below. If you squint at it long enough you will see that it passes all of the required allowed vs not allowed examples there.

// # Allowed
// fn()
// fn(,)
// fn(,,)
// fn(a)
// fn(a, b)
// fn(,,a,,b,,)
// fn(a, # comment_between_commas
// ,)
//
// # Not allowed
// fn(a b)

seq(
  open,
  seq(
    optional(field("argument", $.argument)),
    repeat(
      seq(
        $.comma,
        optional(field("argument", $.argument))
      )
    )
  ),
  close
)

Not entirely sure why, but it does involve function calls so presumably the change here can affect ERROR paths, but it looks fine still (importantly, there is still a sub-ERROR we can narrow down to for diagnostics)
Makes it easier to copy and paste from `tree-sitter test --update` into the corpus test files
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@c094bd5). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #153   +/-   ##
=======================================
  Coverage        ?   82.40%           
=======================================
  Files           ?        7           
  Lines           ?      955           
  Branches        ?        0           
=======================================
  Hits            ?      787           
  Misses          ?      168           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Collaborator

@kevinushey kevinushey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Some things worth verifying:

Do we still get the correct behavior when highlighting the current argument in the signature tooltip? Does this affect what label is highlighted in the presence of missing commas?

Screenshot 2024-11-19 at 12 33 50 PM

Similarly, will this affect how we read / infer the "nth" argument in a function call for diagnostics and other code analysis in ark?

@DavisVaughan
Copy link
Member Author

@kevinushey good questions. IIUC this particular change has 0 effect on the ASTs we were generating on valid R code. i.e. the tree generated from fn(, , ,) before and after this commit is the same, because that is valid R code.

The change is that we now just catch fn(a + b c) as invalid R code in the tree-sitter parser.

Here is current arg signature behavior still working with this commit over in Positron:

Screenshot 2024-11-19 at 3 51 08 PM

@DavisVaughan DavisVaughan merged commit 9a63f59 into r-lib:main Nov 19, 2024
11 checks passed
@DavisVaughan DavisVaughan deleted the feature/side-by-side-args branch November 19, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow argument followed by another argument
2 participants